@InterfaceAudience.Private public abstract class EventHandler extends Object implements Runnable, Comparable<Runnable>
process()
and prepare()
methods. Subclasses
should also do all necessary checks up in their prepare() 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 EventType
.
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.
ExecutorService
Modifier and Type | Field and Description |
---|---|
protected EventType |
eventType |
private static org.slf4j.Logger |
LOG |
private org.apache.htrace.core.Span |
parent |
private long |
seqid |
protected static AtomicLong |
seqids |
protected Server |
server |
protected int |
waitingTimeForEvents |
Constructor and Description |
---|
EventHandler(Server server,
EventType eventType)
Default base class constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Runnable o)
Default prioritized runnable comparator which implements a FIFO ordering.
|
EventType |
getEventType()
Return the event type
|
String |
getInformativeName()
Event implementations should override thie class to provide an
informative name about what event they are handling.
|
int |
getPriority()
Get the priority level for this handler instance.
|
long |
getSeqid() |
protected void |
handleException(Throwable t)
Event exception handler, may be overridden
|
EventHandler |
prepare()
Event handlers should do all the necessary checks in this method (rather than
in the constructor, or in process()) so that the caller, which is mostly executed
in the ipc context can fail fast.
|
abstract void |
process()
This method is the main processing loop to be implemented by the various
subclasses.
|
void |
run() |
String |
toString() |
private static final org.slf4j.Logger LOG
protected static final AtomicLong seqids
private final long seqid
protected int waitingTimeForEvents
private final org.apache.htrace.core.Span parent
public EventHandler(Server server, EventType eventType)
public EventHandler prepare() throws Exception
Exception
- when something goes wrongpublic abstract void process() throws IOException
IOException
public EventType getEventType()
public int getPriority()
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.
public long getSeqid()
public int compareTo(Runnable o)
Subclasses should not override this. Instead, if they want to implement
priority beyond FIFO, they should override getPriority()
.
compareTo
in interface Comparable<Runnable>
public String getInformativeName()
protected void handleException(Throwable t)
t
- Throwable objectCopyright © 2007–2019 The Apache Software Foundation. All rights reserved.