org.apache.qpid.client
Class Closeable

java.lang.Object
  extended by org.apache.qpid.client.Closeable
Direct Known Subclasses:
AMQConnection, AMQSession, BasicMessageConsumer, BasicMessageProducer

public abstract class Closeable
extends Object

Captures the 'closed' state of an object, that is initially open, can be tested to see if it is closed, and provides a 'close' method to close it.

CRC Card
Responsibilities Collaborations
Mark an object as closed.
Check if an object is closed.
Raise a JMS exception if an object is closed.

Todo:
Might be better to make this an interface. This whole class doesn't really encapsulate a terribly neat piece of re-usable functionality. A simple interface defining a close method would suffice., The convenience method checkNotClosed() is not that helpfull, what if the caller wants to do something other than throw an exception? It doesn't really represent a very usefull re-usable piece of code. Consider inlining it and dropping the method.

Field Summary
protected  AtomicBoolean _closed
          We use an atomic boolean so that we do not have to synchronized access to this flag.
protected  AtomicBoolean _closing
          Are we in the process of closing.
 
Constructor Summary
Closeable()
           
 
Method Summary
protected  void checkNotClosed()
          Checks if this is closed, and raises a JMSException if it is.
abstract  void close()
          Closes this object.
 boolean isClosed()
          Checks if this is closed.
 boolean isClosing()
          Checks if this is closis.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_closed

protected final AtomicBoolean _closed
We use an atomic boolean so that we do not have to synchronized access to this flag. Synchronizing access to this flag would mean have a synchronized block in every method.


_closing

protected final AtomicBoolean _closing
Are we in the process of closing. We have this distinction so we can still signal we are in the process of closing so other objects can tell the difference and tidy up.

Constructor Detail

Closeable

public Closeable()
Method Detail

checkNotClosed

protected void checkNotClosed()
                       throws JMSException
Checks if this is closed, and raises a JMSException if it is.

Throws:
JMSException - If this is closed.

isClosed

public boolean isClosed()
Checks if this is closed.

Returns:
true if this is closed, false otherwise.

isClosing

public boolean isClosing()
Checks if this is closis.

Returns:
true if we are closing, false otherwise.

close

public abstract void close()
                    throws JMSException
Closes this object.

Throws:
JMSException - If this cannot be closed for any reason.


Licensed to the Apache Software Foundation