org.exolab.jms.messagemgr
Class PersistentMessageHandle

java.lang.Object
  |
  +--org.exolab.core.foundation.PersistentObject
        |
        +--org.exolab.jms.messagemgr.PersistentMessageHandle
All Implemented Interfaces:
java.lang.Cloneable, java.io.Externalizable, MessageHandle, org.exolab.core.foundation.PersistentCapableIfc, java.io.Serializable

public class PersistentMessageHandle
extends org.exolab.core.foundation.PersistentObject
implements MessageHandle, java.lang.Cloneable

A persistent message handle extends MessageHandle and references a persistent message. These messages can be discarded from the cache and later faulted in through the 'resolve' method.

Version:
$Revision: 1.17 $ $Date: 2003/08/07 13:33:04 $
Author:
Jim Alateras
See Also:
Serialized Form

Constructor Summary
PersistentMessageHandle()
          Default constructor
PersistentMessageHandle(MessageImpl message)
          Create a persistent handle from a message
 
Method Summary
 void clear()
          Override the behaviour of the base class.
 java.lang.Object clone()
          Clone the persistent message handle object
 void destroy()
          Destroy this handle
 boolean equals(java.lang.Object object)
           
 long getAcceptedTime()
          Return the time that the message was accepted by the server
 long getClientId()
          Retrieve the client identity associated with this handle
 java.lang.String getConsumerName()
          Return the consumer namne
 boolean getDelivered()
          Return the delivered state of the message
 JmsDestination getDestination()
          Return the destination for this handle
 long getExpiryTime()
          Return the message expiry time
 MessageImpl getMessage()
          Return the associated message or null if it is invalid
 MessageId getMessageId()
          Return the identity of the underlying message
 int getPriority()
          Return the priority of the corresponding message
 long getSequenceNumber()
          Return message's sequence number
 boolean hasExpired()
          Determines if the message has expired
 int hashCode()
           
 boolean isPersistent()
          Check whether the the DeliveryMode of the underlying message is PERSISTENT
 void readExternal(java.io.ObjectInput stream)
           
 void setAcceptedTime(long time)
          Set the time that the message was accepted by the server
 void setClientId(long clientId)
          Set the client id, that owns this handle
 void setConsumerName(java.lang.String name)
          Set the consumer endpoint that owns this handle.
 void setDelivered()
          This is used to set the message as delivered.
 void setDelivered(boolean value)
          Set the delivered flag for the underlying message.
 void setDestination(JmsDestination destination)
          Set the destination that owns this handle
 void setExpiryTime(long time)
          Set the message expiry time
 void setMessageId(MessageId id)
          Set the identity of the underlying message
 void setPriority(int priority)
          Set the messagee priority
 void setSequenceNumber(long seq)
          Set the message's sequence number
 java.lang.String toString()
           
 void writeExternal(java.io.ObjectOutput stream)
           
 
Methods inherited from class org.exolab.core.foundation.PersistentObject
getId, getMinimumObjectSize, getObjectId, getObjectVersion, getVersion, setId, setMinimumObjectSize, setObjectId, setObjectVersion, setVersion
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PersistentMessageHandle

public PersistentMessageHandle()
Default constructor

PersistentMessageHandle

public PersistentMessageHandle(MessageImpl message)
                        throws javax.jms.JMSException
Create a persistent handle from a message
Parameters:
message - - persistent message
Throws:
javax.jms.JMSException - - if the object cannot be constructed
Method Detail

setMessageId

public void setMessageId(MessageId id)
Set the identity of the underlying message
Parameters:
id - - the message id

getMessageId

public MessageId getMessageId()
Return the identity of the underlying message
Specified by:
getMessageId in interface MessageHandle
Returns:
MessageId

getMessage

public MessageImpl getMessage()
Return the associated message or null if it is invalid
Specified by:
getMessage in interface MessageHandle
Returns:
MessageImpl

setPriority

public void setPriority(int priority)
Set the messagee priority
Specified by:
setPriority in interface MessageHandle
Parameters:
id - the persistent id

getPriority

public int getPriority()
Return the priority of the corresponding message
Specified by:
getPriority in interface MessageHandle
Returns:
int

setDelivered

public void setDelivered(boolean value)
Set the delivered flag for the underlying message. True if an attempt has been made to deliver the message
Specified by:
setDelivered in interface MessageHandle
Parameters:
value - - true if delivered

