com.caucho.jms.queue
Class AbstractDestination

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractQueue
          extended by com.caucho.jms.queue.AbstractDestination
All Implemented Interfaces:
HandleAware, java.io.Serializable, java.lang.Iterable, java.util.Collection, java.util.concurrent.BlockingQueue, java.util.Queue, Destination
Direct Known Subclasses:
AbstractQueue, AbstractTopic, JdbcDestination

public abstract class AbstractDestination
extends java.util.AbstractQueue
implements Destination, java.util.concurrent.BlockingQueue, java.io.Serializable, HandleAware

Implements an abstract queue.

See Also:
Serialized Form

Field Summary
protected  MessageFactory _messageFactory
           
 
Constructor Summary
protected AbstractDestination()
           
 
Method Summary
 void acknowledge(java.lang.String msgId)
          Acknowledge receipt of the message.
 void addMessageAvailableListener(MessageAvailableListener consumer)
          Adds a new listener to receive message available events.
 void close()
           
 int drainTo(java.util.Collection c)
           
 int drainTo(java.util.Collection c, int max)
           
 java.lang.String generateMessageID()
          Creates a new random message identifier.
protected  void generateMessageID(java.lang.StringBuilder cb)
           
 Destination getJMSDestination()
           
 java.lang.String getName()
           
 java.lang.String getQueueName()
           
protected  MessageConsumerImpl getReadConsumer()
           
 java.lang.String getTopicName()
           
 java.lang.String getUrl()
          Returns a descriptive URL for the queue.
protected  JmsSession getWriteSession()
           
 boolean hasMessage()
          Returns true if the queue has at least one message available
 java.util.Iterator iterator()
           
 boolean offer(java.lang.Object value)
           
 boolean offer(java.lang.Object value, long timeout, java.util.concurrent.TimeUnit unit)
          Adds the item to the queue, waiting if necessary
 java.lang.Object peek()
           
 java.lang.Object poll()
           
 java.lang.Object poll(long timeout, java.util.concurrent.TimeUnit unit)
           
 void put(java.lang.Object value)
           
 MessageImpl receive(boolean isAutoAcknowledge)
          Polls the next message from the store.
 int remainingCapacity()
           
 void removeMessageAvailableListener(MessageAvailableListener consumer)
          Removes the consumer receiving messages.
 void rollback(java.lang.String msgId)
          Rollback the message read.
abstract  void send(JmsSession session, MessageImpl msg, int priority, long timeout)
          Sends a message to the queue
 void setName(java.lang.String name)
           
 void setSerializationHandle(java.lang.Object handle)
          Serialization callback from Resin-IoC to set the handle
 int size()
           
 java.lang.Object take()
           
 java.lang.String toString()
           
 
Methods inherited from class java.util.AbstractQueue
add, addAll, clear, element, remove
 
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.concurrent.BlockingQueue
add, contains, remove
 
Methods inherited from interface java.util.Queue
element, remove
 
Methods inherited from interface java.util.Collection
addAll, clear, containsAll, equals, hashCode, isEmpty, removeAll, retainAll, toArray, toArray
 

Field Detail

_messageFactory

protected MessageFactory _messageFactory
Constructor Detail

AbstractDestination

protected AbstractDestination()
Method Detail

setName

public void setName(java.lang.String name)

getName

public java.lang.String getName()

getQueueName

public java.lang.String getQueueName()

getTopicName

public java.lang.String getTopicName()

setSerializationHandle

public void setSerializationHandle(java.lang.Object handle)
Serialization callback from Resin-IoC to set the handle

Specified by:
setSerializationHandle in interface HandleAware

getUrl

public java.lang.String getUrl()
Returns a descriptive URL for the queue.


addMessageAvailableListener

public void addMessageAvailableListener(MessageAvailableListener consumer)
Adds a new listener to receive message available events. The listener will wake or spawn a thread to handle the new message. It MUST NOT handle the message on the event thread. Each listener should be associated with a single thread, i.e. multiple notifyMessageAvailable() calls MUST NOT spawn multiple threads. This single-thread restriction is necessary to properly manage round-robin behavior.

Parameters:
consumer -

removeMessageAvailableListener

public void removeMessageAvailableListener(MessageAvailableListener consumer)
Removes the consumer receiving messages.


send

public abstract void send(JmsSession session,
                          MessageImpl msg,
                          int priority,
                          long timeout)
                   throws JMSException
Sends a message to the queue

Throws:
JMSException

receive

public MessageImpl receive(boolean isAutoAcknowledge)
                    throws JMSException
Polls the next message from the store. Returns null if no message is available.

Parameters:
isAutoAcknowledge - if true, automatically acknowledge the message
Throws:
JMSException

hasMessage

public boolean hasMessage()
Returns true if the queue has at least one message available


acknowledge

public void acknowledge(java.lang.String msgId)
Acknowledge receipt of the message.

Parameters:
msgId - message to acknowledge

rollback

public void rollback(java.lang.String msgId)
Rollback the message read.


generateMessageID

public final java.lang.String generateMessageID()
Creates a new random message identifier.


generateMessageID

protected void generateMessageID(java.lang.StringBuilder cb)

getJMSDestination

public Destination getJMSDestination()

size

public int size()
Specified by:
size in interface java.util.Collection
Specified by:
size in class java.util.AbstractCollection

iterator

public java.util.Iterator iterator()
Specified by:
iterator in interface java.lang.Iterable
Specified by:
iterator in interface java.util.Collection
Specified by:
iterator in class java.util.AbstractCollection

offer

public boolean offer(java.lang.Object value,
                     long timeout,
                     java.util.concurrent.TimeUnit unit)
Adds the item to the queue, waiting if necessary

Specified by:
offer in interface java.util.concurrent.BlockingQueue

poll

public java.lang.Object poll(long timeout,
                             java.util.concurrent.TimeUnit unit)
Specified by:
poll in interface java.util.concurrent.BlockingQueue

offer

public boolean offer(java.lang.Object value)
Specified by:
offer in interface java.util.concurrent.BlockingQueue
Specified by:
offer in interface java.util.Queue

put

public void put(java.lang.Object value)
Specified by:
put in interface java.util.concurrent.BlockingQueue

remainingCapacity

public int remainingCapacity()
Specified by:
remainingCapacity in interface java.util.concurrent.BlockingQueue

peek

public java.lang.Object peek()
Specified by:
peek in interface java.util.Queue

poll

public java.lang.Object poll()
Specified by:
poll in interface java.util.Queue

take

public java.lang.Object take()
Specified by:
take in interface java.util.concurrent.BlockingQueue

drainTo

public int drainTo(java.util.Collection c)
Specified by:
drainTo in interface java.util.concurrent.BlockingQueue

drainTo

public int drainTo(java.util.Collection c,
                   int max)
Specified by:
drainTo in interface java.util.concurrent.BlockingQueue

getWriteSession

protected JmsSession getWriteSession()
                              throws JMSException
Throws:
JMSException

getReadConsumer

protected MessageConsumerImpl getReadConsumer()
                                       throws JMSException
Throws:
JMSException

close

public void close()

toString

public java.lang.String toString()
Overrides:
toString in class java.util.AbstractCollection