cz.cuni.amis.pogamut.base.agent.jmx.adapter
Class AgentMBeanAdapter<T extends IAgent>

java.lang.Object
  extended by cz.cuni.amis.pogamut.base.agent.jmx.adapter.AgentMBeanAdapter<T>
All Implemented Interfaces:
IAgentMBeanAdapter
Direct Known Subclasses:
Agent3DMBeanAdapter

public class AgentMBeanAdapter<T extends IAgent>
extends java.lang.Object
implements IAgentMBeanAdapter

Class for exporting arbitrary agents as managed MBeans.


Field Summary
static java.lang.String AGENT_NAME_FLAG_NAME
           
static java.lang.String AGENT_STATE_FLAG_NAME
           
 
Constructor Summary
AgentMBeanAdapter(T agent, javax.management.ObjectName objectName, javax.management.MBeanServer mbs)
           
 
Method Summary
protected  T getAgent()
           
 java.lang.String getComponentId()
          Returns id of the agent - unique across the JVMs.
 java.lang.String getName()
          Returns human readable name.
 javax.management.ObjectName getObjectName(java.lang.String domain)
          Returns JMX object name of the MBean.
 IAgentState getState()
          Returns the state of the agent (whether it's running / dead / etc.).
 void kill()
          Stops the agent (unconditionally), closing whatever connection it may have, this method must be non-blocking + interrupting all the communication, logic or whatever threads the agent may have.
 void pause()
          This should pause the the agent.
 void resume()
          This should resume the logic of the agent.
 void start()
          Attempt to launch the agent.
 void stop()
          Attempt to stop the agent, usually meaning dropping all running flags and see whether it will stop automatically.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AGENT_STATE_FLAG_NAME

public static final java.lang.String AGENT_STATE_FLAG_NAME
See Also:
Constant Field Values

AGENT_NAME_FLAG_NAME

public static final java.lang.String AGENT_NAME_FLAG_NAME
See Also:
Constant Field Values
Constructor Detail

AgentMBeanAdapter

public AgentMBeanAdapter(T agent,
                         javax.management.ObjectName objectName,
                         javax.management.MBeanServer mbs)
                  throws javax.management.MalformedObjectNameException,
                         javax.management.InstanceAlreadyExistsException,
                         javax.management.MBeanRegistrationException,
                         javax.management.NotCompliantMBeanException
Throws:
javax.management.MalformedObjectNameException
javax.management.InstanceAlreadyExistsException
javax.management.MBeanRegistrationException
javax.management.NotCompliantMBeanException
Method Detail

getAgent

protected T getAgent()

getObjectName

public javax.management.ObjectName getObjectName(java.lang.String domain)
                                          throws javax.management.MalformedObjectNameException
Description copied from interface: IAgentMBeanAdapter
Returns JMX object name of the MBean.

Specified by:
getObjectName in interface IAgentMBeanAdapter
Parameters:
domain - jmx domain
Returns:
name under which the MBean should be exported
Throws:
javax.management.MalformedObjectNameException

getComponentId

public java.lang.String getComponentId()
Description copied from interface: IAgentMBeanAdapter
Returns id of the agent - unique across the JVMs.

Specified by:
getComponentId in interface IAgentMBeanAdapter
Returns:

getState

public IAgentState getState()
Description copied from interface: IAgentMBeanAdapter
Returns the state of the agent (whether it's running / dead / etc.).

Note that the type AgentState wraps two things:

Specified by:
getState in interface IAgentMBeanAdapter
Returns:

start

public void start()
           throws AgentException
Description copied from interface: IAgentMBeanAdapter
Attempt to launch the agent. If it does not throw an exception, agent has been successfully started, also the state of the agent state is changed into Running state.

Specified by:
start in interface IAgentMBeanAdapter
Throws:
AgentException

pause

public void pause()
           throws AgentException
Description copied from interface: IAgentMBeanAdapter
This should pause the the agent. If it does not throw an exception, agent has been successfully started, also the state of the agent state is changed into Paused state.

If your agent can't be paused, throw OperationNotSupportedException.

Specified by:
pause in interface IAgentMBeanAdapter
Throws:
AgentException

resume

public void resume()
            throws AgentException
Description copied from interface: IAgentMBeanAdapter
This should resume the logic of the agent. If it does not throw an exception, agent has been successfully resumed, also the state of the agent state is changed into Running state.

If your agent can't be paused therefore can't be resumed, throw OperationNotSupportedException.

Specified by:
resume in interface IAgentMBeanAdapter
Throws:
AgentException

stop

public void stop()
          throws AgentException
Description copied from interface: IAgentMBeanAdapter
Attempt to stop the agent, usually meaning dropping all running flags and see whether it will stop automatically. This method may be blocking. If it does not throw the exception, the agent has been successfully stopped, also the state of the agent is changed into End state.

If the stop can not complete - it must automatically call kill() method.

Specified by:
stop in interface IAgentMBeanAdapter
Throws:
AgentException

kill

public void kill()
Description copied from interface: IAgentMBeanAdapter
Stops the agent (unconditionally), closing whatever connection it may have, this method must be non-blocking + interrupting all the communication, logic or whatever threads the agent may have.

After calling kill() method, the only method that may be called is getState() to examine state of the agent.

This also equals to "exception happened outside the agent" and "IFatalErrorEvent should be propagated inside the agent"

Specified by:
kill in interface IAgentMBeanAdapter

getName

public java.lang.String getName()
Description copied from interface: IAgentMBeanAdapter
Returns human readable name. getDisplayName is set by agent and doesn't have to be unique, while getName is machine assigned and is unique.

Specified by:
getName in interface IAgentMBeanAdapter