|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.Observable | +--org.objectweb.mobilitools.smi.api.Agency
MobiliTools $Name: $, $Id: Agency.java,v 1.1.1.1 2003/03/28 14:48:05 dillense Exp $
Instances of this class are execution environments for agents, supporting lifecycle/mobility management, using and providing MAFAgentSystem implementation. An agency may be created by directly instantiating this class, by running this class from command line or by running the AgencyGUI class.
An agency may be customized with an AgencyPersonality
implementation. A personality
may be declared when creating a new agency (using the appropriate constructor), or via
inheritance. A personality's main role is to encapsulate agents by intercepting all lifecycle callbacks defined by
interface MobileObject.
AgencyGUI
,
AgencyPersonality
,
MobileObject
Field Summary | |
protected java.util.Hashtable |
agentsByName
|
protected java.util.Hashtable |
agentsByRef
|
protected org.omg.CfMAF.MAFFinder |
my_finder
|
protected org.omg.CfMAF.AgentSystemInfo |
my_info
|
protected Location |
my_location
|
protected java.lang.String |
my_name
|
protected NameService |
my_ns
|
protected java.lang.String |
my_ns_name
|
protected org.omg.CORBA.ORB |
my_orb
|
protected AgencyPersonality |
my_personality
|
protected java.lang.String |
my_region
|
protected AgentSystem |
my_shell
|
static java.lang.String |
NOTIFY_TERMINATE
|
protected org.objectweb.mobilitools.util.thread.ShutdownLock |
shutdownLock
|
protected static boolean |
standalone
if using an agency personality, set this attribute to true if you wish the agency to perform System.exit(0) when terminating the agency. |
protected org.objectweb.mobilitools.smi.idl._MAFAgentSystemComplementImplBase |
tie
|
Constructor Summary | |
Agency(java.lang.String region,
AgencyPersonality personality,
AgentSystem shell,
org.omg.CfMAF.AgentSystemInfo info)
Create a new agency for creating and receiving agents, and customize it with the provided agency personality and shell. |
|
Agency(java.lang.String region,
org.omg.CORBA.ORB orb,
AgencyPersonality personality,
AgentSystem shell,
org.omg.CfMAF.AgentSystemInfo info)
Create a new agency for creating and receiving agents. |
|
Agency(java.lang.String name,
java.lang.String region)
Create a new agency for creating and receiving agents. |
|
Agency(java.lang.String name,
java.lang.String region,
org.omg.CORBA.ORB orb)
Create a new agency for creating and receiving agents. |
Method Summary | |
void |
afterBirth(MobileObject agent,
AgentSystem agency,
AgentInfo entry,
java.lang.Object arguments)
Call afterBirth() on agent. |
void |
afterMove(MobileObject agent,
AgentSystem agency,
Location location,
java.lang.String place)
Call afterMove() on agent. |
void |
afterMoveFailed(MobileObject agent,
Location agency,
java.lang.String place,
int reason,
java.lang.String message)
Call afterMoveFailed on agent. |
void |
agencyShutdown()
Nothing special to do |
void |
beforeDeath(MobileObject agent)
Call beforeDeath() on agent |
void |
beforeMove(MobileObject agent,
Location location,
java.lang.String place)
Call beforeMove() on agent. |
void |
beforeResume(MobileObject agent)
Call beforeResume() on agent |
void |
beforeShutdown(MobileObject agent)
Call beforeShutdown() on agent |
void |
beforeSuspend(MobileObject agent)
Call beforeSuspend() on agent |
AgentInfo |
createLocalAgent(java.lang.String classname,
Name name,
org.omg.CfMAF.AgentProfile profile,
java.lang.String place,
java.lang.String codebase,
byte[] agent_data,
java.lang.Object argument,
org.omg.CfMAF.MAFAgentSystem class_provider)
Creates an agent in current agency. |
AgentInfo |
createLocalAgent(java.lang.String agent_class,
Name name,
java.lang.String place,
java.lang.String codebase,
java.util.Properties properties,
java.lang.Object argument)
Creates an agent in current agency. |
void |
exitOnTerminate(boolean mode,
long delay)
The agency may invoke System.exit() to make the JVM exit when the agency is terminated. |
AgentInfo |
getAgentInfo(MobileObject agent)
|
AgentInfo |
getAgentInfo(Name agent)
|
org.omg.CfMAF.AgentSystemInfo |
getAgentSystemInfo()
|
Location |
getLocation()
|
org.omg.CfMAF.MAFFinder |
getMAFFinder()
|
Name |
getName()
|
java.lang.String |
getNsName()
|
org.omg.CORBA.ORB |
getORB()
|
java.lang.String |
getRegion()
|
org.omg.CfMAF.Name[] |
listAgents(org.omg.CfMAF.AgentProfile profile)
|
org.omg.CfMAF.Name[] |
listAgents(byte[] authority)
|
Name[] |
listLocalAgents(org.omg.CfMAF.AgentProfile profile)
|
boolean |
localAgentIsRunning(MobileObject agent)
|
boolean |
localAgentIsRunning(Name agent)
|
static void |
main(java.lang.String[] args)
Launches a SMI agency. |
org.omg.CfMAF.AgentProfile |
makeAgentProfile(java.util.Properties properties)
|
void |
moveLocalAgent(MobileObject agent,
Location agency,
java.lang.String place)
Invokes the beforeMove() callback on the agent, and then tries
to move it if no exception has been thrown by beforeMove() .
|
void |
moveLocalAgent(Name agent,
Location agency,
java.lang.String place)
Invokes the beforeMove() callback on the agent, and then tries
to move it if no exception has been thrown by beforeMove() .
|
void |
receiveAgent(java.lang.String class_name,
byte[] agent_state,
org.omg.CfMAF.Name agent_name,
org.omg.CfMAF.AgentProfile agent_profile,
java.lang.String place,
java.lang.String code_base,
org.omg.CfMAF.MAFAgentSystem class_provider)
Receives a moving agent, invokes callback afterMove() on the newly installed agent. |
void |
resumeLocalAgent(MobileObject agent)
Invokes the beforeResume() callback on an agent in order to resume its activity.
|
void |
resumeLocalAgent(Name agent)
Invokes the beforeResume() callback on an agent in order to resume its activity.
|
void |
setLocalAgentProperty(MobileObject agent,
java.lang.String property,
java.lang.String value)
Sets, changes or unsets an agent property. |
void |
setLocalAgentProperty(Name agent,
java.lang.String property,
java.lang.String value)
Sets, changes or unsets an agent property. |
void |
suspendLocalAgent(MobileObject agent)
Invokes the beforeSuspend() callback on an agent in order to suspend its activity.
|
void |
suspendLocalAgent(Name agent)
Invokes the beforeSuspend() callback on an agent in order to suspend its activity.
|
void |
terminate()
Calls beforeShutdown() on the hosted agents,
terminates agents that are still hosted, then calls agencyShutdown()
on the agency, and finally shuts the agency down. |
void |
terminateLocalAgent(MobileObject agent)
Invokes the beforeDeath() callback on an agent, and then terminates it. |
void |
terminateLocalAgent(Name agent)
Invokes the beforeDeath() callback on an agent, and then terminates it. |
Methods inherited from class java.util.Observable |
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static boolean standalone
public static final java.lang.String NOTIFY_TERMINATE
protected java.lang.String my_region
protected java.lang.String my_name
protected org.objectweb.mobilitools.smi.idl._MAFAgentSystemComplementImplBase tie
protected NameService my_ns
protected java.lang.String my_ns_name
protected Location my_location
protected org.omg.CORBA.ORB my_orb
protected java.util.Hashtable agentsByRef
protected java.util.Hashtable agentsByName
protected org.omg.CfMAF.MAFFinder my_finder
protected AgencyPersonality my_personality
protected AgentSystem my_shell
protected org.omg.CfMAF.AgentSystemInfo my_info
protected org.objectweb.mobilitools.util.thread.ShutdownLock shutdownLock
Constructor Detail |
public Agency(java.lang.String name, java.lang.String region) throws BadOperation
name
- name of the agency, unique in the given region.region
- name of the region the agency belongs to.BadOperation
- if the name of the agency is not accepted by the MAFFinder (name already used?).public Agency(java.lang.String region, AgencyPersonality personality, AgentSystem shell, org.omg.CfMAF.AgentSystemInfo info) throws BadOperation
region
- name of the region the agency belongs to.personality
- object intercepting agent lifecycle callbacks.shell
- reference that will be given to the agents
created in or moving to this agency.info
- data record describing the customized agency (see MAF).
This info should hold the agency's MAF name, whose identity field is taken as the
agency's unique name in SMI's sense.BadOperation
- if the name of the agency is not accepted by the MAFFinder (name already used).Constants.makeAgentSystemInfo(byte[], byte[])
public Agency(java.lang.String name, java.lang.String region, org.omg.CORBA.ORB orb) throws BadOperation
name
- name of the agency, unique in the given region.region
- name of the region the agency belongs to.orb
- the ORB object to use.BadOperation
- if the name of the agency is not accepted by the MAFFinder (name already used?).ORB.init()
public Agency(java.lang.String region, org.omg.CORBA.ORB orb, AgencyPersonality personality, AgentSystem shell, org.omg.CfMAF.AgentSystemInfo info) throws BadOperation
region
- name of the region the agency belongs to.orb
- the ORB object to use.personality
- the agency personality that will handle the agents. A null value means
no personality (i.e. current agency instance).shell
- agency reference that will be given to the hosted agents after creation or move.
A null value means no specific shell, in which case the host agency will be used.info
- the AgentSystemInfo information record about the agent system personality.
This info should hold the agency's MAF name, whose identity field is taken as the
agency's unique name in SMI's sense.BadOperation
- if the name of the agency is not accepted by the MAFFinder (already used?).ORB.init()
,
Constants.makeAgentSystemInfo(byte[], byte[])
Method Detail |
public static void main(java.lang.String[] args)
args
- command-line arguments should specify:
Agency(String, String, ORB)
public org.omg.CfMAF.AgentSystemInfo getAgentSystemInfo()
public org.omg.CfMAF.AgentProfile makeAgentProfile(java.util.Properties properties)
properties
- the agent properties to be inserted in the profile.public void receiveAgent(java.lang.String class_name, byte[] agent_state, org.omg.CfMAF.Name agent_name, org.omg.CfMAF.AgentProfile agent_profile, java.lang.String place, java.lang.String code_base, org.omg.CfMAF.MAFAgentSystem class_provider) throws org.omg.CfMAF.ClassUnknown, org.omg.CfMAF.DeserializationFailed, org.omg.CfMAF.MAFExtendedException
afterMove()
on the newly installed agent.class_name
- class name of the received agent.agent_state
- the state of the received agent.agent_name
- the MAF unique name of the received agent.agent_profile
- the profile of the received agent (see MAF specifications).place
- the name of the place where to settle the new agent.code_base
- codebase to load classes for this agent.class_provider
- the MAFAgentSystem implementation from where to pick the classes
of the received agent.org.omg.CfMAF.ClassUnknown
- at least one of the needed classes could not be foundorg.omg.CfMAF.DeserializationFailed
- the received agent is not of SMI agent system type,
or an exception was thrown during the agent deserializationorg.omg.CfMAF.MAFExtendedException
- an exception was thrown by the agent afterMove() methodpublic org.omg.CfMAF.MAFFinder getMAFFinder()
public java.lang.String getRegion()
public Name getName()
public java.lang.String getNsName()
/naming context1!kind1/.../object!kind
public Location getLocation()
public AgentInfo getAgentInfo(Name agent)
agent
- the MAF unique name of the agent.public AgentInfo getAgentInfo(MobileObject agent)
agent
- the Java object reference to the agent.public AgentInfo createLocalAgent(java.lang.String agent_class, Name name, java.lang.String place, java.lang.String codebase, java.util.Properties properties, java.lang.Object argument) throws BadOperation
agent_class
- the class name of the new agent.name
- the identity part of the MAF name of the new agent
(must be unique in the set of names of the agency's authority; the authority
part of the MAF agent name will be the same as the agency's).place
- the name of the place where to settle the new agent.codebase
- codebase to load classes for this agent.properties
- agent's properties.argument
- parameter for agent constructor and initialization.BadOperation
- the agent creation failedMobileObject.afterBirth(AgentSystem, AgentInfo, Object)
public AgentInfo createLocalAgent(java.lang.String classname, Name name, org.omg.CfMAF.AgentProfile profile, java.lang.String place, java.lang.String codebase, byte[] agent_data, java.lang.Object argument, org.omg.CfMAF.MAFAgentSystem class_provider) throws BadOperation
classname
- the class name of the new agent.name
- the MAF unique name of the new agent.profile
- agent MAF profile.place
- the name of the place where to settle the new agent.codebase
- codebase to load classes for this agent.agent_data
- ignored if null or empty array ; otherwise, should contain a serialized
Java object which will be used as agent constructor and initialization parameter.argument
- parameter for agent constructor and initialization (ignored if agent_data
is non-null and non-empty).class_provider
- the MAFAgentSystem implementation from where to pick the classes;
(if null, the codebase will be interpreted locally.BadOperation
- the agent creation failedMobileObject.afterBirth(AgentSystem, AgentInfo, Object)
public void moveLocalAgent(Name agent, Location agency, java.lang.String place) throws BadOperation
beforeMove()
callback on the agent, and then tries
to move it if no exception has been thrown by beforeMove()
.
If the move fails, the afterMoveFailed()
callback is invoked
on the agent, and an exception is thrown.agent
- name wrapper for agent's MAF name.agency
- location of the target agency.place
- the name of the target place in the given agency.BadOperation
- on aborted move.MobileObject
,
AgencyPersonality
public void moveLocalAgent(MobileObject agent, Location agency, java.lang.String place) throws BadOperation
beforeMove()
callback on the agent, and then tries
to move it if no exception has been thrown by beforeMove()
.
If the move fails, the afterMoveFailed()
callback is invoked
on the agent, and an exception is thrown.agent
- Java object reference to the agent.agency
- location of the target agency.place
- the name of the target place in the given agency.BadOperation
- on aborted move.MobileObject
,
AgencyPersonality
public void terminate()
beforeShutdown()
on the hosted agents,
terminates agents that are still hosted, then calls agencyShutdown()
on the agency, and finally shuts the agency down.MobileObject
,
AgencyPersonality
public void terminateLocalAgent(Name agent) throws BadOperation
beforeDeath()
callback on an agent, and then terminates it.agent
- MAF unique name of the agent.BadOperation
- the target agent is not known by the agency, or
its termination threw an exception.MobileObject
,
AgencyPersonality
public void terminateLocalAgent(MobileObject agent) throws BadOperation
agent
- the Java object reference to the agent.BadOperation
- the target agent is not known by the agency, or
its termination threw an exception.MobileObject
,
AgencyPersonality
public Name[] listLocalAgents(org.omg.CfMAF.AgentProfile profile)
profile
- the agent profile to be matched; if null, all the agents are selected.public org.omg.CfMAF.Name[] listAgents(org.omg.CfMAF.AgentProfile profile)
profile
- the agent profile to be matched; if null, all the agents are
selected.public org.omg.CfMAF.Name[] listAgents(byte[] authority)
authority
- the agent's authority.public void resumeLocalAgent(Name agent) throws BadOperation
beforeResume()
callback on an agent in order to resume its activity.
Unless this callback throws an exception, the agent activity is then considered as resumed.agent
- MAF unique agent name.BadOperation
- the agent could not be found and resumed, or it was already running.MobileObject
,
AgencyPersonality
public void resumeLocalAgent(MobileObject agent) throws BadOperation
beforeResume()
callback on an agent in order to resume its activity.
Unless this callback throws an exception, the agent activity is then considered as resumed.agent
- the agent's Java object reference.BadOperation
- the agent could not be found and resumed, or it was already running.MobileObject
,
AgencyPersonality
public void suspendLocalAgent(Name agent) throws BadOperation
beforeSuspend()
callback on an agent in order to suspend its activity.
Unless this callback throws an exception, the agent activity is then considered as suspended.agent
- MAF unique agent name.BadOperation
- the agent could not be found and suspended, or was already suspended.MobileObject
,
AgencyPersonality
public void suspendLocalAgent(MobileObject agent) throws BadOperation
beforeSuspend()
callback on an agent in order to suspend its activity.
Unless this callback throws an exception, the agent activity is then considered as suspended.agent
- the agent's Java object reference.BadOperation
- the agent could not be found and suspended, or was already suspended.MobileObject
,
AgencyPersonality
public void setLocalAgentProperty(Name agent, java.lang.String property, java.lang.String value) throws BadOperation
agent
- the agent MAF name wrapper.property
- property name.value
- property value; if null, the property is unset.BadOperation
- the agent could not be found in local agency.public void setLocalAgentProperty(MobileObject agent, java.lang.String property, java.lang.String value) throws BadOperation
agent
- the agent's Java object reference.property
- property name.value
- property value; if null, the property is unset.BadOperation
- the agent could not be found in local agency.public boolean localAgentIsRunning(Name agent) throws BadOperation
agent
- wrapper to the agent's MAF name.BadOperation
- the agent could not be found in local agency.public boolean localAgentIsRunning(MobileObject agent) throws BadOperation
agent
- the agent's Java object reference.BadOperation
- the agent could not be found in local agency.public org.omg.CORBA.ORB getORB()
public void exitOnTerminate(boolean mode, long delay)
mode
- true enables the automatic exit on agency termination, false disables.delay
- delay in ms before calling System.exit(), after all callbacks
(on agents, on agency personality) have returned; a negative value results in
(1) dedicated system property, or (2) previous value set, or (3) default value to be applied.Constants
public void afterBirth(MobileObject agent, AgentSystem agency, AgentInfo entry, java.lang.Object arguments) throws BadOperation
afterBirth
in interface AgencyPersonality
org.objectweb.mobilitools.smi.api.AgencyPersonality
agent
- target agent.agency
- reference to the hosting agency.entry
- a structure of information about the newly created agent.arguments
- arguments for agent initialization.BadOperation
- shall be thrown if the agent refuses to settle.
Identifier BadOperation.REJECTED must be set for this exception.
Note that the agent creation is canceled,
and that beforeDeath()
is not called.public void beforeMove(MobileObject agent, Location location, java.lang.String place) throws BadOperation
beforeMove
in interface AgencyPersonality
org.objectweb.mobilitools.smi.api.AgencyPersonality
agent
- target agentlocation
- location of destination agencyplace
- name of target placeBadOperation
- thrown to reject the move.
Identifier BadOperation.REJECTED must be set for this exception.
The agent move is simply canceled and the thrown exception is
re-thrown by moveAgent()
(note that afterMoveFailed()
is not called).public void afterMove(MobileObject agent, AgentSystem agency, Location location, java.lang.String place) throws BadOperation
afterMove
in interface AgencyPersonality
org.objectweb.mobilitools.smi.api.AgencyPersonality
agent
- target agentagency
- reference to the new hosting agencylocation
- location of new hosting agencyplace
- the name of the new residing placeBadOperation
- thrown if the agent can not be
correctly reinstalled in the new agency.
Identifier BadOperation.REJECTED must be set for this exception.
The agent stays in the source agency, afterMoveFailed()
is invoked,
and moveAgent()
throws an exception.public void afterMoveFailed(MobileObject agent, Location agency, java.lang.String place, int reason, java.lang.String message)
afterMoveFailed
in interface AgencyPersonality
org.objectweb.mobilitools.smi.api.AgencyPersonality
agent
- target agentagency
- location of the target agencyplace
- the target place namereason
- problem identifiermessage
- textual explanationpublic void beforeDeath(MobileObject agent)
beforeDeath
in interface AgencyPersonality
org.objectweb.mobilitools.smi.api.AgencyPersonality
agent
- target agentpublic void beforeSuspend(MobileObject agent) throws BadOperation
beforeSuspend
in interface AgencyPersonality
org.objectweb.mobilitools.smi.api.AgencyPersonality
agent
- target agentBadOperation
- the agent activity was already suspended, or could not be suspended.
Identifier BadOperation.REJECTED must be set for this exception. SMI core detects
whether the agent is already suspended or not, and throws the corresponding exception if
necessary, without invoking this callback.public void beforeResume(MobileObject agent) throws BadOperation
beforeResume
in interface AgencyPersonality
org.objectweb.mobilitools.smi.api.AgencyPersonality
agent
- target agentBadOperation
- the agent activity was already running, or could not be resumed.
Identifier BadOperation.REJECTED must be set for this exception. SMI core detects
whether the agent is already running or not, and throws the corresponding exception if
necessary, without invoking this callback.public void beforeShutdown(MobileObject agent)
beforeShutdown
in interface AgencyPersonality
org.objectweb.mobilitools.smi.api.AgencyPersonality
agent
- target agentpublic void agencyShutdown()
agencyShutdown
in interface AgencyPersonality
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |