jegg
Interface EggContext

All Known Implementing Classes:
EggContextImpl

public interface EggContext

The execution context of an egg. This class mainly provides a set of methods that are useful during the handling of a message.


Method Summary
 void bindToPort(Port p)
          Bind this egg to the specified port which belongs to another egg.
 Message createMessage(java.lang.Object m)
          Create a message at the default priority that is ready to be directly written to a message port.
 Message createMessage(java.lang.Object m, Priority p)
          Create a message at the specified priority that is ready to be directly written to a message port.
 Timer createRepeatingTimer(long interval_msec, long delay_msec)
          Create a timer that will periodically send timeout messages to this egg.
 Timer createSingleShotTimer(long delay_msec)
          Create a timer that will send a single timeout message to this egg.
 Message getCurrentMessage()
          Return the message wrapper of the application message that is currently being handled.
 Dispatcher getDispatcher()
          Return the dispatcher that this egg is assigned to.
 Port getFromPort()
          Return the port of the egg that sent the application message that is currently being handled.
 java.lang.Object getId()
          Return the ID of this egg as assigned to it in the application descriptor.
 java.lang.Class[] getInterface()
          Return the set of message types that this egg recognizes.
 Port getPort()
          Return this egg's message port.
 Property[] getProperties()
          Return all of the properties configured on this egg in the application descriptor.
 java.lang.String getProperty(java.lang.String key)
          Return a property configured on this egg in the application descriptor.
 java.lang.String getProperty(java.lang.String key, java.lang.String defValue)
          Return a property configured on this egg in the application descriptor.
 void publishPort(java.lang.String n)
          Publish this egg's message port in the JEgg framework registry.
 void requestPort(java.lang.String n)
          Request a lookup of a message port in the JEgg framework registry.
 void respond(java.lang.Object message)
          Send a message to the egg that sent the current message.
 void respond(java.lang.Object message, Priority priority)
          Send a message to the egg that sent the current message.
 void respond(Port port, java.lang.Object message)
          Send a message to the egg that the specified port belongs to.
 void respond(Port port, java.lang.Object message, Priority priority)
          Send a message to the egg that the specified port belongs to.
 void send(java.lang.Object msg)
          Broadcast a message to all eggs that have bound to this egg's port (see bindToPort).
 

Method Detail

getProperty

public java.lang.String getProperty(java.lang.String key)
Return a property configured on this egg in the application descriptor.

Parameters:
key - the name of the property.
Returns:
the value of the property or null if the property can't be found.

getProperty

public java.lang.String getProperty(java.lang.String key,
                                    java.lang.String defValue)
Return a property configured on this egg in the application descriptor. If the property can't be found, then a specified default will be returned.

Parameters:
key - the name of the property.
defValue - the value to return if the property can't be found.
Returns:
the value of the property or the specified default.

getProperties

public Property[] getProperties()
Return all of the properties configured on this egg in the application descriptor.

Returns:
non-null array of properties that may be empty.

bindToPort

public void bindToPort(Port p)
Bind this egg to the specified port which belongs to another egg. After the binding, this egg will receive all messages that the other egg broadcasts.

Parameters:
p - the port to bind to in order to receive all broadcast message from the egg that owns the port.

createMessage

public Message createMessage(java.lang.Object m)
Create a message at the default priority that is ready to be directly written to a message port. Usually it is not necessary to call this method since the send method accepts the object message to send and internally wraps it in a message instance.

Parameters:
m - the application message to wrap.
Returns:
the wrapped application message.

createMessage

public Message createMessage(java.lang.Object m,
                             Priority p)
Create a message at the specified priority that is ready to be directly written to a message port.

Parameters:
m - the application message to wrap.
p - the priority to assign to the message.
Returns:
the wrapped application message.

createRepeatingTimer

public Timer createRepeatingTimer(long interval_msec,
                                  long delay_msec)
Create a timer that will periodically send timeout messages to this egg.

Parameters:
interval_msec - the interval, in milliseconds, at which the timeout messages should be sent.
delay_msec - the initial delay, in milliseconds, before the first timeout should be sent.
Returns:

createSingleShotTimer

public Timer createSingleShotTimer(long delay_msec)
Create a timer that will send a single timeout message to this egg.

Parameters:
delay_msec - the initial delay, in milliseconds, before the timeout is sent.
Returns:

getCurrentMessage

public Message getCurrentMessage()
Return the message wrapper of the application message that is currently being handled.

Returns:
the current message or null if a message is not being handled.

getDispatcher

public Dispatcher getDispatcher()
Return the dispatcher that this egg is assigned to.

Returns:
the dispatcher for this egg.

getFromPort

public Port getFromPort()
Return the port of the egg that sent the application message that is currently being handled.

Returns:
the sending egg's message port.

getId

public java.lang.Object getId()
Return the ID of this egg as assigned to it in the application descriptor.

Returns:
this egg's message ID.

getInterface

public java.lang.Class[] getInterface()
Return the set of message types that this egg recognizes. Each class object represents a handle method on this egg that takes that type as an argument.

Returns:
array of class objects, one for each message type that this egg recognizes.

getPort

public Port getPort()
Return this egg's message port.

Returns:
this egg's message port.

publishPort

public void publishPort(java.lang.String n)
Publish this egg's message port in the JEgg framework registry.

Parameters:
n - the name that the message port should be published under.

requestPort

public void requestPort(java.lang.String n)
Request a lookup of a message port in the JEgg framework registry. If found, the port will be delivered to the handle method that takes a port instance. If the port is not registered at the time that the port registry receives this request, the registry will retain the request information and notify the requesting egg once the port has been registered.

Parameters:
n - the name that the requested port is expected to be registered under.

respond

public void respond(java.lang.Object message)
Send a message to the egg that sent the current message. The message will be sent with a medium priority level assigned to it.

Parameters:
message - the message to send to the sending egg.

respond

public void respond(java.lang.Object message,
                    Priority priority)
Send a message to the egg that sent the current message. The message will be sent with the specified priority level assigned to it.

Parameters:
message - the message to send to the sending egg.
priority - the priority to assign to the message.

respond

public void respond(Port port,
                    java.lang.Object message)
Send a message to the egg that the specified port belongs to. This method is useful when a message response has to be delayed until later (so the port is saved for use later). The message will be sent with a medium priority level assigned to it.

Parameters:
port - the port to send the message on.
message - the message to send to the egg that the specified port belongs to.

respond

public void respond(Port port,
                    java.lang.Object message,
                    Priority priority)
Send a message to the egg that the specified port belongs to. This method is useful when a message response has to be delayed until later (so the port is saved for use later). The message will be sent with the specified priority level assigned to it.

Parameters:
port - the port to send the message on.
message - the message to send to the egg that the specified port belongs to.
priority - the message's priority assignment.

send

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