com.netflix.config
Class AbstractPollingScheduler

java.lang.Object
  extended by com.netflix.config.AbstractPollingScheduler
Direct Known Subclasses:
FixedDelayPollingScheduler

public abstract class AbstractPollingScheduler
extends java.lang.Object

This class is responsible for scheduling the periodical polling of a configuration source and applying the polling result to a Configuration.

A subclass should supply the specific scheduling logic in schedule(Runnable) and stop().


Constructor Summary
AbstractPollingScheduler()
          Create an instance where ignoreDeletesFromSource is set to false.
AbstractPollingScheduler(boolean ignoreDeletesFromSource)
           
 
Method Summary
 void addPollListener(PollListener l)
          Add the PollLisetner
protected  java.lang.Object getNextCheckPoint(java.lang.Object lastCheckpoint)
          Get the check point used in next PolledConfigurationSource.poll(boolean, Object).
protected  java.lang.Runnable getPollingRunnable(PolledConfigurationSource source, org.apache.commons.configuration.Configuration config)
          Gets the runnable to be scheduled.
protected  void initialLoad(PolledConfigurationSource source, org.apache.commons.configuration.Configuration config)
          Do an initial poll from the source and apply the result to the configuration.
 boolean isIgnoreDeletesFromSource()
           
protected  void populateProperties(PollResult result, org.apache.commons.configuration.Configuration config)
          Apply the polled result to the configuration.
 void removePollListener(PollListener l)
           
protected abstract  void schedule(java.lang.Runnable pollingRunnable)
          Schedule the runnable for polling the configuration source
 void setIgnoreDeletesFromSource(boolean ignoreDeletesFromSource)
          Set if the scheduler should ignore deletes from source when applying property changes
 void startPolling(PolledConfigurationSource source, org.apache.commons.configuration.Configuration config)
          Initiate the first poll of the configuration source and schedule the runnable.
abstract  void stop()
          Stop the scheduler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractPollingScheduler

public AbstractPollingScheduler(boolean ignoreDeletesFromSource)
Parameters:
ignoreDeletesFromSource - true if deletes happened in the configuration source should be ignored by the Configuration. Warning: If both PollResult.isIncremental() and this parameter are false, any property in the configuration that is missing in the polled result will be deleted once the PollResult is applied.

AbstractPollingScheduler

public AbstractPollingScheduler()
Create an instance where ignoreDeletesFromSource is set to false.

See Also:
AbstractPollingScheduler(boolean)
Method Detail

initialLoad

protected void initialLoad(PolledConfigurationSource source,
                           org.apache.commons.configuration.Configuration config)
Do an initial poll from the source and apply the result to the configuration.

Parameters:
source - source of the configuration
config - Configuration to apply the polling result
Throws:
java.lang.RuntimeException - if any error occurs in polling the configuration source

populateProperties

protected void populateProperties(PollResult result,
                                  org.apache.commons.configuration.Configuration config)
Apply the polled result to the configuration. If the polled result is full result from source, each property in the result is either added to set to the configuration, and any property that is in the configuration but not in the result is deleted if ignoreDeletesFromSource is false. If the polled result is incremental, properties added and changed in the partial result are set with the configuration, and deleted properties are deleted form configuration if ignoreDeletesFromSource is false.

Parameters:
result - Polled result from source

getPollingRunnable

protected java.lang.Runnable getPollingRunnable(PolledConfigurationSource source,
                                                org.apache.commons.configuration.Configuration config)
Gets the runnable to be scheduled. The implementation does the following
  • Gets the next check point
  • call source.poll(fase, checkpoint)
  • fire event for poll listeners
  • If success, update the configuration with the polled result

    Returns:
    Runnable to be scheduled in schedule(Runnable)

  • startPolling

    public void startPolling(PolledConfigurationSource source,
                             org.apache.commons.configuration.Configuration config)
    Initiate the first poll of the configuration source and schedule the runnable. This may start a new thread or thread pool depending on the implementation of schedule(Runnable).

    Parameters:
    source - Configuration source being polled
    config - Configuration where the properties will be updated
    Throws:
    java.lang.RuntimeException - if any error occurs in the initial polling

    addPollListener

    public void addPollListener(PollListener l)
    Add the PollLisetner

    Parameters:
    l -

    removePollListener

    public void removePollListener(PollListener l)

    getNextCheckPoint

    protected java.lang.Object getNextCheckPoint(java.lang.Object lastCheckpoint)
    Get the check point used in next PolledConfigurationSource.poll(boolean, Object). The check point can be used by the PolledConfigurationSource to determine the set of records to return. For example, a check point can be a time stamp and the PolledConfigurationSource can return the records modified since the time stamp. This method is called before the poll. The default implementation returns the check point received from last poll.

    Parameters:
    lastCheckpoint - checkPoint from last PollResult.getCheckPoint()
    Returns:
    the check point to be used for the next poll

    schedule

    protected abstract void schedule(java.lang.Runnable pollingRunnable)
    Schedule the runnable for polling the configuration source

    Parameters:
    pollingRunnable - The runnable to be scheduled.

    stop

    public abstract void stop()
    Stop the scheduler


    isIgnoreDeletesFromSource

    public final boolean isIgnoreDeletesFromSource()
    Returns:
    if the scheduler ignores deletes from source

    setIgnoreDeletesFromSource

    public final void setIgnoreDeletesFromSource(boolean ignoreDeletesFromSource)
    Set if the scheduler should ignore deletes from source when applying property changes