public abstract class WebPoller
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
WebPoller.Factory |
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_ERROR_COUNT_THRESHOLD
The number of error before the poller is marked as failed.
|
static int |
DEFAULT_INTER_ERROR_DURATION
The duration between attempts when in error.
|
static int |
DEFAULT_INTER_REQUEST_DURATION
The duration between polls when not using long polling.
|
| Constructor and Description |
|---|
WebPoller() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
deregister(WebPoller.Factory factory) |
protected void |
doPoll()
Perform actual polling.
|
protected void |
doStart()
Sub-classes should override this method to provide functionality.
|
protected void |
doStop()
Sub-classes should override this method to provide functionality.
|
int |
getErrorCountThreshold() |
int |
getInterErrorDuration() |
int |
getInterRequestDuration() |
java.util.logging.Level |
getLogLevel() |
protected RequestContext |
getRequestContext() |
RequestFactory |
getRequestFactory() |
protected void |
incErrorCount() |
boolean |
inError() |
boolean |
isActive() |
protected boolean |
isInPoll() |
boolean |
isPaused() |
protected abstract boolean |
isTimerActive()
Return true if the timer or the error timer is active.
|
static WebPoller |
newWebPoller() |
protected void |
onEmptyPollResult()
Invoked after a successful poll returning no data.
|
protected void |
onError(java.lang.Throwable exception)
Fire an Error event.
|
protected void |
onMessage(java.util.Map<java.lang.String,java.lang.String> context,
java.lang.String data)
Fire a Message event.
|
protected void |
onStart()
Fire a Start event.
|
protected void |
onStop()
Fire a Stop event.
|
void |
pause()
Pause the active poller.
|
protected void |
poll()
Orchestrate the polling.
|
protected void |
pollReturned()
This should be invoked when the poll has completed.
|
static void |
register(WebPoller.Factory factory) |
protected void |
resetErrorState()
Invoked after a successful poll, regardless of whether data was received or not.
|
void |
resume()
Resume an already paused poller.
|
void |
setErrorCountThreshold(int errorCountThreshold)
Set the number of errors before poller is stopped.
|
void |
setInterErrorDuration(int interErrorDuration) |
void |
setInterRequestDuration(int interRequestDuration) |
void |
setListener(WebPollerListener listener) |
void |
setLogLevel(java.util.logging.Level logLevel) |
void |
setRequestFactory(RequestFactory requestFactory) |
void |
start()
Start polling.
|
protected abstract void |
startErrorTimer() |
protected abstract void |
startTimer()
Start the timer that triggers the polling.
|
void |
stop()
Stop polling.
|
protected abstract void |
stopErrorTimer() |
protected abstract void |
stopTimer()
Stop the timer that is triggering the polling if any exists.
|
public static final int DEFAULT_INTER_REQUEST_DURATION
public static final int DEFAULT_INTER_ERROR_DURATION
public static final int DEFAULT_ERROR_COUNT_THRESHOLD
public static WebPoller newWebPoller()
public static void register(@Nonnull
WebPoller.Factory factory)
public static boolean deregister(@Nonnull
WebPoller.Factory factory)
public java.util.logging.Level getLogLevel()
public void setLogLevel(java.util.logging.Level logLevel)
public boolean isActive()
public boolean inError()
public void start()
throws java.lang.IllegalStateException
java.lang.IllegalStateException - if the poller is already active.public void stop()
throws java.lang.IllegalStateException
java.lang.IllegalStateException - if the poller is not active.public void setRequestFactory(@Nullable
RequestFactory requestFactory)
public final RequestFactory getRequestFactory()
public final int getErrorCountThreshold()
public void setErrorCountThreshold(int errorCountThreshold)
public final int getInterRequestDuration()
public final void setInterRequestDuration(int interRequestDuration)
public int getInterErrorDuration()
public void setInterErrorDuration(int interErrorDuration)
public void setListener(@Nullable
WebPollerListener listener)
public void pause()
java.lang.IllegalStateException - if poller is not active or poller is already pausedpublic void resume()
java.lang.IllegalStateException - if poller is not active or poller is not paused.public boolean isPaused()
protected final void doStop()
protected abstract void stopTimer()
protected abstract boolean isTimerActive()
protected final void doStart()
protected abstract void startErrorTimer()
protected abstract void stopErrorTimer()
protected abstract void startTimer()
protected final void onEmptyPollResult()
protected void resetErrorState()
protected final void onStart()
protected final void onStop()
protected final void onMessage(@Nonnull
java.util.Map<java.lang.String,java.lang.String> context,
@Nonnull
java.lang.String data)
protected final void onError(@Nonnull
java.lang.Throwable exception)
protected void incErrorCount()
protected boolean isInPoll()
protected void pollReturned()
protected void poll()
protected final RequestContext getRequestContext()
protected void doPoll()