Top Description Inners Fields Constructors Methods
org.eclipse.jetty.util.thread

public Class Sweeper

extends AbstractLifeCycle
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable
Imports
java.util.List, java.util.concurrent.CopyOnWriteArrayList, .TimeUnit, java.util.concurrent.atomic.AtomicReference, org.eclipse.jetty.util.component.AbstractLifeCycle, org.slf4j.Logger, .LoggerFactory

A utility class to perform periodic sweeping of resources.

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 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 and Inner Type Summary

Modifier and TypeClass and Description
public static interface
Sweeper.Sweepable

A Sweepable resource implements this interface to signal to a Sweeper or to a parent container if it needs to be swept or not.

Field Summary

Modifier and TypeField and Description
private final AtomicReference<List<Sweeper.Sweepable>>
private static final Logger
private final long
private final Scheduler
private final AtomicReference<Scheduler.Task>
Inherited from org.eclipse.jetty.util.component.AbstractLifeCycle:
FAILEDSTARTEDSTARTINGSTOPPEDSTOPPING

Constructor Summary

AccessConstructor and Description
public
Sweeper(Scheduler scheduler, long period)

Method Summary

Modifier and TypeMethod and Description
private void
private void
protected void
doStart()

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.doStart.

Method to override to start the lifecycle

protected void
doStop()

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.doStop.

Method to override to stop the lifecycle

public int
public boolean
offer(Sweeper.Sweepable sweepable)

public boolean
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

Inherited from org.eclipse.jetty.util.component.AbstractLifeCycle:
addEventListenergetEventListenersgetStategetStateisFailedisRunningisStartedisStartingisStoppedisStoppingremoveEventListenersetEventListenersstartstoptoString

Field Detail

itemsback to summary
private final AtomicReference<List<Sweeper.Sweepable>> items
LOGback to summary
private static final Logger LOG

Hides org.eclipse.jetty.util.component.AbstractLifeCycle.LOG.

periodback to summary
private final long period
schedulerback to summary
private final Scheduler scheduler
taskback to summary
private final AtomicReference<Scheduler.Task> task

Constructor Detail

Sweeperback to summary
public Sweeper(Scheduler scheduler, long period)

Method Detail

activateback to summary
private void activate()
deactivateback to summary
private void deactivate()
doStartback to summary
protected void doStart() throws Exception

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.doStart.

Doc from org.eclipse.jetty.util.component.AbstractLifeCycle.doStart.

Method to override to start the lifecycle

Annotations
@Override
Exceptions
Exception:
If there was a problem starting. Will cause a transition to FAILED state
doStopback to summary
protected void doStop() throws Exception

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.doStop.

Doc from org.eclipse.jetty.util.component.AbstractLifeCycle.doStop.

Method to override to stop the lifecycle

Annotations
@Override
Exceptions
Exception:
If there was a problem stopping. Will cause a transition to FAILED state
getSizeback to summary
public int getSize()
offerback to summary
public boolean offer(Sweeper.Sweepable sweepable)
removeback to summary
public boolean remove(Sweeper.Sweepable sweepable)
runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
org.eclipse.jetty.util.thread back to summary

public Interface Sweeper.Sweepable


A Sweepable resource implements this interface to signal to a Sweeper or to a parent container if it needs to be swept or not.

Typical implementations will check their own internal state and return true or false from sweep() to indicate whether they should be swept.

Method Summary

Modifier and TypeMethod and Description
public boolean
sweep()

Returns: whether this resource should be swept

Method Detail

sweepback to summary
public boolean sweep()
Returns:boolean

whether this resource should be swept