|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--drm.agentbase.Base
A class to host mobile agents. It is able to dispatch and receive them, handles their requests and messages.
Inner Class Summary | |
protected class |
Base.Firewall
This is an implementation of IBase hiding the public functions which are not part of IBase. |
Field Summary | |
static byte |
AGENT
|
protected java.util.Map |
boxes
Stores all agents and related information. |
protected java.util.Properties |
cfg
The configuration properties. |
static byte |
GET_JAR
|
java.lang.String |
group
To store the group name. |
static int |
GROUP_MISMATCH
|
static byte |
ISALIVE
|
static byte |
MESSAGE
|
java.lang.String |
name
A unique name for the base. |
static byte |
NOT_OK
|
static byte |
OK
|
static int |
PROTOCOL_VERSION
The protocol version used by this implementation. |
static int |
RELEASE_VERSION
The version of this release. |
static int |
SENDING_DIR
|
Constructor Summary | |
Base(java.util.Properties c)
Constructs a Base. |
Method Summary | |
void |
addListener(IBaseListener l)
|
void |
close()
Destroys all the agents, stops all the threads, and goes offline. |
void |
destroyAgent(java.lang.String n)
Destroys an agent with all necessary clean up. |
IRequest |
dispatchAgent(java.lang.String n,
Address to)
Dispatches an agent with all necessary clean up. |
IRequest |
fireMessage(Message m)
Fires the given message. |
static java.lang.String |
getBaseName(java.net.InetAddress h,
int p,
java.lang.String grp,
int tout)
Returns the name of the remote base if there is one at the given address and it answers requests. |
protected Base.Firewall |
getFirewall()
This method should return the firewall that is given to the agents. |
java.lang.String |
getJob()
returns group name |
java.lang.String |
getName()
returns base name |
java.util.Set |
getNames()
Gets the names of all agents on this base. |
java.lang.String |
getProperty(java.lang.String prop)
Retuns a base property. |
java.lang.String |
getType()
returns "Base" |
protected java.lang.String |
getUniqueName()
Called only once to inicialize the name of the base. |
void |
goOffline()
After going offline no network traffic is allowed and the base has no valid address. |
int |
goOnline(int portFrom,
int portTo)
The base tries to go online on one of the ports from the given range (inclusive the limits). |
boolean |
handleMessage(Message m,
java.lang.Object object)
This implementation does not handle any types of messages. |
boolean |
isOnline()
Returns the online status of the base. |
IRequest |
launch(java.lang.String method,
IAgent a,
java.lang.Object par)
Launches an agent to a specified destination. |
void |
onArrival(Address from,
Address to)
This implementation is empty, simply returns |
void |
onDestruction()
This should never be called, if called, it is a bug. |
void |
removeListener(IBaseListener l)
|
void |
run()
Main housekeeping tasks. |
void |
setBase(IBase b)
If the parameter is not a firewall to this, exists the jvm with a panic message. |
int |
version()
returns Base.RELEASE_VERSION |
void |
wipeClean(long time)
Cleans the base. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected final java.util.Properties cfg
protected java.util.Map boxes
public static final byte MESSAGE
public static final byte AGENT
public static final byte ISALIVE
public static final byte GET_JAR
public static final int SENDING_DIR
public static final byte OK
public static final byte NOT_OK
public static final int GROUP_MISMATCH
public static final int PROTOCOL_VERSION
public static final int RELEASE_VERSION
public final java.lang.String name
cfg
,
getUniqueName()
,
IBase.getProperty(String)
public final java.lang.String group
Constructor Detail |
public Base(java.util.Properties c)
group
: every base belongs to a group of bases.
Communication is possible only inside a group.
This prameter gives the name of the group this base belongs to.
If not defined then "default" is set, and also stored in the config
properties.cfg
.
System properties are also used for configuration. At the moment the following properties are used:
java.io.tmpdir
gives the directory the base
is allowed to use for storing temporary files as eg the jar files of the
agents.
Note that this is a standard system property.
If the directory is not writable, or cannot be created the system exits.
Method Detail |
protected java.lang.String getUniqueName()
cfg
is already set.protected Base.Firewall getFirewall()
public static java.lang.String getBaseName(java.net.InetAddress h, int p, java.lang.String grp, int tout)
h
- The IP address of the base.p
- The port of the base.grp
- The group of the calling entity.tout
- The timeout to wait for a reply in ms. If zero then
we wait until there's a reply, if the connection can be built.public int goOnline(int portFrom, int portTo)
portFrom
- The number of the port to start with.portTo
- The last port to try.public void goOffline()
public void close()
public void addListener(IBaseListener l)
public void removeListener(IBaseListener l)
public void wipeClean(long time)
The base will go online again if it was online when calling this method. Although it is not very likely, but it can happen that the port the base listens to will change.
public boolean handleMessage(Message m, java.lang.Object object)
handleMessage
in interface IAgent
drm.agentbase.IAgent
m
- The message to handle.object
- The object that is wrapped in the message. If null
then there is no binary content or it is not a serialized object
(in which case it can be read using Message.getBinary()
).Message.setReply(Object)
,
IBase.fireMessage(Message)
public void onArrival(Address from, Address to)
onArrival
in interface IAgent
drm.agentbase.IAgent
from
- The address of the base from which the agent was sent.
If the agent has never been on any base it is null.to
- The address of the local base at the time of the arrival.
It is not guaranteed to remain valid trough the lifetime of the
agent. If the agent has never been on a base it is null.IAgent.setBase(IBase)
public final void onDestruction()
onDestruction
in interface IAgent
public final java.lang.String getName()
getName
in interface IAgent
name
public java.lang.String getJob()
getJob
in interface IAgent
public java.lang.String getType()
getType
in interface IAgent
public final void setBase(IBase b)
setBase
in interface IAgent
drm.agentbase.IAgent
b
- The Base that hosts the agent.public final int version()
version
in interface IAgent
RELEASE_VERSION
public final void run()
run
in interface java.lang.Runnable
public java.lang.String getProperty(java.lang.String prop)
IBase
drm.baseName
The name of the base.getProperty
in interface IBase
drm.agentbase.IBase
prop
- Name of the property.Base(java.util.Properties)
public IRequest launch(java.lang.String method, IAgent a, java.lang.Object par)
IBase
launch
in interface IBase
method
- has to be "DIRECT"a
- has to be non nullpar
- has to be an Address or nullpublic java.util.Set getNames()
IBase
getNames
in interface IBase
public boolean isOnline()
IBase
isOnline
in interface IBase
public final void destroyAgent(java.lang.String n)
IBase
IAgent.onDestruction()
will
be called before removing the agent from the base. The agent has to
stop all its threads (java offers no possibility at the moment
(version 1.4) to stop threads). The agent will be cut off of the
outside world, even if it fails to stop its threads.destroyAgent
in interface IBase
drm.agentbase.IBase
name
- Name of the agent.public final IRequest dispatchAgent(java.lang.String n, Address to)
IBase
destroyAgent
.
The operation is assynchronous.dispatchAgent
in interface IBase
drm.agentbase.IBase
name
- Name of the agent.destination
- Where to send the agent.IBase.destroyAgent(String)
public IRequest fireMessage(Message m)
IBase
fireMessage
in interface IBase
drm.agentbase.IBase
IRequest.getInfo("reply")
returns the reply object to
the message (after it arrives of course).IRequest.getInfo(String)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |