User: chirino
Date: 01/11/13 20:24:08
Added: src/main/org/jboss/mq/pm/file CacheStore.java
CacheStoreMBean.java
Log:
Factored out a CacheStore object from the message store. This should lay the
ground work needed so that the MessageCache can use a PM for saving and loading
messages.
Also fixed a small bug in the file PM. It was not properly restoring the message
after a server restart.
Revision Changes Path
1.1 jbossmq/src/main/org/jboss/mq/pm/file/CacheStore.java
Index: CacheStore.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jboss.mq.pm.file;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.jms.JMSException;
import org.jboss.mq.SpyJMSException;
import org.jboss.mq.SpyMessage;
import org.jboss.mq.server.MessageReference;
import org.jboss.system.ServiceMBeanSupport;
/**
* This class manages the persistence needs of the MessageCache
*
* @author Hiram Chirino
* @version $Revision: 1.1 $
*/
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";
}
/**
* @see CacheStore#loadFromStorage(MessageReference)
*/
public SpyMessage loadFromStorage(MessageReference mh) throws JMSException {
try {
File f = new File(dataFile, "Message-" + mh.referenceId);
ObjectInputStream is = new ObjectInputStream(new BufferedInputStream(new
FileInputStream(f)));
Object rc = is.readObject();
is.close();
return (SpyMessage) rc;
} catch (ClassNotFoundException e) {
throw new SpyJMSException("Could not load message from secondary storage:
", e);
} catch (IOException e) {
throw new SpyJMSException("Could not load message from secondary storage:
", e);
}
}
/**
* @see CacheStore#saveToStorage(MessageReference, SpyMessage)
*/
public void saveToStorage(MessageReference mh, SpyMessage message) throws
JMSException {
try {
File f = new File(dataFile, "Message-" + mh.referenceId);
ObjectOutputStream os = new ObjectOutputStream(new BufferedOutputStream(new
FileOutputStream(f)));
os.writeObject(message);
os.close();
} catch (IOException e) {
throw new SpyJMSException("Could not load message from secondary storage:
", e);
}
}
/**
* @see CacheStore#removeFromStorage(MessageReference)
*/
public void removeFromStorage(MessageReference mh) throws JMSException {
File f = new File(dataFile, "Message-" + mh.referenceId);
f.delete();
}
/**
* @see CacheStoreMBean#getDataDirectory()
*/
public String getDataDirectory() {
return null;
}
/**
* @see CacheStoreMBean#setDataDirectory(String)
*/
public void setDataDirectory(String newDataDirectory) {
dataDirectory = newDataDirectory;
}
/**
* This gets called to start the service.
*/
protected void startService() throws Exception {
File jbossHome = new File(System.getProperty("jboss.system.home"));
dataFile = new File(jbossHome, dataDirectory);
log.debug("Data directory set to: " + dataFile.getCanonicalPath());
dataFile.mkdirs();
if (!dataFile.isDirectory())
throw new Exception("The configured data directory is not valid: " +
dataDirectory);
// Clean out the directory of any previous files.
File files[] = dataFile.listFiles();
log.debug("Removing " + files.length + " file(s) from: " +
dataFile.getCanonicalPath());
for (int i = 0; i < files.length; i++) {
files[i].delete();
}
}
/**
* @see CacheStoreMBean#getCacheStoreInstance()
*/
public Object getInstance() {
return this;
}
}
1.1 jbossmq/src/main/org/jboss/mq/pm/file/CacheStoreMBean.java
Index: CacheStoreMBean.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* 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.
*
* @author Vincent Sheffer ([EMAIL PROTECTED])
* @see <related>
* @version $Revision: 1.1 $
*/
public interface CacheStoreMBean
extends ServiceMBean, org.jboss.mq.pm.CacheStoreMBean
{
/**
* Gets the DataDirectory attribute of the CacheStoreMBean object
*
* @return The DataDirectory value
*/
public java.lang.String getDataDirectory();
/**
* Sets the DataDirectory attribute of the CacheStoreMBean 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