org.ceryle.wiki.plugin.randompages
Class RandomPagesScheduler

java.lang.Object
  extended by org.ceryle.wiki.plugin.randompages.RandomPagesScheduler

public class RandomPagesScheduler
extends Object

The singleton-per-WikiEngine scheduler that handles updates to the random page list (which it also maintains). When this class is instantiated it adds a listener to the WikiEngine so that it can be gracefully shut down along with the WikiEngine.

This is considered a very low-priority thread.

Author:
Murray Altheim

Field Summary
static int DEFAULT_MAXHOURS
          Default value for the maximum number of hours between refreshes.
static int DEFAULT_MAXPAGES
          Default value for the maximum number of pages to return.
static int DEFAULT_MINPAGES
          Default value for the minimum number of pages to return.
static int MIN_PERIOD
          Fixed value for the minimum number (in ms) between refreshes.
 
Method Summary
protected  Set getExclusions()
          Returns an unmodifiable set of pages to exclude.
static RandomPagesScheduler getInstance(WikiEngine engine, int minpages, int maxpages, int maxperiod, String exclude)
          Returns the RandomPagesScheduler for the WikiEngine engine on a per-engine basis.
 int[] getLimits()
          Return the currently-set limits as an int array.
 long getNextScheduledUpdate()
          Returns the Date (in ms) after which the next update is scheduled to occur.
 String getNextScheduledUpdateDisplay(boolean includeTimeRemaining)
          Returns a readable display of the Date after which the next update is scheduled to occur.
 int getRandomPageCount()
          Returns a random page count within the pre-specified range.
 Set getRandomPages()
          Returns a Set of random pages.
protected  void setExclusions(String exclude)
          Set the list of pages to exclude.
protected  void setLimits(WikiEngine engine, int minpages, int maxpages, int maxhours)
          Sanity check and set limits.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_MINPAGES

public static final int DEFAULT_MINPAGES
Default value for the minimum number of pages to return. The value is 5.

See Also:
Constant Field Values

DEFAULT_MAXPAGES

public static final int DEFAULT_MAXPAGES
Default value for the maximum number of pages to return. The value is 10.

See Also:
Constant Field Values

DEFAULT_MAXHOURS

public static final int DEFAULT_MAXHOURS
Default value for the maximum number of hours between refreshes. The value is 24.

See Also:
Constant Field Values

MIN_PERIOD

public static final int MIN_PERIOD
Fixed value for the minimum number (in ms) between refreshes. The value is 900000.

See Also:
Constant Field Values
Method Detail

getInstance

public static RandomPagesScheduler getInstance(WikiEngine engine,
                                               int minpages,
                                               int maxpages,
                                               int maxperiod,
                                               String exclude)
Returns the RandomPagesScheduler for the WikiEngine engine on a per-engine basis. If the scheduler for the engine did not exist prior to the call, its parameters are set according to the limits provided. If the scheduler already exists, the new limits will be used when it is next rescheduled. Because multiple plugins may be setting these limits this is determined simply by who last set them (also somewhat indeterminate!).

Parameters:
engine - The WikiEngine used as a source of page information.
minpages - The minimum number of pages to return.
maxpages - The maximum number of pages to return.
maxperiod - The maximum period (in hours) between refreshes. See the note on setLimits(WikiEngine,int,int,int).
exclude - The space- or comma-delimited list of pages to exclude.

getRandomPageCount

public int getRandomPageCount()
Returns a random page count within the pre-specified range.


getRandomPages

public Set getRandomPages()
Returns a Set of random pages. The count is determined by the current minpages and maxpages parameters. This gets called once each time a new set of random pages is requested, and gets the current set of pages at that time.


getNextScheduledUpdate

public long getNextScheduledUpdate()
Returns the Date (in ms) after which the next update is scheduled to occur.


getNextScheduledUpdateDisplay

public String getNextScheduledUpdateDisplay(boolean includeTimeRemaining)
Returns a readable display of the Date after which the next update is scheduled to occur. This includes the scheduled refresh time and the time remaining prior to update.

Parameters:
includeTimeRemaining - if true includes the time remaining in seconds

getExclusions

protected Set getExclusions()
Returns an unmodifiable set of pages to exclude.


setExclusions

protected void setExclusions(String exclude)
Set the list of pages to exclude. Ignored if null. This is cumulative across all calls to the method.


getLimits

public int[] getLimits()
Return the currently-set limits as an int array. The values are (in order): minimum pages, maximum pages, page count, minimum period (in sec), maximum period (in sec), and the number of seconds until next update.


setLimits

protected void setLimits(WikiEngine engine,
                         int minpages,
                         int maxpages,
                         int maxhours)
Sanity check and set limits. If this is called multiple times (as it may be on a wiki containing multiple instances of the plugin), this only permits increases in the limits, such that any plugin may set the singleton to its maximum, but no plugin can decrease the set limits.

Values for minpages

minpages can be set to anything greater than zero, but if it is larger than m_maxpages (the actual set value, not the unvalidated parameter) it will be set to the value of m_maxpages.

Values for maxpages

maxpages can be set to any value greater or equal to m_minpages (the actual set value, not the unvalidated parameter). The maximum value is limited by the wiki page count.

Values for maxhours

Forces an update of the list on a random period between a minimum of 15 minutes and a maximum of maxperiod hours. If a value is: Since there's not much sense in permitting enormous values for this parameter its maximum is 168 (1 week, 24 times 7).



The Ceryle Project. Copyright ©2001-2007 Murray Altheim, All Rights Reserved. See LICENSE included with distribution.