Agent System POND 1.0 (1.7.2000)

PkgAgentSystem.GUI
Class GUIAgentSystem

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--FIM.Util.Threads.CancellableThread
              |
              +--PkgAgentSystem.AgentSystem
                    |
                    +--PkgAgentSystem.GUI.GUIAgentSystem

public class GUIAgentSystem
extends AgentSystem

Base class for agent systems with a graphical user interface. To be used with class MainFrame.

Can be used as stand-alone:
java PkgAgentSystem.GUI.GUIAgentSystem agentDir libraryDir [Port [savedFile]]

Version:
1.0, 1.7.2000
Author:
Michael Sonntag

Field Summary
protected  MainFrame mainframe
          The main window of the system
 
Fields inherited from class PkgAgentSystem.AgentSystem
DEBUG, MAX_DEFER_DELAY, MIN_DEFER_DELAY, SECURE_CONNECTION, securityStore, servingThreads, STD_PORT
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY, values
 
Constructor Summary
GUIAgentSystem(int port, String libraryDir, String agentDir, boolean exitOnLast, String savedFile)
          Creates a new GUI agent system with the security turned on.
GUIAgentSystem(int port, String libraryDir, String agentDir, boolean exitOnLast, String savedFile, boolean useSecurity)
          Creates a new GUI agent system and shows the main window.
 
Method Summary
(package private)  void addKeyPair(NamedKeyPair nkp)
          Adds a general key pair to the security store.
(package private)  void addTrustedCertificate(String name, Certificate cert)
          Adds a trusted certificate to the security store.
(package private)  boolean agentsExist()
          Returns whether there is at least one agent (either active or persisted) in this system.
protected  void dePersist(AgentData data)
          Restores a persisted agent to the running state.
protected  void destroyPersistedAgent(AgentData data)
          Terminates a currently persisted agent.
(package private)  void doCreateAgent()
          Create a new agent.
protected  void doMoveAgent(AgentBase agent, URL destination)
          Transfers an agent to another host.
(package private)  boolean existsTrustedCertificateName(String name)
          Checks whether a trusted certificate with this name already exists.
protected  String getAgentDirectory()
          Returns the directory from where the agents are loaded.
static void main(String[] args)
          This class can also be used directly to show a GUI agent system:
java PkgAgentSystem.GUI.GUIAgentSystem agentDir libraryDir [Port [savedFile]]
protected  void move(AgentBase agent, URL destination)
          Helper function for transfering an agent.
protected  void onAgentCreated(AgentData data)
          Notify the mainframefor updating the user interface after an agent was created.
protected  void onAgentDepersisted(AgentData data)
          Notify the mainframe for updating the user interface after an agent was depersisted.
protected  void onAgentDestroyed(AgentData data)
          Notify the mainframe for updating the user interface after an agent was destroyed.
protected  void onAgentPersisted(AgentData data)
          Notify the mainframe for updating the user interface after an agent was persisted.
protected  void onAgentReceived(AgentData data)
          Notify the mainframe for updating the user interface after an agent was received.
