[infinispan-commits] Infinispan SVN: r315 - in trunk: core/src/test/java/org/infinispan/config and 1 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Sun May 17 22:27:53 EDT 2009
Author: mircea.markus
Date: 2009-05-17 22:27:52 -0400 (Sun, 17 May 2009)
New Revision: 315
Added:
trunk/core/src/test/java/org/infinispan/config/ConfigFilesConvertor.java
trunk/src/main/resources/xslt/indent.xslt
trunk/src/main/resources/xslt/jgroupsFileGen.xslt
Modified:
trunk/core/src/main/java/org/infinispan/remoting/transport/jgroups/JGroupsTransport.java
trunk/src/main/resources/xslt/jbc3x2infinispan4x.xslt
Log:
better support for transforming migrating jgroups config;
added script to indent the result of the transformation
Modified: trunk/core/src/main/java/org/infinispan/remoting/transport/jgroups/JGroupsTransport.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/remoting/transport/jgroups/JGroupsTransport.java 2009-05-15 10:26:03 UTC (rev 314)
+++ trunk/core/src/main/java/org/infinispan/remoting/transport/jgroups/JGroupsTransport.java 2009-05-18 02:27:52 UTC (rev 315)
@@ -68,7 +68,7 @@
static final Log log = LogFactory.getLog(JGroupsTransport.class);
static final boolean trace = log.isTraceEnabled();
GlobalConfiguration c;
- Properties p;
+ Properties props;
InboundInvocationHandler inboundInvocationHandler;
Marshaller marshaller;
ExecutorService asyncExecutor;
@@ -91,7 +91,7 @@
}
public void start() {
- p = c.getTransportProperties();
+ props = c.getTransportProperties();
distributedSyncTimeout = c.getDistributedSyncTimeout();
log.info("Starting JGroups Channel");
@@ -149,9 +149,9 @@
// in order of preference - we first look for an external JGroups file, then a set of XML properties, and
// finally the legacy JGroups String properties.
String cfg;
- if (p != null) {
- if (p.containsKey(CONFIGURATION_FILE)) {
- cfg = p.getProperty(CONFIGURATION_FILE);
+ if (props != null) {
+ if (props.containsKey(CONFIGURATION_FILE)) {
+ cfg = props.getProperty(CONFIGURATION_FILE);
try {
channel = new JChannel(new FileLookup().lookupFileLocation(cfg));
} catch (Exception e) {
@@ -160,8 +160,8 @@
}
}
- if (p.containsKey(CONFIGURATION_XML)) {
- cfg = p.getProperty(CONFIGURATION_XML);
+ if (props.containsKey(CONFIGURATION_XML)) {
+ cfg = props.getProperty(CONFIGURATION_XML);
try {
channel = new JChannel(XmlConfigHelper.stringToElement(cfg));
} catch (Exception e) {
@@ -170,8 +170,8 @@
}
}
- if (p.containsKey(CONFIGURATION_STRING)) {
- cfg = p.getProperty(CONFIGURATION_STRING);
+ if (props.containsKey(CONFIGURATION_STRING)) {
+ cfg = props.getProperty(CONFIGURATION_STRING);
try {
channel = new JChannel(cfg);
} catch (Exception e) {
@@ -182,7 +182,7 @@
}
if (channel == null) {
- log.info("Unable to use any JGroups configuration mechanisms provided in properties {0}. Using default JGroups configuration!", p);
+ log.info("Unable to use any JGroups configuration mechanisms provided in properties {0}. Using default JGroups configuration!", props);
try {
channel = new JChannel(new FileLookup().lookupFileLocation(DEFAULT_JGROUPS_CONFIGURATION_FILE));
} catch (ChannelException e) {
Added: trunk/core/src/test/java/org/infinispan/config/ConfigFilesConvertor.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/config/ConfigFilesConvertor.java (rev 0)
+++ trunk/core/src/test/java/org/infinispan/config/ConfigFilesConvertor.java 2009-05-18 02:27:52 UTC (rev 315)
@@ -0,0 +1,155 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2000 - 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.infinispan.config;
+
+import org.infinispan.util.FileLookup;
+import org.w3c.dom.Document;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.ByteArrayInputStream;
+
+/**
+ * Class used for converting different configuration files to INFINISPAN format.
+ *
+ * @author Mircea.Markus at jboss.com
+ * @since 4.0
+ */
+public class ConfigFilesConvertor {
+
+ public void parse(InputStream is, OutputStream os, String xsltFile) throws Exception {
+ InputStream xsltInStream = new FileLookup().lookupFile(xsltFile);
+ if (xsltInStream == null) {
+ throw new IllegalStateException("Cold not find xslt file! : " + xsltFile);
+ }
+
+ Document document = getInputDocument(is);
+
+ // Use a Transformer for output
+ Transformer transformer = getTransformer(xsltInStream);
+
+ DOMSource source = new DOMSource(document);
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ StreamResult result = new StreamResult(byteArrayOutputStream);
+ transformer.transform(source, result);
+
+ InputStream indentation = new FileLookup().lookupFile("C:\\jboss\\ifspn\\zzzz_trunk_pristine\\src\\main\\resources\\xslt\\indent.xslt");
+ // Use a Transformer for output
+ transformer = getTransformer(indentation);
+ StreamResult finalResult = new StreamResult(os);
+ StreamSource rawResult = new StreamSource(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
+ transformer.transform(rawResult, finalResult);
+ xsltInStream.close();
+ }
+
+ /**
+ * Writes to the <b>os</b> the 3.x configuration file resulted by transforming the 2.x configuration file passed in
+ * as <b>inputFile</b>. Transformation is performed according to the <b>xsltFile</b>. Both <b>inputFile</b> and he
+ * xslt file are looked up using a {@link org.jboss.cache.util.FileLookup}
+ */
+ public void parse(String inputFile, OutputStream os, String xsltFile) throws Exception {
+ InputStream stream = new FileLookup().lookupFile(inputFile);
+ try {
+ parse(stream, os, xsltFile);
+ }
+ finally {
+ stream.close();
+ }
+ }
+
+ /**
+ * usage : java org.jboss.cache.config.parsing.ConfigFilesConvertor -Dsource=config-2.x.xml
+ * -Ddestination=config-3.x.xnl
+ */
+ public static void main(String[] argv) throws Exception {
+ String sourceName = System.getProperty("source");
+ if (sourceName == null) {
+ System.err.println("Missing property 'source'.");
+ System.exit(1);
+ }
+ String destinationName = System.getProperty("destination");
+ if (destinationName == null) {
+ System.err.println("Missing property 'destination'.");
+ System.exit(1);
+ }
+ File oldConfig = new File(sourceName);
+ if (!oldConfig.exists()) {
+ System.err.println("File specified as input ('" + sourceName + ") does not exist.");
+ System.exit(1);
+ }
+ ConfigFilesConvertor convertor = new ConfigFilesConvertor();
+ FileInputStream is = new FileInputStream(oldConfig);
+ File destination = new File(destinationName);
+ if (!destination.exists()) destination.createNewFile();
+ FileOutputStream fos = new FileOutputStream(destinationName);
+ convertor.parse(is, fos, "C:\\jboss\\ifspn\\zzzz_trunk_pristine\\src\\main\\resources\\xslt\\jbc3x2infinispan4x.xslt");
+ fos.close();
+ is.close();
+
+ String jgroupsConfig = destination.getParent() + File.separator + "jgroupsConfig.xml";
+ File jgroupsConfigFile = new File(jgroupsConfig);
+ if (jgroupsConfigFile.exists()) jgroupsConfigFile.delete();
+ jgroupsConfigFile.createNewFile();
+ is = new FileInputStream(oldConfig);
+ fos = new FileOutputStream(jgroupsConfigFile);
+ convertor = new ConfigFilesConvertor();
+ convertor.parse(is, fos, "C:\\jboss\\ifspn\\zzzz_trunk_pristine\\src\\main\\resources\\xslt\\jgroupsFileGen.xslt");
+ is.close();
+ fos.close();
+
+ System.out.println("jgroupsConfigFile.length() = " + jgroupsConfigFile.length());
+ //now this means that the generated file is basically empty, so delete ie
+ if (jgroupsConfigFile.length() < 5) {
+ jgroupsConfigFile.delete();
+ }
+ System.out.println("---");
+ System.out.println("New configuration file [" + destinationName + "] successfully created.");
+ System.out.println("---");
+ }
+
+ private Transformer getTransformer(InputStream xsltInStream) throws TransformerConfigurationException {
+ TransformerFactory tFactory = TransformerFactory.newInstance();
+ StreamSource stylesource = new StreamSource(xsltInStream);
+ return tFactory.newTransformer(stylesource);
+ }
+
+ private Document getInputDocument(InputStream is) throws ParserConfigurationException, SAXException, IOException {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder.parse(is);
+ }
+}
\ No newline at end of file
Property changes on: trunk/core/src/test/java/org/infinispan/config/ConfigFilesConvertor.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: trunk/src/main/resources/xslt/indent.xslt
===================================================================
--- trunk/src/main/resources/xslt/indent.xslt (rev 0)
+++ trunk/src/main/resources/xslt/indent.xslt 2009-05-18 02:27:52 UTC (rev 315)
@@ -0,0 +1,27 @@
+ <xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+ <xsl:output method="xml"/>
+ <xsl:param name="indent-increment" select="' '" />
+
+ <xsl:template match="*">
+ <xsl:param name="indent" select="'
'"/>
+
+ <xsl:value-of select="$indent"/>
+ <xsl:copy>
+ <xsl:copy-of select="@*" />
+ <xsl:apply-templates>
+ <xsl:with-param name="indent"
+ select="concat($indent, $indent-increment)"/>
+ </xsl:apply-templates>
+ <xsl:if test="*">
+ <xsl:value-of select="$indent"/>
+ </xsl:if>
+ </xsl:copy>
+ </xsl:template>
+
+ <xsl:template match="comment()|processing-instruction()">
+ <xsl:copy />
+ </xsl:template>
+ <xsl:template match="text()[normalize-space(.)='']"/>
+
+</xsl:stylesheet>
\ No newline at end of file
Modified: trunk/src/main/resources/xslt/jbc3x2infinispan4x.xslt
===================================================================
--- trunk/src/main/resources/xslt/jbc3x2infinispan4x.xslt 2009-05-15 10:26:03 UTC (rev 314)
+++ trunk/src/main/resources/xslt/jbc3x2infinispan4x.xslt 2009-05-18 02:27:52 UTC (rev 315)
@@ -1,10 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
-<xsl:stylesheet xmlns="urn:infinispan:config:4.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" version="1.0" encoding="UTF-8" omit-xml-declaration="no"/>
+
<xsl:template match="/jbosscache">
+
<xsl:element name="infinispan">
-
<xsl:element name="global">
<xsl:element name="asyncListenerExecutor">
<xsl:attribute name="factory">org.infinispan.executors.DefaultExecutorFactory</xsl:attribute>
@@ -27,7 +28,7 @@
<property name="threadNamePrefix" value="AsyncListenerThread"/>
</xsl:element>
- <xsl:element name="asyncSerializationExecutor">
+ <xsl:element name="asyncTransportExecutor">
<xsl:attribute name="factory">org.infinispan.executors.DefaultExecutorFactory</xsl:attribute>
<xsl:if test="clustering/async[@serializationExecutorPoolSize]">
<xsl:element name="property">
@@ -85,8 +86,16 @@
</xsl:attribute>
</xsl:element>
</xsl:if>
+ <xsl:if test="clustering/jgroupsConfig/*">
+ <xsl:element name="property">
+ <xsl:attribute name="name">configurationFile</xsl:attribute>
+ <xsl:attribute name="value">jgroupsConfig.xml</xsl:attribute>
+ </xsl:element>
+ </xsl:if>
+
</xsl:element>
+
<xsl:element name="serialization">
<xsl:attribute name="marshallerClass">org.infinispan.marshall.VersionAwareMarshaller</xsl:attribute>
<xsl:attribute name="version">1.0</xsl:attribute>
@@ -237,14 +246,11 @@
<xsl:value-of select="clustering/async/@replQueueMaxElements"/>
</xsl:attribute>
</xsl:if>
+ <xsl:if test="clustering/async[@serializationExecutorPoolSize > 1]">
+ <xsl:attribute name="asyncMarshalling">true</xsl:attribute>
+ </xsl:if>
</xsl:element>
</xsl:element>
-
- <xsl:if test="clustering/jgroupsConfig/*">
- <xsl:message terminate="no">WARNING!!! Use 'transport' element under 'global' config to set up
- transport!!! Existing JGroups config will be ignored!!
- </xsl:message>
- </xsl:if>
</xsl:if>
<xsl:if test="loaders">
@@ -298,7 +304,9 @@
<xsl:value-of select="singletonStore/@enabled"/>
</xsl:attribute>
<xsl:if test="singletonStore/properties">
- <xsl:message terminate="no">WARNING!!! Singleton store was changed and needs to be configured manually!!!!</xsl:message>
+ <xsl:message terminate="no">WARNING!!! Singleton store was changed and needs to be
+ configured manually!!!!
+ </xsl:message>
</xsl:if>
</xsl:if>
</xsl:element>
@@ -339,16 +347,18 @@
<xsl:choose>
<xsl:when test="@algorithmClass">
<xsl:attribute name="strategy">
- <xsl:value-of select="substring-before(substring-after(@algorithmClass,'org.jboss.cache.eviction.'),'Algorithm')"/>
+ <xsl:value-of
+ select="substring-before(substring-after(@algorithmClass,'org.jboss.cache.eviction.'),'Algorithm')"/>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="strategy">
- <xsl:value-of select="substring-before(substring-after(/jbosscache/eviction/default/@algorithmClass,'org.jboss.cache.eviction.'),'Algorithm')"/>
+ <xsl:value-of
+ select="substring-before(substring-after(/jbosscache/eviction/default/@algorithmClass,'org.jboss.cache.eviction.'),'Algorithm')"/>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
-
+
</xsl:element>
</xsl:element>
Added: trunk/src/main/resources/xslt/jgroupsFileGen.xslt
===================================================================
--- trunk/src/main/resources/xslt/jgroupsFileGen.xslt (rev 0)
+++ trunk/src/main/resources/xslt/jgroupsFileGen.xslt 2009-05-18 02:27:52 UTC (rev 315)
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+
+ <xsl:output method="xml" indent="yes" version="1.0" encoding="UTF-8" omit-xml-declaration="yes"
+ xmlns="urn:jboss:jbosscache-core:config:3.0"/>
+
+ <xsl:strip-space elements="*"/>
+
+ <xsl:template match="/jbosscache/clustering/jgroupsConfig">
+ <xsl:element name="config">
+ <xsl:apply-templates mode="copy-no-ns" select="/jbosscache/clustering/jgroupsConfig/*"/>
+ </xsl:element>
+
+ </xsl:template>
+
+ <xsl:template mode="copy-no-ns" match="*">
+ <xsl:element name="{name(.)}" namespace="{namespace-uri(.)}">
+ <xsl:copy-of select="@*"/>
+ <xsl:apply-templates mode="copy-no-ns"/>
+ </xsl:element>
+ </xsl:template>
+
+
+ <xsl:template match="/jbosscache/loaders"/>
+</xsl:stylesheet>
More information about the infinispan-commits
mailing list