one.world.util
Class AbstractHandler

java.lang.Object
  |
  +--one.world.util.AbstractHandler
All Implemented Interfaces:
EventHandler, Serializable
Direct Known Subclasses:
DatagramIO.BindHandler, DatagramIO.Client, EnvironmentHandler, ExceptionHandler, LeaseMaintainer.Cancel, LeaseManager.Acquire, NetworkIO.BindHandler, NetworkIO.Client, NetworkIO.Client.RevokationHandler, NetworkIO.Server, Operation, PendingRequest, ProxyHandler, Synchronous.ResultHandler, Timer.Notification

public abstract class AbstractHandler
extends Object
implements EventHandler, Serializable

Implementation of an abstract event handler. An abstract event handler provides a skeleton implementation of an event handler as well as utility methods to send events and respond to events.

Version:
$Revision: 1.11 $
See Also:
Serialized Form

Constructor Summary
AbstractHandler()
          Create a new abstract handler.
 
Method Summary
 void handle(Event e)
          Handle the specified event.
protected abstract  boolean handle1(Event e)
          Handle the specified event.
protected  boolean isNotValid(Event e)
          Validate the specified event.
protected  void respond(Event request, Event response)
          Send the specified response to the source of the specified request.
protected  void respond(EventHandler remote, Event request, Event response)
          Remotely send the specified response to the source of the specified request.
protected  void respond(EventHandler remote, Event request, SymbolicHandler source, Throwable x)
          Remotely send an exceptional event to the source of the specified request.
protected  void respond(EventHandler remote, Object closure, Event request, Event response)
          Remotely send the specified response to the source of the specified request.
protected  void respond(EventHandler remote, Object closure, Event request, SymbolicHandler source, Throwable x)
          Remotely send an exceptional event to the source of the specified request.
protected  void respond(Event request, Throwable x)
          Send an exceptional event to the source of the specified request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractHandler

public AbstractHandler()
Create a new abstract handler.
Method Detail

handle

public void handle(Event e)
Handle the specified event. This method invokes handle1() on the specified event. After that, it simply returns for handled events. For unhandled events, it logs exceptional events to the system log and responds with an unknown event exception to the source of the specified event for all other events.
Specified by:
handle in interface EventHandler
Parameters:
e - The event to handle.
See Also:
handle1(one.world.core.Event)

handle1

protected abstract boolean handle1(Event e)
Handle the specified event. A concrete implementation of this method should try to handle the specified event. If it is able to handle the event, it returns true. Otherwise it returns false.

Note that the specified event may not be valid. Event handlers can easily validate an event by using the isNotValid(Event) method.

Parameters:
e - The event to handle.
Returns:
true if the specified event was handled by this method.

isNotValid

protected boolean isNotValid(Event e)
Validate the specified event. This method validates the specified event. If the specified event is valid it returns with false. Otherwise, it responds to the source of the event with an appropriate tuple exception and returns true.
Parameters:
e - The event to validate.
Returns:
true if the specified event is not valid.

respond

protected void respond(Event request,
                       Event response)
Send the specified response to the source of the specified request. Before sending the specified response, this method sets the response's closure to the closure of the request.
Parameters:
request - The request to whose source to respond to.
response - The response.
Throws:
NullPointerException - Signals that either of the specified events is null.

respond

protected void respond(Event request,
                       Throwable x)
Send an exceptional event to the source of the specified request. This method creates a new exceptional event for the specified throwable and sends it to the source of the specified request. The source of the new exceptional event is this event handler and the closure is the request's closure.
Parameters:
request - The request to whose source to respond to.
x - The throwable for the new exceptional event.
Throws:
NullPointerException - Signals that either request or x is null.
See Also:
ExceptionalEvent

respond

protected void respond(EventHandler remote,
                       Event request,
                       Event response)
Remotely send the specified response to the source of the specified request. This method sends a remote event to the specified remote event handler, which asks that the specified response should be sent to the source of the specified request. Before doing so, this method sets the response's closure to the closure of the request. The source of the newly created remote event is this object and the closure is null.
Parameters:
remote - The event handler for processing remote events.
request - The request.
response - The response.
Throws:
NullPointerException - Signals that remote, request, or response is null.
IllegalArgumentException - Signals that request.source is not a symbolic handler.

respond

protected void respond(EventHandler remote,
                       Object closure,
                       Event request,
                       Event response)
Remotely send the specified response to the source of the specified request. This method sends a remote event to the specified remote event handler, which asks that the specified response should be sent to the source of the specified request. Before doing so, this method sets the response's closure to the closure of the request. The source of the newly created remote event is this object.
Parameters:
remote - The event handler for processing remote events.
closure - The closure for the newly created remote event.
request - The request.
response - The response.
Throws:
NullPointerException - Signals that remote, request, or response is null.
IllegalArgumentException - Signals that request.source is not a symbolic handler.

respond

protected void respond(EventHandler remote,
                       Event request,
                       SymbolicHandler source,
                       Throwable x)
Remotely send an exceptional event to the source of the specified request. This method creates a new exceptional event for the specified source and throwable and remotely sends it to the source of the specified request. The source of the newly created remote event is this object and the closure is null.
Parameters:
remote - The event handler for processing remote events.
request - The request.
source - The source for the new exceptional event.
x - The throwable for the new exceptional event.
Throws:
NullPointerException - Signals that remote, request, source, or x is null.
IllegalArgumentException - Signals that request.source or source is not a symbolic handler.
See Also:
ExceptionalEvent

respond

protected void respond(EventHandler remote,
                       Object closure,
                       Event request,
                       SymbolicHandler source,
                       Throwable x)
Remotely send an exceptional event to the source of the specified request. This method creates a new exceptional event for the specified source and throwable and remotely sends it to the source of the specified request. The source of the newly created remote event is this object.
Parameters:
remote - The event handler for processing remote events.
closure - The closure for the newly created remote event.
request - The request.
source - The source for the new exceptional event.
x - The throwable for the new exceptional event.
Throws:
NullPointerException - Signals that remote, request, source, or x is null.
IllegalArgumentException - Signals that request.source or source is not a symbolic handler.
See Also:
ExceptionalEvent


(C) Copyright 2001 UW CSE