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;
}
}
| Modifier and Type | Class and Description |
|---|---|
| public static interface | Sweeper.
A |
| Modifier and Type | Field and Description |
|---|---|
| private final AtomicReference | |
| private static final Logger | |
| private final long | |
| private final Scheduler | |
| private final AtomicReference |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| private void | |
| protected void | doStart()
Overrides org. Method to override to start the lifecycle |
| protected void | doStop()
Overrides org. Method to override to stop the lifecycle |
| public int | |
| public boolean | |
| public boolean | |
| public void |
| items | back to summary |
|---|---|
| private final AtomicReference<List<Sweeper. | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG Hides org. | |
| period | back to summary |
|---|---|
| private final long period | |
| scheduler | back to summary |
|---|---|
| private final Scheduler scheduler | |
| task | back to summary |
|---|---|
| private final AtomicReference<Scheduler. | |
| Sweeper | back to summary |
|---|---|
| public Sweeper(Scheduler scheduler, long period) | |
| activate | back to summary |
|---|---|
| private void activate() | |
| deactivate | back to summary |
|---|---|
| private void deactivate() | |
| doStart | back to summary |
|---|---|
| protected void doStart() throws Exception Overrides org. Doc from org. Method to override to start the lifecycle | |
| doStop | back to summary |
|---|---|
| protected void doStop() throws Exception Overrides org. Doc from org. Method to override to stop the lifecycle | |
| getSize | back to summary |
|---|---|
| public int getSize() | |
| offer | back to summary |
|---|---|
| public boolean offer(Sweeper. | |
| remove | back to summary |
|---|---|
| public boolean remove(Sweeper. | |
| run | back to summary |
|---|---|
| public void run() Implements java. Doc from java. Runs this operation.
| |
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.
| Modifier and Type | Method and Description |
|---|---|
| public boolean |
| sweep | back to summary |
|---|---|
public boolean sweep()
| |