org.jboss.mq.pm.jdbc3
Class PersistenceManager

java.lang.Object
  extended byorg.jboss.mx.util.JBossNotificationBroadcasterSupport (src) 
      extended byorg.jboss.system.ServiceMBeanSupport (src) 
          extended byorg.jboss.mq.pm.jdbc3.PersistenceManager
All Implemented Interfaces:
CacheStore (src) , MBeanRegistration (src) , NewPersistenceManager (src) , NotificationBroadcaster (src) , NotificationEmitter (src) , PersistenceManager (src) , java.lang.Runnable, Service (src) , ServiceMBean (src)

public class PersistenceManager
extends ServiceMBeanSupport (src)
implements NewPersistenceManager (src) , CacheStore (src) , java.lang.Runnable

This class manages all persistence related services for JDBC based persistence.


Field Summary
 
Fields inherited from class org.jboss.system.ServiceMBeanSupport (src)
log, server, SERVICE_CONTROLLER_SIG, serviceName
 
Fields inherited from interface org.jboss.system.ServiceMBean (src)
CREATE_EVENT, CREATED, DESTROY_EVENT, DESTROYED, FAILED, REGISTERED, START_EVENT, STARTED, STARTING, states, STOP_EVENT, STOPPED, STOPPING, UNREGISTERED
 
Constructor Summary
PersistenceManager()
          Create a new persistence manager
 
Method Summary
 void add(MessageReference (src)  messageRef, Tx (src)  txId)
          Add a message to the persistent store.
protected  void addMessage(java.sql.Connection c, java.lang.String queue, SpyMessage (src)  message, Tx (src)  txId, java.lang.String mark, java.lang.String lateClone)
          Add a message
 void addMessage(SpyMessage (src)  message)
          Persist the message
protected  void addReference(java.sql.Connection c, java.lang.String queue, MessageReference (src)  message, Tx (src)  txId, java.lang.String mark)
          Add a reference
 void closeQueue(JMSDestination (src)  jmsDest, SpyDestination (src)  dest)
          Close a queue
 void commitPersistentTx(Tx (src)  txId)
          Commit the transaction to the persistent store.
 Tx (src) createPersistentTx()
          Create and return a unique transaction id.
protected  SpyMessage (src) extractMessage(java.sql.ResultSet rs, int column)
          Extract a message from a result
protected  java.sql.Connection getConnection()
          Gets a connection from the datasource, retrying as needed.
 ObjectName (src) getConnectionManager()
          Retrieve the connection manager object name
 int getConnectionRetryAttempts()
          Gets the ConnectionRetryAttempts.
 int getGCPeriodSecs()
          Set the garbage collection period
 java.lang.Object getInstance()
           
 ObjectName (src) getMessageCache()
          Unsupported operation
 MessageCache (src) getMessageCacheInstance()
          Unsupported operation
 java.lang.String getSqlProperties()
          Gets the sqlProperties.
 TxManager (src) getTxManager()
          Get a transaction manager.
 SpyMessage (src) loadFromStorage(MessageReference (src)  messageRef)
          Reads the message refered to by the MessagReference back as a SpyMessage
 void remove(MessageReference (src)  messageRef, Tx (src)  txId)
          Remove message from the persistent store.
 void removeFromStorage(MessageReference (src)  messageRef)
          Removes the message that was stored in secondary storage.
protected  void removeMarkedMessages(java.sql.Connection c, Tx (src)  txid, java.lang.String mark)
          Remove messages for a given transaction and mark
protected  void removeMarkedReferences(java.sql.Connection c, Tx (src)  txid, java.lang.String mark)
          Remove references for a given transaction and mark
protected  void removeTXRecord(java.sql.Connection c, long txid)
          Remove a transaction record
protected  void resolveAllUncommitedTXs()
          Resolve uncommitted transactions
 void restoreQueue(JMSDestination (src)  jmsDest, SpyDestination (src)  dest)
          Restore a queue.
 void rollbackPersistentTx(Tx (src)  txId)
          Rollback the transaction.
 void run()
           
 void saveToStorage(MessageReference (src)  messageRef, SpyMessage (src)  message)
          Stores the given message to secondary storeage.
