net.sf.jbaobab.expirable
Class Expirer<E>

java.lang.Object
  extended by java.lang.Thread
      extended by net.sf.jbaobab.expirable.Expirer<E>
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
ReclaimableExpirer

public class Expirer<E>
extends Thread

A reaper class designed for decorators in net.sf.jbaobab.expirable package. Once an object is registered to Expirer, expiration can't be cancelled. If you want operations like cancel or reclaim, see (@link ReclaimableExpirer}.

Please regard the code below:

 Expirer<String> expirer = new Expirer<String>(new ExpirationHandler<String>() {
        public void expired(String element) {
                System.out.println("{" + element + "} expired");
        }
 });
 expirer.register("I have 5 seconds left", 5000);
 

Author:
Oakyoon Cha
See Also:
ExpirationHandler

Nested Class Summary
static class Expirer.Expirable<E>
          A wrapper class for object that has creation/expiration time.
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
protected  ExpirationHandler<E> handler
           
protected  Queue<Expirer.Expirable<E>> queue
           
protected  boolean working
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
Expirer()
           
Expirer(ExpirationHandler<E> handler)
           
 
Method Summary
protected  void expire(E element)
           
 ExpirationHandler<E> getHandler()
           
 Expirer.Expirable<E> register(E element, long timeout)
           
 void run()
           
 ExpirationHandler<E> setHandler(ExpirationHandler<E> handler)
           
 void shutdown()
           
 void start()
           
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

handler

protected ExpirationHandler<E> handler

queue

protected Queue<Expirer.Expirable<E>> queue

working

protected boolean working
Constructor Detail

Expirer

public Expirer(ExpirationHandler<E> handler)

Expirer

public Expirer()
Method Detail

start

public void start()
Overrides:
start in class Thread

shutdown

public void shutdown()

setHandler

public ExpirationHandler<E> setHandler(ExpirationHandler<E> handler)

getHandler

public ExpirationHandler<E> getHandler()

register

public Expirer.Expirable<E> register(E element,
                                     long timeout)

expire

protected void expire(E element)

run

public void run()
Specified by:
run in interface Runnable
Overrides:
run in class Thread