jegg.impl
Class EggShell

java.lang.Object
  extended byjegg.impl.EggShell

public class EggShell
extends java.lang.Object

Base class for implementing an egg. Concrete classes that extend this class will be plugged into the JEgg framework and be able to send and receive arbitrary messages. The Egg base class also provides convenience methods for the following:

The default constructor will assign this egg to the default thread. Use the constructor that takes a Dispatcher in order to assign the egg to a specific thread.

The derived class should implement handlers for the message types that it expects to receive. A message handler is implemented by overloading the handle method with a version that accepts the expected message type. When the derived class is loaded, the handle methods are reflected and cached in a lookup table to improve the message delivery performance.

The message dispatcher assigned to the egg will only deliver one message at a time to the Egg subclass. If an egg is expected to take a long time to process some messages, then it should be assigned its own dispatcher (see above).

Messages are dispatched to an egg according to their priority, in the order they were sent. So, a more recent message with a high priority can be delivered to the egg before a message that was sent earlier but with a lower priority.


Constructor Summary
EggShell(java.lang.Object id, Egg h)
          Construct an egg that dispatches messages to a user-supplied message handler using a specific message dispatcher.
EggShell(java.lang.Object id, Egg h, Dispatcher d)
           
 
Method Summary
 void assignTo(Dispatcher d)
           
 java.lang.Class[] getInterface()
          Return the message types that this egg will handle.
 Port getPort()
          Return the port used to deliver messages to this egg.
protected  void send(java.lang.Object msg)
          Broadcast a message to all eggs that have bound to this egg's port (see bindToPort).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EggShell

public EggShell(java.lang.Object id,
                Egg h)
Construct an egg that dispatches messages to a user-supplied message handler using a specific message dispatcher.

Parameters:
id - a unique object that can be used to identify this egg. The name should be unique among the eggs instantiated in the JVM.
h - a user-supplied message handler.
Throws:
java.lang.IllegalArgumentException - if any argument is null.

EggShell

public EggShell(java.lang.Object id,
                Egg h,
                Dispatcher d)
Method Detail

assignTo

public void assignTo(Dispatcher d)

getInterface

public final java.lang.Class[] getInterface()
Return the message types that this egg will handle.

Returns:
array of class objects. Each element in the array is a type for which this egg has a specific handler method.

getPort

public final Port getPort()
Return the port used to deliver messages to this egg.

Returns:
this egg's message port.

send

protected final void send(java.lang.Object msg)
Broadcast a message to all eggs that have bound to this egg's port (see bindToPort).



Copyright © 2004 . All Rights Reserved.