cz.cuni.amis.pogamut.base.agent.jmx.proxy
Class AgentJMXProxy

java.lang.Object
  extended by cz.cuni.amis.pogamut.base.agent.jmx.proxy.AgentJMXProxy
All Implemented Interfaces:
IAgent, IComponent, IComponentAware, IControllable
Direct Known Subclasses:
GhostAgentJMXProxy

public class AgentJMXProxy
extends java.lang.Object
implements IAgent

Makes it possible to control agent running in remote JVM through JMX protocol.


Constructor Summary
AgentJMXProxy(java.lang.String agentJmxAddress)
           
 
Method Summary
protected  java.lang.Object call(java.lang.String actionName)
           
protected  java.lang.Object callNoException(java.lang.String actionName)
          All exceptions are wrapped in RuntimeException.
protected  java.lang.Object callNoException(java.lang.String actionName, java.lang.Object[] params, java.lang.String[] sig)
          All exceptions are wrapped in RuntimeException.
protected  java.lang.Object getAttributeNoException(java.lang.String atr)
           
 IAgentId getComponentId()
          Returns agent id - contains also a human-readable name that can be changed
 IComponentBus getEventBus()
          IComponentBus that the instance is working with.
 Folder getIntrospection()
          Returns folder with introspection information.
 java.util.logging.Logger getLog()
           
 IAgentLogger getLogger()
          Returns AgentLogger for the instance allowing creating new log categories or adding new handlers to them.
protected  javax.management.MBeanServerConnection getMBeanServerConnection()
           
 java.lang.String getName()
          Returns human-readable agent's name.
 javax.management.ObjectName getObjectName()
           
 ImmutableFlag<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 startPaused()
          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
 

Constructor Detail

AgentJMXProxy

public AgentJMXProxy(java.lang.String agentJmxAddress)
Method Detail

getMBeanServerConnection

protected javax.management.MBeanServerConnection getMBeanServerConnection()

getObjectName

public javax.management.ObjectName getObjectName()

getLogger

public IAgentLogger getLogger()
Description copied from interface: IAgent
Returns AgentLogger for the instance allowing creating new log categories or adding new handlers to them.

Specified by:
getLogger in interface IAgent
Returns:

getLog

public java.util.logging.Logger getLog()

getState

public ImmutableFlag<IAgentState> getState()
Description copied from interface: IAgent
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 IAgent
Returns:

callNoException

protected java.lang.Object callNoException(java.lang.String actionName)
All exceptions are wrapped in RuntimeException.

Parameters:
actionName -
Returns:

callNoException

protected java.lang.Object callNoException(java.lang.String actionName,
                                           java.lang.Object[] params,
                                           java.lang.String[] sig)
All exceptions are wrapped in RuntimeException.

Parameters:
actionName -
Returns:

call

protected java.lang.Object call(java.lang.String actionName)
                         throws AgentException
Throws:
AgentException

getAttributeNoException

protected java.lang.Object getAttributeNoException(java.lang.String atr)

start

public void start()
           throws AgentException
Description copied from interface: IAgent
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.

This method is not suitable for simultaneous start of multiple agents that should start working together in the environment. (I.e., during tournaments of agents when you need to synchronize their start in the environment.) In such cases use IAgent.startPaused() and then multiple threads+barrier to execute IAgent.resume() of all agents at once.

Specified by:
start in interface IAgent
Specified by:
start in interface IControllable
Throws:
AgentException

startPaused

public void startPaused()
                 throws ComponentCantStartException
Description copied from interface: IAgent
Attempt to launch the agent. If it does not throw an exception, agent has been successfully started (paused).

In contrast with IAgent.start() this method will initialize the agent inside the environment but pauses it after the start (i.e., its reasoning should not run, the action should not do any decisions).

To fully start the agent, you need to IAgent.resume() it.

It is designed to provide safe synchronization of multiple agent simulations when you need to start the reasoning of agents synchronously.

Specified by:
startPaused in interface IAgent
Throws:
ComponentCantStartException

pause

public void pause()
           throws AgentException
Description copied from interface: IAgent
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 IAgent
Throws:
AgentException

resume

public void resume()
            throws AgentException
Description copied from interface: IAgent
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 IAgent
Throws:
AgentException

stop

public void stop()
Description copied from interface: IAgent
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 IAgent
Specified by:
stop in interface IControllable

kill

public void kill()
Description copied from interface: IAgent
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 IAgent
Specified by:
kill in interface IControllable

getComponentId

public IAgentId getComponentId()
Description copied from interface: IAgent
Returns agent id - contains also a human-readable name that can be changed

Specified by:
getComponentId in interface IAgent
Specified by:
getComponentId in interface IComponent
Returns:

getName

public java.lang.String getName()
Description copied from interface: IAgent
Returns human-readable agent's name.

Do not use as unique id of the agent:

1) the name might change during the life of agent

2) we do not ensure it's unique

Use getComponentId().getToken() instead!

Use getComponentId().getName().setFlag() to change the name of the agent.

Specified by:
getName in interface IAgent
Returns:

getIntrospection

public Folder getIntrospection()
Description copied from interface: IAgent
Returns folder with introspection information. Useful for showing agent model variables and parameters.

Specified by:
getIntrospection in interface IAgent
Returns:
Folder with introspection info

getEventBus

public IComponentBus getEventBus()
Description copied from interface: IComponentAware
IComponentBus that the instance is working with.

Note that by design-choice - the IComponentBus is a singleton inside AgentScoped, therefore you don't have to necessarily obtain the instance through the component, it suffice to obtain it using injection into your object.

Specified by:
getEventBus in interface IComponentAware
Returns: