org.exolab.jms.messagemgr
Class MessageLeaseHelper

java.lang.Object
  |
  +--org.exolab.jms.messagemgr.MessageLeaseHelper
All Implemented Interfaces:
LeaseEventListenerIfc

public class MessageLeaseHelper
extends java.lang.Object
implements LeaseEventListenerIfc

This is a helper class for registering leases for messages with LeaseManager. The lease is based on the JMSExpiration property of the message.
When the lease expires, the listener's onLeaseExpired() method is invoked with a MessageHandle object passed as the argument.
If JMSExpiration is 0, the message never expires.

Version:
$Revision: 1.16 $ $Date: 2003/08/17 01:32:24 $
Author:
Tim Anderson
See Also:
MessageHandle, LeaseManager, LeaseEventListenerIfc

Constructor Summary
MessageLeaseHelper(java.sql.Connection connection, DestinationCache listener)
          Construct a helper for the specified destination cache.
MessageLeaseHelper(DestinationCache listener)
          Construct a helper for the specified destination cache.
 
Method Summary
 void addLease(MessageHandle handle)
          Add a lease for the handle to notify listener when message expires.
 void addLease(MessageImpl message)
          Add a lease for message to notify listener when message expires.
 void clear()
          Clears all leases
protected  void init(DestinationCache listener, java.sql.Connection connection)
          This method is used for all common initialization code.
 void onLeaseExpired(java.lang.Object handle)
          Invoked when a lease has expired.
 void removeLease(MessageImpl message)
          Remove a lease for a message
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageLeaseHelper

public MessageLeaseHelper(DestinationCache listener)
                   throws PersistenceException
Construct a helper for the specified destination cache.
Parameters:
listener - the object to notify when a lease expires
Throws:
PersistenceException - if the destination is administered and the set of non-expired messages cannot be determined

MessageLeaseHelper

public MessageLeaseHelper(java.sql.Connection connection,
                          DestinationCache listener)
                   throws PersistenceException
Construct a helper for the specified destination cache.

This method is only called during cache init time and is used to retrieve persistent messages with leases.

Parameters:
connection - the connection to use to retrieve persistent messages with leases
listener - the object to notify when a lease expires
Throws:
PersistenceException - if the destination is administered and the set of non-expired messages cannot be determined
Method Detail

addLease

public void addLease(MessageImpl message)
Add a lease for message to notify listener when message expires. The lease uses JMSExpiration property of the message. If this is unset or 0, then no lease is registered. If non-zero, a MessageHandle object is registered with LeaseManager, and the listener will be notified with this object when the lease expires.
Parameters:
message - the message to add a lease for

addLease

public void addLease(MessageHandle handle)
Add a lease for the handle to notify listener when message expires. The lease uses JMSExpiration property of the message. If this is unset or 0, then no lease is registered. If non-zero, a MessageHandle object is registered with LeaseManager, and the listener will be notified with this object when the lease expires.
Parameters:
handle - message handle to add

removeLease

public void removeLease(MessageImpl message)
Remove a lease for a message
Parameters:
message - the message to remove the lease for

clear

public void clear()
Clears all leases

onLeaseExpired

public void onLeaseExpired(java.lang.Object handle)
Invoked when a lease has expired.
It removes the local lease, and notifies the listener.
Specified by:
onLeaseExpired in interface LeaseEventListenerIfc
Parameters:
handle - An instance of MessageHandle

init

protected void init(DestinationCache listener,
                    java.sql.Connection connection)
             throws PersistenceException
This method is used for all common initialization code. It basically retrieves all non-expired messages and places them in the memory
Parameters:
listener - the cache listening for expired leases.
connection - the persistent connection to use
Throws:
PersistenceException - if the destination is administered and the set of non-expired messages cannot be determined


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