org.jlab.coda.afecs.agent
Class AAgent

java.lang.Object
  extended by org.jlab.coda.afecs.system.ABase
      extended by org.jlab.coda.afecs.archive.AAgent
Direct Known Subclasses:
ARepresenter, ASupervisor

public abstract class AAgent
extends ABase

JSA: Thomas Jefferson National Accelerator Facility
This software was developed under a United States Government license,
described in the NOTICE file included as part of this distribution.
Copyright (c), Aug 18, 2009

This is the base class for all real world component rerpesenting agents, as well as Afecs platform native (java) agents including control supervisor agents. Does configure (based on cool configuration details), creates instance/s of the physical component plugins (IAClientCommunication), start processes, etc. Subscribes AConstants.AgentInfoRequest and messages. Subscribes AConstants.AgentControlRequest messages. Includes agent data object AComponent details of wich is described in the cool configuration file.

Version:
1.4
Author:
Vardan Gyurjyan

Nested Class Summary
 class AAgent.AsyncProcessThread
          Inner class that runs an async process in the separate thread.
 class AAgent.MonProcessThread
          Inner class for running agent described periodic processes
 class AAgent.ReportDalogThread
          Inner class for reporting to entire pub/sub space dalog messages.
 class AAgent.ReportLoadThread
          Inner class for reporting to the Container admin the load, i.e.
 class AAgent.ReportStatusThread
          Inner class for reporting to the superviosr agent/agents the state of this agent.
 class AAgent.ShellExecutionThread
          Inner class extends Thread and runs the shell scripts
 
Field Summary
 java.util.concurrent.atomic.AtomicBoolean AbortRequest
           
 java.util.concurrent.atomic.AtomicBoolean activeMoveToState
           
 int cMsgRequests
           
 AComponent me
           
 double myLoad
           
 java.util.concurrent.ConcurrentHashMap<java.lang.String,AAgent.MonProcessThread> myMonProcesses
           
 IAClientCommunication myPlugin
           
 java.lang.String myStartTime
           
 java.util.concurrent.atomic.AtomicBoolean ResetRequest
           
 
Fields inherited from class org.jlab.coda.afecs.system.ABase
myConfig, myCRCClientConnection, myName, myPlatformConnection, myRcDomainConnection
 
Constructor Summary
AAgent()
          Basic constructor.
 
Method Summary
abstract  void agentControlRequestAbort(java.lang.String initiator)
          Abstract method of agent service/molvestate abort
abstract  void agentControlRequestClientReconnect(org.jlab.coda.cMsg.cMsgMessage msg)
           
abstract  void agentControlRequestConfigure(AComponent ac)
           
abstract  void agentControlRequestMoveToState(java.lang.String state)
           
abstract  void agentControlRequestPlatformDisconnect()
          This will disconnect agent from the platform.
abstract  void agentControlRequestReleaseComponent()
           
abstract  void agentControlRequestReset(java.lang.String initiator)
          Abstract method of agent reset
abstract  void agentControlrequestSetRunNumber(int runnum)
           
 void configure(AComponent ad)
          Configures agent based on the cool description
 void connect2cMsg(AComponent ad)
           
 void differentiate(AComponent ad)
          This method connects to the platform, completes basic subscriptions ( at this moment only AgentInfoRequest messages), registeres with the platform registrar, creats an instance of the representative component communication plugin, and starts the status reporting thread.
 boolean doSubscriptions()
          Agent basic subscriptions.
 void executeProcess(AProcess p, java.lang.String resultState)
          The main process execution method.
 void executeProcess(java.lang.String pn)
          Executes the process defined by the name
 boolean executeShellScript(AScript scr, java.lang.String sn, boolean before)
          Method executes shell scripts.
 boolean isSet(AChannel c1, AChannel c2)
          Compares two AChannel objects
 void moveToState(java.lang.String sn)
          Chaecks if the required state is known then moves to the state by executing state dependent processes.
 boolean register()
          Register with the platform registration services
 boolean removeRegistration()
          Sends the request to remove registration from the platform registration services
 boolean reportLoad()
          Sends the request to the container to update load for this agent
 boolean reportStatus(boolean isObjectRequested)
          Sends status ( payload of AComponent object) to every one subscribing to the subject = session.
 void reset()
          General reset N.B.
 void startDalogReporting()
          Starts dalog reporting thread with the default AConstants.ADLRP preiodicity.
 void startLoadReporting()
          Starts load reporting thread with the default AConstants.ALRP preiodicity.
 void startStatusReporting()
          Starts status reporting thread.
 void stopDalogReporting()
          Stops dalog reporting thread.
 void stopLoadReporting()
          Stops load reporting thread.
 void stopMonProcesses()
          Stops all started periodic processes, and clears the hashmap for the periodic processes.
 void stopStatusReporting()
          Stops status reporting thread.
abstract  void supervisorControlRequestConfigure(AControl control)
           
 void unsubscribeAll()
          Unsubscribes agent info and control messages
 
Methods inherited from class org.jlab.coda.afecs.system.ABase
B2O, connect, connect, connect, dalogMsg, dalogMsg, disconnect, getCurrentTime, getCurrentTime, getCurrentTimeInMs, getPlDescription, getPlEXPID, getPlMulticastUDL, getPlUDL, isConnected, isRCDomainConnected, msg2xml, msgForward, multicastConnect, multicastConnect, O2B, p2pSend, p2pSend, p2pSend, p2pSend, rcConnect, rcDomaindisconnect, rcMonitor, rcp2pSend, rcSend, rcSend, rcSend, rcSend, rcSend, rcSend, rcSend, removeUnixShellProcess, reporAlarmMsg, reportAlarmMsg, reportAlarmMsg, runShellCommand, send, send, send, send, send, send, send, sleep, updateHostUdl
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AbortRequest