(package private)  String openFile(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.
protected  void reportError(String msg)
          Report an error to the user.
(package private)  String saveFile(String password)
          Saves the agent system with all contained agents to the default file.
(package private)  String saveFileAs(String filename, String password)
          Saves the agent system with all contained agents to a file.
protected  AgentBase startAgent(String className, String codeOrigin, boolean forceLocalCode, AgentIdentity identity, PrivateKey privateKey, Object param, boolean start)
          For starting an agent by the system.
protected  void stopAgent(AgentBase agent, boolean destroyed)
          Terminates a running agent.
 
Methods inherited from class PkgAgentSystem.AgentSystem
agentCount, allowArrivalOfAgent, buyPermission, buyPermissionSet, cancel, challengeAgent, checkAdditionalClassification, doTimerAction, dumpClassification, findAgentContext, getAgentContext, getClassificationStatus, getLibraryDirectory, getLocation, getOptionalPermissions, getPrice, getResource, getResourceAsStream, getResources, getSetPrice, localBroadcastMessage, offerAdditionalClassification, open, receiveAgent, returnPermission, returnPermissionSet, run, save, saveAs, sendMessage, startAgent, terminate
 
Methods inherited from class FIM.Util.Threads.CancellableThread
isCancelled
 
Methods inherited from class java.lang.Thread
, activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mainframe

protected MainFrame mainframe
The main window of the system
Constructor Detail

GUIAgentSystem

public GUIAgentSystem(int port,
                      String libraryDir,
                      String agentDir,
                      boolean exitOnLast,
                      String savedFile)
Creates a new GUI agent system with the security turned on.
Parameters:
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 located
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 file

GUIAgentSystem

public GUIAgentSystem(int port,
                      String libraryDir,
                      String agentDir,
                      boolean exitOnLast,
                      String savedFile,
                      boolean useSecurity)
Creates a new GUI agent system and shows the main window.
Parameters:
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 located
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 file
useSecurity - false if no security system is wanted
Method Detail

onAgentCreated

protected void onAgentCreated(AgentData data)
Notify the mainframefor updating the user interface after an agent was created.
Parameters:
data - the management data of the new agent
Overrides:
onAgentCreated in class AgentSystem

onAgentReceived

protected void onAgentReceived(AgentData data)
Notify the mainframe for updating the user interface after an agent was received.
Parameters:
data - the management data of the new agent
Overrides:
onAgentReceived in class AgentSystem

onAgentPersisted

protected void onAgentPersisted(AgentData data)
Notify the mainframe for updating the user interface after an agent was persisted.
Parameters:
data - the management data of the now persisted agent
Overrides:
onAgentPersisted in class AgentSystem

onAgentDepersisted

protected void onAgentDepersisted(AgentData data)
Notify the mainframe for updating the user interface after an agent was depersisted.
Parameters:
data - the management data of the restored agent
Overrides:
onAgentDepersisted in class AgentSystem

onAgentDestroyed

protected void onAgentDestroyed(AgentData data)
Notify the mainframe for updating the user interface after an agent was destroyed.
Parameters:
data - the management data of the removed agent
Overrides:
onAgentDestroyed in class AgentSystem

stopAgent

protected void stopAgent(AgentBase agent,
                         boolean destroyed)
Terminates a running agent. Repeated here so Mainframe can access it.
Parameters:
agent - the agent to stop
destroy - if the agent should be completely destroyed (false when persisting)
Overrides:
stopAgent in class AgentSystem

destroyPersistedAgent

protected void destroyPersistedAgent(AgentData data)
Terminates a currently persisted agent. Repeated here so Mainframe can access it.
Parameters:
data - the management data of the agent to destroy
Overrides:
destroyPersistedAgent in class AgentSystem

persist

protected void persist(AgentBase agent)
                throws NotSerializableException
Persists an agent to the disk. Repeated here so Mainframe can access it.
Parameters:
agent - the agent to persist
Throws:
NotSerializableException - if the agent cannot be serialized
Overrides:
persist in class AgentSystem
See Also:
AgentBase, PersistingDeniedException

dePersist

protected void dePersist(AgentData data)
                  throws CreateAgentFailureException
Restores a persisted agent to the running state. Repeated here so Mainframe can access it.
Parameters:
data - the management data of the agent to depersist
Throws:
CreateAgentFailureException - if an error occured when starting the agent (class not found or stream error during reading)
Overrides:
dePersist in class AgentSystem
See Also:
AgentBase

move

protected void move(AgentBase agent,
                    URL destination)
             throws ReceiveAgentDeniedException,
                    CannotSendException
Helper function for transfering an agent. Cannot call super from within the thread ans cannot assign it to a variable.
Parameters:
agent - the agent to move
destination - URL of the system the agent shall be moved to
Throws:
ReceiveAgentDeniedException - if the other host denies to receive the agent (problem on remote host)
CannotSendException - if an error occured during sending (problem on this host)
Overrides:
move in class AgentSystem

doMoveAgent

protected void doMoveAgent(AgentBase agent,
                           URL destination)
                    throws ReceiveAgentDeniedException,
                           CannotSendException
Transfers an agent to another host. Repeated here so Mainframe can access it.
Parameters:
agent - the agent to move
destination - URL of the system the agent shall be moved to
Throws:
ReceiveAgentDeniedException - if the other host denies to receive the agent (problem on remote host)
CannotSendException - if an error occured during sending (problem on this host)

startAgent

protected AgentBase startAgent(String className,
                               String codeOrigin,
                               boolean forceLocalCode,
                               AgentIdentity identity,
                               PrivateKey privateKey,
                               Object param,
                               boolean start)
                        throws CreateAgentFailureException,
                               InitializationException
For starting an agent by the system. Necessary, as it will be called from an inner class (Other Thread, see below in doCreateAgent)
Parameters:
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 not
identity - the identity of the agent
privateKey - 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 agent
start - true if the agent should be started (if false, it can be started later with ".start()" )
Throws:
CreateAgentFailureException - if any exception or error happens while creating thre agent
InitializationException - if an error occured during initialization
Overrides:
startAgent in class AgentSystem

doCreateAgent

void doCreateAgent()
Create a new agent. Shows a dialog for selecting the class and the for selecting/creating an identity. Shows a "Please wait" dialog as starting may take some time. Package access, so it can be called from class Mainframe.
See Also:
CreateAgentDialog, SelectIdentityDialog

getAgentDirectory

protected String getAgentDirectory()
Returns the directory from where the agents are loaded. Repeated here so Mainframe can access it.
Returns:
the directory from where the agents are loaded
Overrides:
getAgentDirectory in class AgentSystem

agentsExist

boolean agentsExist()
Returns whether there is at least one agent (either active or persisted) in this system.
Returns:
true if at least one agent exists

saveFileAs

String saveFileAs(String filename,
                  String password)
            throws FileNotFoundException
Saves the agent system with all contained agents to a file. Repeated here so Mainframe can access it.
Parameters:
filename - the name of the file to which the system is saved
password - the password used for encrypting the file
Returns:
string with errors on all agents, which could not be saved to the file
Throws:
FileNotFoundException - if the file could not be written to

saveFile

String saveFile(String password)
          throws FileNotFoundException
Saves the agent system with all contained agents to the default file. Repeated here so Mainframe can access it.
Parameters:
password - the password used for encrypting the file
Returns:
string with errors on all agents, which could not be saved to the file
Throws:
FileNotFoundException - if the file could not be written to

openFile

String openFile(String filename,
                String password)
          throws FileNotFoundException
Reades the agent system with all contained agents from a file. Repeated here so Mainframe can access it.
Parameters:
filename - the name of the file from which the system is restored
password - the password used for decrypting the file
Returns:
string with errors on all agents, which could not be restored from the file
Throws:
FileNotFoundException - if the file could not be found

existsTrustedCertificateName

boolean existsTrustedCertificateName(String name)
                               throws KeyStoreException
Checks whether a trusted certificate with this name already exists.
Parameters:
name - the name under which the trusted certificate should be stored
Returns:
true if this name already exists as an trusted certificate
Throws:
KeyStoreException - if an error occured during checking the name

addTrustedCertificate

void addTrustedCertificate(String name,
                           Certificate cert)
                     throws KeyStoreException
Adds a trusted certificate to the security store.
Parameters:
name - the name under which the trusted certificate should be stored
cert - the trusted certificate
Throws:
KeyStoreException - if an error occured during storing the certificate

addKeyPair

void addKeyPair(NamedKeyPair nkp)
          throws KeyStoreException
Adds a general key pair to the security store.
Parameters:
nkp - the named pair of keys to be stored
Throws:
KeyStoreException - if an error occured during storing the keys

reportError

protected void reportError(String msg)
Report an error to the user. Shows an error-dialog after calling super.reportError(msg).
Parameters:
msg - the error message to report
Overrides:
reportError in class AgentSystem

main

public static void main(String[] args)
This class can also be used directly to show a GUI agent system:
java PkgAgentSystem.GUI.GUIAgentSystem agentDir libraryDir [Port [savedFile]]

Agent System POND 1.0 (1.7.2000)

Submit a bug

Copyright 2000 Michael Sonntag & Institute for Information Processing and Microprocessor Technology (FIM), Johannes-Kepler-University Linz, Altenbergerstr. 69, A-4040 Linz, Austria.