SOMA.agent
Class AgentWorker

java.lang.Object
  extended bySOMA.agent.AgentWorker
All Implemented Interfaces:
Daemon, java.lang.Runnable

public class AgentWorker
extends java.lang.Object
implements java.lang.Runnable, Daemon

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.

Author:
Livio Profiri
See Also:
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

agent

public final Agent agent
Riferimento all'agente.


agentThreadGroup

public java.lang.ThreadGroup agentThreadGroup
Tutti i threads creati dall'agente si troveranno in questo ThreadGroup.


agentThread

java.lang.Thread agentThread

status

java.lang.Object status

IDLE

public static final 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.


GONE

public static final 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.


DEAD

public static final java.lang.Object DEAD
Il worker e' nello stato DEAD dopo la morte, ossia dopo che il metodo di avvio e' terminato.


STOPPED

public static final 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.


KILLED

public static final java.lang.Object KILLED
Il worker e' nello stato KILLED a seguito del metodo kill.


env

Environment env
Constructor Detail

AgentWorker

public AgentWorker(Agent agent,
                   Environment env)
Costruttore.

Parameters:
agent - L'agente
env - Il riferimento all'Environment, accessibile al worker, ma non all'agente.
Method Detail

toString

public java.lang.String toString()
Restituisce una stringa di descrizione del worker.


getStatus

public java.lang.Object getStatus()
Restituisce lo stato del worker.

Specified by:
getStatus in interface Daemon

start

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().

Specified by:
start in interface Daemon
Throws:
AgentWorker.AgentWorkerException

stop

public void stop()
          throws AgentWorker.AgentWorkerException
Metodo di arresto del worker.

Specified by:
stop in interface Daemon
Throws:
AgentWorker.AgentWorkerException
See Also:
start()

run

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.

Specified by:
run in interface java.lang.Runnable

remove

public void remove()
            throws AgentWorker.AgentWorkerException
Throws:
AgentWorker.AgentWorkerException

go

public void go(PlaceID destination)
        throws CantGoException
Metodo che effettua la migrazione dell'agente.

Questo metodo si interfaccia direttamente al NetworkManager.

Il metodo e' sincronizzato per il cambiamento di stato.

Throws:
CantGoException

idle

public void idle()
L'agente va nello stato IDLE.


kill

public void kill()
Distrugge il worker senza farsi scrupoli di alcun genere.

Attenzione: fa uso di ThreadGroup.stop(), metodo deprecato.


WaitForOtherThreads

public static void WaitForOtherThreads(java.io.PrintStream out)


Copyright © 2004 Luca Foschini