User: user57
Date: 02/02/12 20:26:38
Modified: src/main/org/jboss/mq/pm/file CacheStore.java
CacheStoreMBean.java PersistenceManager.java
PersistenceManagerMBean.java
Log:
o These are all kinda related, so I am commiting them together
o This is the second half of the migration to using ObjectName OBJECT_NAME
o Not using jboss.system.* properties anywhere (one place in testsuite
which I am ignoring for now)
o StateManager will now read its config from a url (configURL), and only
attempt to write it back out if that is a file URL. Need to fix this
to not need to write back to a config file.
o Still setting jboss.home & jboss.system.home, but use ServerConfigMBean
to get the proper bits, will eventually abstract all file access out
o Added a simple locator to find a mbean server. This is trivial code,
but helps clean up client code and makes it obvious what it does.
Revision Changes Path
1.4 +22 -23 jbossmq/src/main/org/jboss/mq/pm/file/CacheStore.java
Index: CacheStore.java
===================================================================
RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/pm/file/CacheStore.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- CacheStore.java 5 Jan 2002 06:38:13 -0000 1.3
+++ CacheStore.java 13 Feb 2002 04:26:37 -0000 1.4
@@ -20,30 +20,27 @@
import org.jboss.mq.SpyMessage;
import org.jboss.mq.server.MessageReference;
import org.jboss.system.ServiceMBeanSupport;
+import org.jboss.system.ServerConfigMBean;
/**
- * This class manages the persistence needs of the MessageCache
+ * This class manages the persistence needs of the MessageCache
*
* @author Hiram Chirino
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*/
-public class CacheStore extends ServiceMBeanSupport implements
org.jboss.mq.pm.CacheStore, CacheStoreMBean {
+public class CacheStore
+ extends ServiceMBeanSupport
+ implements org.jboss.mq.pm.CacheStore, CacheStoreMBean
+{
String dataDirectory;
- File dataFile;
-
- /**
- * @see ServiceMBeanSupport#getName()
- */
- public String getName() {
- return "JBossMQ-CacheStore";
- }
+ File dataDir;
/**
* @see CacheStore#loadFromStorage(MessageReference)
*/
public SpyMessage loadFromStorage(MessageReference mh) throws JMSException {
try {
- File f = new File(dataFile, "Message-" + mh.referenceId);
+ File f = new File(dataDir, "Message-" + mh.referenceId);
ObjectInputStream is = new ObjectInputStream(new BufferedInputStream(new
FileInputStream(f)));
Object rc = is.readObject();
is.close();
@@ -60,7 +57,7 @@
*/
public void saveToStorage(MessageReference mh, SpyMessage message) throws
JMSException {
try {
- File f = new File(dataFile, "Message-" + mh.referenceId);
+ File f = new File(dataDir, "Message-" + mh.referenceId);
ObjectOutputStream os = new ObjectOutputStream(new
BufferedOutputStream(new FileOutputStream(f)));
os.writeObject(message);
os.close();
@@ -73,7 +70,7 @@
* @see CacheStore#removeFromStorage(MessageReference)
*/
public void removeFromStorage(MessageReference mh) throws JMSException {
- File f = new File(dataFile, "Message-" + mh.referenceId);
+ File f = new File(dataDir, "Message-" + mh.referenceId);
f.delete();
}
@@ -96,24 +93,26 @@
*/
protected void startService() throws Exception {
boolean debug = log.isDebugEnabled();
- log.warn("using jboss.system.home property");
- File jbossHome = new File(System.getProperty("jboss.system.home"));
- dataFile = new File(jbossHome, dataDirectory);
+
+ // Get the system home directory (may want to use dataDir or tempDir)
+ File systemHomeDir = (File)
+ server.getAttribute(ServerConfigMBean.OBJECT_NAME, "HomeDir");
+
+ dataDir = new File(systemHomeDir, dataDirectory);
if (debug)
- log.debug("Data directory set to: " + dataFile.getCanonicalPath());
+ log.debug("Data directory set to: " + dataDir.getCanonicalPath());
- dataFile.mkdirs();
- if (!dataFile.isDirectory())
+ dataDir.mkdirs();
+ if (!dataDir.isDirectory())
throw new Exception("The configured data directory is not valid: " +
dataDirectory);
// Clean out the directory of any previous files.
- File files[] = dataFile.listFiles();
+ File files[] = dataDir.listFiles();
if (debug)
- log.debug("Removing " + files.length + " file(s) from: " +
dataFile.getCanonicalPath());
+ log.debug("Removing " + files.length + " file(s) from: " +
dataDir.getCanonicalPath());
for (int i = 0; i < files.length; i++) {
files[i].delete();
}
-
}
/**
1.2 +7 -7 jbossmq/src/main/org/jboss/mq/pm/file/CacheStoreMBean.java
Index: CacheStoreMBean.java
===================================================================
RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/pm/file/CacheStoreMBean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CacheStoreMBean.java 14 Nov 2001 04:24:08 -0000 1.1
+++ CacheStoreMBean.java 13 Feb 2002 04:26:37 -0000 1.2
@@ -4,32 +4,32 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
+
package org.jboss.mq.pm.file;
import org.jboss.system.ServiceMBean;
import javax.management.ObjectName;
/**
- * <description>MBean interface for the JBossMQ JMX service.
+ * MBean interface for the JBossMQ JMX service.
*
* @author Vincent Sheffer ([EMAIL PROTECTED])
- * @see <related>
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
*/
public interface CacheStoreMBean
extends ServiceMBean, org.jboss.mq.pm.CacheStoreMBean
{
/**
- * Gets the DataDirectory attribute of the CacheStoreMBean object
+ * Gets the DataDirectory attribute of the CacheStoreMBean object
*
* @return The DataDirectory value
*/
- public java.lang.String getDataDirectory();
+ String getDataDirectory();
/**
- * Sets the DataDirectory attribute of the CacheStoreMBean object
+ * Sets the DataDirectory attribute of the CacheStoreMBean object
*
* @param newDataDirectory The new DataDirectory value
*/
- public void setDataDirectory(java.lang.String newDataDirectory);
+ void setDataDirectory(String newDataDirectory);
}
1.17 +91 -87 jbossmq/src/main/org/jboss/mq/pm/file/PersistenceManager.java
Index: PersistenceManager.java
===================================================================
RCS file:
/cvsroot/jboss/jbossmq/src/main/org/jboss/mq/pm/file/PersistenceManager.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- PersistenceManager.java 2 Feb 2002 03:54:20 -0000 1.16
+++ PersistenceManager.java 13 Feb 2002 04:26:37 -0000 1.17
@@ -4,6 +4,7 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
+
package org.jboss.mq.pm.file;
import java.io.File;
@@ -33,44 +34,53 @@
import org.jboss.mq.server.MessageReference;
import org.jboss.mq.server.MessageCache;
import org.jboss.system.ServiceMBeanSupport;
+import org.jboss.system.ServerConfigMBean;
+
/**
- * This class manages all persistence related services for file based
- * persistence.
+ * This class manages all persistence related services for file based
+ * persistence.
*
* @author Paul Kendall ([EMAIL PROTECTED])
- * @version $Revision: 1.16 $
+ * @version $Revision: 1.17 $
*/
-public class PersistenceManager extends ServiceMBeanSupport implements
PersistenceManagerMBean, org.jboss.mq.pm.PersistenceManager
+public class PersistenceManager
+ extends ServiceMBeanSupport
+ implements PersistenceManagerMBean, org.jboss.mq.pm.PersistenceManager
{
-
protected final static int MAX_POOL_SIZE = 50;
-
private ObjectName messageCacheName;
private MessageCache messageCache;
- protected java.util.ArrayList txPool = new java.util.ArrayList();
+ protected ArrayList txPool = new ArrayList();
protected long tidcounter = Long.MIN_VALUE;
- // The directory where persistence data should be stored
+ /**
+ * The sub-directory under the system home where persistence
+ * data will be stored.
+ */
String dataDirectory;
- File dataDirFile;
- //tx manager
+
+ /** A reference to the actual data directory. */
+ File dataDir;
+
+ /** tx manager. */
org.jboss.mq.pm.TxManager txManager;
- // Maps SpyDestinations to SpyMessageLogs
+
+ /** Maps SpyDestinations to SpyMessageLogs */
HashMap messageLogs = new HashMap();
- // Maps (Long)txIds to LinkedList of AddFile tasks
+
+ /** Maps (Long)txIds to LinkedList of AddFile tasks */
HashMap transactedTasks = new HashMap();
- //Holds unrestored messages read from queues, indexed by queue name.
+
+ /** Holds unrestored messages read from queues, indexed by queue name. */
Map unrestoredMessages = new HashMap();
/**
- * PersistenceManager constructor.
- *
- * @exception javax.jms.JMSException Description of Exception
+ * Sets up the transaction manager.
*/
- public PersistenceManager() throws javax.jms.JMSException
+ public PersistenceManager() throws JMSException
{
txManager = new TxManager(this);
}
@@ -100,27 +110,17 @@
*
* @param newDataDirectory The new DataDirectory value
*/
- public void setDataDirectory(java.lang.String newDataDirectory)
+ public void setDataDirectory(String newDataDirectory)
{
dataDirectory = newDataDirectory;
}
/**
- * Gets the Name attribute of the PersistenceManager object
- *
- * @return The Name value
- */
- public String getName()
- {
- return "JBossMQ-PersistenceManager";
- }
-
- /**
* Gets the DataDirectory attribute of the PersistenceManager object
*
* @return The DataDirectory value
*/
- public java.lang.String getDataDirectory()
+ public String getDataDirectory()
{
return dataDirectory;
}
@@ -136,22 +136,30 @@
}
/**
- * #Description of the Method
- *
- * @exception Exception Description of Exception
+ * Setup the data directory, where messages will be stored, connects
+ * to the message cache and restores transactions.
*/
public void startService() throws Exception
{
- log.warn("using jboss.system.home property");
- File jbossHome = new File(System.getProperty("jboss.system.home"));
- dataDirFile = new File(jbossHome, dataDirectory);
- dataDirFile.mkdirs();
- if( !dataDirFile.isDirectory() )
- throw new Exception("The data directory is not valid:
"+dataDirFile.getCanonicalPath());
- messageCache = (MessageCache)getServer().invoke(messageCacheName,
"getInstance", new Object[] {}, new String[] {});
+ // Get the system home directory (may want to use dataDir)
+ File systemHomeDir = (File)
+ server.getAttribute(ServerConfigMBean.OBJECT_NAME, "HomeDir");
+
+ dataDir = new File(systemHomeDir, dataDirectory);
+ if (log.isDebugEnabled()) {
+ log.debug("Using data directory: " + dataDir);
+ }
+
+ dataDir.mkdirs();
+ if (!dataDir.isDirectory())
+ throw new Exception("The data directory is not valid: " +
dataDir.getCanonicalPath());
+
+ messageCache = (MessageCache)
+ getServer().invoke(messageCacheName,
+ "getInstance",
+ new Object[0], new String[0]);
restoreTransactions();
-
}
/**
@@ -161,15 +169,15 @@
* When a queue or topic is started, it will collect these pre-restored
* messages and add them to its in memory queue.
*
- * @exception javax.jms.JMSException if an error occurs
+ * @exception JMSException if an error occurs
*/
- private void restoreTransactions() throws javax.jms.JMSException
+ private void restoreTransactions() throws JMSException
{
boolean debug = log.isDebugEnabled();
TreeSet txs = new TreeSet();
- File[] transactFiles = dataDirFile.listFiles();
- int queueNameOffset = dataDirFile.toString().length()+1;
+ File[] transactFiles = dataDir.listFiles();
+ int queueNameOffset = dataDir.toString().length()+1;
if(transactFiles != null)
{
for (int i = 0; i < transactFiles.length; i++)
@@ -192,7 +200,7 @@
try
{
Long tx = new Long(Long.parseLong(transactFiles[i].getName()));
- java.util.ArrayList removingMessages = readTxFile(transactFiles[i]);
+ ArrayList removingMessages = readTxFile(transactFiles[i]);
if (testRollBackTx(tx, removingMessages))
{
txs.add(tx);
@@ -251,15 +259,15 @@
* the JMSDestination to get them back into the in-memory queue.
*
* @param jmsDest a <code>JMSDestination</code> value
- * @exception javax.jms.JMSException if an error occurs
+ * @exception JMSException if an error occurs
*/
- public void restoreDestination(JMSDestination jmsDest) throws
javax.jms.JMSException
+ public void restoreDestination(JMSDestination jmsDest) throws JMSException
{
if (jmsDest instanceof JMSQueue)
{
SpyDestination spyDest = jmsDest.getSpyDestination();
restoreQueue(jmsDest, spyDest);
- } // end of if ()
+ }
else if (jmsDest instanceof JMSTopic)
{
Collection persistQList = ((JMSTopic)jmsDest).getPersistentQueues();
@@ -269,11 +277,8 @@
SpyDestination spyDest =
((PersistentQueue)pq.next()).getSpyDestination();
restoreQueue(jmsDest, spyDest);
-
- } // end of while ()
-
- } // end of if ()
-
+ }
+ }
}
/**
@@ -298,7 +303,7 @@
if (info == null)
{
//must be new, set up directory etc.
- File logDir = new File(dataDirFile, queueName);
+ File logDir = new File(dataDir, queueName);
MessageLog msgLog = new MessageLog(messageCache, logDir);
info = new LogInfo(msgLog, dest);
synchronized (messageLogs)
@@ -337,11 +342,11 @@
} // end of if ()
}
- public void initQueue(SpyDestination dest) throws javax.jms.JMSException
+ public void initQueue(SpyDestination dest) throws JMSException
{
try
{
- File logDir = new File(dataDirFile, dest.toString());
+ File logDir = new File(dataDir, dest.toString());
MessageLog log = new MessageLog(messageCache, logDir);
LogInfo info = new LogInfo(log, dest);
synchronized (messageLogs)
@@ -351,7 +356,7 @@
}
catch (Exception e)
{
- javax.jms.JMSException newE = new javax.jms.JMSException("Invalid
configuration.");
+ JMSException newE = new JMSException("Invalid configuration.");
newE.setLinkedException(e);
throw newE;
}
@@ -361,13 +366,13 @@
* #Description of the Method
*
* @param dest Description of Parameter
- * @exception javax.jms.JMSException Description of Exception
+ * @exception JMSException Description of Exception
*/
- public void destroyQueue(SpyDestination dest) throws javax.jms.JMSException
+ public void destroyQueue(SpyDestination dest) throws JMSException
{
try
{
- File file = new File(dataDirFile, dest.toString());
+ File file = new File(dataDir, dest.toString());
LogInfo logInfo;
synchronized (messageLogs)
{
@@ -380,13 +385,13 @@
logInfo.log.close();
file.delete();
}
- catch (javax.jms.JMSException e)
+ catch (JMSException e)
{
throw e;
}
catch (Exception e)
{
- javax.jms.JMSException newE = new javax.jms.JMSException("Invalid
configuration.");
+ JMSException newE = new JMSException("Invalid configuration.");
newE.setLinkedException(e);
throw newE;
}
@@ -397,9 +402,9 @@
*
* @param message Description of Parameter
* @param txId Description of Parameter
- * @exception javax.jms.JMSException Description of Exception
+ * @exception JMSException Description of Exception
*/
- public void add(MessageReference messageRef, org.jboss.mq.pm.Tx txId) throws
javax.jms.JMSException
+ public void add(MessageReference messageRef, org.jboss.mq.pm.Tx txId) throws
JMSException
{
SpyMessage message = messageRef.getMessage();
LogInfo logInfo;
@@ -409,7 +414,7 @@
}
if (logInfo == null)
{
- throw new javax.jms.JMSException("Destination was not initalized with the
PersistenceManager");
+ throw new JMSException("Destination was not initalized with the
PersistenceManager");
}
logInfo.log.add(messageRef, txId);
if (txId == null)
@@ -425,7 +430,7 @@
}
if (info == null)
{
- throw new javax.jms.JMSException("Transaction is not active 5.");
+ throw new JMSException("Transaction is not active 5.");
}
synchronized (info.tasks)
{
@@ -438,9 +443,9 @@
* #Description of the Method
*
* @param txId Description of Parameter
- * @exception javax.jms.JMSException Description of Exception
+ * @exception JMSException Description of Exception
*/
- public void commitPersistentTx(org.jboss.mq.pm.Tx txId) throws
javax.jms.JMSException
+ public void commitPersistentTx(org.jboss.mq.pm.Tx txId) throws JMSException
{
TxInfo info;
synchronized (transactedTasks)
@@ -475,9 +480,9 @@
* #Description of the Method
*
* @return Description of the Returned Value
- * @exception javax.jms.JMSException Description of Exception
+ * @exception JMSException Description of Exception
*/
- public org.jboss.mq.pm.Tx createPersistentTx() throws javax.jms.JMSException
+ public org.jboss.mq.pm.Tx createPersistentTx() throws JMSException
{
org.jboss.mq.pm.Tx txId = null;
synchronized (transactedTasks)
@@ -493,9 +498,9 @@
*
* @param message Description of Parameter
* @param txId Description of Parameter
- * @exception javax.jms.JMSException Description of Exception
+ * @exception JMSException Description of Exception
*/
- public void remove(MessageReference messageRef, org.jboss.mq.pm.Tx txId) throws
javax.jms.JMSException
+ public void remove(MessageReference messageRef, org.jboss.mq.pm.Tx txId) throws
JMSException
{
SpyMessage message = messageRef.getMessage();
LogInfo logInfo;
@@ -507,7 +512,7 @@
if (logInfo == null)
{
- throw new javax.jms.JMSException("Destination was not initalized with the
PersistenceManager");
+ throw new JMSException("Destination was not initalized with the
PersistenceManager");
}
logInfo.log.remove(message, txId);
@@ -524,7 +529,7 @@
}
if (info == null)
{
- throw new javax.jms.JMSException("Transaction is not active 6.");
+ throw new JMSException("Transaction is not active 6.");
}
try
{
@@ -548,9 +553,9 @@
* #Description of the Method
*
* @param txId Description of Parameter
- * @exception javax.jms.JMSException Description of Exception
+ * @exception JMSException Description of Exception
*/
- public void rollbackPersistentTx(org.jboss.mq.pm.Tx txId) throws
javax.jms.JMSException
+ public void rollbackPersistentTx(org.jboss.mq.pm.Tx txId) throws JMSException
{
TxInfo info;
synchronized (transactedTasks)
@@ -630,7 +635,7 @@
for (Iterator it = clone.keySet().iterator(); !found && it.hasNext(); )
{
String dirName = (String)it.next();
- File dir = new File(dataDirFile, dirName);
+ File dir = new File(dataDir, dirName);
File[] messageFiles = dir.listFiles();
for (int j = 0; j < messageFiles.length; ++j)
{
@@ -670,23 +675,23 @@
- protected void deleteTxFile(File file) throws javax.jms.JMSException
+ protected void deleteTxFile(File file) throws JMSException
{
if (!file.delete())
{
Thread.yield();
if (file.exists() && !file.delete())
{
- throw new javax.jms.JMSException("Unable to delete committing
transaction record.");
+ throw new JMSException("Unable to delete committing transaction
record.");
}
}
}
- protected java.util.ArrayList readTxFile(File file) throws javax.jms.JMSException
+ protected ArrayList readTxFile(File file) throws JMSException
{
try
{
- java.util.ArrayList result = new java.util.ArrayList();
+ ArrayList result = new ArrayList();
java.io.RandomAccessFile raf = new java.io.RandomAccessFile(file, "r");
try
{
@@ -695,9 +700,8 @@
result.add(raf.readUTF());
}
}
- catch (java.io.EOFException e)
- {
- }
+ catch (java.io.EOFException ignore) {}
+
raf.close();
return result;
}
@@ -709,14 +713,14 @@
}
}
- protected File createTxFile(org.jboss.mq.pm.Tx txId) throws
javax.jms.JMSException
+ protected File createTxFile(org.jboss.mq.pm.Tx txId) throws JMSException
{
try
{
- File file = new File(dataDirFile, txId.toString());
+ File file = new File(dataDir, txId.toString());
if (!file.createNewFile())
{
- throw new javax.jms.JMSException("Error creating tx file.");
+ throw new JMSException("Error creating tx file.");
}
return file;
}
1.6 +7 -8
jbossmq/src/main/org/jboss/mq/pm/file/PersistenceManagerMBean.java
Index: PersistenceManagerMBean.java
===================================================================
RCS file:
/cvsroot/jboss/jbossmq/src/main/org/jboss/mq/pm/file/PersistenceManagerMBean.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- PersistenceManagerMBean.java 10 Nov 2001 21:38:05 -0000 1.5
+++ PersistenceManagerMBean.java 13 Feb 2002 04:26:38 -0000 1.6
@@ -4,32 +4,31 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
+
package org.jboss.mq.pm.file;
import org.jboss.system.ServiceMBean;
-import javax.management.ObjectName;
/**
- * <description>MBean interface for the JBossMQ JMX service.
+ * MBean interface for the JBossMQ JMX service.
*
* @author Vincent Sheffer ([EMAIL PROTECTED])
- * @see <related>
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public interface PersistenceManagerMBean
extends ServiceMBean, org.jboss.mq.pm.PersistenceManagerMBean
{
/**
- * Gets the DataDirectory attribute of the PersistenceManagerMBean object
+ * Gets the DataDirectory attribute of the PersistenceManagerMBean object
*
* @return The DataDirectory value
*/
- public java.lang.String getDataDirectory();
+ String getDataDirectory();
/**
- * Sets the DataDirectory attribute of the PersistenceManagerMBean object
+ * Sets the DataDirectory attribute of the PersistenceManagerMBean object
*
* @param newDataDirectory The new DataDirectory value
*/
- public void setDataDirectory(java.lang.String newDataDirectory);
+ void setDataDirectory(String newDataDirectory);
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development