org.jboss.messaging.core.impl
Class ChannelSupport

java.lang.Object
  extended by org.jboss.messaging.core.impl.ChannelSupport
All Implemented Interfaces:
Channel, DeliveryObserver, 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 for reliable messages.

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

Field Summary
protected  boolean active
           
protected  long channelID
           
protected  SynchronizedInt deliveringCount
           
protected  Distributor distributor
           
protected  java.lang.Object lock
           
protected  int maxSize
           
protected  PriorityLinkedList messageRefs
           
protected  SynchronizedInt messagesAdded
           
protected  PersistenceManager pm
           
protected  boolean receiversReady
           
protected  boolean recoverable
           
protected  java.util.Set scheduledDeliveries
           
 
Constructor Summary
protected ChannelSupport(long channelID, PersistenceManager pm, boolean recoverable, int maxSize)
           
 
Method Summary
 void acknowledge(Delivery d, Transaction tx)
           
protected  void acknowledgeInternal(Delivery d, Transaction tx, boolean persist)
           
 void activate()
          Activate the channel.
protected  void addReferenceInMemory(MessageReference ref)
           
 java.util.List browse(Filter filter)
           
 void cancel(Delivery del)
           
protected  void cancelInternal(MessageReference ref)
           
protected  boolean checkAndSchedule(MessageReference ref)
           
protected  void checkClosed()
           
protected  void clearAllScheduledDeliveries()
           
 void close()
          Close the channel
 void deactivate()
          Deactivate the channel
 void deliver()
          Delivers as many references as possible to its router until receivers will accept no more
protected  void deliverInternal()
          This methods delivers as many messages as possible to the distributor until no more deliveries are returned.
protected  boolean deliverScheduled(MessageReference ref)
           
protected  org.jboss.messaging.core.impl.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()
          Get the total number of messages added since this channel was started
protected  boolean getReceiversReady()
           
 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()
           
 int memoryRefCount()
           
protected  void processMessageBeforeStorage(MessageReference reference)
          Give subclass a chance to process the message before storing it internally.
 void removeAllReferences()
          Remove all the references in the channel
protected  MessageReference removeFirstInMemory()
           
 void setMaxSize(int newSize)
          Set the maximum number of references this channel can store
protected  void setReceiversReady(boolean receiversReady)
           
 java.util.List undelivered(Filter filter)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jboss.messaging.core.contract.Channel
load, unload
 

Field Detail

channelID

protected long channelID

distributor

protected Distributor distributor

receiversReady

protected boolean receiversReady

messageRefs

protected PriorityLinkedList messageRefs

recoverable

protected boolean recoverable

pm

protected PersistenceManager pm

lock

protected java.lang.Object lock

active

protected volatile 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,
                         PersistenceManager pm,
                         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

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 even if the channel is recoverable.

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 receivers will accept no more

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()
Description copied from interface: Channel
Activate the channel.

Specified by:
activate in interface Channel

deactivate

public void deactivate()
Description copied from interface: Channel
Deactivate the channel

Specified by:
deactivate in interface Channel

isActive

public boolean isActive()
Specified by:
isActive in interface Channel
Returns:
true if the channel is active

getMaxSize

public int getMaxSize()
Specified by:
getMaxSize in interface Channel
Returns:
The maxiumum number of references this channel can store

setMaxSize

public void setMaxSize(int newSize)
Description copied from interface: Channel
Set the maximum number of references this channel can store

Specified by:
setMaxSize in interface Channel

getMessagesAdded

public int getMessagesAdded()
Description copied from interface: Channel
Get the total number of messages added since this channel was started

Specified by:
getMessagesAdded in interface Channel
Returns:

memoryRefCount

public int memoryRefCount()

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 distributor 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.impl.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

getReceiversReady

protected boolean getReceiversReady()

setReceiversReady

protected void setReceiversReady(boolean receiversReady)

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.