Package sunlabs.brazil.handler
Class PollHandler
java.lang.Object
java.lang.Thread
sunlabs.brazil.handler.PollHandler
- Direct Known Subclasses:
RePollHandler
Handler for periodically polling another web site, whose
results are (optionally) added to the server's properties.
This also includes the ability to request URL's on a cron-like schedule.
The result of fetching the url is expected to be a text document in java Properties format.
Properties:
- url
- URL to fetch periodically. any ${...} constructs are evaluated at each poll, with the values in the server properties object. If the URL starts with "/", then the current server is used.
- post
- The "post" data, if any. ${...} are evaluates as per
url
above. - headers
- A list of white space delimited tokens that refer to
additional HTTP headers that are added onto the polled
request. For each token the server properties
[token].name
and[token].value
define a new http header. - interval
- The interval (in seconds) to fetch the url. Defaults to 10 seconds. If match is specified, this is the interval used to check for a time/date match. At each "interval", the current time format is computed, based on "format", below. If the computed format has not changed since the previous poll, then no poll is done. The interval is recalculated after each poll.
- fast
- If set, don't wait "interval" before 1st poll.
- prepend
- The string to prepend to the properties. If not supplied no properties are loaded.
- namespace
- The namespace to use to store the properties to.
If the
sessionTable
(see below)parameter is identical to thesessionTable
parameter of theSetTemplate
, then this specifies thenamespace
parameter that may be used with theSetTemplate
"namespace" parameter to obtain the extracted data. Defaults to the "prepend" parameter. - match
- If specified, a regular expression that must match the current time for this URL to run. The format to match is specified by the "format" parameter, below. "EEE-dd-HH-mm" (eg: Thu-Dec, 14, 14:12 pm).
- format
- a
date format specifier
to use for matching "match" patterns. Defaults to "EE-MM-dd-HH-mm". - proxy
- If specified, connect through a proxy. This should be
in the form
host:port
, orhost
it the desired port is80
. - sessionTable
- The name of the SessionManager table to use for
storing values. By default, properties are stored in
server.props. The value should match the
sessionTable
used by theSetTemplate
to allow values obtained by this handler to be accessable from within templates.If the
sessionTable
is set, thenamespace
value is used to name the table (e.g. thenamespace
specified bySetTemplate
. If no namespace parameter is given, thenprepend
is used as the namespace parameter.
If prepend is specified, the following additional properties are created, and added to the properties with the specified prefix.
- count.attempts
- The total number of polls attemped.
- count.errors
- The total number of poll failures.
- error.at
- The poll attempt # for the last failure.
- error.msg
- The message describing the last failure.
- error.time
- The timestamp of the last failure.
- timestamp
- The timestamp for the last successful poll.
- Version:
- %V% PollHandler.java 2.5
- Author:
- Stephen Uhler
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
FieldsFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
fillProps
(Properties props, HttpRequest target) Fill the properties from the input streamboolean
Set up the initial configuration, and kick off a thread to periodically fetch the url.boolean
This might allow control over the polling via requests at a later date.void
run()
Periodically poll the url, and copy the results into the server properties.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Field Details
-
url
-
post
-
interval
public int interval
-
-
Constructor Details
-
PollHandler
public PollHandler()
-
-
Method Details
-
init
Set up the initial configuration, and kick off a thread to periodically fetch the url.- Specified by:
init
in interfaceHandler
- Parameters:
server
- The HTTP server that created thisHandler
. TypicalHandler
s will useServer.props
to obtain run-time configuration information.prefix
- The handlers name. The string thisHandler
may prepend to all of the keys that it uses to extract configuration information fromServer.props
. This is set (by theServer
andChainHandler
) to help avoid configuration parameter namespace collisions.- Returns:
true
if thisHandler
initialized successfully,false
otherwise. Iffalse
is returned, thisHandler
should not be used.
-
respond
This might allow control over the polling via requests at a later date. For now, it always returns false. -
run
public void run()Periodically poll the url, and copy the results into the server properties. -
fillProps
Fill the properties from the input stream- Throws:
IOException
-