org.kaariboga.core
Class Kaariboga

java.lang.Object
  |
  +--org.kaariboga.core.Kaariboga
All Implemented Interfaces:
KbMessageHandler, java.lang.Runnable, java.io.Serializable
Direct Known Subclasses:
BillyTheBit, Counter, Executer, HelloAgent, HelloDomain, HelloPlugInAgent, HelloTraveler, KbPlugIn, MessageReceiver, MessageSender, Reproducer, ReturnAgent, ServerLister

public class Kaariboga
extends java.lang.Object
implements java.lang.Runnable, java.io.Serializable, KbMessageHandler

The Kaariboga class implements the base class of a mobile agent. It is able to jump from host to host and runs there in it's own thread. Each kaariboga needs a KaaribogaBase object that handles it's requests and sends and receives it.

See Also:
Serialized Form

Inner Class Summary
(package private)  class Kaariboga.FireEventThread
          Fires kaariboga events to the kaaribogaListener.
(package private)  class Kaariboga.FireMessageThread
          Fires KaaribogaMessage to the kaaribogaMessageListener.
 
Field Summary
protected  KaaribogaBase base
          The base is the KaaribogaBase that hosts the kaariboga.
protected  KaaribogaAddress destination
          This is the destination the kaariboga wants to be transfered next.
protected  KaaribogaListener kaaribogaListener
          The event listener that receives all KaaribogaEvents.
protected  KaaribogaMessageListener messageListener
          The message listener that receives all KaaribogaMessages.
private  java.lang.String name
          This is simply the name of the agent.
 
Constructor Summary
Kaariboga(java.lang.String name)
          Constructs a new agent with it's name.
 
Method Summary
 void addKaaribogaListener(KaaribogaListener l)
          Adds the event listener for kaariboga events.
 void addKaaribogaMessageListener(KaaribogaMessageListener l)
          Adds the message listener for kaariboga messages.
protected  void fireDestroyRequest()
          Fires a destroy request to the kaaribogaListener.
protected  void fireDispatchRequest()
          Fires a dispatch request to the kaaribogaListener.
protected  void fireKaaribogaMessage(KaaribogaMessage m)
          Fires a message to the kaaribogaMessageListener.
protected  void fireSleepRequest()
          Fires a sleep request to the kaaribogaListener.
 KaaribogaAddress getDestination()
          Gets the destination the kaariboga is going to be transfered next.
 java.lang.String getName()
          Returns the name of this agent.
 void handleMessage(KaaribogaMessage msg)
          Handles all kinds of kaariboga messages.
 void onArrival()
          This is called when the kaariboga arrives on a new base.
 void onAwake()
          Called when the kaariboga is waked up again.
 void onCreate()
          This function is called on the first creation of the kaariboga.
 void onDestroy()
          This is called before the kaariboga is destroyed by the base.
 void onDispatch()
          This is called before the kaariboga is going to be dispatched to a new location.
 void onSleep()
          Called before the kaariboga is send to sleep, maybe because it is going to be saved on a disk or just to save computation time.
 void run()
          Run is the main method of the kaariboga thread.
 void setBase(KaaribogaBase b)
          This is called by the base if a new kaariboga is created or received.
 java.lang.String toString()
          Prints out an agents String representation.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

base

protected transient KaaribogaBase base
The base is the KaaribogaBase that hosts the kaariboga. A kaariboga can only live on a base.

name

private java.lang.String name
This is simply the name of the agent.

destination

protected KaaribogaAddress destination
This is the destination the kaariboga wants to be transfered next. It is read by the base through the getDestination() method.

kaaribogaListener

protected transient KaaribogaListener kaaribogaListener
The event listener that receives all KaaribogaEvents. It is normally set by the base on arrival.

messageListener

protected transient KaaribogaMessageListener messageListener
The message listener that receives all KaaribogaMessages. It is normally set by the base on arrival.
Constructor Detail

Kaariboga

public Kaariboga(java.lang.String name)
Constructs a new agent with it's name. The name must be unique, because it is used to administrate agents on the server.
Parameters:
name - The name of the agent. The Base class provides a method to generate a unique name.
Method Detail

run

public void run()
Run is the main method of the kaariboga thread. It is called by the kaariboga base if it receives or creates a new Kaariboga object.
Specified by:
run in interface java.lang.Runnable

setBase

public final void setBase(KaaribogaBase b)
This is called by the base if a new kaariboga is created or received. A kaariboga can only exist on base.
Parameters:
b - The KaaribogaBase that hosts the agent.

getName

public java.lang.String getName()
Returns the name of this agent.

onCreate

public void onCreate()
This function is called on the first creation of the kaariboga. At this time the base is already set.

onDestroy

public void onDestroy()
This is called before the kaariboga is destroyed by the base.

onArrival

public void onArrival()
This is called when the kaariboga arrives on a new base.

onDispatch

public void onDispatch()
This is called before the kaariboga is going to be dispatched to a new location.

onSleep

public void onSleep()
Called before the kaariboga is send to sleep, maybe because it is going to be saved on a disk or just to save computation time.

onAwake

public void onAwake()
Called when the kaariboga is waked up again.

handleMessage

public void handleMessage(KaaribogaMessage msg)
Handles all kinds of kaariboga messages. Note that messages can contain arbitrary contents. So you can handle your own set of messages for different kinds of agents.
Specified by:
handleMessage in interface KbMessageHandler

fireDispatchRequest

protected void fireDispatchRequest()
Fires a dispatch request to the kaaribogaListener. Before the event is fired the destination must be set. This event is fired if the kaariboga wants to be send to another base.

fireDestroyRequest

protected void fireDestroyRequest()
Fires a destroy request to the kaaribogaListener. The kaariboga fires a destroy request if it wants to be destroyed, usually when it's work has been done.

fireSleepRequest

protected void fireSleepRequest()
Fires a sleep request to the kaaribogaListener. The sleep request is inteded to be send if the kaariboga wants to be out of action for a longer period of time.

fireKaaribogaMessage

protected void fireKaaribogaMessage(KaaribogaMessage m)
Fires a message to the kaaribogaMessageListener. A message is fired if the kaariboga agents wants to get into contact with another agent or to retrieve information from servers.

getDestination

public KaaribogaAddress getDestination()
Gets the destination the kaariboga is going to be transfered next.

addKaaribogaListener

public void addKaaribogaListener(KaaribogaListener l)
Adds the event listener for kaariboga events. At the moment a kaariboga can only have one event listener.
Parameters:
l - The KaaribogaEventListener that listens to kaariboga events from this agent, usually the base.

addKaaribogaMessageListener

public void addKaaribogaMessageListener(KaaribogaMessageListener l)
Adds the message listener for kaariboga messages. At the moment a kaariboga can only have one message listener.
Parameters:
l - The KaaribogaMessageListener that listens to kaariboga messages from this agent, usually the base.

toString

public java.lang.String toString()
Prints out an agents String representation.
Overrides:
toString in class java.lang.Object