net.sf.mmm.util.component.impl
Class PeriodicRefresherImpl

java.lang.Object
  extended by net.sf.mmm.util.component.base.AbstractComponent
      extended by net.sf.mmm.util.component.base.AbstractLoggableComponent
          extended by net.sf.mmm.util.component.impl.PeriodicRefresherImpl
All Implemented Interfaces:
Closeable, Runnable, PeriodicRefresher

@Singleton
@Named
public class PeriodicRefresherImpl
extends AbstractLoggableComponent
implements PeriodicRefresher, Runnable, Closeable

This is the implementation of PeriodicRefresher.

Since:
1.0.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Field Summary
private  boolean active
           
private static int DEFAULT_REFRESH_DELAY_IN_SECONDS
          The default refresh-delay.
private  Executor executor
           
private static Integer MIN_DELAY
          The minimum value allowed for refreshDelayInSeconds.
private  Set<Refreshable> refreshableSet
          The Set of Refreshables.
private  int refreshDelayInSeconds
           
private  Thread refreshThread
           
private  boolean shutdown
           
 
Constructor Summary
PeriodicRefresherImpl()
          The constructor.
 
Method Summary
 void addRefreshable(Refreshable refreshable)
          This method will register the given refreshable so it will be refreshed periodically.
 void close()
          
protected  void doInitialize()
          This method performs the actual initialization.
protected  Executor getExecutor()
           
 int getRefreshDelaySeconds()
           
protected  String getThreadName()
          This method gets the thread-name.
 void removeRefreshable(Refreshable refreshable)
          This method removes the given refreshable from this PeriodicRefresher.
 void run()
          
 void setExecutor(Executor executor)
           
 void setRefreshDelayInSeconds(int refreshDelayInSeconds)
          This method sets the refresh-delay in seconds.
 void startup()
          This method will initialize and startup this refresher.
 
Methods inherited from class net.sf.mmm.util.component.base.AbstractLoggableComponent
getLogger, setLogger
 
Methods inherited from class net.sf.mmm.util.component.base.AbstractComponent
doInitialized, getInitializationState, initialize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_REFRESH_DELAY_IN_SECONDS

private static final int DEFAULT_REFRESH_DELAY_IN_SECONDS
The default refresh-delay.

See Also:
Constant Field Values

MIN_DELAY

private static final Integer MIN_DELAY
The minimum value allowed for refreshDelayInSeconds.


executor

private Executor executor
See Also:
getExecutor()

refreshDelayInSeconds

private int refreshDelayInSeconds
See Also:
getRefreshDelaySeconds()

active

private boolean active
See Also:
startup()

shutdown

private volatile boolean shutdown
See Also:
close()

refreshableSet

private Set<Refreshable> refreshableSet
The Set of Refreshables.


refreshThread

private Thread refreshThread
See Also:
close()
Constructor Detail

PeriodicRefresherImpl

public PeriodicRefresherImpl()
The constructor.

Method Detail

doInitialize

protected void doInitialize()
This method performs the actual initialization. It is called when AbstractComponent.initialize() is invoked for the first time.
ATTENTION:
When you override this method from a sub-class you need to do a super.AbstractComponent.doInitialize().

Overrides:
doInitialize in class AbstractLoggableComponent

startup

public void startup()
This method will initialize and startup this refresher. On the first call of this method a new thread will be started, that periodically performs a refresh.
Multiple calls of this method have no further effect unless the refresher is closed.
NOTE:
This is intentionally NOT performed automatically via AbstractComponent.initialize() so the startup only happens if explicitly required and not accidently because this component if found and managed by some container.


addRefreshable

public void addRefreshable(Refreshable refreshable)
This method will register the given refreshable so it will be refreshed periodically.
A common implementation will use a central thread that is started if the first Refreshable is added here.
ATTENTION:
Please be careful with automatic refreshes and only add a Refreshable if this is really desired and its implementation of Refreshable.refresh() is fast or only takes performance if something that rarely changes has been modified.
Further the given Refreshable has to have a proper implementation of Object.equals(Object) and Object.hashCode() as it may be stored in a Collection.

Specified by:
addRefreshable in interface PeriodicRefresher
Parameters:
refreshable - is the Refreshable to register and refresh periodically.

removeRefreshable

public void removeRefreshable(Refreshable refreshable)
This method removes the given refreshable from this PeriodicRefresher. This will typically happen when the according Refreshable shall be closed or disposed.
If the given searchEngine has never been registered, this method has no effect.

Specified by:
removeRefreshable in interface PeriodicRefresher
Parameters:
refreshable - is the Refreshable to de-register.

close

@PreDestroy
public void close()

Specified by:
close in interface Closeable

getThreadName

protected String getThreadName()
This method gets the thread-name.

Returns:
the thread-name for debugging.

run

public void run()

Specified by:
run in interface Runnable

getExecutor

protected Executor getExecutor()
Returns:
the executor

setExecutor

@Inject
public void setExecutor(Executor executor)
Parameters:
executor - is the executor to set

getRefreshDelaySeconds

public int getRefreshDelaySeconds()
Returns:
the refreshDelaySeconds

setRefreshDelayInSeconds

public void setRefreshDelayInSeconds(int refreshDelayInSeconds)
This method sets the refresh-delay in seconds. A reasonable value should be at least 5 seconds but better in the range of minutes.

Parameters:
refreshDelayInSeconds - is the refreshDelayInSeconds to set


Copyright © 2001-2010 mmm-Team. All Rights Reserved.