|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--SOMA.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.
Agent
,
AgentSystem
Inner Class Summary | |
interface |
AgentWorker.AgentWorkerException
|
Field Summary | |
Agent |
agent
Riferimento all'agente. |
Constructor Summary | |
AgentWorker(Agent agent,
Environment env)
Costruttore. |
Method Summary | |
int |
getStatus()
Restituisce lo stato del worker. |
void |
go(PlaceID destination)
Metodo che effettua la migrazione dell'agente. |
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. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
public final Agent agent
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 int getStatus()
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()
.
Attenzione: i metodi start()
e stop()
sincronizzano la loro esecuzione
sul monitor dell'agente (= synchronized( agent )
). Questo fornisce un semplice meccanismo
per interrompere e riavviare l'esecuzione di un agente senza correre il rischio che l'agente venga
a trovarsi in uno stato inconsistente. Infatti e' sufficiente, nel programmare un agente,
utilizzare il costrutto synchronized
per isolare le parti di codice
che devono eseguire operazioni atomiche di modifica dello stato dell'agente.
public void stop() throws 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.
public void go(PlaceID destination) throws CantGoException
NetworkManager
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |