JBoss Remoting 3.0.0.GA

org.jboss.remoting.spi
Class AbstractHandleableCloseable<T>

java.lang.Object
  extended by org.jboss.remoting.spi.AbstractHandleableCloseable<T>
All Implemented Interfaces:
Closeable, HandleableCloseable<T>
Direct Known Subclasses:
AbstractAutoCloseable, AbstractSimpleCloseable

public abstract class AbstractHandleableCloseable<T>
extends Object
implements HandleableCloseable<T>

A basic implementation of a closeable resource. Use as a convenient base class for your closeable resources. Ensures that the close() method is idempotent; implements the registry of close handlers.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jboss.remoting.HandleableCloseable
HandleableCloseable.Key
 
Field Summary
protected  Executor executor
           
 
Constructor Summary
protected AbstractHandleableCloseable(Executor executor)
          Basic constructor.
 
Method Summary
 HandleableCloseable.Key addCloseHandler(CloseHandler<? super T> handler)
          Add a handler that will be called upon close.
 void close()
          Close, waiting for any outstanding processing to finish.
protected  void closeAction()
          Called exactly once when the close() method is invoked; the actual close operation should take place here.
protected  void finalize()
          Finalize this closeable instance.
protected  Executor getExecutor()
          Get the executor to use for handler invocation.
protected  boolean isOpen()
          Read the status of this resource.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

executor

protected final Executor executor
Constructor Detail

AbstractHandleableCloseable

protected AbstractHandleableCloseable(Executor executor)
Basic constructor.

Parameters:
executor - the executor used to execute the close notification handlers
Method Detail

isOpen

protected boolean isOpen()
Read the status of this resource. This is just a snapshot in time; there is no guarantee that the resource will remain open for any amount of time, even if this method returns true.

Returns:
true if the resource is still open

closeAction

protected void closeAction()
                    throws IOException
Called exactly once when the close() method is invoked; the actual close operation should take place here.

Throws:
RemotingException - if the close failed
IOException

close

public final void close()
                 throws IOException
Close, waiting for any outstanding processing to finish.

Specified by:
close in interface Closeable
Specified by:
close in interface HandleableCloseable<T>
Throws:
IOException - if the close failed

addCloseHandler

public HandleableCloseable.Key addCloseHandler(CloseHandler<? super T> handler)
Add a handler that will be called upon close. The handler may be called before or after the close acutally takes place.

Specified by:
addCloseHandler in interface HandleableCloseable<T>
Parameters:
handler - the close handler
Returns:
a key which may be used to later remove this handler

getExecutor

protected Executor getExecutor()
Get the executor to use for handler invocation.

Returns:
the executor

finalize

protected void finalize()
                 throws Throwable
Finalize this closeable instance. If the instance hasn't been closed, it is closed and a warning is logged.

Overrides:
finalize in class Object
Throws:
Throwable

JBoss Remoting 3.0.0.GA

Copyright © 2008 JBoss, a division of Red Hat, Inc.