org.apache.hadoop.hbase.executor
Class EventHandler

java.lang.Object
  extended by org.apache.hadoop.hbase.executor.EventHandler
All Implemented Interfaces:
Comparable<Runnable>, Runnable
Direct Known Subclasses:
ClosedRegionHandler, CloseRegionHandler, DisableTableHandler, EnableTableHandler, OpenedRegionHandler, OpenRegionHandler, ServerShutdownHandler, TableEventHandler

public abstract class EventHandler
extends Object
implements Runnable, Comparable<Runnable>

Abstract base class for all HBase event handlers. Subclasses should implement the process() method. Subclasses should also do all necessary checks up in their constructor if possible -- check table exists, is disabled, etc. -- so they fail fast rather than later when process is running. Do it this way because process be invoked directly but event handlers are also run in an executor context -- i.e. asynchronously -- and in this case, exceptions thrown at process time will not be seen by the invoker, not till we implement a call-back mechanism so the client can pick them up later.

Event handlers have an EventHandler.EventType. EventHandler.EventType is a list of ALL handler event types. We need to keep a full list in one place -- and as enums is a good shorthand for an implemenations -- because event handlers can be passed to executors when they are to be run asynchronously. The hbase executor, see ExecutorService, has a switch for passing event type to executor.

Event listeners can be installed and will be called pre- and post- process if this EventHandler is run in a Thread (its a Runnable so if its run() method gets called). Implement EventHandler.EventHandlerListeners, and registering using setListener(EventHandlerListener).

See Also:
ExecutorService

Nested Class Summary
static interface EventHandler.EventHandlerListener
          This interface provides pre- and post-process hooks for events.
static class EventHandler.EventType
          List of all HBase event handler types.
 
Field Summary
protected  EventHandler.EventType eventType
           
protected static AtomicLong seqids
           
protected  Server server
           
protected  int waitingTimeForEvents
           
 
Constructor Summary
EventHandler(Server server, EventHandler.EventType eventType)
          Default base class constructor.
 
Method Summary
 int compareTo(Runnable o)
          Default prioritized runnable comparator which implements a FIFO ordering.
 EventHandler.EventType getEventType()
          Return the event type
 EventHandler.EventHandlerListener getListener()
           
 int getPriority()
          Get the priority level for this handler instance.
 long getSeqid()
           
abstract  void process()
          This method is the main processing loop to be implemented by the various subclasses.
 void run()
           
 void setListener(EventHandler.EventHandlerListener listener)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

eventType

protected EventHandler.EventType eventType

server

protected Server server

seqids

protected static AtomicLong seqids

waitingTimeForEvents

protected final int waitingTimeForEvents
Constructor Detail

EventHandler

public EventHandler(Server server,
                    EventHandler.EventType eventType)
Default base class constructor.

Method Detail

run

public void run()
Specified by:
run in interface Runnable

process

public abstract void process()
                      throws IOException
This method is the main processing loop to be implemented by the various subclasses.

Throws:
IOException

getEventType

public EventHandler.EventType getEventType()
Return the event type

Returns:
The event type.

getPriority

public int getPriority()
Get the priority level for this handler instance. This uses natural ordering so lower numbers are higher priority.

Lowest priority is Integer.MAX_VALUE. Highest priority is 0.

Subclasses should override this method to allow prioritizing handlers.

Handlers with the same priority are handled in FIFO order.

Returns:
Integer.MAX_VALUE by default, override to set higher priorities

getSeqid

public long getSeqid()
Returns:
This events' sequence id.

compareTo

public int compareTo(Runnable o)
Default prioritized runnable comparator which implements a FIFO ordering.

Subclasses should not override this. Instead, if they want to implement priority beyond FIFO, they should override getPriority().

Specified by:
compareTo in interface Comparable<Runnable>

getListener

public EventHandler.EventHandlerListener getListener()
Returns:
Current listener or null if none set.

setListener

public void setListener(EventHandler.EventHandlerListener listener)
Parameters:
listener - Listener to call pre- and post- process().


Copyright © 2011 The Apache Software Foundation. All Rights Reserved.