[jboss-cvs] JBossCache/src/org/jboss/cache/factories ...
Manik Surtani
msurtani at jboss.com
Thu Jan 4 00:35:37 EST 2007
User: msurtani
Date: 07/01/04 00:35:37
Modified: src/org/jboss/cache/factories NodeFactory.java
UnitTestCacheFactory.java
XmlConfigurationParser.java
Log:
Major changes around nodes, and the way they interact with the interceptor stack.
Also removed redundant methods in NodeSPI and removed the need for casting to NodeSPI in most cases.
Revision Changes Path
1.20 +6 -6 JBossCache/src/org/jboss/cache/factories/NodeFactory.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: NodeFactory.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/factories/NodeFactory.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- NodeFactory.java 3 Jan 2007 01:21:37 -0000 1.19
+++ NodeFactory.java 4 Jan 2007 05:35:37 -0000 1.20
@@ -64,7 +64,7 @@
* should be copied into the new node's data field.
* @return the new node
*/
- public Node createDataNode(Object childName, Fqn fqn, Node parent, Map data, boolean mapSafe)
+ public NodeSPI createDataNode(Object childName, Fqn fqn, NodeSPI parent, Map data, boolean mapSafe)
{
return optimistic ? new VersionedNode(childName, fqn, parent, data, cache) : new UnversionedNode(childName, fqn, data, mapSafe, cache);
}
@@ -78,23 +78,23 @@
{
if (template instanceof WorkspaceNode)
{
- Node dataNodeParent = ((WorkspaceNode) parent).getNode();
+ NodeSPI dataNodeParent = ((WorkspaceNode) parent).getNode();
TransactionWorkspace workspace = ((WorkspaceNode) template).getTransactionWorkspace();
return createWorkspaceNode(dataNodeParent, workspace);
}
// not a workspace node.
- return createDataNode(childName, new Fqn(parent.getFqn(), childName), parent, data, false);
+ return createDataNode(childName, new Fqn(parent.getFqn(), childName), (NodeSPI) parent, data, false);
}
- public WorkspaceNode createWorkspaceNode(Node dataNode, TransactionWorkspace workspace)
+ public WorkspaceNode createWorkspaceNode(NodeSPI dataNode, TransactionWorkspace workspace)
{
- return new WorkspaceNodeImpl((NodeSPI) dataNode, workspace);
+ return new WorkspaceNodeImpl(dataNode, workspace);
}
public NodeSPI createRootDataNode()
{
- return (NodeSPI) createDataNode(null, Fqn.ROOT, null, null, false);
+ return createDataNode(null, Fqn.ROOT, null, null, false);
}
}
1.3 +68 -111 JBossCache/src/org/jboss/cache/factories/UnitTestCacheFactory.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UnitTestCacheFactory.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/factories/UnitTestCacheFactory.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- UnitTestCacheFactory.java 4 Jan 2007 03:36:42 -0000 1.2
+++ UnitTestCacheFactory.java 4 Jan 2007 05:35:37 -0000 1.3
@@ -6,27 +6,23 @@
*/
package org.jboss.cache.factories;
-import java.io.InputStream;
-
import org.jboss.cache.Cache;
import org.jboss.cache.CacheImpl;
-import org.jboss.cache.config.CacheLoaderConfig;
import org.jboss.cache.config.Configuration;
-import org.jboss.cache.config.ConfigurationException;
-import org.jboss.cache.config.EvictionConfig;
import org.jboss.cache.config.Configuration.CacheMode;
+import org.jboss.cache.config.ConfigurationException;
import org.jboss.cache.xml.XmlHelper;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
+import java.io.InputStream;
+
/**
* Cache factory used by unit tests.
- *
- *
*/
public class UnitTestCacheFactory
{
- public static String JGROUPS_CHANNEL = "udp"; //use udp by default
+ public static String JGROUPS_CHANNEL = "udp";//use udp by default
public static String JGROUPS_STACK_TYPE = "jgroups.stack";
public static String DEFAULT_CONFIGURATION_FILE = "META-INF/unit-test-cache-service.xml";
@@ -59,18 +55,7 @@
public static Configuration createConfiguration(CacheMode mode, boolean useEviction, boolean usePassivation) throws ConfigurationException
{
UnitTestXmlConfigurationParser parser = new UnitTestXmlConfigurationParser();
- Configuration c = parser.parseFile(DEFAULT_CONFIGURATION_FILE,mode);
-
- if(!useEviction)
- {
- c.setEvictionConfig(null);
- }
-
- if(!usePassivation)
- {
- c.setCacheLoaderConfig(null);
- }
-
+ Configuration c = parser.parseFile(DEFAULT_CONFIGURATION_FILE, mode);
return c;
}
@@ -95,58 +80,30 @@
}
}
- public static CacheLoaderConfig getSingleCacheLoaderConfig(String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean shared) throws Exception
- {
- return getSingleCacheLoaderConfig(preload, cacheloaderClass, properties, async, fetchPersistentState, shared, false);
- }
-
- public static CacheLoaderConfig getSingleCacheLoaderConfig(String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean shared, boolean purgeOnStartup) throws Exception
- {
- return getSingleCacheLoaderConfig(false, preload, cacheloaderClass, properties, async, fetchPersistentState, shared, purgeOnStartup);
- }
-
- protected static CacheLoaderConfig getSingleCacheLoaderConfig(boolean passivation, String preload, String cacheloaderClass, String properties, boolean async, boolean fetchPersistentState, boolean shared, boolean purgeOnStartup) throws Exception
- {
- String xml = "<config>\n" +
- "<passivation>" + passivation + "</passivation>\n" +
- "<preload>" + preload + "</preload>\n" +
- "<cacheloader>\n" +
- "<class>" + cacheloaderClass + "</class>\n" +
- "<properties>" + properties + "</properties>\n" +
- "<async>" + async + "</async>\n" +
- "<shared>" + shared + "</shared>\n" +
- "<fetchPersistentState>" + fetchPersistentState + "</fetchPersistentState>\n" +
- "<purgeOnStartup>" + purgeOnStartup + "</purgeOnStartup>\n" +
- "</cacheloader>\n" +
- "</config>";
- Element element = XmlHelper.stringToElement(xml);
- return XmlConfigurationParser.parseCacheLoaderConfig(element);
- }
-
private static class UnitTestXmlConfigurationParser extends XmlConfigurationParser
{
public Configuration parseFile(String filename, CacheMode mode)
{
- return parseStream(getAsInputStreamFromClassLoader(DEFAULT_CONFIGURATION_FILE),mode);
+ return parseStream(getAsInputStreamFromClassLoader(DEFAULT_CONFIGURATION_FILE), mode);
}
- public Configuration parseStream(InputStream stream,CacheMode mode)
+ public Configuration parseStream(InputStream stream, CacheMode mode)
{
// loop through all elements in XML.
if (stream == null) throw new ConfigurationException("Input stream for configuration xml is null!");
- Element root= XmlHelper.getDocumentRoot(stream);
- Element mbeanElement= getMBeanElement(root);
+ Element root = XmlHelper.getDocumentRoot(stream);
+ Element mbeanElement = getMBeanElement(root);
ParsedAttributes attributes = extractAttributes(mbeanElement);
// Special handling for the old separate property for
// eviction policy -- just cache it and use with the eviction XML
- String defaultEvictionClass = (String) attributes.stringAttribs.remove("EvictionPolicyClass");
+ String defaultEvictionClass = attributes.stringAttribs.remove("EvictionPolicyClass");
// Deal with rename of the old property that controlled MBean registration
- String keepStats = (String) attributes.stringAttribs.remove("UseMbean");
+ String keepStats = attributes.stringAttribs.remove("UseMbean");
if (keepStats != null && attributes.stringAttribs.get("ExposeManagementStatistics") == null)
{
attributes.stringAttribs.put("ExposeManagementStatistics", keepStats);
@@ -167,7 +124,7 @@
if (stackName.startsWith(JGROUPS_CHANNEL))
{
Element jgroupsStack = (Element) stack.getElementsByTagName("config").item(0);
- if(mode == CacheMode.REPL_ASYNC && !stackName.contains("-"))
+ if (mode == CacheMode.REPL_ASYNC && !stackName.contains("-"))
{
c.setClusterConfig(jgroupsStack);
c.setCacheMode(CacheMode.REPL_ASYNC);
1.10 +463 -445 JBossCache/src/org/jboss/cache/factories/XmlConfigurationParser.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: XmlConfigurationParser.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/factories/XmlConfigurationParser.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- XmlConfigurationParser.java 3 Jan 2007 20:41:36 -0000 1.9
+++ XmlConfigurationParser.java 4 Jan 2007 05:35:37 -0000 1.10
@@ -64,17 +64,17 @@
// loop through all elements in XML.
if (stream == null) throw new ConfigurationException("Input stream for configuration xml is null!");
- Element root= XmlHelper.getDocumentRoot(stream);
- Element mbeanElement=getMBeanElement(root);
+ Element root = XmlHelper.getDocumentRoot(stream);
+ Element mbeanElement = getMBeanElement(root);
ParsedAttributes attributes = extractAttributes(mbeanElement);
// Special handling for the old separate property for
// eviction policy -- just cache it and use with the eviction XML
- String defaultEvictionClass = (String) attributes.stringAttribs.remove("EvictionPolicyClass");
+ String defaultEvictionClass = attributes.stringAttribs.remove("EvictionPolicyClass");
// Deal with rename of the old property that controlled MBean registration
- String keepStats = (String) attributes.stringAttribs.remove("UseMbean");
+ String keepStats = attributes.stringAttribs.remove("UseMbean");
if (keepStats != null && attributes.stringAttribs.get("ExposeManagementStatistics") == null)
{
attributes.stringAttribs.put("ExposeManagementStatistics", keepStats);
@@ -96,16 +96,16 @@
protected Element getMBeanElement(Element root)
{
// This is following JBoss convention.
- NodeList list=root.getElementsByTagName(XmlHelper.ROOT);
- if(list == null) throw new ConfigurationException("Can't find " + XmlHelper.ROOT + " tag");
+ NodeList list = root.getElementsByTagName(XmlHelper.ROOT);
+ if (list == null) throw new ConfigurationException("Can't find " + XmlHelper.ROOT + " tag");
- if(list.getLength() > 1) throw new ConfigurationException("Has multiple " + XmlHelper.ROOT + " tag");
+ if (list.getLength() > 1) throw new ConfigurationException("Has multiple " + XmlHelper.ROOT + " tag");
- Node node=list.item(0);
- Element element=null;
- if(node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE)
+ Node node = list.item(0);
+ Element element = null;
+ if (node.getNodeType() == org.w3c.dom.Node.ELEMENT_NODE)
{
- element=(Element)node;
+ element = (Element) node;
}
else
{
@@ -132,12 +132,12 @@
if (isXmlAttribs)
{
method = objectClass.getMethod(setter, new Class[]{Element.class});
- method.invoke(target, new Object[]{ entry.getValue() });
+ method.invoke(target, new Object[]{entry.getValue()});
}
else
{
method = objectClass.getMethod(setter, new Class[]{String.class});
- method.invoke(target, new Object[]{ entry.getValue() });
+ method.invoke(target, new Object[]{entry.getValue()});
}
continue;
@@ -158,11 +158,17 @@
if (setter.equals(m.getName()))
{
Class paramTypes[] = m.getParameterTypes();
- if (paramTypes.length != 1) throw new ConfigurationException("Setter " + setter + " does not contain the expected number of params. Has " + paramTypes.length + " instead of just 1.");
+ if (paramTypes.length != 1)
+ {
+ throw new ConfigurationException("Setter " + setter + " does not contain the expected number of params. Has " + paramTypes.length + " instead of just 1.");
+ }
Class parameterType = paramTypes[0];
- PropertyEditor editor= PropertyEditorManager.findEditor(parameterType);
- if(editor == null) throw new ConfigurationException("Couldn't find a property editor for parameter type " + parameterType);
+ PropertyEditor editor = PropertyEditorManager.findEditor(parameterType);
+ if (editor == null)
+ {
+ throw new ConfigurationException("Couldn't find a property editor for parameter type " + parameterType);
+ }
editor.setAsText((String) attribs.get(propName));
@@ -184,7 +190,7 @@
protected void setXmlValues(Configuration conf, Map<String, Element> attribs, String defaultEvictionClass)
{
- for (Iterator it = attribs.entrySet().iterator(); it.hasNext(); )
+ for (Iterator it = attribs.entrySet().iterator(); it.hasNext();)
{
Map.Entry entry = (Entry) it.next();
String propname = (String) entry.getKey();
@@ -238,11 +244,15 @@
finally
{
if (log.isDebugEnabled())
+ {
log.debug("Using buddy communication timeout of " + brc.getBuddyCommunicationTimeout() + " millis");
}
+ }
String buddyPoolName = XmlHelper.readStringContents(element, "buddyPoolName");
if ("".equals(buddyPoolName))
+ {
buddyPoolName = null;
+ }
brc.setBuddyPoolName(buddyPoolName);
@@ -250,7 +260,9 @@
String buddyLocatorClass = XmlHelper.readStringContents(element, "buddyLocatorClass");
if (buddyLocatorClass == null || buddyLocatorClass.length() == 0)
+ {
buddyLocatorClass = NextMemberBuddyLocator.class.getName();
+ }
Properties props = null;
try
{
@@ -334,7 +346,9 @@
}
if (wakeupIntervalSeconds <= 0)
+ {
wakeupIntervalSeconds = EvictionConfig.WAKEUP_DEFAULT;
+ }
ec.setWakeupIntervalSeconds(wakeupIntervalSeconds);
@@ -362,7 +376,9 @@
{
org.w3c.dom.Node node = list.item(i);
if (node.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE)
+ {
continue;
+ }
try
{
regionConfigs.add(parseEvictionRegionConfig((Element) node, defaultEvictionClass, eventQueueSize));
@@ -431,7 +447,7 @@
EvictionPolicyConfig epc = null;
try
{
- epc = (EvictionPolicyConfig) policy.getEvictionConfigurationClass().newInstance();
+ epc = policy.getEvictionConfigurationClass().newInstance();
}
catch (RuntimeException e)
{
@@ -515,23 +531,23 @@
{
Map<String, String> stringAttribs = new HashMap<String, String>();
Map<String, Element> xmlAttribs = new HashMap<String, Element>();
- NodeList list=source.getElementsByTagName(XmlHelper.ATTR);
+ NodeList list = source.getElementsByTagName(XmlHelper.ATTR);
if (log.isDebugEnabled()) log.debug("Attribute size: " + list.getLength());
// loop through attributes
- for(int loop=0; loop < list.getLength(); loop++)
+ for (int loop = 0; loop < list.getLength(); loop++)
{
- Node node=list.item(loop);
- if(node.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE) continue;
+ Node node = list.item(loop);
+ if (node.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE) continue;
// for each element (attribute) ...
- Element element=(Element)node;
+ Element element = (Element) node;
String name = element.getAttribute(XmlHelper.NAME);
String valueStr = XmlHelper.getElementContent(element, true);
- Element valueXml=null;
- if(valueStr.length() == 0)
+ Element valueXml = null;
+ if (valueStr.length() == 0)
{
// This may be an XML element ...
valueXml = XmlHelper.getConfigSubElement(element);
@@ -553,8 +569,10 @@
{
sb.append(propName.substring(0, 1).toUpperCase());
if (propName.length() > 1)
+ {
sb.append(propName.substring(1));
}
+ }
return sb.toString();
}
More information about the jboss-cvs-commits
mailing list