protected  void setBlob(java.sql.PreparedStatement stmt, int column, SpyMessage (src)  message)
          Store the message in a blob
 void setConnectionManager(ObjectName (src)  connectionManagerName)
          Set the connection manager object name
 void setConnectionRetryAttempts(int value)
          Sets the ConnectionRetryAttempts.
 void setGCPeriodSecs(int gcPeriodSecs)
          Set the garbage collection period in seconds
 void setMessageCache(ObjectName (src)  messageCache)
          Unsupported operation
 void setSqlProperties(java.lang.String value)
          Sets the sqlProperties.
protected  void startService()
          Sub-classes should override this method to provide custum 'start' logic.
protected  void stopService()
          Sub-classes should override this method to provide custum 'stop' logic.
 void update(MessageReference (src)  messageRef, Tx (src)  txId)
          Update message in the persistent store.
 
Methods inherited from class org.jboss.system.ServiceMBeanSupport (src)
create, createService, destroy, destroyService, getLog, getName, getNextNotificationSequenceNumber, getObjectName, getServer, getServiceName, getState, getStateString, jbossInternalCreate, jbossInternalDescription, jbossInternalDestroy, jbossInternalLifecycle, jbossInternalStart, jbossInternalStop, postDeregister, postRegister, preDeregister, preRegister, start, stop
 
Methods inherited from class org.jboss.mx.util.JBossNotificationBroadcasterSupport (src)
addNotificationListener, getNotificationInfo, handleNotification, removeNotificationListener, removeNotificationListener, sendNotification
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PersistenceManager

public PersistenceManager()
                   throws JMSException (src) 
Create a new persistence manager

Throws:
JMSException (src) - for any error
Method Detail

getConnectionManager

public ObjectName (src)  getConnectionManager()
Retrieve the connection manager object name


setConnectionManager

public void setConnectionManager(ObjectName (src)  connectionManagerName)
Set the connection manager object name


getGCPeriodSecs

public int getGCPeriodSecs()
Set the garbage collection period


setGCPeriodSecs

public void setGCPeriodSecs(int gcPeriodSecs)
Set the garbage collection period in seconds


getConnectionRetryAttempts

public int getConnectionRetryAttempts()
Gets the ConnectionRetryAttempts.

Returns:
the number of retry events

setConnectionRetryAttempts

public void setConnectionRetryAttempts(int value)
Sets the ConnectionRetryAttempts.

Parameters:
value - the number of retry attempts

getSqlProperties

public java.lang.String getSqlProperties()
Gets the sqlProperties.

Returns:
Returns the Properties

setSqlProperties

public void setSqlProperties(java.lang.String value)
Sets the sqlProperties.


createPersistentTx

public Tx (src)  createPersistentTx()
                      throws JMSException (src) 
Description copied from interface: PersistenceManager (src)
Create and return a unique transaction id.

Specified by:
createPersistentTx in interface PersistenceManager (src)
Returns:
the transaction
Throws:
JMSException (src) - for any error

commitPersistentTx

public void commitPersistentTx(Tx (src)  txId)
                        throws JMSException (src) 
Description copied from interface: PersistenceManager (src)
Commit the transaction to the persistent store.

Specified by:
commitPersistentTx in interface PersistenceManager (src)
Parameters:
txId - Description of Parameter
Throws:
JMSException (src) - for any error

rollbackPersistentTx

public void rollbackPersistentTx(Tx (src)  txId)
                          throws JMSException (src) 
Description copied from interface: PersistenceManager (src)
Rollback the transaction.

Specified by:
rollbackPersistentTx in interface PersistenceManager (src)
Parameters:
txId - Description of Parameter
Throws:
JMSException (src) - for any error

add

public void add(MessageReference (src)  messageRef,
                Tx (src)  txId)
         throws JMSException (src) 
Description copied from interface: PersistenceManager (src)
Add a message to the persistent store. If the message is part of a transaction, txId is not null.

Specified by:
add in interface PersistenceManager (src)
Parameters:
messageRef - the message
txId - the transaction
Throws:
JMSException (src) - for any error

update

public void update(MessageReference (src)  messageRef,
                   Tx (src)  txId)
            throws JMSException (src) 
Description copied from interface: PersistenceManager (src)
Update message in the persistent store. If the message is part of a transaction, txId is not null (not currently supported).

Specified by:
update in interface PersistenceManager (src)
Parameters:
messageRef -
txId - Description of Parameter
Throws:
JMSException (src) - for any error

remove

public void remove(MessageReference (src)  messageRef,
                   Tx (src)  txId)
            throws JMSException (src) 
Description copied from interface: PersistenceManager (src)
Remove message from the persistent store. If the message is part of a transaction, txId is not null.

Specified by:
remove in interface PersistenceManager (src)
Parameters:
messageRef - the message
txId - the transaction
Throws:
JMSException (src) - for any error

restoreQueue

public void restoreQueue(JMSDestination (src)  jmsDest,
                         SpyDestination (src)  dest)
                  throws JMSException (src) 
Description copied from interface: PersistenceManager (src)
Restore a queue.

Specified by:
restoreQueue in interface PersistenceManager (src)
Parameters:
jmsDest - the jms destination
dest - the client destination
Throws:
JMSException (src) - for any error

getTxManager

public TxManager (src)  getTxManager()
Description copied from interface: PersistenceManager (src)
Get a transaction manager.

Specified by:
getTxManager in interface PersistenceManager (src)
Returns:
the transaction manager

closeQueue

public void closeQueue(JMSDestination (src)  jmsDest,
                       SpyDestination (src)  dest)
                throws JMSException (src) 
Description copied from interface: PersistenceManager (src)
Close a queue

Specified by:
closeQueue in interface PersistenceManager (src)
Parameters:
jmsDest - the jms destination
dest - the client destination
Throws:
JMSException (src) - for any error

getMessageCacheInstance

public MessageCache (src)  getMessageCacheInstance()
Unsupported operation

Specified by:
getMessageCacheInstance in interface PersistenceManager (src)
Returns:
the instance of the message cache

addMessage

public void addMessage(SpyMessage (src)  message)
                throws JMSException (src) 
Description copied from interface: NewPersistenceManager (src)
Persist the message

Specified by:
addMessage in interface NewPersistenceManager (src)
Parameters:
message - the message to persist
Throws:
JMSException (src) - for any error

getInstance

public java.lang.Object getInstance()

getMessageCache

public ObjectName (src)  getMessageCache()
Unsupported operation


setMessageCache

public void setMessageCache(ObjectName (src)  messageCache)
Unsupported operation


loadFromStorage

public SpyMessage (src)  loadFromStorage(MessageReference (src)  messageRef)
                           throws JMSException (src) 
Description copied from interface: CacheStore (src)
Reads the message refered to by the MessagReference back as a SpyMessage

Specified by:
loadFromStorage in interface CacheStore (src)
Parameters:
messageRef - the message reference
Returns:
the message
Throws:
JMSException (src) - for any error

removeFromStorage

public void removeFromStorage(MessageReference (src)  messageRef)
                       throws JMSException (src) 
Description copied from interface: CacheStore (src)
Removes the message that was stored in secondary storage.

Specified by:
removeFromStorage in interface CacheStore (src)
Parameters:
messageRef - the message reference
Throws:
JMSException (src) - for any error

saveToStorage

public void saveToStorage(MessageReference (src)  messageRef,
                          SpyMessage (src)  message)
                   throws JMSException (src) 
Description copied from interface: CacheStore (src)
Stores the given message to secondary storeage. You should be able to use the MessagReference to load the message back later.

Specified by:
saveToStorage in interface CacheStore (src)
Parameters:
messageRef - the message reference
message - the message
Throws:
JMSException (src) - for any error

run

public void run()
Specified by:
run in interface java.lang.Runnable

startService

protected void startService()
                     throws java.lang.Exception
Description copied from class: ServiceMBeanSupport (src)
Sub-classes should override this method to provide custum 'start' logic.

This method is empty, and is provided for convenience when concrete service classes do not need to perform anything specific for this state change.

Overrides:
startService in class ServiceMBeanSupport (src)
Throws:
java.lang.Exception

stopService

protected void stopService()
                    throws java.lang.Exception
Description copied from class: ServiceMBeanSupport (src)
Sub-classes should override this method to provide custum 'stop' logic.

This method is empty, and is provided for convenience when concrete service classes do not need to perform anything specific for this state change.

Overrides:
stopService in class ServiceMBeanSupport (src)
Throws:
java.lang.Exception

resolveAllUncommitedTXs

protected void resolveAllUncommitedTXs()
                                throws JMSException (src) 
Resolve uncommitted transactions

Throws:
JMSException (src) - for any error

removeTXRecord

protected void removeTXRecord(java.sql.Connection c,
                              long txid)
                       throws java.sql.SQLException
Remove a transaction record

Parameters:
c - the connection
txid - the transaction
Throws:
java.sql.SQLException - for any error

addMessage

protected void addMessage(java.sql.Connection c,
                          java.lang.String queue,
                          SpyMessage (src)  message,
                          Tx (src)  txId,
                          java.lang.String mark,
                          java.lang.String lateClone)
                   throws java.sql.SQLException,
                          java.io.IOException
Add a message

Parameters:
c - the connection
queue - the queue name
message - the message
mark - the mark to set for the message
Throws:
java.sql.SQLException - for an error in the db
java.io.IOException - for an error serializing the message

addReference

protected void addReference(java.sql.Connection c,
                            java.lang.String queue,
                            MessageReference (src)  message,
                            Tx (src)  txId,
                            java.lang.String mark)
                     throws java.sql.SQLException,
                            java.io.IOException
Add a reference

Parameters:
c - the connection
queue - the queue name
message - the reference
mark - the mark to set for the message
Throws:
java.sql.SQLException - for an error in the db
java.io.IOException - for an error serializing the message

removeMarkedMessages

protected void removeMarkedMessages(java.sql.Connection c,
                                    Tx (src)  txid,
                                    java.lang.String mark)
                             throws java.sql.SQLException
Remove messages for a given transaction and mark

Parameters:
c - the connection
txid - the transaction id
mark - the mark
Throws:
java.sql.SQLException - for any error

removeMarkedReferences

protected void removeMarkedReferences(java.sql.Connection c,
                                      Tx (src)  txid,
                                      java.lang.String mark)
                               throws java.sql.SQLException
Remove references for a given transaction and mark

Parameters:
c - the connection
txid - the transaction id
mark - the mark
Throws:
java.sql.SQLException - for any error

setBlob

protected void setBlob(java.sql.PreparedStatement stmt,
                       int column,
                       SpyMessage (src)  message)
                throws java.io.IOException,
                       java.sql.SQLException
Store the message in a blob

Parameters:
stmt - the prepared statement
column - the column in the prepared statement
message - the message
Throws:
java.io.IOException
java.sql.SQLException

extractMessage

protected SpyMessage (src)  extractMessage(java.sql.ResultSet rs,
                                    int column)
                             throws java.sql.SQLException,
                                    java.io.IOException
Extract a message from a result

Parameters:
rs - the result set
column - the column number
Returns:
the message
Throws:
java.sql.SQLException - for an error accessing the db
java.io.IOException - for an error extracting the message

getConnection

protected java.sql.Connection getConnection()
                                     throws java.sql.SQLException
Gets a connection from the datasource, retrying as needed. This was implemented because in some minimal configurations (i.e. little logging and few services) the database wasn't ready when we tried to get a connection. We, therefore, implement a retry loop wich is controled by the ConnectionRetryAttempts attribute. Submitted by terry@amicas.com

Throws:
java.sql.SQLException - if an error occurs.