|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectSOMA.agent.AgentWorker
Classe che rappresenta un agente in esecuzione.
Ad ogni agente agente il place associa un worker, un componente che effettua tutte le operazioni di base di un agente. Il worker possiede anche il thread di esecuzione dell'agente, che puo' essere avviato ed interrotto.
Il worker implementa l'interfaccia Daemon
.
Questa comprende i metodi per avviare ed interrompere il thread di un worker, ossia di un agente.
L'interfaccia prevede anche uno stato del worker. Infine per gestire da menu gli agenti
si puo' utilizzare la voce di menu DaemonExplorerItem
utilizzata allo stesso modo in altri contesti.
Il worker ha uno stato che puņ essere ON, OFF, GONE, IDLE, STOPPED, DEAD. Tutti i metodi che agiscono sullo stato sono sincronizzati.
Agent
,
AgentSystem
Nested Class Summary | |
static class |
AgentWorker.AgentWorkerException
|
Field Summary | |
Agent |
agent
Riferimento all'agente. |
(package private) java.lang.Thread |
agentThread
|
java.lang.ThreadGroup |
agentThreadGroup
Tutti i threads creati dall'agente si troveranno in questo ThreadGroup. |
static java.lang.Object |
DEAD
Il worker e' nello stato DEAD dopo la morte, ossia dopo che il metodo di avvio e' terminato. |
(package private) Environment |
env
|
static java.lang.Object |
GONE
Il worker e' nello stato GONE dal momento in cui l'agente ha effettuato la migrazione, al momento in cui il thread dell'agente termina, a questo punto il worker viene eliminato. |
static java.lang.Object |
IDLE
Il worker e' nello stato IDLE dal momento in cui l'agente ha richiesto di andare in Idle, al momento in cui il thread dell'agente termina, a questo punto l'agente va nello stato OFF. |
static java.lang.Object |
KILLED
Il worker e' nello stato KILLED a seguito del metodo kill. |
(package private) java.lang.Object |
status
|
static java.lang.Object |
STOPPED
Il worker e' nello stato STOPPED dal momento in cui l'agente ha terminato l'esecuzione del metodo stop() al momento in cui il suo thread principale termina. |
Fields inherited from interface SOMA.network.connection.Daemon |
ERROR, OFF, ON |
Constructor Summary | |
AgentWorker(Agent agent,
Environment env)
Costruttore. |
Method Summary | |
java.lang.Object |
getStatus()
Restituisce lo stato del worker. |
void |
go(PlaceID destination)
Metodo che effettua la migrazione dell'agente. |
void |
idle()
L'agente va nello stato IDLE. |
void |
kill()
Distrugge il worker senza farsi scrupoli di alcun genere. |
void |
remove()
|
void |
run()
Metodo di avvio del thread del worker. |
void |
start()
Metodo di avvio del worker. |
void |
stop()
Metodo di arresto del worker. |
java.lang.String |
toString()
Restituisce una stringa di descrizione del worker. |
static void |
WaitForOtherThreads(java.io.PrintStream out)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public final Agent agent
public java.lang.ThreadGroup agentThreadGroup
java.lang.Thread agentThread
java.lang.Object status
public static final java.lang.Object IDLE
public static final java.lang.Object GONE
public static final java.lang.Object DEAD
public static final java.lang.Object STOPPED
public static final java.lang.Object KILLED
Environment env
Constructor Detail |
public AgentWorker(Agent agent, Environment env)
agent
- L'agenteenv
- Il riferimento all'Environment, accessibile al worker,
ma non all'agente.Method Detail |
public java.lang.String toString()
public java.lang.Object getStatus()
getStatus
in interface Daemon
public void start() throws AgentWorker.AgentWorkerException
Metodo di avvio del worker.
Questo metodo mette in esecuzione l'agente gestito dal worker ed e' il complementare del metodo stop()
.
start
in interface Daemon
AgentWorker.AgentWorkerException
public void stop() throws AgentWorker.AgentWorkerException
stop
in interface Daemon
AgentWorker.AgentWorkerException
start()
public void run()
Metodo di avvio del thread del worker.
Chiama il metodo dell'agente indicato dal campo start
.
Terminata l'esecuzione dell'agente il worker viene eliminato.
run
in interface java.lang.Runnable
public void remove() throws AgentWorker.AgentWorkerException
AgentWorker.AgentWorkerException
public void go(PlaceID destination) throws CantGoException
Questo metodo si interfaccia direttamente al NetworkManager
.
Il metodo e' sincronizzato per il cambiamento di stato.
CantGoException
public void idle()
public void kill()
Attenzione: fa uso di ThreadGroup.stop(), metodo deprecato.
public static void WaitForOtherThreads(java.io.PrintStream out)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |