Valescom Java API

com.valescom.support.event.java
Class EventHandler

java.lang.Object
  |
  +--com.valescom.support.event.java.EventHandler
Direct Known Subclasses:
PingedHandler, PingHandler, StoredHandler, StoreHandler, Timer

public abstract class EventHandler
extends Object

Responsibility:
Handling Events based on a Subscription.
Behaviour:
The handle method is called when an Event matching the Subscription is published.
If a handler is created using an Event then its subscription is based upon the Categories it contains.
States:
Started, the EventHandler is ready to handle the Event.
Stopped, the EventHandler is not ready to handle the Event.
Usage:

// remote event handler
EventHandler myHandler1 = new EventHandler(new Expression(
    "class = 'com.valescom.support.event.java.RemoteEvent'"),
    true)
{
    public final void
    handle(Event anEvent)
    {
        // do something
    }
};
myHandler1.start();
// local event handler
Event myEvent = new LocalEvent();
EventHandler myHandler2 = new EventHandler(myEvent)
// myEvent categories are used as a subscription
{
    public final void
    handle(Event anEvent)
    {
        // do something
    }
};
myHandler2.start();

See Also:
Handler, EventManager
 

Constructor Summary
protected EventHandler(Event anEvent)
          Construct an EventHandler instance for anEvent Pre conditions: anEvent may not be null.
protected EventHandler(Subscription aSubscription)
          Construct a EventHandler instance for aSubscription.
protected EventHandler(Subscription aSubscription, boolean aRemote)
          Construct a EventHandler instance for aSubscription and aRemote.
 
Method Summary
 long delay()
          Before an EventHandler is handled by the EventDispatcher, the delay is set.
abstract  void handle(Event anEvent)
          Override this method if you want to implement a handler that does something with the handled event.
 boolean isStarted()
          Indicates whether this EventHandler is started or not.
 void start()
          Start this EventHandler if it has not already been started.
 void stop()
          Stop this EventHandler if it has not already been stopped.
 Subscription subscription()
          Returns the subscription for which this is a EventHandler.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EventHandler

protected EventHandler(Subscription aSubscription,
                       boolean aRemote)
Construct a EventHandler instance for aSubscription and aRemote.

Pre conditions:
aSubscription may not be null.

Parameters:
aSubscription - The subscription for which to create a EventHandler.
aRemote - The remote indicating whether the subscription should be send remote or not.

EventHandler

protected EventHandler(Subscription aSubscription)
Construct a EventHandler instance for aSubscription.

Pre conditions:
aSubscription may not be null.

Parameters:
aSubscription - The subscription for which to create a EventHandler.

EventHandler

protected EventHandler(Event anEvent)
Construct an EventHandler instance for anEvent

Pre conditions:
anEvent may not be null.

Parameters:
anEvent - The event for which to create a EventHandler.
Method Detail

isStarted

public boolean isStarted()
Indicates whether this EventHandler is started or not.

Pre conditions:
theHandler may not be null.

Returns:
true if started, otherwise false.

start

public void start()
Start this EventHandler if it has not already been started.

Pre conditions:
theHandler may not be null.


stop

public void stop()
Stop this EventHandler if it has not already been stopped.

Pre conditions:
theHandler may not be null.


delay

public long delay()
Before an EventHandler is handled by the EventDispatcher, the delay is set. This way, inside the handle() method, an application has a notice of the delay of the event (The HandleTime - PublicationTime).

Pre conditions:
theHandler may not be null.


subscription

public Subscription subscription()
Returns the subscription for which this is a EventHandler.

Pre conditions:
theHandler may not be null.

Returns:
The subscription.

handle

public abstract void handle(Event anEvent)
Override this method if you want to implement a handler that does something with the handled event.

Pre conditions:
anEvent may not be null.

Parameters:
anEvent - The event to handle.

Valescom Java API

Copyright 1998, 2003 - Valescom