Package org.eclipse.jetty.util.thread
Class Sweeper
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.util.thread.Sweeper
-
- All Implemented Interfaces:
java.lang.Runnable,LifeCycle
public class Sweeper extends AbstractLifeCycle implements java.lang.Runnable
A utility class to perform periodic sweeping of resources.
Sweeper.Sweepableresources may be added to or removed from aSweeperand the resource implementation decides whether it should be swept or not.If a
Sweeper.Sweepableresources is itself a container of other sweepable resources, it will forward the sweep operation to children resources, and so on recursively.Typical usage is to add
Sweeperas a bean to an existing container:Server server = new Server(); server.addBean(new Sweeper(), true); server.start();
Code that knows it has sweepable resources can then lookup theSweeperand offer the sweepable resources to it:class MyComponent implements Sweeper.Sweepable { private final long creation; private volatile destroyed; MyComponent(Server server) { this.creation = System.nanoTime(); Sweeper sweeper = server.getBean(Sweeper.class); sweeper.offer(this); } void destroy() { destroyed = true; } @Override public boolean sweep() { return destroyed; } }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceSweeper.SweepableASweeper.Sweepableresource implements this interface to signal to aSweeperor to a parent container if it needs to be swept or not.-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddoStart()protected voiddoStop()intgetSize()booleanoffer(Sweeper.Sweepable sweepable)booleanremove(Sweeper.Sweepable sweepable)voidrun()-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, setStopTimeout, start, stop, toString
-
-
-
-
Constructor Detail
-
Sweeper
public Sweeper(Scheduler scheduler, long period)
-
-
Method Detail
-
doStart
protected void doStart() throws java.lang.Exception- Overrides:
doStartin classAbstractLifeCycle- Throws:
java.lang.Exception
-
doStop
protected void doStop() throws java.lang.Exception- Overrides:
doStopin classAbstractLifeCycle- Throws:
java.lang.Exception
-
getSize
public int getSize()
-
offer
public boolean offer(Sweeper.Sweepable sweepable)
-
remove
public boolean remove(Sweeper.Sweepable sweepable)
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable
-
-