User: user57
Date: 02/02/12 20:26:38
Modified: src/main/org/jboss/mq/server MessageCache.java
MessageCacheMBean.java StateManager.java
StateManagerMBean.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.14 +5 -3 jbossmq/src/main/org/jboss/mq/server/MessageCache.java
Index: MessageCache.java
===================================================================
RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/server/MessageCache.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- MessageCache.java 2 Feb 2002 03:54:21 -0000 1.13
+++ MessageCache.java 13 Feb 2002 04:26:38 -0000 1.14
@@ -4,6 +4,7 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
+
package org.jboss.mq.server;
import java.io.File;
@@ -31,9 +32,11 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Hiram Chirino</a>
* @author <a href="mailto:[EMAIL PROTECTED]">David Maplesden</a>
- * @version $Revision: 1.13 $
+ * @version $Revision: 1.14 $
*/
-public class MessageCache extends ServiceMBeanSupport implements MessageCacheMBean,
MBeanRegistration, Runnable
+public class MessageCache
+ extends ServiceMBeanSupport
+ implements MessageCacheMBean, MBeanRegistration, Runnable
{
// The cached messages are orded in a LRU linked list
private LRUCache lruCache = new LRUCache();
@@ -373,7 +376,6 @@
*/
public void testBigLoad() throws Exception
{
-
MessageCache cache = new MessageCache();
File tempDir = new File("Temp-" + System.currentTimeMillis());
tempDir.mkdirs();
1.4 +36 -25 jbossmq/src/main/org/jboss/mq/server/MessageCacheMBean.java
Index: MessageCacheMBean.java
===================================================================
RCS file:
/cvsroot/jboss/jbossmq/src/main/org/jboss/mq/server/MessageCacheMBean.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MessageCacheMBean.java 14 Nov 2001 04:23:27 -0000 1.3
+++ MessageCacheMBean.java 13 Feb 2002 04:26:38 -0000 1.4
@@ -4,76 +4,87 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
+
package org.jboss.mq.server;
+
import org.jboss.system.ServiceMBean;
import javax.management.ObjectName;
-
+
/**
* Defines the managment interface that is exposed to the MessageCache
*
* @author <a href="mailto:[EMAIL PROTECTED]">Hiram Chirino</a>
- * @version $Revision: 1.3 $
+ * @version $Revision: 1.4 $
*/
-public interface MessageCacheMBean extends ServiceMBean {
-
/**
+public interface MessageCacheMBean
+ extends ServiceMBean
+{
+ /**
* Gets the hardRefCacheSize
+ *
* @return Returns a int
*/
- public int getHardRefCacheSize();
-
+ int getHardRefCacheSize();
+
/**
* Gets the softRefCacheSize
+ *
* @return Returns a int
*/
- public int getSoftRefCacheSize();
-
+ int getSoftRefCacheSize();
+
/**
* Gets the totalCacheSize
+ *
* @return Returns a int
*/
- public int getTotalCacheSize();
+ int getTotalCacheSize();
-
/**
* Gets the cacheMisses
+ *
* @return Returns a int
*/
- public int getCacheMisses();
-
+ int getCacheMisses();
+
/**
* Gets the cacheHits
+ *
* @return Returns a int
*/
- public int getCacheHits();
+ int getCacheHits();
/**
* Gets the highMemoryMark
+ *
* @return Returns a long
*/
- public long getHighMemoryMark();
-
+ long getHighMemoryMark();
+
/**
* Sets the highMemoryMark
+ *
* @param highMemoryMark The highMemoryMark to set
*/
- public void setHighMemoryMark(long highMemoryMark);
-
+ void setHighMemoryMark(long highMemoryMark);
+
/**
* Gets the maxMemoryMark
+ *
* @return Returns a long
*/
- public long getMaxMemoryMark();
-
+ long getMaxMemoryMark();
+
/**
* Sets the maxMemoryMark
+ *
* @param maxMemoryMark The maxMemoryMark to set
*/
- public void setMaxMemoryMark(long maxMemoryMark);
-
-
- public long getCurrentMemoryUsage();
-
- public MessageCache getInstance();
+ void setMaxMemoryMark(long maxMemoryMark);
+
+ long getCurrentMemoryUsage();
+
+ MessageCache getInstance();
void setCacheStore(ObjectName cacheStore);
}
1.14 +76 -73 jbossmq/src/main/org/jboss/mq/server/StateManager.java
Index: StateManager.java
===================================================================
RCS file: /cvsroot/jboss/jbossmq/src/main/org/jboss/mq/server/StateManager.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- StateManager.java 2 Feb 2002 04:02:24 -0000 1.13
+++ StateManager.java 13 Feb 2002 04:26:38 -0000 1.14
@@ -4,12 +4,17 @@
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
-package org.jboss.mq.server;
-
+package org.jboss.mq.server;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.PrintStream;
+import java.io.InputStream;
+import java.io.BufferedInputStream;
+import java.io.IOException;
import java.net.URL;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
@@ -17,6 +22,7 @@
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Set;
+
import javax.jms.InvalidClientIDException;
import javax.jms.JMSException;
import javax.jms.JMSSecurityException;
@@ -28,41 +34,50 @@
import org.jboss.mq.server.JMSServer;
import org.jboss.mq.xml.XElement;
import org.jboss.mq.xml.XElementException;
+
import org.jboss.system.ServiceMBeanSupport;
+import org.jboss.system.ServerConfigMBean;
/**
- * This class is a simple User Manager. It handles credential issues.
+ * This class is a simple User Manager. It handles credential issues.
*
* @author Norbert Lataille ([EMAIL PROTECTED])
* @author <a href="[EMAIL PROTECTED]">Hiram Chirino</a>
- * @version $Revision: 1.13 $
+ * @version $Revision: 1.14 $
*/
-public class StateManager extends ServiceMBeanSupport implements StateManagerMBean
+public class StateManager
+ extends ServiceMBeanSupport
+ implements StateManagerMBean
{
-
XElement stateConfig;
private final Set loggedOnClientIds = new HashSet();
private String stateFile = "conf/default/jbossmq-state.xml";
-
-
+ private URL systemConfigURL;
+
/**
* Constructor for the StateManager object
*
- * @exception org.jboss.mq.xml.XElementException Description of Exception
+ * @exception XElementException Description of Exception
*/
- public StateManager() throws org.jboss.mq.xml.XElementException
+ public StateManager() throws XElementException
{
//loggedOnClientIds = new HashSet();
}
+ protected void createService() throws Exception {
+ // Get the system configuration URL
+ systemConfigURL = (URL)
+ server.getAttribute(ServerConfigMBean.OBJECT_NAME, "ConfigURL");
+ }
+
/**
* Insert the method's description here. Creation date: (7/10/2001 11:17:33
* PM)
*
* @param newStateFile java.lang.String
*/
- public void setStateFile(java.lang.String newStateFile)
+ public void setStateFile(String newStateFile)
{
stateFile = newStateFile.trim();
}
@@ -80,7 +95,8 @@
* @param topic The new DurableSubscription value
* @exception JMSException Description of Exception
*/
- public void setDurableSubscription(JMSServer server, DurableSubscriptionID sub,
SpyTopic topic) throws JMSException
+ public void setDurableSubscription(JMSServer server, DurableSubscriptionID sub,
SpyTopic topic)
+ throws JMSException
{
boolean debug = log.isDebugEnabled();
if (debug)
@@ -175,15 +191,16 @@
}
// Could not find that user..
- throw new JMSException("ClientID '" + sub.getClientID() + "' cannot create
durable subscriptions.");
+ throw new JMSException("ClientID '" + sub.getClientID() +
+ "' cannot create durable subscriptions.");
}
- catch (java.io.IOException e)
+ catch (IOException e)
{
JMSException newE = new SpyJMSException("Could not setup the durable
subscription");
newE.setLinkedException(e);
throw newE;
}
- catch (org.jboss.mq.xml.XElementException e)
+ catch (XElementException e)
{
JMSException newE = new SpyJMSException("Could not setup the durable
subscription");
newE.setLinkedException(e);
@@ -193,22 +210,12 @@
}
/**
- * Gets the Name attribute of the StateManager object
- *
- * @return The Name value
- */
- public String getName()
- {
- return "JBossMQ-StateManager";
- }
-
- /**
* Insert the method's description here. Creation date: (7/10/2001 11:17:33
* PM)
*
* @return java.lang.String
*/
- public java.lang.String getStateFile()
+ public String getStateFile()
{
return stateFile;
}
@@ -256,7 +263,9 @@
{
if (loggedOnClientIds.contains(clientId))
{
- throw new JMSSecurityException("The login id has an
assigned client id. That client id is already connected to the server!");
+ throw new JMSSecurityException
+ ("The login id has an assigned client id. " +
+ "That client id is already connected to the server!");
}
loggedOnClientIds.add(clientId);
}
@@ -267,7 +276,7 @@
throw new JMSSecurityException("This user does not exist");
}
}
- catch (org.jboss.mq.xml.XElementException e)
+ catch (XElementException e)
{
log.error(e);
throw new JMSException("Invalid server user configuration.");
@@ -279,7 +288,7 @@
* object
*
* @param ID The feature to be added to the LoggedOnClientId
- * attribute
+ * attribute
* @exception JMSException Description of Exception
*/
public void addLoggedOnClientId(String ID) throws JMSException
@@ -308,7 +317,7 @@
throw new InvalidClientIDException("This loggedOnClientIds is
password protected !");
}
}
- catch (org.jboss.mq.xml.XElementException ignore)
+ catch (XElementException ignore)
{
}
}
@@ -380,14 +389,15 @@
} // end of try-catch
return durableSubs;
}
+
/**
* #Description of the Method
*
* @param server Description of Parameter
- * @exception org.jboss.mq.xml.XElementException Description of Exception
+ * @exception XElementException Description of Exception
*/
/*
- public void initDurableSubscriptions(JMSServer server) throws
org.jboss.mq.xml.XElementException
+ public void initDurableSubscriptions(JMSServer server) throws XElementException
{
//Set the known Ids
@@ -426,67 +436,60 @@
}
*/
- /**
- * #Description of the Method
- *
- * @exception java.io.IOException Description of Exception
- * @exception org.jboss.mq.xml.XElementException Description of Exception
- */
- public void loadConfig() throws java.io.IOException,
org.jboss.mq.xml.XElementException
+
+ public void loadConfig() throws IOException, XElementException
{
- log.warn("using jboss.system.home property");
- java.io.File jbossHome = new
java.io.File(System.getProperty("jboss.system.home"));
- if (!jbossHome.exists())
- {
- log.error("jboss.system.configurationDirectory not found! : " + jbossHome);
+ URL configURL = new URL(systemConfigURL, stateFile);
+ if (log.isDebugEnabled()) {
+ log.debug("Loading config from: " + configURL);
}
- java.io.File file = new java.io.File(jbossHome, stateFile);
- if (!file.exists())
- {
- log.error("statefile not found! : " + file);
+
+ InputStream in = new BufferedInputStream(configURL.openStream());
+ try {
+ stateConfig = XElement.createFrom(in);
+ }
+ finally {
+ in.close();
}
- java.io.InputStream in = new java.io.BufferedInputStream(new
java.io.FileInputStream(file));
- stateConfig = XElement.createFrom(in);
- in.close();
}
- /**
- * #Description of the Method
- *
- * @exception java.io.IOException Description of Exception
- */
- public void saveConfig() throws java.io.IOException
+ public void saveConfig() throws IOException
{
+ URL configURL = new URL(systemConfigURL, stateFile);
+
+ if (configURL.getProtocol().equals("file")) {
+ File file = new File(configURL.getFile());
+ if (log.isDebugEnabled()) {
+ log.debug("Saving config to: " + file);
+ }
- String file =
getClass().getClassLoader().getResource("jbossmq-state.xml").getFile();
- java.io.PrintStream stream = new java.io.PrintStream(new
java.io.FileOutputStream(file));
- stream.print(stateConfig.toXML(true));
- stream.close();
-
+ PrintStream stream = new PrintStream(new FileOutputStream(file));
+ try {
+ stream.print(stateConfig.toXML(true));
+ }
+ finally {
+ stream.close();
+ }
+ }
+ else {
+ log.error("Can not save configuration to non-file URL: " + configURL);
+ }
}
- /**
- * #Description of the Method
- *
- * @return Description of the Returned Value
- * @exception Exception Description of Exception
- */
public String displayStateConfig() throws Exception
{
return stateConfig.toString();
}
- /**
- * #Description of the Class
- */
public class Identity
{
-
String login;
String passwd;
String loggedOnClientIds;
- Identity(String login, String passwd, String loggedOnClientIds)
+ Identity(final String login,
+ final String passwd,
+ final String loggedOnClientIds)
{
this.login = login;
this.passwd = passwd;
1.6 +10 -18 jbossmq/src/main/org/jboss/mq/server/StateManagerMBean.java
Index: StateManagerMBean.java
===================================================================
RCS file:
/cvsroot/jboss/jbossmq/src/main/org/jboss/mq/server/StateManagerMBean.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- StateManagerMBean.java 10 Nov 2001 21:38:05 -0000 1.5
+++ StateManagerMBean.java 13 Feb 2002 04:26:38 -0000 1.6
@@ -9,37 +9,29 @@
import org.jboss.system.ServiceMBean;
/**
- * <description>MBean interface for the JBossMQ JMX service.
+ * MBean interface for the JBossMQ JMX service.
*
* @author <a href="[EMAIL PROTECTED]">Hiram Chirino</a>
- * @see <related>
- * @version $Revision: 1.5 $
+ * @version $Revision: 1.6 $
*/
public interface StateManagerMBean
- extends ServiceMBean
+ extends ServiceMBean
{
/**
- * Gets the StateFile attribute of the StateManagerMBean object
+ * Gets the StateFile attribute of the StateManagerMBean object
*
* @return The StateFile value
*/
- public java.lang.String getStateFile();
+ String getStateFile();
/**
- * Sets the StateFile attribute of the StateManagerMBean object
+ * Sets the StateFile attribute of the StateManagerMBean object
*
- * @param newStateFile The new StateFile value
+ * @param newStateFile The new StateFile value
*/
- public void setStateFile(java.lang.String newStateFile);
+ void setStateFile(String newStateFile);
+ StateManager getInstance();
- public StateManager getInstance();
-
- /**
- * #Description of the Method
- *
- * @return Description of the Returned Value
- * @exception Exception Description of Exception
- */
- public String displayStateConfig() throws Exception;
+ String displayStateConfig() throws Exception;
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development