org.jboss.messaging.core
Class ChannelSupport

java.lang.Object
  extended byorg.jboss.messaging.core.ChannelSupport
All Implemented Interfaces:
Channel, DeliveryObserver, Distributor, Receiver
Direct Known Subclasses:
PagingChannelSupport

public abstract class ChannelSupport
extends java.lang.Object
implements Channel

This class provides much of the functionality needed to implement a channel. This partial implementation supports atomicity, isolation and recoverability of reliable messages.

Version:
$Revision: 2724 $ $Id: ChannelSupport.java,v 1.65 2006/06/27 19:44:39 timfox Exp $
Author:
Ovidiu Feodorov, Tim Fox

Field Summary
protected  boolean acceptReliableMessages
           
protected  boolean active
           
protected  long channelID
           
protected  SynchronizedInt deliveringCount
           
protected  int maxSize
           
protected  PriorityLinkedList messageRefs
           
protected  SynchronizedInt messagesAdded
           
protected  MessageStore ms
           
protected  PersistenceManager pm
           
protected  boolean receiversReady
           
protected  boolean recoverable
           
protected  java.lang.Object refLock
           
protected  Router router
           
protected  java.util.Set scheduledDeliveries
           
 
Constructor Summary
protected ChannelSupport(long channelID, MessageStore ms, PersistenceManager pm, boolean acceptReliableMessages, boolean recoverable, int maxSize)
           
 
Method Summary
 boolean acceptReliableMessages()
          A non-recoverable channel cannot guarantee recoverability for reliable messages so by default it won't accept reliable messages.
 void acknowledge(Delivery d, Transaction tx)
           
protected  void acknowledgeInternal(Delivery d, Transaction tx, boolean persist)
           
 void activate()
           
 boolean add(Receiver r)
          Add a local receiver to this distributor.
protected  void addReferenceInMemory(MessageReference ref)
           
 java.util.List browse()
           
 java.util.List browse(Filter filter)
           
 void cancel(Delivery del)
           
protected  void cancelInternal(MessageReference ref)
           
protected  boolean checkAndSchedule(MessageReference ref)
           
protected  void checkClosed()
           
 void clear()
          Clears non-recoverable state but not persisted state, so a recovery of the channel is possible TODO really?
protected  void clearAllScheduledDeliveries()
           
 void close()
          Close the channel
 boolean contains(Receiver r)
           
 void deactivate()
           
 void deliver()
          Delivers as many references as possible to its router until no more deliveries are returned.
protected  void deliverInternal()
          This methods delivers as many messages as possible to the router until no more deliveries are returned.
protected  boolean deliverScheduled(MessageReference ref)
           
protected  org.jboss.messaging.core.ChannelSupport.InMemoryCallback getCallback(Transaction tx)
           
 long getChannelID()
           
 int getDeliveringCount()
           
 int getMaxSize()
           
 int getMessageCount()
          Returns the count of messages stored AND being delivered AND scheduled
 int getMessagesAdded()
           
 int getNumberOfReceivers()
           
 int getScheduledCount()
          Count scheduled for delivery
 Delivery handle(DeliveryObserver sender, MessageReference ref, Transaction tx)
          A receiver can return an active, "done" or null delivery.
protected  Delivery handleInternal(DeliveryObserver sender, MessageReference ref, Transaction tx, boolean persist)
           
 boolean isActive()
           
 boolean isRecoverable()
           
 java.util.Iterator iterator()
           
 int memoryRefCount()
           
protected  void processMessageBeforeStorage(MessageReference reference)
          Give subclass a chance to process the message before storing it internally.
 java.util.List recoverDeliveries(java.util.List messageIds)
           
 boolean remove(Receiver r)
          Remove a local receiver from this distributor.
 void removeAllReferences()
          Remove all the references in the channel
protected  MessageReference removeFirstInMemory()
           
 void setMaxSize(int newSize)
           
 java.lang.String toString()
           
 java.util.List undelivered(Filter filter)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jboss.messaging.core.Channel
load, unload
 

Field Detail

channelID

protected long channelID

router

protected Router router

ms

protected MessageStore ms

receiversReady

protected boolean receiversReady

messageRefs

protected PriorityLinkedList messageRefs

acceptReliableMessages

protected boolean acceptReliableMessages

recoverable

protected boolean recoverable

pm

protected PersistenceManager pm

refLock

protected java.lang.Object refLock

active

protected boolean active

deliveringCount

protected SynchronizedInt deliveringCount

scheduledDeliveries

protected java.util.Set scheduledDeliveries

maxSize

protected int maxSize

messagesAdded

protected SynchronizedInt messagesAdded
Constructor Detail

ChannelSupport

protected ChannelSupport(long channelID,
                         MessageStore ms,
                         PersistenceManager pm,
                         boolean acceptReliableMessages,
                         boolean recoverable,
                         int maxSize)
Method Detail

handle

public Delivery handle(DeliveryObserver sender,
                       MessageReference ref,
                       Transaction tx)
Description copied from interface: Receiver
A receiver can return an active, "done" or null delivery. The method returns null in case the receiver doesn't accept the message. The return value is unspecified when the message is submitted in the context of a transaction (tx not null).

Specified by:
handle in interface Receiver
Parameters:
sender - - the component the delivery should be acknowledged to.
See Also:
Delivery, DeliveryObserver

acknowledge

public void acknowledge(Delivery d,
                        Transaction tx)
                 throws java.lang.Throwable
Specified by:
acknowledge in interface DeliveryObserver
Throws:
java.lang.Throwable

cancel

public void cancel(Delivery del)
            throws java.lang.Throwable
Specified by:
cancel in interface DeliveryObserver
Throws:
java.lang.Throwable

