jegg.impl
Class EggContextImpl

java.lang.Object
  extended byjegg.impl.EggContextImpl
All Implemented Interfaces:
EggContext

public class EggContextImpl
extends java.lang.Object
implements EggContext

Author:
Bruce Lowery

Constructor Summary
EggContextImpl(EggShell e)
           
 
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).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EggContextImpl

public EggContextImpl(EggShell e)
Method Detail

getProperty

public java.lang.String getProperty(java.lang.String key)
Description copied from interface: EggContext
Return a property configured on this egg in the application descriptor.

Specified by:
getProperty in interface EggContext
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)
Description copied from interface: EggContext
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.

Specified by:
getProperty in interface EggContext
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()
Description copied from interface: EggContext
Return all of the properties configured on this egg in the application descriptor.

Specified by:
getProperties in interface EggContext
Returns:
non-null array of properties that may be empty.

bindToPort

public final void bindToPort(Port p)
Description copied from interface: EggContext
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.

Specified by:
bindToPort in interface EggContext
Parameters:
p - the port to bind to in order to receive all broadcast message from the egg that owns the port.

createMessage

public final Message createMessage(java.lang.Object m)
Description copied from interface: EggContext
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.

Specified by:
createMessage in interface EggContext
Parameters:
m - the application message to wrap.
Returns:
the wrapped application message.

createMessage

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

Specified by:
createMessage in interface EggContext
Parameters:
m - the application message to wrap.
p - the priority to assign to the message.
Returns:
the wrapped application message.

createRepeatingTimer

public final Timer createRepeatingTimer(long interval_msec,
                                        long delay_msec)
Description copied from interface: EggContext
Create a timer that will periodically send timeout messages to this egg.

Specified by:
createRepeatingTimer in interface EggContext
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 final Timer createSingleShotTimer(long delay_msec)
Description copied from interface: EggContext
Create a timer that will send a single timeout message to this egg.

Specified by:
createSingleShotTimer in interface EggContext
Parameters:
delay_msec - the initial delay, in milliseconds, before the timeout is sent.
Returns:

getCurrentMessage

public final Message getCurrentMessage()
Description copied from interface: EggContext
Return the message wrapper of the application message that is currently being handled.

Specified by:
getCurrentMessage in interface EggContext
Returns:
the current message or null if a message is not being handled.

getDispatcher

public final Dispatcher getDispatcher()
Description copied from interface: EggContext
Return the dispatcher that this egg is assigned to.

Specified by:
getDispatcher in interface EggContext
Returns:
the dispatcher for this egg.

getFromPort

public final Port getFromPort()
Description copied from interface: EggContext
Return the port of the egg that sent the application message that is currently being handled.

Specified by:
getFromPort in interface EggContext
Returns:
the sending egg's message port.

getId

public final java.lang.Object getId()
Description copied from interface: EggContext
Return the ID of this egg as assigned to it in the application descriptor.

Specified by:
getId in interface EggContext
Returns:
this egg's message ID.

getInterface

public final java.lang.Class[] getInterface()
Description copied from interface: EggContext
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.

Specified by:
getInterface in interface EggContext
Returns:
array of class objects, one for each message type that this egg recognizes.

getPort

public final Port getPort()
Description copied from interface: EggContext
Return this egg's message port.

Specified by:
getPort in interface EggContext
Returns:
this egg's message port.

publishPort

public final void publishPort(java.lang.String n)
Description copied from interface: EggContext
Publish this egg's message port in the JEgg framework registry.

Specified by:
publishPort in interface EggContext
Parameters:
n - the name that the message port should be published under.

requestPort

public final void requestPort(java.lang.String n)
Description copied from interface: EggContext
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.

Specified by:
requestPort in interface EggContext
Parameters:
n - the name that the requested port is expected to be registered under.

respond

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

Specified by:
respond in interface EggContext
Parameters:
message - the message to send to the sending egg.

respond

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

Specified by:
respond in interface EggContext
Parameters:
message - the message to send to the sending egg.
priority - the priority to assign to the message.

respond

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

Specified by:
respond in interface EggContext
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 final 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.

Specified by:
respond in interface EggContext
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 final void send(java.lang.Object msg)
Broadcast a message to all eggs that have bound to this egg's port (see bindToPort).

Specified by:
send in interface EggContext


Copyright © 2004 . All Rights Reserved.