For typical use, create an anonymous subclass inline, and implement the {@link #poll()} method:
{@code}new Poller( times(10), every(100, MILLISECONDS) ) public void poll() { assertThat(someMethodCall(), is("Success")); } }; }This assertion will be called a number of times (configurable by using the different constructors). The first poll is tried immediately, so if you specify 3 attempts with 1 second pause, the total execution time will be about 2 seconds.
This class catches any {@link AssertionError} thrown in the first n-1 attempts. If any other kind of Exception is encountered, or an AssertionError is thrown at the last attempt then itwill be thrown immediately and your test will fail. All AssertionErrors except the last are swallowed.
For debugging purposes you may call {@link #loudly()} in your poll method, and interim AssertionErrors will be logged to System.out rather than being simply ignored.
Poller takes care of periodical feeds updates. It makes regular scans of the feeds lists attempting to find the feeds requiring to be updated. The period of these scans is defined by scanPeriod
property.
Poller is always dedicated to some guides set and works only with it. This decision was made to simplify scanning of feeds and does not limit the functionality as the application always have only one active guide set.
This class has convenient methods to force updates of the feeds out of the schedule. They are:
update()
- updates all feeds (indirectly) in all guides.update(IGuide)
- updates all feeds (indirectly) in given guide.update(IFeed)
- updates the feed. The feed can be updated directly (meaning that the updating of this particular feed is required) or indirectly (meaning that the updating of the feed happens as a part of bigger update: guide or whole set). Before actually doing the update Poller asks each of the feeds whether they can be updated or not. The feed decides, taking in account the fact of direct or indirect call, last poll date and other factors, if it would like to be updated. If it would like to then the Poller puts the feed in queue for updates.
Poller owns some number of worker threads which are waiting for the tasks in the queue. Once they grab the task from the queue, they follow update procedure. After they finish they move back to the fetching of the next task.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|