getDelivered

public boolean getDelivered()
Return the delivered state of the message
Specified by:
getDelivered in interface MessageHandle
Returns:
long

setAcceptedTime

public void setAcceptedTime(long time)
Set the time that the message was accepted by the server
Specified by:
setAcceptedTime in interface MessageHandle
Parameters:
long - - time since epoch

getAcceptedTime

public long getAcceptedTime()
Return the time that the message was accepted by the server
Specified by:
getAcceptedTime in interface MessageHandle
Returns:
long - time in ms since epoch

setSequenceNumber

public void setSequenceNumber(long seq)
Set the message's sequence number
Specified by:
setSequenceNumber in interface MessageHandle
Parameters:
seq - - sequence time

getSequenceNumber

public long getSequenceNumber()
Return message's sequence number
Specified by:
getSequenceNumber in interface MessageHandle
Returns:
long - the sequence number

setExpiryTime

public void setExpiryTime(long time)
Set the message expiry time
Specified by:
setExpiryTime in interface MessageHandle
Following copied from interface: org.exolab.jms.message.MessageHandle
Parameters:
time - - time that it was set in ms

getExpiryTime

public long getExpiryTime()
Return the message expiry time
Specified by:
getExpiryTime in interface MessageHandle
Returns:
long - time in ms since epoch

hasExpired

public boolean hasExpired()
Determines if the message has expired
Returns:
true if the message has expired, otherwise false

setConsumerName

public void setConsumerName(java.lang.String name)
Description copied from interface: MessageHandle
Set the consumer endpoint that owns this handle. If it is set then a consumer owns it exclusively, otherwise the handle may be shared across a number of consumers.
Specified by:
setConsumerName in interface MessageHandle
Following copied from interface: org.exolab.jms.message.MessageHandle
Parameters:
name - - consumer name

getConsumerName

public java.lang.String getConsumerName()
Description copied from interface: MessageHandle
Return the consumer namne
Specified by:
getConsumerName in interface MessageHandle
Following copied from interface: org.exolab.jms.message.MessageHandle
Returns:
String

isPersistent

public boolean isPersistent()
Description copied from interface: MessageHandle
Check whether the the DeliveryMode of the underlying message is PERSISTENT
Specified by:
isPersistent in interface MessageHandle

setDestination

public void setDestination(JmsDestination destination)
Set the destination that owns this handle
Specified by:
setDestination in interface MessageHandle
Parameters:
destination - - the destination

getDestination

public JmsDestination getDestination()
Return the destination for this handle
Specified by:
getDestination in interface MessageHandle
Returns:
JmsDestination

setClientId

public void setClientId(long clientId)
Set the client id, that owns this handle
Specified by:
setClientId in interface MessageHandle
Parameters:
clientId - - client identity

getClientId

public long getClientId()
Retrieve the client identity associated with this handle
Specified by:
getClientId in interface MessageHandle
Returns:
long

clear

public void clear()
Override the behaviour of the base class. I don't think we want to clear the handle unless there are definitely no more references.
Specified by:
clear in interface MessageHandle

destroy

public void destroy()
Destroy this handle
Specified by:
destroy in interface MessageHandle

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clone the persistent message handle object
Overrides:
clone in class org.exolab.core.foundation.PersistentObject
Returns:
copy of a PersistentMessageHandle
Throws:
java.lang.CloneNotSupportedException -  

equals

public boolean equals(java.lang.Object object)
Overrides:
equals in class org.exolab.core.foundation.PersistentObject

toString

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

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

setDelivered

public void setDelivered()
This is used to set the message as delivered. This can only be called by the delivery engine and should not be used anywhere else. This will mark the message as being delivered and also update the database

We do not really throw an exception here....and it seems that this is a very fine grained approach to dealing with this...basically translates to a transaction for every message.

Specified by:
setDelivered in interface MessageHandle

writeExternal

public void writeExternal(java.io.ObjectOutput stream)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Overrides:
writeExternal in class org.exolab.core.foundation.PersistentObject

readExternal

public void readExternal(java.io.ObjectInput stream)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Overrides:
readExternal in class org.exolab.core.foundation.PersistentObject


Copyright © 1999-2004 The OpenJMS Group. All Rights Reserved.