JEgg FAQ


What is an Egg?
Why should I use Eggs?
What kind of messages can an Egg receive?
How is a message handled by an Egg?
Should all of my Java classes be Eggs?
How do I create an Egg?
How are messages sent?
How does an Egg respond to a message?
Can an Egg send messages to more than one Egg at a time?
What is a Message Dispatcher?
What is a Message Port?
What is the Port Locator?
What is an Egg Timer?



What is an Egg?

An Egg is a Java active object that is only supports asynchronous message-based communication instead of synchronous method invocations.

Why should I use Eggs?

To reduce the complexity of your multithreaded code and make it more robust.  An Egg-based application is intrinsically multithreaded, but the threads are hidden since they are only used to dispatch messages. The threads are also decoupled from the eggs, which can be assigned to the same thread or different threads - either way, the egg's implementation doesn't change in any way.  Additionally, since an Egg only has to handle one message at a time, the Egg's code can be written without the use of explicit synchronization so deadlocks are no longer a worry and any race conditions become explicit. 

What kind of messages can an Egg receive?

Any Java object can be passed as a message to any Egg.

How is a message handled by an Egg?

The application-specific Egg implements handler methods for each type of message that it expects to receive.  When the message is delivered to the Egg, it's passed to the most specific handler that matches the message's concrete type, which should be intuitive.

Should all of  my Java classes be Eggs?

No.  Passive objects (containers, utility classes, etc) shouldn't be Eggs.

How do I create an Egg?

Just implement the the jegg.Egg interface, or better yet, extend the class jegg.impl.EggBase class.  See the javadoc for the jegg.* package for more details.

How are messages sent?

Each Egg has a message port.  To send a message to an Egg, get its port, either directly or from the port locator (see later item), and pass the message to the port's send method.  The message will be queued in the Egg's message queue until it's delivered by the message dispatcher (see later item) assigned to the Egg.  By default, messages are sent with a medium priority level, but they can also be sent with a higher or lower priority.  High priority messages are always dispatched before lower priority messages.

How does an Egg respond to a message?

While an Egg is processing a message, information about the message is available from the JEgg framework, including the message port of the Egg that sent the message.  Convenience methods on the EggContext, a special object that each egg has access to, use that information to allow a response object to be transparently sent to the message sender without any special effort in the handler method.

Can an Egg send messages to more than one Egg at a time?

This is called message broadcast, and an Egg can broadcast a message to all Eggs that have explicitly bound to its message port.  A convenience method in the EggContext, bindToPort, allows an Egg to bind to another Egg's port in order to receive broadcast messages from that Egg.

What is a Message Dispatcher?

A message dispatcher is a JEgg framework class that is reponsible for dispatching messages to Eggs.  A dispatcher is assigned to an Egg when the Egg is created, and a dispatcher can be assigned to multiple Eggs.  By default, all Eggs are assigned to the default dispatcher.  However, if a given Egg will potentially take a long time to handle some of its messages, then it should be explicitly assigned to a separate dispatcher. Eggs are assigned to a dispatcher in the application descriptor, which is a special file that you create that enumerates the eggs in your application (see the package documentation for the jegg.* package).

What is a Message Port?

Each Egg has a message port, which is what other Eggs use to send that Egg a message.  There are two ways to get access to an Egg's port:  (1) by specifying a dependency in the application descriptor (see the jegg.* package documentation) or (2) by using the the requestPort method on the EggContext.

What is the Port Locator?

The port locator is a JEgg built-in service that allows the port of an arbitrary egg to be looked up at runtime. See the requestPort method on the EggContext for more details.

What is an Egg Timer?

The JEgg framework includes a special timer that can be used to deliver a timeout message at a specfied time, or periodically. The EggContext includes convenience methods for creating either a single-shot or a repeating timer.