|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object de.nava.informa.utils.poller.Poller
public class Poller
Background poller of channels and groups of channels. Default poller period of channel is set to an hour.
Each Poller instance has its own scheduler to manage the schedule of updates and worker threads manager to manage processing of updates.
Right after the instance of Poller is created you might be interested in adding some
observers (addObserver()
) to receive events on channels updates. Registered
observers are added to the composite observer which is following Composite pattern to
combine all of the listeners and present them as single instance convenient for operation.
This instance is passed to all newly created worker threads. Later it will be used by
worker threads to report about changes.
If you are interested in making changes directly in persistence storage then, please,
look at PersistenceObserver
class. It's simple implementation of persistence
changer based on Observer events.
You also may require to filter newly found items in channels being polled. Using Approvers you can receive events only when wanted items are detected. Each registered Approver votes for addition of newly detected item in channel. All of registered Approvers should vote for addition in order to send event about newly detected item to Observers.
Finally, you need to register some channels to get benefits from Poller. Using appropriate methods you can register and unregister channels, request immediate updates and change polling period for all regitered channels at once.
Poller has different item scanning policies. By default, it uses POLICY_SCAN_ALL
which means that every item in the feed is scanned. It's possible to tell Poller to skip
items which are going after the first detected existing item. It is very convenient when you
need to find only really new items. Use POLICY_SKIP_AFTER_EXISTING
policy for
that.
It's also possible to specify user-agent name to be used when making connection through HTTP protocol. You can do so only during Poller construction.
When the poller will be ready to parse the feed it will pass the opened InputStream
to InputSourceProviderIF
implementation specified during Poller creation.
It's convenient if some additional wrapping of input streams is required to, for example,
pre-process data in some way before it gets into the parser. One of the coolest applications
could be is reading of compressed streams, which are decompressed in real-time. The parser
will get decompressed copy and will not notice the change.
Field Summary | |
---|---|
static int |
POLICY_SCAN_ALL
Scanning for new items performed fully. |
static int |
POLICY_SKIP_AFTER_EXISTING
Scanning for new items in channel finishes when existing item detected. |
Constructor Summary | |
---|---|
Poller()
Creates poller with default number of worker threads, POLICY_SCAN_ALL scanning policy and default user agent. |
|
Poller(int workerThreads)
Creates poller with POLICY_SCAN_ALL scanning policy and default user agent. |
|
Poller(int workerThreads,
int itemScanningPolicy)
Creates poller with default user agent. |
|
Poller(int workerThreads,
int itemScanningPolicy,
String userAgent)
Creates poller. |
|
Poller(int workerThreads,
int itemScanningPolicy,
String userAgent,
InputSourceProviderIF inputSourceProvider,
InputStreamProviderIF inputStreamProvider)
Creates poller. |
Method Summary | |
---|---|
void |
addApprover(PollerApproverIF approver)
Adds approver to the list. |
void |
addObserver(PollerObserverIF observer)
Adds observer to the list of interested parties. |
void |
registerChannel(ChannelIF channel)
Register new channel for background poller. |
void |
registerChannel(ChannelIF channel,
long period)
Register new channel for background poller with custom period. |
void |
registerChannel(ChannelIF channel,
long delay,
long period)
Register new channel for background poller with custom period. |
void |
removeApprover(PollerApproverIF approver)
Removes approver from the list. |
void |
removeObserver(PollerObserverIF observer)
Removes observer from the list. |
void |
setPeriod(long period)
Sets global update period to the specified value. |
void |
setWorkerThreads(int count)
Sets count on number of poller threads. |
void |
unregisterChannel(ChannelIF channel)
Unregister the channel from background poller. |
void |
updateChannel(ChannelIF channel)
Performs immediate update of the channel and reworks the schedule starting from current time. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int POLICY_SKIP_AFTER_EXISTING
public static final int POLICY_SCAN_ALL
Constructor Detail |
---|
public Poller()
public Poller(int workerThreads)
workerThreads
- desired number of worker threads.public Poller(int workerThreads, int itemScanningPolicy)
workerThreads
- desired number of worker threads.itemScanningPolicy
- policy of item scanning.public Poller(int workerThreads, int itemScanningPolicy, String userAgent)
workerThreads
- desired number of worker threads.itemScanningPolicy
- policy of item scanning.userAgent
- user agent to be used for HTTP connections or NULL for default.public Poller(int workerThreads, int itemScanningPolicy, String userAgent, InputSourceProviderIF inputSourceProvider, InputStreamProviderIF inputStreamProvider)
workerThreads
- desired number of worker threads.itemScanningPolicy
- policy of item scanning.userAgent
- user agent to be used for HTTP connections or NULL for default.inputSourceProvider
- provider of InputSource
ready for parsing for a
given feed InputStream
.inputStreamProvider
- provider of InputStream
ready for fetching data of
feed.Method Detail |
---|
public final void setWorkerThreads(int count)
count
- new count on number of poller threads.public final void registerChannel(ChannelIF channel)
channel
- channel to register.public final void registerChannel(ChannelIF channel, long period)
channel
- channel.period
- period in millis.public final void registerChannel(ChannelIF channel, long delay, long period)
channel
- channel.delay
- delay before first check.period
- period in millis.public final void updateChannel(ChannelIF channel)
channel
- channel to update.public final void unregisterChannel(ChannelIF channel)
channel
- channel to unregister.public final void addObserver(PollerObserverIF observer)
observer
- new observer.public final void removeObserver(PollerObserverIF observer)
observer
- observer to remove.public final void addApprover(PollerApproverIF approver)
approver
- approver.public final void removeApprover(PollerApproverIF approver)
approver
- approver object.public final void setPeriod(long period)
period
- period in millis.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |