User: chirino Date: 01/08/16 20:04:05 Modified: src/main/org/jboss/mq/pm PersistenceManager.java Tx.java TxManager.java Log: Used the ejbdoclet pretty task to auto-indent the source files to the 3 space standard. Revision Changes Path 1.2 +86 -91 jbossmq/src/main/org/jboss/mq/pm/PersistenceManager.java Index: PersistenceManager.java =================================================================== RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/pm/PersistenceManager.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- PersistenceManager.java 2001/08/11 20:59:14 1.1 +++ PersistenceManager.java 2001/08/17 03:04:04 1.2 @@ -6,108 +6,103 @@ */ package org.jboss.mq.pm; -import javax.jms.JMSException; - import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; - - - - - - +import javax.jms.JMSException; +import org.jboss.mq.ConnectionToken; import org.jboss.mq.SpyDestination; -import org.jboss.mq.xml.XElement; -import org.jboss.mq.ConnectionToken; import org.jboss.mq.SpyMessage; +import org.jboss.mq.xml.XElement; /** - * This class allows provides the base for user supplied persistence packages. - * - * @author Hiram Chirino ([EMAIL PROTECTED]) - * @author Paul Kendall ([EMAIL PROTECTED]) + * This class allows provides the base for user supplied persistence packages. * - * @version $Revision: 1.1 $ + * @author Hiram Chirino ([EMAIL PROTECTED]) + * @author Paul Kendall ([EMAIL PROTECTED]) + * @created August 16, 2001 + * @version $Revision: 1.2 $ */ public interface PersistenceManager { - - - - - - - - - - - - - - - - - - - - - /** - * Create and return a unique transaction id. - */ - public abstract Tx createPersistentTx() throws javax.jms.JMSException; - - /** - * Commit the transaction to the persistent store. - */ - public abstract void commitPersistentTx(Tx txId) throws javax.jms.JMSException; - - /** - * Rollback the transaction. - */ - public abstract void rollbackPersistentTx(Tx txId) throws javax.jms.JMSException; - - - - - - - - - - public TxManager getTxManager(); - - - - /** - * Remove message from the persistent store. - * If the message is part of a transaction, txId is not null. - */ - public abstract void add(SpyMessage message, Tx txId) throws javax.jms.JMSException; - - /** - * Remove the queue, and all messages in it, from the persistent store - */ - public abstract void destroyQueue( SpyDestination dest ) throws javax.jms.JMSException; - - /** - * Initialize the queue. - */ - public abstract void initQueue( SpyDestination dest ) throws javax.jms.JMSException; - - /** - * Remove message from the persistent store. - * If the message is part of a transaction, txId is not null. - */ - public abstract void remove(SpyMessage message, Tx txId) throws javax.jms.JMSException; - -/** - * - * @param server org.jboss.mq.server.JMSServer - * @exception javax.jms.JMSException The exception description. - */ -void restore(org.jboss.mq.server.JMSServer server) throws javax.jms.JMSException; -} \ No newline at end of file + /** + * Create and return a unique transaction id. + * + * @return Description of the Returned Value + * @exception javax.jms.JMSException Description of Exception + */ + public abstract Tx createPersistentTx() + throws javax.jms.JMSException; + + /** + * Commit the transaction to the persistent store. + * + * @param txId Description of Parameter + * @exception javax.jms.JMSException Description of Exception + */ + public abstract void commitPersistentTx( Tx txId ) + throws javax.jms.JMSException; + + /** + * Rollback the transaction. + * + * @param txId Description of Parameter + * @exception javax.jms.JMSException Description of Exception + */ + public abstract void rollbackPersistentTx( Tx txId ) + throws javax.jms.JMSException; + + + public TxManager getTxManager(); + + + /** + * Remove message from the persistent store. If the message is part of a + * transaction, txId is not null. + * + * @param message Description of Parameter + * @param txId Description of Parameter + * @exception javax.jms.JMSException Description of Exception + */ + public abstract void add( SpyMessage message, Tx txId ) + throws javax.jms.JMSException; + + /** + * Remove the queue, and all messages in it, from the persistent store + * + * @param dest Description of Parameter + * @exception javax.jms.JMSException Description of Exception + */ + public abstract void destroyQueue( SpyDestination dest ) + throws javax.jms.JMSException; + + /** + * Initialize the queue. + * + * @param dest Description of Parameter + * @exception javax.jms.JMSException Description of Exception + */ + public abstract void initQueue( SpyDestination dest ) + throws javax.jms.JMSException; + + /** + * Remove message from the persistent store. If the message is part of a + * transaction, txId is not null. + * + * @param message Description of Parameter + * @param txId Description of Parameter + * @exception javax.jms.JMSException Description of Exception + */ + public abstract void remove( SpyMessage message, Tx txId ) + throws javax.jms.JMSException; + + /** + * @param server org.jboss.mq.server.JMSServer + * @exception javax.jms.JMSException The exception description. + */ + void restore( org.jboss.mq.server.JMSServer server ) + throws javax.jms.JMSException; +} 1.2 +50 -44 jbossmq/src/main/org/jboss/mq/pm/Tx.java Index: Tx.java =================================================================== RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/pm/Tx.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- Tx.java 2001/08/11 20:59:14 1.1 +++ Tx.java 2001/08/17 03:04:04 1.2 @@ -1,46 +1,52 @@ package org.jboss.mq.pm; -public class Tx implements Comparable, java.io.Serializable, java.io.Externalizable{ - - long value = 0; - public Tx() { - } - - public Tx(long value) { - this.value = value; - } - - public void setValue(long tx){ - value = tx; - } - - public int hashCode() { - return (int)(value ^ (value >> 32)); - } - - public int compareTo(Tx anotherLong) { - long thisVal = this.value; - long anotherVal = anotherLong.value; - return (thisVal<anotherVal ? -1 : (thisVal==anotherVal ? 0 : 1)); - } - - public int compareTo(Object o) { - return compareTo((Tx)o); - } - - public void readExternal(java.io.ObjectInput in) throws java.io.IOException{ - value = in.readLong(); - } - - public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException{ - out.writeLong(value); - } - - public long longValue(){ - return value; - } - - public String toString(){ - return ""+value; - } -} \ No newline at end of file +/** + * @created August 16, 2001 + */ +public class Tx implements Comparable, java.io.Serializable, java.io.Externalizable { + + long value = 0; + + public Tx() { + } + + public Tx( long value ) { + this.value = value; + } + + public void setValue( long tx ) { + value = tx; + } + + public int hashCode() { + return ( int )( value ^ ( value >> 32 ) ); + } + + public int compareTo( Tx anotherLong ) { + long thisVal = this.value; + long anotherVal = anotherLong.value; + return ( thisVal < anotherVal ? -1 : ( thisVal == anotherVal ? 0 : 1 ) ); + } + + public int compareTo( Object o ) { + return compareTo( ( Tx )o ); + } + + public void readExternal( java.io.ObjectInput in ) + throws java.io.IOException { + value = in.readLong(); + } + + public void writeExternal( java.io.ObjectOutput out ) + throws java.io.IOException { + out.writeLong( value ); + } + + public long longValue() { + return value; + } + + public String toString() { + return "" + value; + } +} 1.2 +253 -224 jbossmq/src/main/org/jboss/mq/pm/TxManager.java Index: TxManager.java =================================================================== RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/pm/TxManager.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- TxManager.java 2001/08/11 20:59:14 1.1 +++ TxManager.java 2001/08/17 03:04:04 1.2 @@ -6,240 +6,269 @@ */ package org.jboss.mq.pm; -import javax.jms.JMSException; - import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; - - - - - - +import javax.jms.JMSException; +import org.jboss.mq.ConnectionToken; import org.jboss.mq.SpyDestination; -import org.jboss.mq.xml.XElement; -import org.jboss.mq.ConnectionToken; -import org.jboss.mq.SpyMessage; import org.jboss.mq.SpyJMSException; +import org.jboss.mq.SpyMessage; +import org.jboss.mq.xml.XElement; /** - * This class allows provides the base for user supplied persistence packages. - * - * @author Hiram Chirino ([EMAIL PROTECTED]) - * @author Paul Kendall ([EMAIL PROTECTED]) + * This class allows provides the base for user supplied persistence packages. * - * @version $Revision: 1.1 $ + * @author Hiram Chirino ([EMAIL PROTECTED]) + * @author Paul Kendall ([EMAIL PROTECTED]) + * @created August 16, 2001 + * @version $Revision: 1.2 $ */ public class TxManager { - // Maps (Long)txIds to LinkedList of Runnable tasks - HashMap postCommitTasks = new HashMap(); - // Maps (Long)txIds to LinkedList of Runnable tasks - HashMap postRollbackTasks = new HashMap(); - // Maps Global transactions to local transactions - HashMap globalToLocal = new HashMap(); - - protected static int MAX_POOL_SIZE = 500; - //pool of linked lists to use for storing txs tasks - java.util.ArrayList listPool = new java.util.ArrayList(); - - protected LinkedList getList(){ - synchronized(listPool){ - if(listPool.isEmpty()){ - return new LinkedList(); - }else{ - return (LinkedList)listPool.remove(listPool.size()-1); - } - } - } - - protected void releaseList(LinkedList list){ - synchronized(listPool){ - if(listPool.size() < MAX_POOL_SIZE){ - list.clear(); - listPool.add(list); - } - } - } - - - class GlobalXID implements Runnable { - ConnectionToken dc; - Object xid; - - GlobalXID(ConnectionToken dc,Object xid) { - this.dc = dc; - this.xid = xid; - } - - public boolean equals(Object obj) - { - if (obj==null) return false; - if (obj.getClass()!=GlobalXID.class) return false; - return ((GlobalXID)obj).xid.equals( xid ) && - ((GlobalXID)obj).dc.equals(dc); - } - - public int hashCode() { - return xid.hashCode(); - } - - public void run() { - synchronized (globalToLocal) { - globalToLocal.remove(this); - } - } - } - - /** - * Create and return a unique transaction id. - */ - public final Tx createTx() throws javax.jms.JMSException { - Tx txId = persistenceManager.createPersistentTx(); - synchronized (postCommitTasks) { - postCommitTasks.put(txId, getList()); - postRollbackTasks.put(txId, getList()); - } - return txId; - } - - /** - * Commit the transaction to the persistent store. - */ - public final void commitTx(Tx txId) throws javax.jms.JMSException { - - LinkedList tasks; - synchronized( postCommitTasks ) { - tasks = (LinkedList)postCommitTasks.remove(txId); - releaseList((LinkedList)postRollbackTasks.remove(txId)); - } - if( tasks == null ) - throw new javax.jms.JMSException("Transaction is not active for commit."); - - persistenceManager.commitPersistentTx(txId); - - synchronized(tasks){ - Iterator iter = tasks.iterator(); - while( iter.hasNext() ) { - Runnable task = (Runnable)iter.next(); - task.run(); - } - } - releaseList(tasks); - } - - public final void addPostCommitTask(Tx txId, Runnable task) throws javax.jms.JMSException { - - if( txId == null ) { - task.run(); - return; - } - - LinkedList tasks; - synchronized (postCommitTasks) { - tasks = (LinkedList) postCommitTasks.get(txId); - } - if (tasks == null) - throw new javax.jms.JMSException("Transaction is not active."); - synchronized (tasks) { - tasks.addLast(task); - } - - } - - /** - * Rollback the transaction. - */ - public final void rollbackTx(Tx txId) throws javax.jms.JMSException { - - LinkedList tasks; - synchronized( postCommitTasks ) { - tasks = (LinkedList)postRollbackTasks.remove(txId); - releaseList((LinkedList)postCommitTasks.remove(txId)); - } - if( tasks == null ) - throw new javax.jms.JMSException("Transaction is not active 3."); - - persistenceManager.rollbackPersistentTx(txId); - - synchronized(tasks){ - Iterator iter = tasks.iterator(); - while( iter.hasNext() ) { - Runnable task = (Runnable)iter.next(); - task.run(); - } - } - - releaseList(tasks); - } - - public final void addPostRollbackTask(Tx txId, Runnable task) throws javax.jms.JMSException { - - if( txId == null ) { - return; - } - - LinkedList tasks; - synchronized( postCommitTasks ) { - tasks = (LinkedList)postRollbackTasks.get(txId); - } - if( tasks == null ) - throw new javax.jms.JMSException("Transaction is not active 4."); - synchronized (tasks) { - tasks.addLast(task); - } - - } - - PersistenceManager persistenceManager; - - public TxManager( PersistenceManager pm ) { - persistenceManager = pm; - } - - /** - * Create and return a unique transaction id. - * - * Given a distributed connection and a transaction id object, - * allocate a unique local transaction id if the remote id is not already - * known. - */ - public final Tx createTx(ConnectionToken dc, Object xid) throws javax.jms.JMSException { - - GlobalXID gxid = new GlobalXID(dc, xid); - synchronized(globalToLocal){ - if( globalToLocal.containsKey(gxid) ) - throw new SpyJMSException("Duplicate transaction from: "+dc.getClientID()+" xid="+xid); - } - - Tx txId = createTx(); - synchronized(globalToLocal){ - globalToLocal.put(gxid, txId); - } - - //Tasks to remove the global to local mappings on commit/rollback - addPostCommitTask(txId, gxid); - addPostRollbackTask(txId, gxid); - - return txId; - } - - /** - * Return the local transaction id for a distributed transaction id. - */ - public final Tx getPrepared(ConnectionToken dc, Object xid) throws javax.jms.JMSException { - - GlobalXID gxid = new GlobalXID(dc, xid); - Tx txid; - synchronized(globalToLocal){ - txid = (Tx)globalToLocal.get(gxid); - } - if( txid == null ) - throw new SpyJMSException("Transaction does not exist from: "+dc.getClientID()+" xid="+xid); - - return txid; - } -} \ No newline at end of file + // Maps (Long)txIds to LinkedList of Runnable tasks + HashMap postCommitTasks = new HashMap(); + // Maps (Long)txIds to LinkedList of Runnable tasks + HashMap postRollbackTasks = new HashMap(); + // Maps Global transactions to local transactions + HashMap globalToLocal = new HashMap(); + //pool of linked lists to use for storing txs tasks + java.util.ArrayList listPool = new java.util.ArrayList(); + + PersistenceManager persistenceManager; + + protected static int MAX_POOL_SIZE = 500; + + public TxManager( PersistenceManager pm ) { + persistenceManager = pm; + } + + /** + * Return the local transaction id for a distributed transaction id. + * + * @param dc Description of Parameter + * @param xid Description of Parameter + * @return The Prepared value + * @exception javax.jms.JMSException Description of Exception + */ + public final Tx getPrepared( ConnectionToken dc, Object xid ) + throws javax.jms.JMSException { + + GlobalXID gxid = new GlobalXID( dc, xid ); + Tx txid; + synchronized ( globalToLocal ) { + txid = ( Tx )globalToLocal.get( gxid ); + } + if ( txid == null ) { + throw new SpyJMSException( "Transaction does not exist from: " + dc.getClientID() + " xid=" + xid ); + } + + return txid; + } + + /** + * Create and return a unique transaction id. + * + * @return Description of the Returned Value + * @exception javax.jms.JMSException Description of Exception + */ + public final Tx createTx() + throws javax.jms.JMSException { + Tx txId = persistenceManager.createPersistentTx(); + synchronized ( postCommitTasks ) { + postCommitTasks.put( txId, getList() ); + postRollbackTasks.put( txId, getList() ); + } + return txId; + } + + /** + * Commit the transaction to the persistent store. + * + * @param txId Description of Parameter + * @exception javax.jms.JMSException Description of Exception + */ + public final void commitTx( Tx txId ) + throws javax.jms.JMSException { + + LinkedList tasks; + synchronized ( postCommitTasks ) { + tasks = ( LinkedList )postCommitTasks.remove( txId ); + releaseList( ( LinkedList )postRollbackTasks.remove( txId ) ); + } + if ( tasks == null ) { + throw new javax.jms.JMSException( "Transaction is not active for commit." ); + } + + persistenceManager.commitPersistentTx( txId ); + + synchronized ( tasks ) { + Iterator iter = tasks.iterator(); + while ( iter.hasNext() ) { + Runnable task = ( Runnable )iter.next(); + task.run(); + } + } + releaseList( tasks ); + } + + public final void addPostCommitTask( Tx txId, Runnable task ) + throws javax.jms.JMSException { + + if ( txId == null ) { + task.run(); + return; + } + + LinkedList tasks; + synchronized ( postCommitTasks ) { + tasks = ( LinkedList )postCommitTasks.get( txId ); + } + if ( tasks == null ) { + throw new javax.jms.JMSException( "Transaction is not active." ); + } + synchronized ( tasks ) { + tasks.addLast( task ); + } + + } + + /** + * Rollback the transaction. + * + * @param txId Description of Parameter + * @exception javax.jms.JMSException Description of Exception + */ + public final void rollbackTx( Tx txId ) + throws javax.jms.JMSException { + + LinkedList tasks; + synchronized ( postCommitTasks ) { + tasks = ( LinkedList )postRollbackTasks.remove( txId ); + releaseList( ( LinkedList )postCommitTasks.remove( txId ) ); + } + if ( tasks == null ) { + throw new javax.jms.JMSException( "Transaction is not active 3." ); + } + + persistenceManager.rollbackPersistentTx( txId ); + + synchronized ( tasks ) { + Iterator iter = tasks.iterator(); + while ( iter.hasNext() ) { + Runnable task = ( Runnable )iter.next(); + task.run(); + } + } + + releaseList( tasks ); + } + + public final void addPostRollbackTask( Tx txId, Runnable task ) + throws javax.jms.JMSException { + + if ( txId == null ) { + return; + } + + LinkedList tasks; + synchronized ( postCommitTasks ) { + tasks = ( LinkedList )postRollbackTasks.get( txId ); + } + if ( tasks == null ) { + throw new javax.jms.JMSException( "Transaction is not active 4." ); + } + synchronized ( tasks ) { + tasks.addLast( task ); + } + + } + + /** + * Create and return a unique transaction id. Given a distributed connection + * and a transaction id object, allocate a unique local transaction id if + * the remote id is not already known. + * + * @param dc Description of Parameter + * @param xid Description of Parameter + * @return Description of the Returned Value + * @exception javax.jms.JMSException Description of Exception + */ + public final Tx createTx( ConnectionToken dc, Object xid ) + throws javax.jms.JMSException { + + GlobalXID gxid = new GlobalXID( dc, xid ); + synchronized ( globalToLocal ) { + if ( globalToLocal.containsKey( gxid ) ) { + throw new SpyJMSException( "Duplicate transaction from: " + dc.getClientID() + " xid=" + xid ); + } + } + + Tx txId = createTx(); + synchronized ( globalToLocal ) { + globalToLocal.put( gxid, txId ); + } + + //Tasks to remove the global to local mappings on commit/rollback + addPostCommitTask( txId, gxid ); + addPostRollbackTask( txId, gxid ); + + return txId; + } + + protected LinkedList getList() { + synchronized ( listPool ) { + if ( listPool.isEmpty() ) { + return new LinkedList(); + } else { + return ( LinkedList )listPool.remove( listPool.size() - 1 ); + } + } + } + + protected void releaseList( LinkedList list ) { + synchronized ( listPool ) { + if ( listPool.size() < MAX_POOL_SIZE ) { + list.clear(); + listPool.add( list ); + } + } + } + + + /** + * @created August 16, 2001 + */ + class GlobalXID implements Runnable { + ConnectionToken dc; + Object xid; + + GlobalXID( ConnectionToken dc, Object xid ) { + this.dc = dc; + this.xid = xid; + } + + public boolean equals( Object obj ) { + if ( obj == null ) { + return false; + } + if ( obj.getClass() != GlobalXID.class ) { + return false; + } + return ( ( GlobalXID )obj ).xid.equals( xid ) && + ( ( GlobalXID )obj ).dc.equals( dc ); + } + + public int hashCode() { + return xid.hashCode(); + } + + public void run() { + synchronized ( globalToLocal ) { + globalToLocal.remove( this ); + } + } + } +} _______________________________________________ Jboss-development mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-development