sunlabs.brazil.handler
Class PollHandler
public
class
PollHandler
extends Thread
implements Handler
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 the sessionTable
parameter of
the SetTemplate
, then this specifies the
namespace
parameter that may be used with
the SetTemplate
"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 {@link java.text.SimpleDateFormat 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
, or host
it the desired port is 80
.
- 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 the {@link sunlabs.brazil.template.SetTemplate} to allow
values obtained by this handler to be accessable from within
templates.
If the sessionTable
is set, the namespace
value is used to name the table (e.g. the namespace
specified by {@link sunlabs.brazil.template.SetTemplate}. If no
namespace parameter is given, then prepend
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
Method Summary |
void | fillProps(Properties props, HttpRequest target)
Fill the properties from the input stream |
boolean | init(Server server, String prefix)
Set up the initial configuration, and kick off a thread
to periodically fetch the url. |
boolean | respond(Request request)
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. |
public int interval
public String post
public String url
public void fillProps(Properties props,
HttpRequest target)
Fill the properties from the input stream
public boolean init(
Server server, String prefix)
Set up the initial configuration, and kick off a thread
to periodically fetch the url.
public boolean respond(
Request request)
This might allow control over the polling via requests at a later date.
For now, it always returns false.
public void run()
Periodically poll the url, and copy the results into the server
properties.