|
Agent System POND 1.2 (28.2.2002) | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Thread | +--FIM.Util.Threads.CancellableThread | +--PkgAgentSystem.AgentSystem
Main class of the agent system.
Field Summary | |
static boolean |
DEBUG
Flag for debugging. |
static boolean |
HAND_OFF
Flag for whether Hand-Off should take place or not |
static int |
MAX_DEFER_DELAY
Maximum allowed for delaying persisting or moving through request of the agent |
static int |
MIN_DEFER_DELAY
Minimum allowed for delaying persisting or moving through request of the agent |
protected static Currency |
priceCurrency
The currency used for prices when selling permissions. |
static boolean |
SECURE_CONNECTION
If true, the connection to another agent-system will be cryptographically secure. |
protected PersonalSecurityStore |
securityStore
The security store of the owner of this agent system |
(package private) Vector |
servingThreads
List of all serving threads currently active. |
(package private) static int |
STD_PORT
The standard port of the agent system. |
Fields inherited from class java.lang.Thread |
inheritableThreadLocals, MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY, threadLocals |
Constructor Summary | |
|
AgentSystem(int port,
String libraryDir,
String agentDir,
String systemDir,
boolean exitOnLast,
String savedFile)
Creates a new agent system with the security turned on. |
protected |
AgentSystem(int port,
String libraryDir,
String agentDir,
String systemDir,
boolean exitOnLast,
String savedFile,
boolean useSecurity)
Creates a new agent system. |
|
AgentSystem(String libraryDir,
String systemDir)
Creates a new agent system with the default value for the port and the users home directory as directory from where the agents are loaded. |
Method Summary | |
protected boolean |
acceptPayment(AgentData agData,
Payment payment)
Check whether we want to accept this payment for a permission from a certain agent. |
protected int |
agentCount()
Returns the number of agents in this system. |
protected boolean |
allowArrivalOfAgent(URL whereFrom,
AgentIdentity identity,
CertificateWrapper[] codeSigners,
String agentClass)
Checks whether this agent is allowed to arrive at this host. |
Permission |
buyPermission(AgentBase agent,
Permission perm,
Payment payment)
Allows the agent to buy a permission. |
PermissionCollection |
buyPermissionSet(AgentBase agent,
PermissionCollection perms,
Payment payment)
Allows the agent to buy a set of permissions. |
void |
cancel()
Method to stop the agent system gracefully. |
protected void |
challengeAgent(AgentData data)
Challenges the agent for the knowledge of its private key. |
protected boolean |
checkAdditionalClassification(AgentData agData,
AgentClassification classification)
Checks whether an additional classification is accepted. |
protected void |
dePersist(AgentData data)
Restores a persisted agent to the running state. |
void |
deploy(AgentData agData)
Deploys the agent by signing the current state (i. e. the initialization parameters) and the code used if applicable (digest over the code signatures) |
protected void |
destroyPersistedAgent(AgentData data)
Terminates a currently persisted agent. |
(package private) void |
doTimerAction(long id)
Handles delayed requests. |
void |
dumpClassification(AgentBase agent)
Prints the classification information to System.out .
|
protected AgentData |
getAgentContext(AgentBase agent)
Get the management data of an agent from a supplied reference to it. |
protected AgentData |
getAgentContext(AgentIdentity identity)
Get the management data of an agent from its identity. |
protected String |
getAgentDirectory()
Returns the directory from where the agents are loaded. |
AgentIdentity |
getAgentIdentityByID(String ID)
Retrieve the identity of a local agent by its unique ID. |
ClassificationSet |
getClassificationStatus(AgentBase agent)
Allows an agent to get information on his current status of additional classifications. |
Certificate[] |
getCodeCertificates(AgentBase agent)
Allows an agent to get information on his accepted code certificates. |
protected String |
getLibraryDirectory()
Returns the directory where the shared libraries are located. |
URL |
getLocation()
Returns the URL of the local agent system. |
PermissionCollection |
getOptionalPermissions(AgentBase agent)
Returns a collection of all optional permissions. |
Invoice |
getPrice(AgentBase agent,
Permission perm)
Return the price of a permission for an agent. |
URL |
getResource(AgentBase agent,
String name)
Finds the resource with the given name. |
InputStream |
getResourceAsStream(AgentBase agent,
String name)
Finds the resource with the given name and returns an input stream for reading it. |
Enumeration |
getResources(AgentBase agent,
String name)
Finds all the resources with the given name. |
Invoice |
getSetPrice(AgentBase agent,
PermissionCollection perms)
Return the price of a set of permissions for an agent. |
protected String |
getSystemDirectory()
Returns the directory where the agentsystem files are located. |
protected boolean |
isPrivilegedSource(CodeSource codesource)
Check whether a code is form a privileged package or not. |
(package private) void |
localBroadcastMessage(AgentBase sender,
BroadcastMessage msg)
Sends a message to all agents in the local system, except the sender and the persisted ones. |
static void |
main(String[] args)
This class can also be used directly to show a GUI-less agent system: java PkgAgentSystem.AgentSystem agentDir libraryDir [Port [savedFile]] |
protected void |
move(AgentBase agent,
URL destination)
Transfers an agent to another host. |
ClassificationSet |
offerAdditionalClassification(AgentBase agent,
ClassificationSet offer)
Allows an agent to offer additional classifications to receive more/cheaper permissions. |
protected void |
onAgentCreated(AgentData data)
Placeholder for updating the user interface after an agent was created. |
protected void |
onAgentDepersisted(AgentData data)
Placeholder for updating the user interface after an agent was depersisted. |
protected void |
onAgentDestroyed(AgentData data)
Placeholder for updating the user interface after an agent was destroyed. |
protected void |
onAgentPersisted(AgentData data)
Placeholder for updating the user interface after an agent was persisted. |
protected void |
onAgentReceived(AgentData data)
Placeholder for updating the user interface after an agent was received. |
protected String |
open(String filename,
String password)
Reades the agent system with all contained agents from a file. |
protected void |
persist(AgentBase agent)
Persists an agent to the disk. |
(package private) void |
receiveAgent(AgentData data)
Starts a received agent. |
protected void |
reportError(String msg)
Report an error to the user. |
void |
returnPermission(AgentBase agent,
Permission perm)
An agent can return a permission, indicating that he no longer needs it. |
void |
returnPermissionSet(AgentBase agent,
PermissionCollection perms)
An agent can return permissions, indicating that he no longer needs them. |
void |
run()
Main method of the system: Wait for incoming requests and handle them. |
protected String |
save(String password)
Saves the agent system with all contained agents to the default file. |
protected String |
saveAs(String filename,
String password)
Saves the agent system with all contained agents to a file. |
protected void |
saveHandOff(boolean sender,
Certificate otherASIdentity,
AgentIdentity agentIdentity,
byte[] digest,
byte[] outSig,
byte[] inSig)
Store the hand-off we received (and sent) in a file. |
(package private) void |
sendMessage(AgentBase sender,
Message msg)
Sends a message to another agent. |
AgentBase |
startAgent(AgentBase requester,
String className,
boolean fromMyCodePackage,
AgentIdentity identity,
PrivateKey privateKey,
Serializable param)
For starting an agent by another agent. |
protected AgentBase |
startAgent(String className,
String codeOrigin,
boolean forceLocalCode,
AgentIdentity identity,
PrivateKey privateKey,
Object param,
boolean start)
For starting an agent by the system: there is no requester. |
protected void |
stopAgent(AgentBase agent,
boolean destroy)
Terminates a running agent. |
boolean |
storeInReadOnlyStore(AgentBase requester,
AgentIdentity destination,
Serializable key,
Serializable value)
Tries to store an object under a certain key in the ReadOnlyStore of another agent. |
protected void |
storePayment(AgentData agData,
Payment payment)
Store the payment we received for granting a permission in a file. |
boolean |
terminate(long maxWaitToDie)
Method to stop the agent system. |
protected Serializable |
transferObject(Serializable obj,
ClassLoader cll)
Transfers an object from one classloader to another. |
Methods inherited from class FIM.Util.Threads.CancellableThread |
isCancelled |
Methods inherited from class java.lang.Thread |
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final boolean DEBUG
public static final boolean HAND_OFF
public static final boolean SECURE_CONNECTION
public static final int MIN_DEFER_DELAY
public static final int MAX_DEFER_DELAY
static final int STD_PORT
Vector servingThreads
protected PersonalSecurityStore securityStore
protected static final Currency priceCurrency
Constructor Detail |
public AgentSystem(String libraryDir, String systemDir)
libraryDir
- the directory where the common libraries are stored. Must be provided.sytemDir
- the directory, where the system is located; the keystores are located there as well as logfiles and payment-files, etc.public AgentSystem(int port, String libraryDir, String agentDir, String systemDir, boolean exitOnLast, String savedFile)
port
- the port the system will listen on (must be >1024 or -1)libraryDir
- the directory, where the common libraries are from; All agents will load classes
first from there and only after not finding them there from their local path/package. Must be provided.agentDir
- the directory, where the AGENTS are from, NOT where the JDK or the agent system is locatedsytemDir
- the directory, where the system is located; the keystores are located there as well as logfiles and payment-files, etc.exitOnLast
- if true the system will terminate after the last agent is destroyed (may start empty however)savedFile
- if not null, the agentsystem will load the state from this fileprotected AgentSystem(int port, String libraryDir, String agentDir, String systemDir, boolean exitOnLast, String savedFile, boolean useSecurity)
port
- the port the system will listen on (must be >1024 or -1)libraryDir
- the directory, where the common libraries are from; All agents will load classes
first from there and only after not finding them there from their local path/package. Must be provided.agentDir
- the directory, where the AGENTS are from, NOT where the JDK or the agent system is locatedsytemDir
- the directory, where the system is located; the keystores are located there as well as logfiles and payment-files, etc.exitOnLast
- if true the system will terminate after the last agent is destroyed (may start empty however)savedFile
- if not null, the agentsystem will load the state from this fileuseSecurity
- false if no security system is wantedMethod Detail |
public void run()
run
in class CancellableThread
ServingThread
public void cancel()
cancel
in class CancellableThread
public boolean terminate(long maxWaitToDie)
stop
is deprecated; sets
their priority to a minimum then.terminate
in class CancellableThread
maxWaitToDie
- number of secods to wait befor forceful termination (0 = wait indefinitely)Thread
public URL getLocation()
URL
of the local agent system. Can be used to move agents to this one.protected String getAgentDirectory()
protected String getSystemDirectory()
protected String getLibraryDirectory()
protected int agentCount()
void doTimerAction(long id)
id
- the id of the action to takeprotected void stopAgent(AgentBase agent, boolean destroy)
agent
- the agent to stopdestroy
- if the agent should be completely destroyed (false when persisting)protected void destroyPersistedAgent(AgentData data)
data
- the management data of the agent to destroyprotected void persist(AgentBase agent) throws NotSerializableException
PersistingDeniedException
.
In this implementation this works only once. If after the allotted time the agent denies being
persisted agein, it is terminated.agent
- the agent to persistNotSerializableException
- if the agent cannot be serializedAgentBase
,
PersistingDeniedException
protected void dePersist(AgentData data) throws CreateAgentFailureException
data
- the management data of the agent to depersistCreateAgentFailureException
- if an error occured when starting the agent (class not found or stream error during reading)AgentBase
public AgentBase startAgent(AgentBase requester, String className, boolean fromMyCodePackage, AgentIdentity identity, PrivateKey privateKey, Serializable param) throws CreateAgentFailureException, InitializationException
requester
- the agent who wants to create another agentclassName
- name of the class of the agent to start (including all packages)fromMyCodePackage
- if true, the code will be loaded from the package of the requesting agent. Otherwise it will be searched for normallyidentity
- the identity of the new agentprivateKey
- the private key of the agent (might be null if identity has no public key or just not provided)param
- the parameter passed to the method initialize, which is called after starting the agentCreateAgentFailureException
- if any exception or error happens while creating thre agent (e. g. when (de-)serializing the initialization parameter)InitializationException
- if an error occured during initializationprotected AgentBase startAgent(String className, String codeOrigin, boolean forceLocalCode, AgentIdentity identity, PrivateKey privateKey, Object param, boolean start) throws CreateAgentFailureException, InitializationException
className
- name of the class of the agent to start (including all packages)codeOrigin
- file or directory where from where the code should be loaded. If null, searches for it in the agent-directory.forceLocalCode
- if true, the code will be marked as from the local host, even if it is notidentity
- the identity of the agentprivateKey
- the private key of the agent (might be null if identity has no public key or just not provided)param
- the parameter passed to the method initialize, which is called after starting the agentstart
- true if the agent should be started (if false, it can be started later with "CreateAgentFailureException
- if any exception or error happens while creating thre agentInitializationException
- if an error occured during initializationprotected void move(AgentBase agent, URL destination) throws ReceiveAgentDeniedException, CannotSendException
agent
- the agent to movedestination
- URL
of the system the agent shall be moved toReceiveAgentDeniedException
- if the other host denies to receive the agent (problem on remote host)CannotSendException
- if an error occured during sending (problem on this host)void receiveAgent(AgentData data) throws ReceiveAgentDeniedException
data
- management data of the agent to receiveReceiveAgentDeniedException
- if this systems denies this agent access (happens here only if an error occured during starting it)public URL getResource(AgentBase agent, String name)
agent
- the agent who wants a resourcename
- name of the resourceURL
to the resource or null if not foundpublic final Enumeration getResources(AgentBase agent, String name) throws IOException
agent
- the agent who wants a resourcename
- name of the resourceEnumeration
of the resources. If none found, the enumeration is emptyIOException
- public InputStream getResourceAsStream(AgentBase agent, String name)
agent
- the agent who wants a resourcename
- name of the resourceInputStream
for reading the resource or null if not foundprotected final AgentData getAgentContext(AgentBase agent) throws AgentNotRegisteredException
agent
- the reference to the agent, for which the data shall be returnedAgentNotRegisteredException
- if the agent could not be found in the internal listprotected final AgentData getAgentContext(AgentIdentity identity) throws AgentNotRegisteredException
identity
- the identity of the agent, for which the data shall be returnedAgentNotRegisteredException
- if the agent could not be found in the internal listprotected void onAgentCreated(AgentData data)
data
- the management data of the new agentprotected void onAgentReceived(AgentData data)
data
- the management data of the new agentprotected void onAgentPersisted(AgentData data)
data
- the management data of the now persisted agentprotected void onAgentDepersisted(AgentData data)
data
- the management data of the restored agentprotected void onAgentDestroyed(AgentData data)
data
- the management data of the removed agentfinal void sendMessage(AgentBase sender, Message msg) throws MessageException
sender
- the agent who wants to send the message. Must be the same as the sender that is contained in the message.msg
- the message to sendUnknownAgentException
- if the sender or the recipient is unknownMessageException
- if the sending agent is not the sender of the messageMessageDeliveryException
- if the recipient was persisted and could not be depersistedMessageDeliveryException
- if the message could not be (de-)serializedfinal void localBroadcastMessage(AgentBase sender, BroadcastMessage msg) throws MessageException
sender
- the agent who wants to send the message. Must be the same as the sender that is contained in the message.msg
- the message to sendUnknownAgentException
- if the sender or a recipient is unknownMessageException
- if the sending agent is not the sender of the messageMessageDeliveryException
- if the recipient was persisted and could not be depersistedMessageDeliveryException
- if the message could not be (de-)serializedprotected String save(String password) throws FileNotFoundException
password
- the password used for encrypting the fileFileNotFoundException
- if the file could not be written toprotected String saveAs(String filename, String password) throws FileNotFoundException
filename
- the name of the file to which the system is savedpassword
- the password used for encrypting the fileFileNotFoundException
- if the file could not be written toprotected String open(String filename, String password) throws FileNotFoundException
filename
- the name of the file from which the system is restoredpassword
- the password used for decrypting the fileFileNotFoundException
- if the file could not be foundprotected void reportError(String msg)
msg
- the error message to reportpublic Invoice getPrice(AgentBase agent, Permission perm)
agent
- the agent who asks for the priceperm
- the permission the agent wantspublic Invoice getSetPrice(AgentBase agent, PermissionCollection perms)
agent
- the agent who asks for the priceperms
- the permissions the agent wantspublic Permission buyPermission(AgentBase agent, Permission perm, Payment payment)
agent
- the agent who buys the permissionperm
- the permission the agent wantspayment
- the payment for the permission (must currently be exact the price of the permission)public PermissionCollection buyPermissionSet(AgentBase agent, PermissionCollection perms, Payment payment)
agent
- the agent who buys the permissionsperms
- the permissions the agent wantspayment
- the payment for the permission (must currently be exact the price of the set)public void returnPermission(AgentBase agent, Permission perm)
agent
- the agent returning the permissionperm
- the returned permissionpublic void returnPermissionSet(AgentBase agent, PermissionCollection perms)
agent
- the agent returning the set of permissionsperms
- the returned permissionspublic PermissionCollection getOptionalPermissions(AgentBase agent)
agent
- the inquiring agentprotected void challengeAgent(AgentData data)
data
- the management data of the agent to challengePolicyByValue
,
AgentBase.replyToChallenge(String,byte[])
protected boolean allowArrivalOfAgent(URL whereFrom, AgentIdentity identity, CertificateWrapper[] codeSigners, String agentClass)
whereForm
- from where the agent arrivesidentity
- the identity of the agentcodeSigners
- array of all certificates, who signed the codeagentClass
- name of the main class of the agentpublic ClassificationSet getClassificationStatus(AgentBase agent)
agent
- the agent which requests its statuspublic Certificate[] getCodeCertificates(AgentBase agent)
agent
- the agent which requests its statuspublic ClassificationSet offerAdditionalClassification(AgentBase agent, ClassificationSet offer)
agent
- the agent offering additional classificationsoffer
- the additional classificationsprotected boolean checkAdditionalClassification(AgentData agData, AgentClassification classification)
agData
- the management data of the agent requesting the checkclassification
- the classification to inspect and verifypublic void dumpClassification(AgentBase agent)
System.out
.
Used for testing purposes only.
To be removed for final version.agent
- the agent whose classification should be printedpublic void deploy(AgentData agData) throws InvalidKeyException, NoSuchAlgorithmException, SignatureException
agData
- the agent to deployInvalidKeyException
- if one of the private keys provided is invalidNoSuchAlgorithmException
- if one of the algorithms provided is unknownSignatureException
- if an error occured during signing or the agent is alread deployedpublic AgentIdentity getAgentIdentityByID(String ID)
ID
- the ID of the agentnull
if not foundpublic boolean storeInReadOnlyStore(AgentBase requester, AgentIdentity destination, Serializable key, Serializable value)
ReadOnlyStore
of another agent. To be used for
non-repudiable delivery. The destination can just decline it without any reason. Will fail if the recipient has no
such store.requester
- the agent wanting to store the valuedestination
- the identity of the agent, in whichs store to place the valuekey
- the key under which the value should be storedvalue
- the value to be storedtrue
if successful, false
otherwise (in all cases; regardless whether the
recipient has no such store, he declined, or an error occured!)ReadOnlyStore
,
HasReadOnlyStore
,
HasVetoableReadOnlyStore
protected Serializable transferObject(Serializable obj, ClassLoader cll) throws IOException, ClassNotFoundException
obj
- the object to transfercll
- the classloader, to which to convert itIOException
- if the object could not be serializedClassNotFoundException
- if the object could not be deserializedprotected boolean acceptPayment(AgentData agData, Payment payment)
FIMVoucher
).
In addition, an empty payment is allowed, if the price is 0.agData
- the management data for the agent requesting to paypayment
- the payment info to checktrue
if the payment should be acceptedFIMVoucher
protected void storePayment(AgentData agData, Payment payment)
agData
- the management data for the agent payingpayment
- the payment info to storeprotected void saveHandOff(boolean sender, Certificate otherASIdentity, AgentIdentity agentIdentity, byte[] digest, byte[] outSig, byte[] inSig)
sender
- true
if we were the sender of the agent, false
if we received itotherASIdentity
- the certificate of the other agent systemagentIdentity
- the identity of the agent that was transferreddigest
- the MD5 digest, which was signedoutSig
- the signature we sent to the other systeminSig
- the signature we received from the other systemprotected boolean isPrivilegedSource(CodeSource codesource)
AllPermission
. Necessary only for libraries, which are used by the agentsystem
(not when used by agents!) and use factory methods (e. g. "Class.forName()") to create objects.
These packages must ALSO be included with appropriate permissions in the default policy
file (usually "java.policy").codesource
- the codesourcetrue
if the code is from a privileged packagPolicyByValue.getPermissions(CodeSource)
public static void main(String[] args)
java PkgAgentSystem.AgentSystem agentDir libraryDir [Port [savedFile]]
|
Agent System POND 1.2 (28.2.2002) | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |