User: chirino
Date: 01/08/31 20:01:00
Modified: src/main/org/jboss/mq/pm/rollinglogged
PersistenceManager.java
PersistenceManagerMBean.java
Log:
Fixing compile problems due to migration of classes from jboss.util to jboss.system
Revision Changes Path
1.5 +456 -285
jbossmq/src/main/org/jboss/mq/pm/rollinglogged/PersistenceManager.java
Index: PersistenceManager.java
===================================================================
RCS file:
/cvsroot/jboss/jbossmq/src/main/org/jboss/mq/pm/rollinglogged/PersistenceManager.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- PersistenceManager.java 2001/08/30 02:35:55 1.4
+++ PersistenceManager.java 2001/09/01 03:01:00 1.5
@@ -1,3 +1,9 @@
+/*
+ * JBoss, the OpenSource J2EE webOS
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
package org.jboss.mq.pm.rollinglogged;
import java.net.URL;
@@ -6,7 +12,6 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.TreeSet;
-
import javax.jms.JMSException;
import javax.management.*;
@@ -20,53 +25,54 @@
import org.jboss.mq.server.JMSDestination;
import org.jboss.mq.server.JMSServer;
import org.jboss.mq.xml.XElement;
-
import org.jboss.system.ServiceMBeanSupport;
/**
* This class manages all persistence related services.
*
* @author David Maplesden ([EMAIL PROTECTED])
- * @created August 16, 2001
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
-public class PersistenceManager extends org.jboss.system.ServiceMBeanSupport
implements org.jboss.mq.pm.PersistenceManager, PersistenceManagerMBean {
+public class PersistenceManager extends ServiceMBeanSupport implements
org.jboss.mq.pm.PersistenceManager, PersistenceManagerMBean
+{
+ public final static int ROLL_OVER_SIZE = 1000;
+ public final static String TRANS_FILE_NAME = "transactions.dat";
+ public final static boolean DEBUG = false;
+
+ protected static int MAX_POOL_SIZE = 50;
+
protected java.util.ArrayList listPool = new java.util.ArrayList();
protected java.util.ArrayList txPool = new java.util.ArrayList();
- protected int messageCounter = 0;
- int numRollOvers = 0;
- HashMap queues = new HashMap();
+ protected int messageCounter = 0;
+ int numRollOvers = 0;
+ HashMap queues = new HashMap();
// Log file used to store commited transactions.
- SpyTxLog currentTxLog;
- long nextTxId = Long.MIN_VALUE;
+ SpyTxLog currentTxLog;
+ long nextTxId = Long.MIN_VALUE;
// Maps txLogs to Maps of SpyDestinations to SpyMessageLogs
- HashMap messageLogs = null;
+ HashMap messageLogs = new HashMap();
// Maps transactionIds to txInfos
- HashMap transToTxLogs = new HashMap();
+ HashMap transToTxLogs = new HashMap();
- // The directory where persistence data should be stored
- URL dataDirURL;
- TxManager txManager;
- private String dataDirectory;
- public final static int ROLL_OVER_SIZE = 1000;
- public final static String TRANS_FILE_NAME = "transactions.dat";
- public final static boolean DEBUG = false;
+ // The directory where persistence data should be stored
+ URL dataDirURL;
+ TxManager txManager;
- protected static int MAX_POOL_SIZE = 50;
+ private String dataDirectory;
/**
* NewPersistenceManager constructor.
*
* @exception javax.jms.JMSException Description of Exception
*/
- public PersistenceManager()
- throws javax.jms.JMSException {
- txManager = new TxManager( this );
+ public PersistenceManager() throws javax.jms.JMSException
+ {
+ txManager = new TxManager(this);
}
@@ -76,7 +82,8 @@
*
* @param newDataDirectory java.lang.String
*/
- public void setDataDirectory( java.lang.String newDataDirectory ) {
+ public void setDataDirectory(java.lang.String newDataDirectory)
+ {
dataDirectory = newDataDirectory;
}
@@ -86,11 +93,18 @@
*
* @return java.lang.String
*/
- public java.lang.String getDataDirectory() {
+ public java.lang.String getDataDirectory()
+ {
return dataDirectory;
}
- public String getName() {
+ /**
+ * Gets the Name attribute of the PersistenceManager object
+ *
+ * @return The Name value
+ */
+ public String getName()
+ {
return "JBossMQ-PersistenceManager";
}
@@ -99,39 +113,49 @@
*
* @return The TxManager value
*/
- public org.jboss.mq.pm.TxManager getTxManager() {
+ public org.jboss.mq.pm.TxManager getTxManager()
+ {
return txManager;
}
- public void initQueue( SpyDestination dest )
- throws javax.jms.JMSException {
+ /**
+ * #Description of the Method
+ *
+ * @param dest Description of Parameter
+ * @exception javax.jms.JMSException Description of Exception
+ */
+ public void initQueue(SpyDestination dest) throws javax.jms.JMSException
+ {
String key = "" + dest;
- queues.put( key, dest );
+ queues.put(key, dest);
SpyTxLog txLog = null;
- if ( messageLogs == null ) {
- return;
- }
-
HashMap logs;
- synchronized ( messageLogs ) {
- logs = ( HashMap )messageLogs.get( currentTxLog );
- if ( logs == null ) {
+ synchronized (messageLogs)
+ {
+ logs = (HashMap)messageLogs.get(currentTxLog);
+ if (logs == null)
+ {
logs = new HashMap();
- messageLogs.put( currentTxLog, logs );
+ messageLogs.put(currentTxLog, logs);
}
- synchronized ( logs ) {
- LogInfo logInfo = ( LogInfo )logs.get( dest.toString() );
-
- if ( logInfo == null ) {
- try {
- SpyMessageLog log = new SpyMessageLog( new URL( dataDirURL,
dest.toString() + ".dat" + numRollOvers ).getFile() );
- logInfo = new LogInfo( log, dest, currentTxLog );
- logs.put( "" + dest, logInfo );
- } catch ( java.net.MalformedURLException e ) {
- JMSException jme = new SpyJMSException( "Error rolling over logs
to new files." );
- jme.setLinkedException( e );
+ synchronized (logs)
+ {
+ LogInfo logInfo = (LogInfo)logs.get(dest.toString());
+
+ if (logInfo == null)
+ {
+ try
+ {
+ SpyMessageLog log = new SpyMessageLog(new URL(dataDirURL,
dest.toString() + ".dat1").getFile());
+ logInfo = new LogInfo(log, dest, currentTxLog);
+ logs.put("" + dest, logInfo);
+ }
+ catch (java.net.MalformedURLException e)
+ {
+ JMSException jme = new SpyJMSException("Error rolling over logs
to new files.");
+ jme.setLinkedException(e);
throw jme;
}
}
@@ -140,312 +164,424 @@
}
- public void destroyQueue( SpyDestination dest )
- throws javax.jms.JMSException {
+ /**
+ * #Description of the Method
+ *
+ * @param dest Description of Parameter
+ * @exception javax.jms.JMSException Description of Exception
+ */
+ public void destroyQueue(SpyDestination dest) throws javax.jms.JMSException
+ {
- try {
+ try
+ {
String key = "" + dest;
- queues.remove( key );
+ queues.remove(key);
SpyMessageLog log = null;
HashMap logs;
- synchronized ( messageLogs ) {
- logs = ( HashMap )messageLogs.get( currentTxLog );
+ synchronized (messageLogs)
+ {
+ logs = (HashMap)messageLogs.get(currentTxLog);
+ }
+ synchronized (logs)
+ {
+ log = (SpyMessageLog)logs.remove(key);
+ }
+ if (log == null)
+ {
+ throw new SpyJMSException("The persistence log was never initialized");
}
- synchronized ( logs ) {
- log = ( SpyMessageLog )logs.remove( key );
- }
- if ( log == null ) {
- throw new SpyJMSException( "The persistence log was never initialized"
);
- }
log.close();
log.delete();
HashSet deleteLogs = new HashSet();
- synchronized ( messageLogs ) {
- for ( Iterator it = messageLogs.values().iterator(); it.hasNext(); ) {
- logs = ( HashMap )it.next();
- synchronized ( logs ) {
- log = ( SpyMessageLog )logs.remove( key );
+ synchronized (messageLogs)
+ {
+ for (Iterator it = messageLogs.values().iterator(); it.hasNext(); )
+ {
+ logs = (HashMap)it.next();
+ synchronized (logs)
+ {
+ log = (SpyMessageLog)logs.remove(key);
}
- if ( log != null ) {
- deleteLogs.add( log );
+ if (log != null)
+ {
+ deleteLogs.add(log);
}
}
}
- for ( Iterator it = deleteLogs.iterator(); it.hasNext(); ) {
- log = ( SpyMessageLog )it.next();
+ for (Iterator it = deleteLogs.iterator(); it.hasNext(); )
+ {
+ log = (SpyMessageLog)it.next();
log.close();
log.delete();
}
- } catch ( javax.jms.JMSException e ) {
+ }
+ catch (javax.jms.JMSException e)
+ {
throw e;
- } catch ( Exception e ) {
- javax.jms.JMSException newE = new javax.jms.JMSException( "Invalid
configuration." );
- newE.setLinkedException( e );
+ }
+ catch (Exception e)
+ {
+ javax.jms.JMSException newE = new javax.jms.JMSException("Invalid
configuration.");
+ newE.setLinkedException(e);
throw newE;
}
}
- public void initService()
- throws Exception {
+ /**
+ * #Description of the Method
+ *
+ * @exception Exception Description of Exception
+ */
+ public void initService() throws Exception
+ {
- if ( DEBUG ) {
- System.out.println( "Using new rolling logged persistence manager." );
+ if (DEBUG)
+ {
+ System.out.println("Using new rolling logged persistence manager.");
}
- URL configFile = getClass().getClassLoader().getResource( "jboss.jcml" );
- dataDirURL = new URL( configFile, dataDirectory );
+ URL configFile = getClass().getClassLoader().getResource("jboss.jcml");
+ dataDirURL = new URL(configFile, dataDirectory);
//Get an InitialContext
- JMSServer server = ( JMSServer )getServer().invoke( new ObjectName(
org.jboss.mq.server.JBossMQServiceMBean.OBJECT_NAME ), "getJMSServer", new Object[]{
+ JMSServer server = (JMSServer)getServer().invoke(new
ObjectName(org.jboss.mq.server.JBossMQServiceMBean.OBJECT_NAME), "getJMSServer", new
Object[]{
}, new String[]{
- } );
- server.setPersistenceManager( this );
+ });
+ server.setPersistenceManager(this);
}
- public void startService()
- throws Exception {
+ /**
+ * #Description of the Method
+ *
+ * @exception Exception Description of Exception
+ */
+ public void startService() throws Exception
+ {
- JMSServer server = ( JMSServer )getServer().invoke( new ObjectName(
org.jboss.mq.server.JBossMQServiceMBean.OBJECT_NAME ), "getJMSServer", new Object[]{
+ JMSServer server = (JMSServer)getServer().invoke(new
ObjectName(org.jboss.mq.server.JBossMQServiceMBean.OBJECT_NAME), "getJMSServer", new
Object[]{
}, new String[]{
- } );
- restore( server );
+ });
+ restore(server);
}
- public void add( org.jboss.mq.SpyMessage message, org.jboss.mq.pm.Tx txId )
- throws javax.jms.JMSException {
+ /**
+ * #Description of the Method
+ *
+ * @param message Description of Parameter
+ * @param txId Description of Parameter
+ * @exception javax.jms.JMSException Description of Exception
+ */
+ public void add(org.jboss.mq.SpyMessage message, org.jboss.mq.pm.Tx txId) throws
javax.jms.JMSException
+ {
//System.out.println("Add message "+Long.toHexString(message.messageId)+" in
trans "+Long.toHexString(txId.longValue())+" to "+message.getJMSDestination());
LogInfo logInfo;
SpyTxLog txLog = null;
- if ( txId == null ) {
+ if (txId == null)
+ {
txLog = currentTxLog;
- } else {
- synchronized ( transToTxLogs ) {
- txLog = ( ( TxInfo )transToTxLogs.get( txId ) ).log;
+ }
+ else
+ {
+ synchronized (transToTxLogs)
+ {
+ txLog = ((TxInfo)transToTxLogs.get(txId)).log;
}
}
HashMap logs;
- synchronized ( messageLogs ) {
- logs = ( HashMap )messageLogs.get( txLog );
+ synchronized (messageLogs)
+ {
+ logs = (HashMap)messageLogs.get(txLog);
}
- synchronized ( logs ) {
- logInfo = ( LogInfo )logs.get( message.getJMSDestination().toString() );
+ synchronized (logs)
+ {
+ logInfo = (LogInfo)logs.get(message.getJMSDestination().toString());
}
- if ( logInfo == null ) {
- throw new javax.jms.JMSException( "Destination was not initalized with the
PersistenceManager" );
+ if (logInfo == null)
+ {
+ throw new javax.jms.JMSException("Destination was not initalized with the
PersistenceManager");
}
- synchronized ( logInfo ) {
+ synchronized (logInfo)
+ {
logInfo.liveMessages++;
message.persistData = logInfo;
- logInfo.log.add( message, txId );
+ logInfo.log.add(message, txId);
}
- if ( txId != null ) {
- synchronized ( transToTxLogs ) {
- TxInfo txInfo = ( TxInfo )transToTxLogs.get( txId );
- txInfo.addMessages.add( message );
+ if (txId != null)
+ {
+ synchronized (transToTxLogs)
+ {
+ TxInfo txInfo = (TxInfo)transToTxLogs.get(txId);
+ txInfo.addMessages.add(message);
}
}
checkRollOver();
}
- public void commitPersistentTx( org.jboss.mq.pm.Tx txId )
- throws javax.jms.JMSException {
+ /**
+ * #Description of the Method
+ *
+ * @param txId Description of Parameter
+ * @exception javax.jms.JMSException Description of Exception
+ */
+ public void commitPersistentTx(org.jboss.mq.pm.Tx txId) throws
javax.jms.JMSException
+ {
//System.out.println("Committing TX "+Long.toHexString(txId.longValue()));
TxInfo info = null;
LinkedList messagesToDelete = null;
- synchronized ( transToTxLogs ) {
- info = ( TxInfo )transToTxLogs.remove( txId );
+ synchronized (transToTxLogs)
+ {
+ info = (TxInfo)transToTxLogs.remove(txId);
messagesToDelete = info.ackMessages;
}
- deleteMessages( messagesToDelete );
- info.log.commitTx( txId );
- synchronized ( transToTxLogs ) {
- releaseTx( txId );
- releaseTxInfo( info );
+ deleteMessages(messagesToDelete);
+ info.log.commitTx(txId);
+ synchronized (transToTxLogs)
+ {
+ releaseTx(txId);
+ releaseTxInfo(info);
}
- checkCleanup( info.log );
+ checkCleanup(info.log);
}
- public org.jboss.mq.pm.Tx createPersistentTx()
- throws javax.jms.JMSException {
+ /**
+ * #Description of the Method
+ *
+ * @return Description of the Returned Value
+ * @exception javax.jms.JMSException Description of Exception
+ */
+ public org.jboss.mq.pm.Tx createPersistentTx() throws javax.jms.JMSException
+ {
org.jboss.mq.pm.Tx txId = null;
SpyTxLog txLog = currentTxLog;
- synchronized ( transToTxLogs ) {
- txId = getTx( ++nextTxId );
- transToTxLogs.put( txId, getTxInfo( txId, txLog ) );
+ synchronized (transToTxLogs)
+ {
+ txId = getTx(++nextTxId);
+ transToTxLogs.put(txId, getTxInfo(txId, txLog));
}
txLog.createTx();
return txId;
}
- public void remove( org.jboss.mq.SpyMessage message, org.jboss.mq.pm.Tx txId )
- throws javax.jms.JMSException {
+ /**
+ * #Description of the Method
+ *
+ * @param message Description of Parameter
+ * @param txId Description of Parameter
+ * @exception javax.jms.JMSException Description of Exception
+ */
+ public void remove(org.jboss.mq.SpyMessage message, org.jboss.mq.pm.Tx txId)
throws javax.jms.JMSException
+ {
//System.out.println("Removing message
"+Long.toHexString(message.messageId)+" in trans
"+Long.toHexString(txId.longValue())+" from "+message.getJMSDestination());
LogInfo logInfo;
-
- SpyTxLog txLog = ( ( LogInfo )message.persistData ).txLog;
- synchronized ( messageLogs ) {
- HashMap logs = ( HashMap )messageLogs.get( txLog );
- logInfo = ( LogInfo )logs.get( message.getJMSDestination().toString() );
- }
-
- if ( logInfo == null ) {
- throw new javax.jms.JMSException( "Destination was not initalized with the
PersistenceManager" );
- }
- synchronized ( logInfo.log ) {
- logInfo.log.remove( message, txId );
- }
- if ( txId != null ) {
- synchronized ( transToTxLogs ) {
- TxInfo txInfo = ( TxInfo )transToTxLogs.get( txId );
- txInfo.ackMessages.add( message );
- }
- }
- if ( txId == null ) {
- synchronized ( logInfo ) {
+ SpyTxLog txLog = ((LogInfo)message.persistData).txLog;
+ synchronized (messageLogs)
+ {
+ HashMap logs = (HashMap)messageLogs.get(txLog);
+ logInfo = (LogInfo)logs.get(message.getJMSDestination().toString());
+ }
+
+ if (logInfo == null)
+ {
+ throw new javax.jms.JMSException("Destination was not initalized with the
PersistenceManager");
+ }
+
+ synchronized (logInfo.log)
+ {
+ logInfo.log.remove(message, txId);
+ }
+ if (txId != null)
+ {
+ synchronized (transToTxLogs)
+ {
+ TxInfo txInfo = (TxInfo)transToTxLogs.get(txId);
+ txInfo.ackMessages.add(message);
+ }
+ }
+ if (txId == null)
+ {
+ synchronized (logInfo)
+ {
--logInfo.liveMessages;
}
- checkCleanup( txLog );
+ checkCleanup(txLog);
}
}
- public void restore( org.jboss.mq.server.JMSServer server )
- throws javax.jms.JMSException {
+ /**
+ * #Description of the Method
+ *
+ * @param server Description of Parameter
+ * @exception javax.jms.JMSException Description of Exception
+ */
+ public void restore(org.jboss.mq.server.JMSServer server) throws
javax.jms.JMSException
+ {
TreeSet commitedTxs = new TreeSet();
HashMap txLogs = new HashMap();
- java.io.File dir = new java.io.File( dataDirURL.getFile() );
+ java.io.File dir = new java.io.File(dataDirURL.getFile());
java.io.File[] dataFiles = dir.listFiles();
-
- messageLogs = new HashMap();
- for ( int i = 0; i < dataFiles.length; ++i ) {
+ for (int i = 0; i < dataFiles.length; ++i)
+ {
String name = dataFiles[i].getName();
- if ( name.startsWith( TRANS_FILE_NAME ) ) {
- int index = name.indexOf( ".dat" );
- if ( index < 0 ) {
+ if (name.startsWith(TRANS_FILE_NAME))
+ {
+ int index = name.indexOf(".dat");
+ if (index < 0)
+ {
continue;
}
- String sRollOver = name.substring( index + 4 );
- int rollOver = Integer.parseInt( sRollOver );
- numRollOvers = Math.max( numRollOvers, rollOver + 1 );
- SpyTxLog txLog = new SpyTxLog( dataFiles[i].getAbsolutePath() );
- txLog.restore( commitedTxs );
- txLogs.put( new Integer( rollOver ), txLog );
- messageLogs.put( txLog, new HashMap() );
+ String sRollOver = name.substring(index + 4);
+ int rollOver = Integer.parseInt(sRollOver);
+ numRollOvers = Math.max(numRollOvers, rollOver + 1);
+ SpyTxLog txLog = new SpyTxLog(dataFiles[i].getAbsolutePath());
+ txLog.restore(commitedTxs);
+ txLogs.put(new Integer(rollOver), txLog);
+ messageLogs.put(txLog, new HashMap());
}
}
- if ( !commitedTxs.isEmpty() ) {
- nextTxId = ( ( org.jboss.mq.pm.Tx )commitedTxs.last() ).longValue();
+ if (!commitedTxs.isEmpty())
+ {
+ nextTxId = ((org.jboss.mq.pm.Tx)commitedTxs.last()).longValue();
}
- for ( int i = 0; i < dataFiles.length; ++i ) {
+ for (int i = 0; i < dataFiles.length; ++i)
+ {
String name = dataFiles[i].getName();
- if ( !name.startsWith( TRANS_FILE_NAME ) ) {
- int index = name.indexOf( ".dat" );
- if ( index < 0 ) {
+ if (!name.startsWith(TRANS_FILE_NAME))
+ {
+ int index = name.indexOf(".dat");
+ if (index < 0)
+ {
continue;
}
- String sRollOver = name.substring( index + 4 );
- int rollOver = Integer.parseInt( sRollOver );
- String key = name.substring( 0, name.length() - ( sRollOver.length() +
4 ) );
- SpyMessageLog messageLog = new SpyMessageLog(
dataFiles[i].getAbsolutePath() );
- SpyMessage[] messages = messageLog.restore( commitedTxs );
- SpyTxLog txLog = ( SpyTxLog )txLogs.get( new Integer( rollOver ) );
- SpyDestination dest = ( SpyDestination )queues.get( key );
- if ( dest != null ) {
- JMSDestination q = server.getJMSDestination( dest );
- LogInfo info = new LogInfo( messageLog, dest, txLog );
+ String sRollOver = name.substring(index + 4);
+ int rollOver = Integer.parseInt(sRollOver);
+ String key = name.substring(0, name.length() - (sRollOver.length() +
4));
+ SpyMessageLog messageLog = new
SpyMessageLog(dataFiles[i].getAbsolutePath());
+ SpyMessage[] messages = messageLog.restore(commitedTxs);
+ SpyTxLog txLog = (SpyTxLog)txLogs.get(new Integer(rollOver));
+ SpyDestination dest = (SpyDestination)queues.get(key);
+ if (dest != null)
+ {
+ JMSDestination q = server.getJMSDestination(dest);
+ LogInfo info = new LogInfo(messageLog, dest, txLog);
info.liveMessages = messages.length;
- HashMap logs = ( HashMap )messageLogs.get( txLog );
- logs.put( key, info );
+ HashMap logs = (HashMap)messageLogs.get(txLog);
+ logs.put(key, info);
//TODO: make sure this lock is good enough
- synchronized ( q ) {
- for ( int j = 0; j < messages.length; j++ ) {
+ synchronized (q)
+ {
+ for (int j = 0; j < messages.length; j++)
+ {
messages[j].persistData = info;
- q.restoreMessage( messages[j] );
+ q.restoreMessage(messages[j]);
}
}
}
}
}
- for ( Iterator it = txLogs.values().iterator(); it.hasNext(); ) {
- checkCleanup( ( SpyTxLog )it.next() );
+ for (Iterator it = txLogs.values().iterator(); it.hasNext(); )
+ {
+ checkCleanup((SpyTxLog)it.next());
}
- try {
+ try
+ {
- URL txLogFile = new URL( dataDirURL, TRANS_FILE_NAME + numRollOvers );
- currentTxLog = new SpyTxLog( txLogFile.getFile() );
- messageLogs.put( currentTxLog, new HashMap() );
+ URL txLogFile = new URL(dataDirURL, TRANS_FILE_NAME + numRollOvers);
+ currentTxLog = new SpyTxLog(txLogFile.getFile());
+ messageLogs.put(currentTxLog, new HashMap());
- for ( Iterator it = queues.values().iterator(); it.hasNext(); ) {
- SpyDestination dest = ( SpyDestination )it.next();
+ for (Iterator it = queues.values().iterator(); it.hasNext(); )
+ {
+ SpyDestination dest = (SpyDestination)it.next();
String key = "" + dest;
- URL logFile = new URL( dataDirURL, dest.toString() + ".dat" +
numRollOvers );
- SpyMessageLog log = new SpyMessageLog( logFile.getFile() );
+ URL logFile = new URL(dataDirURL, dest.toString() + ".dat" +
numRollOvers);
+ SpyMessageLog log = new SpyMessageLog(logFile.getFile());
- synchronized ( messageLogs ) {
- LogInfo logInfo = new LogInfo( log, dest, currentTxLog );
- HashMap logs = ( HashMap )messageLogs.get( currentTxLog );
- logs.put( key, logInfo );
+ synchronized (messageLogs)
+ {
+ LogInfo logInfo = new LogInfo(log, dest, currentTxLog);
+ HashMap logs = (HashMap)messageLogs.get(currentTxLog);
+ logs.put(key, logInfo);
}
}
- } catch ( Exception e ) {
- javax.jms.JMSException newE = new javax.jms.JMSException( "Invalid
configuration." );
- newE.setLinkedException( e );
+ }
+ catch (Exception e)
+ {
+ javax.jms.JMSException newE = new javax.jms.JMSException("Invalid
configuration.");
+ newE.setLinkedException(e);
throw newE;
}
}
- public void rollbackPersistentTx( org.jboss.mq.pm.Tx txId )
- throws javax.jms.JMSException {
+ /**
+ * #Description of the Method
+ *
+ * @param txId Description of Parameter
+ * @exception javax.jms.JMSException Description of Exception
+ */
+ public void rollbackPersistentTx(org.jboss.mq.pm.Tx txId) throws
javax.jms.JMSException
+ {
TxInfo info = null;
LinkedList messagesToDelete = null;
- synchronized ( transToTxLogs ) {
- info = ( TxInfo )transToTxLogs.remove( txId );
+ synchronized (transToTxLogs)
+ {
+ info = (TxInfo)transToTxLogs.remove(txId);
messagesToDelete = info.addMessages;
}
- deleteMessages( messagesToDelete );
- info.log.rollbackTx( txId );
- synchronized ( transToTxLogs ) {
- releaseTx( txId );
- releaseTxInfo( info );
- }
- checkCleanup( info.log );
- }
-
- protected org.jboss.mq.pm.Tx getTx( long value ) {
- if ( txPool.isEmpty() ) {
- return new org.jboss.mq.pm.Tx( value );
- } else {
- org.jboss.mq.pm.Tx tx = ( org.jboss.mq.pm.Tx )txPool.remove(
listPool.size() - 1 );
- tx.setValue( value );
+ deleteMessages(messagesToDelete);
+ info.log.rollbackTx(txId);
+ synchronized (transToTxLogs)
+ {
+ releaseTx(txId);
+ releaseTxInfo(info);
+ }
+ checkCleanup(info.log);
+ }
+
+ protected org.jboss.mq.pm.Tx getTx(long value)
+ {
+ if (txPool.isEmpty())
+ {
+ return new org.jboss.mq.pm.Tx(value);
+ }
+ else
+ {
+ org.jboss.mq.pm.Tx tx = (org.jboss.mq.pm.Tx)txPool.remove(listPool.size()
- 1);
+ tx.setValue(value);
return tx;
}
}
- protected TxInfo getTxInfo( org.jboss.mq.pm.Tx txId, SpyTxLog txLog ) {
- if ( listPool.isEmpty() ) {
- return new TxInfo( txId, txLog );
- } else {
- TxInfo info = ( TxInfo )listPool.remove( listPool.size() - 1 );
+ protected TxInfo getTxInfo(org.jboss.mq.pm.Tx txId, SpyTxLog txLog)
+ {
+ if (listPool.isEmpty())
+ {
+ return new TxInfo(txId, txLog);
+ }
+ else
+ {
+ TxInfo info = (TxInfo)listPool.remove(listPool.size() - 1);
info.txId = txId;
info.log = txLog;
return info;
@@ -453,126 +589,159 @@
}
- protected void releaseTxInfo( TxInfo list ) {
- if ( listPool.size() < MAX_POOL_SIZE ) {
+ protected void releaseTxInfo(TxInfo list)
+ {
+ if (listPool.size() < MAX_POOL_SIZE)
+ {
list.ackMessages.clear();
list.addMessages.clear();
- listPool.add( list );
+ listPool.add(list);
}
}
+
- protected void deleteMessages( LinkedList messages )
- throws javax.jms.JMSException {
- for ( Iterator it = messages.iterator(); it.hasNext(); ) {
- LogInfo info = ( ( LogInfo )( ( SpyMessage )it.next() ).persistData );
- synchronized ( info ) {
+
+
+
+ protected void deleteMessages(LinkedList messages) throws javax.jms.JMSException
+ {
+ for (Iterator it = messages.iterator(); it.hasNext(); )
+ {
+ LogInfo info = ((LogInfo)((SpyMessage)it.next()).persistData);
+ synchronized (info)
+ {
--info.liveMessages;
}
- checkCleanup( info.txLog );
+ checkCleanup(info.txLog);
}
}
- protected void checkRollOver()
- throws JMSException {
- synchronized ( queues ) {
+ protected void checkRollOver() throws JMSException
+ {
+ synchronized (queues)
+ {
int max = queues.size();
- if ( max == 0 ) {
+ if (max == 0)
+ {
max = ROLL_OVER_SIZE;
- } else {
+ }
+ else
+ {
max *= ROLL_OVER_SIZE;
}
- if ( ++messageCounter > max ) {
+ if (++messageCounter > max)
+ {
messageCounter = 0;
rollOverLogs();
}
}
}
- protected void rollOverLogs()
- throws JMSException {
- try {
+ protected void rollOverLogs() throws JMSException
+ {
+ try
+ {
HashMap logs = new HashMap();
++numRollOvers;
- SpyTxLog newTxLog = new SpyTxLog( new URL( dataDirURL, TRANS_FILE_NAME +
numRollOvers ).getFile() );
+ SpyTxLog newTxLog = new SpyTxLog(new URL(dataDirURL, TRANS_FILE_NAME +
numRollOvers).getFile());
- for ( Iterator it = queues.values().iterator(); it.hasNext(); ) {
- SpyDestination dest = ( SpyDestination )it.next();
- SpyMessageLog log = new SpyMessageLog( new URL( dataDirURL,
dest.toString() + ".dat" + numRollOvers ).getFile() );
- LogInfo logInfo = new LogInfo( log, dest, newTxLog );
- logs.put( "" + dest, logInfo );
+ for (Iterator it = queues.values().iterator(); it.hasNext(); )
+ {
+ SpyDestination dest = (SpyDestination)it.next();
+ SpyMessageLog log = new SpyMessageLog(new URL(dataDirURL,
dest.toString() + ".dat" + numRollOvers).getFile());
+ LogInfo logInfo = new LogInfo(log, dest, newTxLog);
+ logs.put("" + dest, logInfo);
}
SpyTxLog oldLog = currentTxLog;
- synchronized ( messageLogs ) {
+ synchronized (messageLogs)
+ {
currentTxLog = newTxLog;
- messageLogs.put( newTxLog, logs );
+ messageLogs.put(newTxLog, logs);
}
- checkCleanup( oldLog );
- } catch ( java.net.MalformedURLException e ) {
- JMSException jme = new SpyJMSException( "Error rolling over logs to new
files." );
- jme.setLinkedException( e );
+ checkCleanup(oldLog);
+ }
+ catch (java.net.MalformedURLException e)
+ {
+ JMSException jme = new SpyJMSException("Error rolling over logs to new
files.");
+ jme.setLinkedException(e);
throw jme;
}
}
- protected void checkCleanup( SpyTxLog txLog )
- throws JMSException {
- if ( txLog == currentTxLog ) {
+ protected void checkCleanup(SpyTxLog txLog) throws JMSException
+ {
+ if (txLog == currentTxLog)
+ {
return;
}
HashMap logs;
- synchronized ( messageLogs ) {
- logs = ( HashMap )messageLogs.get( txLog );
+ synchronized (messageLogs)
+ {
+ logs = (HashMap)messageLogs.get(txLog);
}
- synchronized ( logs ) {
+ synchronized (logs)
+ {
//if no live messages and no live transactions then cleanup
- for ( Iterator it = logs.values().iterator(); it.hasNext(); ) {
- LogInfo info = ( LogInfo )it.next();
- synchronized ( info ) {
- if ( info.liveMessages != 0 ) {
+ for (Iterator it = logs.values().iterator(); it.hasNext(); )
+ {
+ LogInfo info = (LogInfo)it.next();
+ synchronized (info)
+ {
+ if (info.liveMessages != 0)
+ {
return;
}
}
}
}
- if ( !txLog.completed() ) {
+ if (!txLog.completed())
+ {
return;
}
- if ( DEBUG ) {
- System.out.println( "Cleaning up" );
+ if (DEBUG)
+ {
+ System.out.println("Cleaning up");
}
//close and delete all logs, remove data from data structures.
- synchronized ( messageLogs ) {
- logs = ( HashMap )messageLogs.remove( txLog );
+ synchronized (messageLogs)
+ {
+ logs = (HashMap)messageLogs.remove(txLog);
}
- if ( logs == null ) {
+ if (logs == null)
+ {
return;
}
txLog.close();
txLog.delete();
- for ( Iterator it = logs.values().iterator(); it.hasNext(); ) {
- LogInfo info = ( LogInfo )it.next();
+ for (Iterator it = logs.values().iterator(); it.hasNext(); )
+ {
+ LogInfo info = (LogInfo)it.next();
info.log.close();
info.log.delete();
}
}
- protected void releaseTx( org.jboss.mq.pm.Tx tx ) {
- if ( txPool.size() < MAX_POOL_SIZE ) {
- txPool.add( tx );
+ protected void releaseTx(org.jboss.mq.pm.Tx tx)
+ {
+ if (txPool.size() < MAX_POOL_SIZE)
+ {
+ txPool.add(tx);
}
}
/**
- * @created August 16, 2001
+ * #Description of the Class
*/
- static class LogInfo {
+ static class LogInfo
+ {
SpyMessageLog log;
SpyDestination destination;
- int liveMessages = 0;
- SpyTxLog txLog;
+ int liveMessages = 0;
+ SpyTxLog txLog;
- LogInfo( SpyMessageLog log, SpyDestination destination, SpyTxLog txLog ) {
+ LogInfo(SpyMessageLog log, SpyDestination destination, SpyTxLog txLog)
+ {
this.log = log;
this.destination = destination;
this.txLog = txLog;
@@ -581,15 +750,17 @@
}
/**
- * @created August 16, 2001
+ * #Description of the Class
*/
- static class TxInfo {
+ static class TxInfo
+ {
org.jboss.mq.pm.Tx txId;
- LinkedList addMessages = new LinkedList();
- LinkedList ackMessages = new LinkedList();
- SpyTxLog log;
+ LinkedList addMessages = new LinkedList();
+ LinkedList ackMessages = new LinkedList();
+ SpyTxLog log;
- TxInfo( org.jboss.mq.pm.Tx txId, SpyTxLog log ) {
+ TxInfo(org.jboss.mq.pm.Tx txId, SpyTxLog log)
+ {
this.txId = txId;
this.log = log;
}
1.4 +17 -15
jbossmq/src/main/org/jboss/mq/pm/rollinglogged/PersistenceManagerMBean.java
Index: PersistenceManagerMBean.java
===================================================================
RCS file:
/cvsroot/jboss/jbossmq/src/main/org/jboss/mq/pm/rollinglogged/PersistenceManagerMBean.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PersistenceManagerMBean.java 2001/08/30 02:35:55 1.3
+++ PersistenceManagerMBean.java 2001/09/01 03:01:00 1.4
@@ -1,34 +1,36 @@
-package org.jboss.mq.pm.rollinglogged;
-
/*
- * jBoss, the OpenSource EJB server
+ * JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
+package org.jboss.mq.pm.rollinglogged;
+
+import org.jboss.system.ServiceMBean;
/**
* <description>MBean interface for the JBossMQ JMX service.
*
* @author Vincent Sheffer ([EMAIL PROTECTED])
- * @created August 16, 2001
* @see <related>
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*/
public interface PersistenceManagerMBean
- extends org.jboss.system.ServiceMBean {
- // Constants -----------------------------------------------------
+ extends ServiceMBean
+{
public final static String OBJECT_NAME = ":service=JBossMQ";
-
- // Public --------------------------------------------------------
-
-
- // Public --------------------------------------------------------
-
- // Public --------------------------------------------------------
- // Public --------------------------------------------------------
+ /**
+ * Gets the DataDirectory attribute of the PersistenceManagerMBean object
+ *
+ * @return The DataDirectory value
+ */
public java.lang.String getDataDirectory();
- public void setDataDirectory( java.lang.String newDataDirectory );
+ /**
+ * Sets the DataDirectory attribute of the PersistenceManagerMBean object
+ *
+ * @param newDataDirectory The new DataDirectory value
+ */
+ public void setDataDirectory(java.lang.String newDataDirectory);
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development