public volatile java.util.concurrent.atomic.AtomicBoolean AbortRequest

activeMoveToState

public java.util.concurrent.atomic.AtomicBoolean activeMoveToState

cMsgRequests

public volatile int cMsgRequests

me

public AComponent me

myLoad

public volatile double myLoad

myMonProcesses

public java.util.concurrent.ConcurrentHashMap<java.lang.String,AAgent.MonProcessThread> myMonProcesses

myPlugin

public IAClientCommunication myPlugin

myStartTime

public java.lang.String myStartTime

ResetRequest

public volatile java.util.concurrent.atomic.AtomicBoolean ResetRequest
Constructor Detail

AAgent

public AAgent()
Basic constructor. No configuration information is available.

Method Detail

agentControlRequestAbort

public abstract void agentControlRequestAbort(java.lang.String initiator)
Abstract method of agent service/molvestate abort

Parameters:
initiator - agent name who initiates the reset

agentControlRequestClientReconnect

public abstract void agentControlRequestClientReconnect(org.jlab.coda.cMsg.cMsgMessage msg)

agentControlRequestConfigure

public abstract void agentControlRequestConfigure(AComponent ac)

agentControlRequestMoveToState

public abstract void agentControlRequestMoveToState(java.lang.String state)

agentControlRequestPlatformDisconnect

public abstract void agentControlRequestPlatformDisconnect()
This will disconnect agent from the platform. i.e. it will be garbage collected.


agentControlRequestReleaseComponent

public abstract void agentControlRequestReleaseComponent()

agentControlRequestReset

public abstract void agentControlRequestReset(java.lang.String initiator)
Abstract method of agent reset

Parameters:
initiator - agent name who initiates the reset

agentControlrequestSetRunNumber

public abstract void agentControlrequestSetRunNumber(int runnum)

configure

public void configure(AComponent ad)
Configures agent based on the cool description

Parameters:
ad - AComponent base component structure.

connect2cMsg

public void connect2cMsg(AComponent ad)

differentiate

public void differentiate(AComponent ad)
This method connects to the platform, completes basic subscriptions ( at this moment only AgentInfoRequest messages), registeres with the platform registrar, creats an instance of the representative component communication plugin, and starts the status reporting thread.

Parameters:
ad - AComponent object

doSubscriptions

public boolean doSubscriptions()
Agent basic subscriptions. Subscribes AgentInfoRequest and AgentControlRequest messages

Returns:
status of the method execution.

executeProcess

public void executeProcess(AProcess p,
                           java.lang.String resultState)
The main process execution method. This is a public method using private startPr method. Starts thread for periodic process execution, and /or executes (in sync or async) processes. If the result of the sync execution is successful change the state of this agent.

Parameters:
p - AProcess reference
resultState - state name that this agent must transition in case of successful process execution.

executeProcess

public void executeProcess(java.lang.String pn)
Executes the process defined by the name

Parameters:
pn - the name of the process (String)

executeShellScript

public boolean executeShellScript(AScript scr,
                                  java.lang.String sn,
                                  boolean before)
Method executes shell scripts. N.B. All the processes define before of after state transitions as usually are executed as shell scripts.

Parameters:
scr - AScript object
sn - The name of the state
before - Boolean value defines if script is running before (true) or after (false) state transition
Returns:
status of the execution

isSet

public boolean isSet(AChannel c1,
                     AChannel c2)
Compares two AChannel objects

Parameters:
c1 - AChannel object was set
c2 - AChannel object read
Returns:
true if AChannel.setValue of c1 is equal to AChannel.getValue() of c2.

moveToState

public void moveToState(java.lang.String sn)
Chaecks if the required state is known then moves to the state by executing state dependent processes. If the state is in "ing" or "ating" ( in the middle of transition) mode or the required state is not known return false.

Parameters:
sn - The name of the state

register

public boolean register()
Register with the platform registration services

Returns:
status of the registration

removeRegistration

public boolean removeRegistration()
Sends the request to remove registration from the platform registration services

Returns:
status of the operation

reportLoad

public boolean reportLoad()
Sends the request to the container to update load for this agent

Returns:
status of the operation

reportStatus

public boolean reportStatus(boolean isObjectRequested)
Sends status ( payload of AComponent object) to every one subscribing to the subject = session. N.B. This is a design choice. All supervisor/s must subscribe the subject session. This is done in order to simplify the life of any graphical interface that is ready to visualize information of the specific agent.

Parameters:
isObjectRequested - if true we need to send entire AComponent object for this agent to the requester. Otherwise we send only subset of the AComponent object including only run time specific parameters as a payload items.
Returns:
status of the operation.

reset

public void reset()
General reset N.B. Every components base state is AConstants.booted


startDalogReporting

public void startDalogReporting()
Starts dalog reporting thread with the default AConstants.ADLRP preiodicity.


startLoadReporting

public void startLoadReporting()
Starts load reporting thread with the default AConstants.ALRP preiodicity.


startStatusReporting

public void startStatusReporting()
Starts status reporting thread. This will start reporting with the periodicity defined in the AComponent object (result of COOL based agent configuration parsing). In the case agent configuration lacks periodicity deffinition the default AConstants.ARP is used.


stopDalogReporting

public void stopDalogReporting()
Stops dalog reporting thread.


stopLoadReporting

public void stopLoadReporting()
Stops load reporting thread.


stopMonProcesses

public void stopMonProcesses()
Stops all started periodic processes, and clears the hashmap for the periodic processes.


stopStatusReporting

public void stopStatusReporting()
Stops status reporting thread.


supervisorControlRequestConfigure

public abstract void supervisorControlRequestConfigure(AControl control)

unsubscribeAll

public void unsubscribeAll()
Unsubscribes agent info and control messages