|
Agent System POND 1.0 (1.7.2000) | ||||||||
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. |
Fields inherited from class java.lang.Thread |
MAX_PRIORITY,
MIN_PRIORITY,
NORM_PRIORITY,
values |
Constructor Summary | |
protected |
AgentBase()
Constructor for class AgentBase . |
Method Summary | |
void |
addMessage(Message 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 |
firePermissionChange(PermissionEvent permEvent)
Call this to send a PermissionEvent to all registered listeners. |
String |
getAgentName()
The public, non-unique plaintext name of the agent. |
protected 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 Conversation |
getOngoingConversation(long convID)
Retrieve a certain currently ongoing conversation. |
protected long[] |
getOngoingConversationIDs()
Retrieve the IDs of all currently ongoing conversations. |
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. |
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
.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 registerConversation
protected void registerReplaceConversation(Conversation conv)
conv
- the prototype of the conversation to registerConversation
protected void initialize(Object param) throws InitializationException
param
- Generic parameter for the Agent (can be anything the agent knows how to interpret)InitializationException
final void setAgentSystem(AgentSystem sys)
sys
- the AgentSystemfinal 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)protected 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()
protected AgentSystem getAgentSystem()
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.MovingDeniedException
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
.agentMain()
protected void agentMain()
public final void addMessage(Message 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)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 final void sendMessage(Message msg) throws MessageException
msg
- the message to sendprotected final void broadcastMessage(BroadcastMessage msg) throws MessageException
msg
- the message to sendprotected 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()
|
Agent System POND 1.0 (1.7.2000) | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |