Interface Agent

All Known Implementing Classes:
CompositeAgent, DynamicCompositeAgent

public interface Agent
An Agent is scheduled to do work on a thread on a duty cycle. Each Agent should have a defined role in a system.

onStart(), doWork(), and onClose() will all be called by the same thread and in a threadsafe manner if the agent runs successfully. onClose() will be called if the agent fails to run.

  • Method Summary

    Modifier and Type
    Method
    Description
    int
    An agent should implement this method to do its work.
    default void
    To be overridden by Agents that need to do resource cleanup on close.
    default void
    To be overridden by Agents that need to do resource init on start.
    Get the name of this agent's role.
  • Method Details

    • onStart

      default void onStart()
      To be overridden by Agents that need to do resource init on start.

      This method will be called by the agent thread once on start.

    • doWork

      int doWork() throws Exception
      An agent should implement this method to do its work.

      The return value is used for implementing a backoff strategy that can be employed when no work is currently available for the agent to process.

      If the Agent wished to terminate and close then a AgentTerminationException can be thrown.

      Returns:
      0 to indicate no work was currently available, a positive value otherwise.
      Throws:
      Exception - if an error has occurred
    • onClose

      default void onClose()
      To be overridden by Agents that need to do resource cleanup on close.

      This method will be called after the agent thread has terminated or if the agent is closed before it runs.

    • roleName

      String roleName()
      Get the name of this agent's role.
      Returns:
      the name of this agent's role.