JBoss Remoting 3 3.2.0.CR6

org.jboss.remoting3.spi
Class AbstractHandleableCloseable<T extends HandleableCloseable<T>>

java.lang.Object
  extended by org.jboss.remoting3.spi.AbstractHandleableCloseable<T>
Type Parameters:
T - the type of the closeable resource
All Implemented Interfaces:
Closeable, HandleableCloseable<T>

public abstract class AbstractHandleableCloseable<T extends HandleableCloseable<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.remoting3.HandleableCloseable
HandleableCloseable.Key
 
Constructor Summary
protected AbstractHandleableCloseable(Executor executor)
          Basic constructor.
protected AbstractHandleableCloseable(Executor executor, boolean autoClose)
          Basic constructor.
 
Method Summary
 HandleableCloseable.Key addCloseHandler(CloseHandler<? super T> handler)
          Add a handler that will be called upon close.
 void awaitClosed()
          Wait for a resource close to complete.
 void awaitClosedUninterruptibly()
          Wait for a resource close to complete.
protected  void checkOpen()
          Check if open, throwing an exception if it is not.
 void close()
          Close this resource.
protected  void closeAction()
          Called exactly once when the close() method is invoked; the actual close operation should take place here.
 void closeAsync()
          Asynchronously close this resource.
protected  void closeComplete()
          Call when close is complete.
protected  void closeFailed(IOException cause)
          Call if an async close has failed.
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
 

Constructor Detail

AbstractHandleableCloseable

protected AbstractHandleableCloseable(Executor executor)
Basic constructor.

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

AbstractHandleableCloseable

protected AbstractHandleableCloseable(Executor executor,
                                      boolean autoClose)
Basic constructor.

Parameters:
executor - the executor used to execute the close notification handlers
autoClose - true if this instance should automatically close on finalize
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. This method must call closeComplete(), directly or indirectly, for the close operation to finish (it may happen in another thread but it must happen). This method should not expect the closeComplete() call to be made from another thread from the same thread pool that may cause close(). As close will block, this can result in situations where all threads in the pool are blocked on close() method calls, which means the closeComplete() will never be run.

Throws:
RemotingException - if the close failed
IOException

close

public void close()
           throws IOException
Close this resource. Call any registered close handlers. Calling this method more than once will not have any additional effect.

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

closeComplete

protected void closeComplete()
Call when close is complete.


closeFailed

protected void closeFailed(IOException cause)
Call if an async close has failed.

Parameters:
cause - the failure cause

awaitClosed

public void awaitClosed()
                 throws InterruptedException
Wait for a resource close to complete.

Specified by:
awaitClosed in interface HandleableCloseable<T extends HandleableCloseable<T>>
Throws:
InterruptedException - if the operation is interrupted

awaitClosedUninterruptibly

public void awaitClosedUninterruptibly()
Wait for a resource close to complete.

Specified by:
awaitClosedUninterruptibly in interface HandleableCloseable<T extends HandleableCloseable<T>>

closeAsync

public void closeAsync()
Asynchronously close this resource. Returns immediately.

Specified by:
closeAsync in interface HandleableCloseable<T extends HandleableCloseable<T>>

addCloseHandler

public HandleableCloseable.Key addCloseHandler(CloseHandler<? super T> handler)
Add a handler that will be called upon close. If the resource is already closed, the handler will be called immediately.

Specified by:
addCloseHandler in interface HandleableCloseable<T extends 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

checkOpen

protected void checkOpen()
                  throws NotOpenException
Check if open, throwing an exception if it is not.

Throws:
NotOpenException - if not open

JBoss Remoting 3 3.2.0.CR6

Copyright © 2012 JBoss, a division of Red Hat, Inc.. All Rights Reserved.