|
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.AgentBase
Base class for all agents. Contains the following parts:
AgentSystem
,
Message
,
NamedKeyPair
,
NamedKeyAndCertificate
, Serialized FormField Summary | |
protected Hashtable |
conversationArchive
Previous conversations that were archived. |
(package private) Object |
initializeParam
The parameter to pass to initialize |
(package private) static int |
STARTUP_ACTION_AFTER_DEPERSIST
When starting, call onAfterDePersist |
(package private) static int |
STARTUP_ACTION_AFTER_MOVING
When starting, call onAfterMoving |
(package private) static int |
STARTUP_ACTION_INITIALIZE
When starting, call initialize |
(package private) static int |
STARTUP_ACTION_NONE
When starting do nothing, just enter main method/message-loop |
(package private) int |
startupAction
What the agent should do when starting (initialize, onAfterMoving, onAfterDepersist; or nothing) |
Fields inherited from class java.lang.Thread |
inheritableThreadLocals, MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY, threadLocals |
Constructor Summary | |
protected |
AgentBase()
Constructor for class AgentBase . |
Method Summary | |
void |
addMessage(MessageType msg)
Add a message to the queue. |
protected void |
addOwnExperience(Statement stat,
boolean broadcast)
Adds a statement to our own experiences. |
protected void |
addPermissionListener(PermissionChangeListener listener)
Add a listener for permission changes. |
protected void |
agentMain()
Main loop of the agent. |
protected void |
broadcastMessage(BroadcastMessage msg)
Sends a message to all other local agents. |
protected boolean |
createConversationAllowed(long convTypeID)
Checks, whether it is currently allowed to create this type of conversation. |
URL |
currentLocation()
Returns the current location of the agent in form of an URL . |
(package private) void |
endConversation(Conversation conv,
boolean shouldArchive)
Ends a conversation. |
(package private) void |
endConversations()
Terminates all ongoing conversations and removes all messages pending handling. |
(package private) void |
firePermissionChange(PermissionEvent permEvent)
Call this to send a PermissionEvent to all registered listeners. |
String |
getAgentName()
The public, non-unique plaintext name of the agent. |
AgentSystem |
getAgentSystem()
Returns the agent system where the agent currently is located. |
protected Conversation |
getArchivedConversation(long convID)
Retrieve a certain conversation from the archive. |
protected long[] |
getArchivedConversationIDs()
Retrieve the IDs of all archived conversations. |
Experiences |
getExperiences()
Returns the experiences object of this agent. |
AgentIdentity |
getIdentity()
The identity of the agent (contains the public key). |
protected NamedKeyAndCertificate |
getKeyAndCertificate(String name)
Retrieve a private key and the matching certificate from the certificate-store by its name |
protected Enumeration |
getKeyAndCertificates()
Returns an enumeration of all the names, under which private keys and matching certificates are stored in the certificate-store. |
protected NamedKeyPair |
getKeyPair(String name)
Retrieve a keypair from the key-store by its name |
protected Enumeration |
getKeyPairs()
Returns an enumeration of all the names, under which keys are stored in the key-store. |
protected Vector |
getLog()
Returns a copy of the log |
protected MessageType |
getNextMessage()
Retrieve the next message in the queue. |
protected Conversation |
getOngoingConversation(long convID)
Retrieve a certain currently ongoing conversation. |
protected long[] |
getOngoingConversationIDs()
Retrieve the IDs of all currently ongoing conversations. |
boolean |
hasPermission(Permission perm)
Allows the agent to inquiry whether he currently actually has a permission (NOT "could get it", ...). |
protected void |
initialize(Object param)
Initialization of the agent. |
void |
logMessage(String msg)
Adds the message to the internal log. |
protected void |
move(URL destination)
Helper function to initiate moving this agent to another system. |
Conversation |
newConversation(long convTypeID,
AgentIdentity counterpart)
Method for creatign a new conversation. |
protected void |
onAfterDePersist()
Called after restoring the agent from a secondary storage and before starting it again. |
protected void |
onAfterMoving()
Called after receiving the agent from another host and before starting it again. |
protected void |
onBeforeMoving()
Called before moving (When trying to transfer the agent to another host and stop it afterwards). |
protected void |
onBeforePersist()
Called before persisting (When trying to safe the agent to a secondary storage and stop it afterwards). |
protected void |
persist()
Helper function to initiate persisting this agent by itself. |
protected void |
registerConversation(Conversation conv)
Registers a conversation. |
protected void |
registerReplaceConversation(Conversation conv)
Registers a conversation. |
protected void |
removeKeyAndCertificate(String name)
Remove a private key and the matching certificate from the certificate-store |
protected void |
removeKeyPair(String name)
Remove a keypair from the key-store |
protected void |
removePermissionListener(PermissionChangeListener listener)
Remove a listener for permission changes. |
byte[] |
replyToChallenge(byte[] challenge)
This method can be used to verify, whether the agent knows a certain private key. |
byte[] |
replyToChallenge(String keyname,
byte[] challenge)
This method can be used to verify, whether the agent knows a certain private key. |
void |
run()
The main method which is run when the agent is started. |
protected void |
sendMessage(Message msg)
Sends a message to another agent. |
(package private) void |
setAgentIdentity(AgentIdentity identity,
PrivateKey agentPrivateKey)
Method for setting the identity and the private key of the agent. |
(package private) void |
setAgentSystem(AgentSystem sys)
Method for setting the agent system the agent is in. |
protected void |
setKeyAndCertificate(NamedKeyPair nkp)
Store a private key and the matching certificate in the certificate-store under the provided name. |
protected void |
setKeyPair(NamedKeyPair nkp)
Store a keypair in the key-store under the provided name. |
boolean |
startConversation(Conversation conv)
Starts a conversation. |
protected void |
stopAgent()
Helper function to stop this agent. |
protected boolean |
typeIsRegistered(long conversationTypeID)
Checks, wheter a conversation is registered under this id or not. |
boolean |
verifySignedMessage(SignedMessage msg)
To verify a signed message. |
protected void |
writeExperiencesTo(PrintWriter out)
Dump the experiences to a stream. |
protected void |
writeLogTo(PrintWriter out)
Writes the log to a PrintWriter stream. |
Methods inherited from class FIM.Util.Threads.CancellableThread |
cancel, isCancelled, terminate |
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 |
protected Hashtable conversationArchive
Conversation.setShouldArchive
.static final int STARTUP_ACTION_NONE
static final int STARTUP_ACTION_INITIALIZE
static final int STARTUP_ACTION_AFTER_MOVING
static final int STARTUP_ACTION_AFTER_DEPERSIST
transient Object initializeParam
transient int startupAction
Constructor Detail |
protected AgentBase()
AgentBase
. The conversations registered are:
TerminateAgentConversation
ExperienceExchangeConversation
TerminateAgentConversation
,
ExperienceExchangeConversation
Method Detail |
protected void registerConversation(Conversation conv)
conv
- the prototype of the conversation to registerIllegalArgumentException
- if a conversation with this typeID is already registered (or none provided)Conversation
protected void registerReplaceConversation(Conversation conv)
null
value is provided, the conversation will be removed (unregistering).conv
- the prototype of the conversation to registerConversation
protected boolean typeIsRegistered(long conversationTypeID)
conversationTypeID
- the id to checktrue
if a conversation is registered under this idConversation
protected void initialize(Object param) throws InitializationException
param
- Generic parameter for the Agent (can be anything the agent knows how to interpret)InitializationException
- if an exception occurs during initializationInitializationException
final void setAgentSystem(AgentSystem sys)
sys
- the AgentSystemSecurityException
- if the agent system has already been setfinal void setAgentIdentity(AgentIdentity identity, PrivateKey agentPrivateKey)
identity
- the identity of the agentagentPrivateKey
- the private key of the agent (ignored if no public key in the identity)SecurityException
- if the agents identity has already been setprotected NamedKeyPair getKeyPair(String name)
name
- the name of the keypairNamedKeyPair
protected void removeKeyPair(String name)
name
- the name of the keypair to removeNamedKeyPair
protected void setKeyPair(NamedKeyPair nkp)
nkp
- the named keypair to storeNamedKeyPair
protected Enumeration getKeyPairs()
Enumeration
of all names of stored keysNamedKeyPair
protected NamedKeyAndCertificate getKeyAndCertificate(String name)
name
- the name of the certificateNamedKeyAndCertificate
protected void removeKeyAndCertificate(String name)
name
- the name of the private key and certificate to removeNamedKeyAndCertificate
protected void setKeyAndCertificate(NamedKeyPair nkp)
nkp
- the named private key and certificate to storeNamedKeyAndCertificate
protected Enumeration getKeyAndCertificates()
Enumeration
of all names of stored private keys and certificatesNamedKeyAndCertificate
public final byte[] replyToChallenge(byte[] challenge)
challenge
- the challenge, which may consist of up to 16 bytespublic final byte[] replyToChallenge(String keyname, byte[] challenge)
keyname
- the name of the keypair to use for signing (if null, the agents own keys are used; same as providing "Agents own keys")challenge
- the challenge, which may consist of up to 16 bytespublic String getAgentName()
public AgentIdentity getIdentity()
protected void onBeforePersist() throws PersistingDeniedException
PersistingDeniedException
to avoid or delay this. Take care: The agent system may
not allow deferring or disabling persisting, so the agent may be killed in this case!AgentSystem.persist(AgentBase)
,
PersistingDeniedException
protected void onAfterDePersist()
AgentSystem.dePersist(AgentData)
protected void onBeforeMoving() throws MovingDeniedException
MovingDeniedException
to avoid or delay this. Take care: The agent system may
not allow deferring or disabling moving, so the agent may be killed in this case!AgentSystem.move(AgentBase,URL)
,
MovingDeniedException
protected void onAfterMoving()
public final AgentSystem getAgentSystem()
SecurityException
- if the agent system is not set (This should not happen)public URL currentLocation()
URL
. The url could be used to transfer an agent
to this agent system (Protocol: AMP; Host: Current hostname; Port: Address of this agent system).
Convenience method instead of getAgentSystem.getLocation()
.URL
for the current agent system.protected void persist()
PersistingDeniedException
in onBeforePersisting
!
Will fail silently if the agent could not be serialized. If successful, the method will NOT be returned from if called by the agent.PersistingDeniedException
protected void move(URL destination) throws ReceiveAgentDeniedException, CannotSendException
MovingDeniedException
in onBeforeMoving
!
If successful, the method will NOT be returned from if called by the agent.destination
- URL for the destination. May be another host or another port to move to another agent system.ReceiveAgentDeniedException
- if the remote host denied the agent accessCannotSendException
- if there was an error during transfering the agentMovingDeniedException
protected void stopAgent()
public void logMessage(String msg)
msg
- the message to add to the logprotected void writeLogTo(PrintWriter out)
PrintWriter
stream.out
- the stream to write the log toprotected Vector getLog()
Vector
)public final void run()
agentMain
.run
in class CancellableThread
IllegalStateException
- if the agent system or the agents identity is not setThreadDeath
- if terminated from within its own threadError
- if the agents main thread terminated because of an exception or erroragentMain()
protected void agentMain()
protected MessageType getNextMessage() throws InterruptedException
InterruptedException
- if the agent was waiting for a message but was interruptedpublic final void addMessage(MessageType msg)
public Conversation newConversation(long convTypeID, AgentIdentity counterpart)
createConversationAllowed
is NOT checked here: The user should know when he wants to start which conversation!convTypeID
- type of the conversation to createcounterpart
- the identity of the other agent. null
if there is no single other agent (e. g. for sending broadcasts)null
is the conversation type ID is wrong (i. e. unknown conversation type)startConversation(Conversation)
protected boolean createConversationAllowed(long convTypeID)
true
.convTypeID
- the type id od the conversation, which shall be createdtrue
if it is currently allowed to create this type of conversationConversation
public boolean startConversation(Conversation conv)
handleMessage
will be called with a null
parameter.
After this method has completed, the conversation can receive messages.conv
- the conversation to starttrue
if successfully started (return value from conv.handleMessage(null)
)Conversation
void endConversation(Conversation conv, boolean shouldArchive)
conv
- the conversation to stopshouldArchive
- true if the conversation shall be moved to the conversationsArchiveConversation
protected void sendMessage(Message msg) throws MessageException
msg
- the message to sendMessageException
- if an error occured during sending the messageprotected void broadcastMessage(BroadcastMessage msg) throws MessageException
msg
- the message to sendMessageException
- if an error occured during sending the messagevoid endConversations()
protected void addOwnExperience(Statement stat, boolean broadcast)
stat
- the statement to addbroadcast
- if true, the statement will be broadcast to all other agentsExperienceExchangeConversation
public Experiences getExperiences()
protected void writeExperiencesTo(PrintWriter out)
out
- the PrintWriter
stream to write the experience data toprotected final void addPermissionListener(PermissionChangeListener listener)
listener
- the listener to addprotected final void removePermissionListener(PermissionChangeListener listener)
listener
- the listener to removefinal void firePermissionChange(PermissionEvent permEvent)
PermissionEvent
to all registered listeners. Package access as only internally used.permEvent
- the event to distributepublic boolean verifySignedMessage(SignedMessage msg)
msg
- the signed messageprotected Conversation getArchivedConversation(long convID)
convID
- the ID of the conversation to retrievenull
if this is an invalid ID or the conversation was not archived (or did not exist)protected long[] getArchivedConversationIDs()
protected Conversation getOngoingConversation(long convID)
convID
- the ID of the conversation to retrievenull
if this is an invalid ID or the conversation does not currently existsprotected long[] getOngoingConversationIDs()
public boolean hasPermission(Permission perm)
perm
- the permission the agent wants to know about (if null
, return true
)true
if the agent currently has this permission
|
Agent System POND 1.2 (28.2.2002) | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |