Class AgentPresenceManager

java.lang.Object
org.lsst.ccs.messaging.AgentPresenceManager
All Implemented Interfaces:
ClusterMembershipListener, MessageListener, StatusMessageListener

public class AgentPresenceManager extends Object implements StatusMessageListener, ClusterMembershipListener
Tracks agent connection and disconnection on the buses.
Author:
emarin
  • Constructor Details

  • Method Details

    • onStatusMessage

      public void onStatusMessage(StatusMessage s)
      Description copied from interface: StatusMessageListener
      Called when a status message is received. The implementation should be thread-safe: the framework makes no guarantees on what thread this method will be called on, and it can be called concurrently for several messages. The implementation should also return immediately : any blocking operations should be scheduled on a separate thread.
      Specified by:
      onStatusMessage in interface StatusMessageListener
      Parameters:
      s - Status bus message to be processed.
    • listConnectedAgents

      public List<AgentInfo> listConnectedAgents()
      Returns:
      The list with the currently connected Agents
    • waitForFirstContact

      public final void waitForFirstContact(long timeout, TimeUnit unit)
    • membersLeft

      public void membersLeft(List<String> left)
      Specified by:
      membersLeft in interface ClusterMembershipListener
    • membersJoined

      public void membersJoined(List<String> joined, boolean isMerge)
      Specified by:
      membersJoined in interface ClusterMembershipListener
    • processConnectionDisconnectionEvent

      public void processConnectionDisconnectionEvent(AgentPresenceManager.AgentPresenceState state, AgentInfo... agentInfos)
    • addAgentPresenceListener

      public void addAgentPresenceListener(AgentPresenceListener l)
    • removeAgentPresenceListener

      public void removeAgentPresenceListener(AgentPresenceListener l)
    • agentExists

      public boolean agentExists(String agentName)
      This method returns true as soon as the AgentPresenceManager is aware of the existence of the given agent by name. At this point we don't guarantee that the corresponding agent is ready to receive command requests as it might still be INITIALIZING. To be sure that an agent is fully connected, OPERATIONAL and ready to receive message use method #isAgentConnected(String) instead.
      Parameters:
      agentName - The name of the agent
      Returns:
      true if the AgentPresenceManager is aware of the existence of this agent.
    • isAgentConnected

      public boolean isAgentConnected(String agentName)
      This method returns true when the given agent is fully connected, OPERATIONAL and ready to receive commands.
      Parameters:
      agentName - The name of the Agent.
      Returns:
      true when the given agent is fully connected.
    • isAgentConnected

      public boolean isAgentConnected(AgentPropertyPredicate agentPredicate)
      This method returns true when the given agent is fully connected, OPERATIONAL and ready to receive commands.
      Parameters:
      agentPredicate - The predicate to select the Agent.
      Returns:
      true when the given agent is fully connected.
    • waitForAgent

      @Deprecated public final boolean waitForAgent(String name, long timeout, TimeUnit unit) throws InterruptedException
      Deprecated.
      use method waitForConnectedAgent
      Wait for an Agent to be fully connected: all the listeners have been notified on the connected method.
      Parameters:
      name - The name of the Agent
      timeout - The time to wait for the agent to become available.
      unit - The TimeUnit for the timeout.
      Returns:
      True if the Agent is fully connected within the provided timeout, false otherwise.
      Throws:
      InterruptedException
    • waitForConnectedAgent

      public final void waitForConnectedAgent(String name, long timeout, TimeUnit unit) throws InterruptedException, TimeoutException
      Throws:
      InterruptedException
      TimeoutException
    • waitForAgent

      @Deprecated public final boolean waitForAgent(AgentPropertyPredicate predicate, long timeout, TimeUnit unit) throws InterruptedException
      Deprecated.
      use method waitForAgentPredicate
      Wait for an AgentPredicate to be met.
      Parameters:
      predicate - The predicate to be met
      timeout - The time to wait for the agent to become available.
      unit - The TimeUnit for the timeout.
      Returns:
      True if the Agent is fully connected within the provided timeout, false otherwise.
      Throws:
      InterruptedException
    • waitForAgentPredicate

      public final void waitForAgentPredicate(AgentPropertyPredicate predicate, long timeout, TimeUnit unit) throws InterruptedException, TimeoutException
      Throws:
      InterruptedException
      TimeoutException
    • waitForAgentDisconnection

      @Deprecated public final boolean waitForAgentDisconnection(String name, long timeout, TimeUnit unit) throws InterruptedException
      Deprecated.
      Use method waitForDisconnectedAgent
      Wait for an Agent to be fully disconnected: all the listeners have been notified on the disconnected method.
      Parameters:
      name - The name of the Agent
      timeout - The time to wait for the agent to become available.
      unit - The TimeUnit for the timeout.
      Returns:
      True if the Agent is disconnected from the buses within the provided timeout, false otherwise.
      Throws:
      InterruptedException
    • waitForDisconnectedAgent

      public final void waitForDisconnectedAgent(String name, long timeout, TimeUnit unit) throws InterruptedException, TimeoutException
      Throws:
      InterruptedException
      TimeoutException