add

public boolean add(Receiver r)
Description copied from interface: Distributor
Add a local receiver to this distributor.

Specified by:
add in interface Distributor
Returns:
true if the distributor did not already contain the specified receiver and the receiver was added to the distributor, false otherwise.

remove

public boolean remove(Receiver r)
Description copied from interface: Distributor
Remove a local receiver from this distributor.

Specified by:
remove in interface Distributor
Returns:
true if this distributor contained the specified receiver.

clear

public void clear()
Description copied from interface: Channel
Clears non-recoverable state but not persisted state, so a recovery of the channel is possible TODO really?

Specified by:
clear in interface Channel

contains

public boolean contains(Receiver r)
Specified by:
contains in interface Distributor

iterator

public java.util.Iterator iterator()
Specified by:
iterator in interface Distributor
Returns:
an iterator of local receivers

getNumberOfReceivers

public int getNumberOfReceivers()
Specified by:
getNumberOfReceivers in interface Distributor
Returns:
The number of receivers in the distributor

getChannelID

public long getChannelID()
Specified by:
getChannelID in interface Channel
Returns:
the unique ID of the channel

isRecoverable

public boolean isRecoverable()
Specified by:
isRecoverable in interface Channel
Returns:
true if the channel can guarantee recoverability for reliable messages. Recoverability is not guaranteed for non-reliable messages (and should not be provided by default, for performance reasons), even if the channel is recoverable.

acceptReliableMessages

public boolean acceptReliableMessages()
Description copied from interface: Channel
A non-recoverable channel cannot guarantee recoverability for reliable messages so by default it won't accept reliable messages. However, there are situations when discarding a reliable message is acceptable for a specific instance of a channel, so it should be a way to configure the channel to do so. A channel indicates unequivocally whether it accepts reliable messages or not returning true or false as result of this method. A recoverable channel must always accept reliable messages, so this method must always return true for a recoverable channel.

Specified by:
acceptReliableMessages in interface Channel
Returns:
false if the channel doesn't accept reliable messages.

browse

public java.util.List browse()
Specified by:
browse in interface Channel
Returns:
a List containing messages being held by the channel.

browse

public java.util.List browse(Filter filter)
Specified by:
browse in interface Channel
Parameters:
filter - - may be null, in which case no filter is applied.
Returns:
a List containing message references of messages whose state is maintained by this State instance.

deliver

public void deliver()
Description copied from interface: Channel
Delivers as many references as possible to its router until no more deliveries are returned.

Specified by:
deliver in interface Channel

close

public void close()
Description copied from interface: Channel
Close the channel

Specified by:
close in interface Channel

removeAllReferences

public void removeAllReferences()
                         throws java.lang.Throwable
Description copied from interface: Channel
Remove all the references in the channel

Specified by:
removeAllReferences in interface Channel
Throws:
java.lang.Throwable

undelivered

public java.util.List undelivered(Filter filter)

getMessageCount

public int getMessageCount()
Returns the count of messages stored AND being delivered AND scheduled

Specified by:
getMessageCount in interface Channel
Returns:
Total message count = undelivered + delivering + scheduled

getDeliveringCount

public int getDeliveringCount()
Specified by:
getDeliveringCount in interface Channel
Returns:
Count being delivered

getScheduledCount

public int getScheduledCount()
Description copied from interface: Channel
Count scheduled for delivery

Specified by:
getScheduledCount in interface Channel

activate

public void activate()
Specified by:
activate in interface Channel

deactivate

public void deactivate()
Specified by:
deactivate in interface Channel

isActive

public boolean isActive()
Specified by:
isActive in interface Channel

recoverDeliveries

public java.util.List recoverDeliveries(java.util.List messageIds)
Specified by:
recoverDeliveries in interface Channel

getMaxSize

public int getMaxSize()
Specified by:
getMaxSize in interface Channel

setMaxSize

public void setMaxSize(int newSize)
Specified by:
setMaxSize in interface Channel

getMessagesAdded

public int getMessagesAdded()
Specified by:
getMessagesAdded in interface Channel

memoryRefCount

public int memoryRefCount()

toString

public java.lang.String toString()

clearAllScheduledDeliveries

protected void clearAllScheduledDeliveries()

cancelInternal

protected void cancelInternal(MessageReference ref)
                       throws java.lang.Exception
Throws:
java.lang.Exception

deliverInternal

protected void deliverInternal()
This methods delivers as many messages as possible to the router until no more deliveries are returned. This method should never be called at the same time as handle.

See Also:
Channel.deliver()

deliverScheduled

protected boolean deliverScheduled(MessageReference ref)

handleInternal

protected Delivery handleInternal(DeliveryObserver sender,
                                  MessageReference ref,
                                  Transaction tx,
                                  boolean persist)

checkAndSchedule

protected boolean checkAndSchedule(MessageReference ref)

acknowledgeInternal

protected void acknowledgeInternal(Delivery d,
                                   Transaction tx,
                                   boolean persist)
                            throws java.lang.Exception
Throws:
java.lang.Exception

getCallback

protected org.jboss.messaging.core.ChannelSupport.InMemoryCallback getCallback(Transaction tx)

removeFirstInMemory

protected MessageReference removeFirstInMemory()
                                        throws java.lang.Exception
Throws:
java.lang.Exception

addReferenceInMemory

protected void addReferenceInMemory(MessageReference ref)
                             throws java.lang.Exception
Throws:
java.lang.Exception

processMessageBeforeStorage

protected void processMessageBeforeStorage(MessageReference reference)
Give subclass a chance to process the message before storing it internally. TODO - Do we really need this?


checkClosed

protected void checkClosed()


Copyright © 2006 JBoss Inc. All Rights Reserved.