Package org.eclipse.jetty.util.thread
Class Sweeper
java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.thread.Sweeper
A utility class to perform periodic sweeping of resources.
Sweeper.Sweepable
resources may be added to or removed from a
Sweeper
and the resource implementation decides whether
it should be swept or not.
If a Sweeper.Sweepable
resources 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 Sweeper
as 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 the
Sweeper
and 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 ClassesModifier and TypeClassDescriptionstatic interface
ASweeper.Sweepable
resource implements this interface to signal to aSweeper
or 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
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AtomicReference<List<Sweeper.Sweepable>>
private static final Logger
private final long
private final Scheduler
private final AtomicReference<Scheduler.Task>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
activate()
private void
protected void
doStart()
protected void
doStop()
int
getSize()
boolean
offer
(Sweeper.Sweepable sweepable) boolean
remove
(Sweeper.Sweepable sweepable) void
run()
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
-
Field Details
-
LOG
-
items
-
task
-
scheduler
-
period
private final long period
-
-
Constructor Details
-
Sweeper
-
-
Method Details
-
doStart
- Overrides:
doStart
in classAbstractLifeCycle
- Throws:
Exception
-
doStop
- Overrides:
doStop
in classAbstractLifeCycle
- Throws:
Exception
-
getSize
public int getSize() -
offer
-
remove
-
run
public void run() -
activate
private void activate() -
deactivate
private void deactivate()
-