ostore.apps.test
Class TapestryHowto

java.lang.Object
  |
  +--ostore.apps.test.TapestryHowto
All Implemented Interfaces:
EventHandlerIF

public class TapestryHowto
extends Object
implements EventHandlerIF

A simple example of how to write your own DD client and message types. The example is as follows. We bring up two machines, a sender and a receiver. The sender sends a Ping message to the receiver, which the receiver acknoledges with a Pong. This happens a number of times, and then the test exits. It's simple, but it covers most of the things you need to know to do more complicated things. Please just read the source, it's well commented.

First off, this class is going to be a SEDA/Sandstorm stage, so it has to inherit from EventHandlerIF.

Version:
$Id: TapestryHowto.java,v 1.15 2004/05/13 19:42:42 hweather Exp $
Author:
Sean C. Rhea

Nested Class Summary
static class TapestryHowto.Ping
          One of two DD messages used in this test.
static class TapestryHowto.Pong
          This class is identical in all by type from the Ping class above, so I'm not going to comment it further.
 
Constructor Summary
TapestryHowto()
           
 
Method Summary
 void destroy()
          Sandstorm calls this function when it unloads your stage, which to my knowledge, it never does.
 void handleEvent(QueueElementIF item)
          This is the function that will be called when a stage dispatches a message that we've subscribed to.
 void handleEvents(QueueElementIF[] items)
          If Sandstorm has more than one event waiting for this stage, it will call this function instead of handleEvent.
 void init(ConfigDataIF config)
          Initializes the stage once Sandstorm is up and running.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TapestryHowto

public TapestryHowto()
Method Detail

init

public void init(ConfigDataIF config)
          throws Exception
Initializes the stage once Sandstorm is up and running.

You'll notice that most stages won't have constructors. The reason is that all initialization can take place here, where you have the information from your stage's config file to help you. I'll detail the important things you want to do in this function below.

Specified by:
init in interface EventHandlerIF
Exception

handleEvent

public void handleEvent(QueueElementIF item)
                 throws EventHandlerException
This is the function that will be called when a stage dispatches a message that we've subscribed to.

Specified by:
handleEvent in interface EventHandlerIF
EventHandlerException

handleEvents

public void handleEvents(QueueElementIF[] items)
                  throws EventHandlerException
If Sandstorm has more than one event waiting for this stage, it will call this function instead of handleEvent. If you wanted to get fancy, you could do something like sorting these events based on priority before handling them.

Specified by:
handleEvents in interface EventHandlerIF
EventHandlerException

destroy

public void destroy()
             throws Exception
Sandstorm calls this function when it unloads your stage, which to my knowledge, it never does. I think it's safe to ignore it completely.

Specified by:
destroy in interface EventHandlerIF
Exception