You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by ru...@apache.org on 2007/09/24 07:39:09 UTC
svn commit: r578664 [1/2] - in
/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse:
./ config/ config/xml/ startup/ startup/quartz/
Author: ruwan
Date: Sun Sep 23 22:39:08 2007
New Revision: 578664
URL: http://svn.apache.org/viewvc?rev=578664&view=rev
Log:
Refactoring startup configuration and serialization and adding comments to startup code
Added:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/AbstractStartup.java
Modified:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ManagedLifecycle.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Startup.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/Entry.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractMediatorSerializer.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ConfigurationFactory.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ConfigurationFactoryAndSerializerFinder.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ConfigurationSerializer.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupFactory.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupFinder.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupSerializer.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigurationBuilder.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigurationSerializer.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartz.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzFactory.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzSerializer.java
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ManagedLifecycle.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ManagedLifecycle.java?rev=578664&r1=578663&r2=578664&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ManagedLifecycle.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/ManagedLifecycle.java Sun Sep 23 22:39:08 2007
@@ -1,8 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
package org.apache.synapse;
import org.apache.synapse.core.SynapseEnvironment;
+/**
+ * This interface defines all the manged statefull parts of Synapse
+ * including the configuration itself
+ */
public interface ManagedLifecycle {
- public void init(SynapseEnvironment se);
- public void destroy();
+
+ /**
+ * This method should implement the initialization of the
+ * implemented parts of the configuraiton
+ *
+ * @param se SynapseEnvironment to be used for initialization
+ */
+ public void init(SynapseEnvironment se);
+
+ /**
+ * This method should implement the destroying of the
+ * implemented parts of the configuration
+ */
+ public void destroy();
}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Startup.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Startup.java?rev=578664&r1=578663&r2=578664&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Startup.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Startup.java Sun Sep 23 22:39:08 2007
@@ -24,12 +24,26 @@
/**
* This startup interface will be instatiated to create startup tasks
*/
-public interface Startup extends ManagedLifecycle{
+public interface Startup extends ManagedLifecycle {
/**
* This will return the configuration tag QName of the implemented startup
- *
+ *
* @return QName representing the configuraiton element for the startup
*/
- public QName getTagQName();
+ public abstract QName getTagQName();
+
+ /**
+ * This will return the id of the startup
+ *
+ * @return String representing the id
+ */
+ public String getId();
+
+ /**
+ * This will set the id of a Startup
+ *
+ * @param id String id to be set to the startup
+ */
+ public void setId(String id);
}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/Entry.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/Entry.java?rev=578664&r1=578663&r2=578664&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/Entry.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/Entry.java Sun Sep 23 22:39:08 2007
@@ -156,6 +156,12 @@
return value != null;
}
+ public void clearCache() {
+ if (this.isDynamic()) {
+ value = null;
+ }
+ }
+
public boolean isDynamic() {
return type == REMOTE_ENTRY;
}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java?rev=578664&r1=578663&r2=578664&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java Sun Sep 23 22:39:08 2007
@@ -23,10 +23,7 @@
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.SynapseConstants;
-import org.apache.synapse.ManagedLifecycle;
-import org.apache.synapse.Mediator;
-import org.apache.synapse.SynapseException;
+import org.apache.synapse.*;
import org.apache.synapse.config.xml.MediatorFactoryFinder;
import org.apache.synapse.config.xml.endpoints.XMLToEndpointMapper;
import org.apache.synapse.core.SynapseEnvironment;
@@ -45,8 +42,7 @@
*/
public class SynapseConfiguration implements ManagedLifecycle {
- private static final Log log = LogFactory
- .getLog(SynapseConfiguration.class);
+ private static final Log log = LogFactory.getLog(SynapseConfiguration.class);
/**
* The remote registry made available to the Synapse configuration. Only one
@@ -54,16 +50,22 @@
*/
Registry registry = null;
- private QName defaultQName = null;
+ /**
+ * This holds the default QName of the configuraiton
+ */
+ private QName defaultQName = null;
- /** Holds Proxy services defined through Synapse */
+ /**
+ * Holds Proxy services defined through Synapse
+ */
private Map proxyServices = new HashMap();
- private List startup = null; // this will be a list of ManagedLifecycle
-
- // objects
+ /**
+ * This holds a Map of ManagedLifecycle objects
+ */
+ private Map startups = new HashMap();
- /**
+ /**
* The local registry is a simple HashMap and provides the ability to
* override definitions of a remote registry for entries defined locally
* with the same key
@@ -220,7 +222,28 @@
}
}
- /**
+ /**
+ * Gives the set of remote entries that are cached in localRegistry as mapping of entry key
+ * to the Entry definition
+ *
+ * @return Map of locally cached entries
+ */
+ public Map getCachedEntries() {
+ Map cachedEntries = new HashMap();
+ for (Iterator itr = localRegistry.values().iterator(); itr.hasNext();) {
+ Object o = itr.next();
+ if (o != null && o instanceof Entry) {
+ Entry entry = (Entry) o;
+ if (entry.isDynamic() && entry.isCached()) {
+ cachedEntries.put(entry.getKey(), entry);
+ }
+ }
+ }
+
+ return cachedEntries;
+ }
+
+ /**
* Returns the map of defined entries in the configuraiton excluding the
* fetched entries from remote registry
*
@@ -304,7 +327,35 @@
localRegistry.remove(key);
}
- /**
+ /**
+ * Clears the cache of the remote entry with the key specified
+ *
+ * @param key - String key of the entry
+ */
+ public void clearCachedEntry(String key) {
+ Entry entry = getEntryDefinition(key);
+ if (entry.isDynamic() && entry.isCached()) {
+ entry.clearCache();
+ }
+ }
+
+ /**
+ * Clears the cache of all the remote entries which has been
+ * cached in the configuration
+ */
+ public void clearCache() {
+ for (Iterator itr = localRegistry.values().iterator(); itr.hasNext();) {
+ Object o = itr.next();
+ if (o != null && o instanceof Entry) {
+ Entry entry = (Entry) o;
+ if (entry.isDynamic() && entry.isCached()) {
+ entry.clearCache();
+ }
+ }
+ }
+ }
+
+ /**
* Define a named endpoint with the given key
*
* @param key
@@ -513,37 +564,79 @@
this.pathToConfigFile = pathToConfigFile;
}
- private void handleException(String msg) {
- log.error(msg);
- throw new SynapseException(msg);
- }
-
- public void setDefaultQName(QName defaultQName) {
+ /**
+ * Set the default QName of the Synapse Configuration
+ *
+ * @param defaultQName
+ * QName specifying the default QName of the configuration
+ */
+ public void setDefaultQName(QName defaultQName) {
this.defaultQName = defaultQName;
}
- public QName getDefaultQName() {
+ /**
+ * Get the default QName of the configuraiton
+ *
+ * @return default QName of the configuration
+ */
+ public QName getDefaultQName() {
return defaultQName;
}
- public void setStartup(List l) {
- startup = l;
- }
-
- public List getStartup() {
- return startup;
- }
-
+ /**
+ * Get the timer object for the Synapse Configuration
+ *
+ * @return synapseTimer timer object of the configuration
+ */
public Timer getSynapseTimer() {
return synapseTimer;
}
+ /**
+ * Get the startup collection in the configuration
+ *
+ * @return collection of startup objects registered
+ */
+ public Collection getStartups() {
+ return startups.values();
+ }
+
+ /**
+ * Get the Startup with the specified id
+ *
+ * @param id
+ * String id of the startup to be retrieved
+ * @return Startup object with the specified id or null
+ */
+ public Startup getStartup(String id) {
+ return (Startup) startups.get(id);
+ }
+
+ /**
+ * Add a startup to the startups map in the configuration
+ *
+ * @param startup
+ * Startup object to be added
+ */
+ public void addStartup(Startup startup) {
+ startups.put(startup.getId(), startup);
+ }
+
+ /**
+ * This method will be called on the soft shutdown or destroying the configuration
+ * and will destroy all the statefull managed parts of the configuration
+ */
public void destroy() {
+
if (log.isDebugEnabled()) {
- log.debug("destroy");
+ log.debug("Destroying the Synapse Configuration");
}
+
+ // clear the timer tasks of Synapse
synapseTimer.cancel();
synapseTimer = null;
+
+ // stop and shutdown all the proxy services
for (Iterator it = getProxyServices().iterator(); it.hasNext();) {
Object o = it.next();
if (o instanceof ProxyService) {
@@ -557,6 +650,7 @@
}
}
+ // destroy the managed mediators
Map sequences = getDefinedSequences();
for (Iterator it = sequences.entrySet().iterator(); it.hasNext();) {
Object o = it.next();
@@ -565,8 +659,10 @@
m.destroy();
}
}
- if (startup != null) {
- for (Iterator it = startup.iterator(); it.hasNext();) {
+
+ // destroy the startups
+ if (startups != null) {
+ for (Iterator it = startups.values().iterator(); it.hasNext();) {
Object o = it.next();
if (o instanceof ManagedLifecycle) {
ManagedLifecycle m = (ManagedLifecycle) o;
@@ -576,10 +672,20 @@
}
}
+ /**
+ * This method will be called in the startup of Synapse or in an initiation
+ * and will initialize all the managed parts of the Synapse Configuration
+ *
+ * @param se
+ * SynapseEnvironment specifying the env to be initialized
+ */
public void init(SynapseEnvironment se) {
+
if (log.isDebugEnabled()) {
- log.debug("init");
+ log.debug("Initializing the Synapse Configuration");
}
+
+ // initialize all the proxy services
for (Iterator it = getProxyServices().iterator(); it.hasNext();) {
Object o = it.next();
if (o instanceof ProxyService) {
@@ -593,6 +699,7 @@
}
}
+ // initialize managed mediators
Map sequences = getDefinedSequences();
for (Iterator it = sequences.values().iterator(); it.hasNext();) {
Object o = it.next();
@@ -601,8 +708,10 @@
m.init(se);
}
}
- if (startup != null) {
- for (Iterator it = startup.iterator(); it.hasNext();) {
+
+ // initialize the startups
+ if (startups != null) {
+ for (Iterator it = startups.values().iterator(); it.hasNext();) {
Object o = it.next();
if (o instanceof ManagedLifecycle) {
ManagedLifecycle m = (ManagedLifecycle) o;
@@ -611,4 +720,9 @@
}
}
}
+
+ private void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractMediatorSerializer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractMediatorSerializer.java?rev=578664&r1=578663&r2=578664&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractMediatorSerializer.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractMediatorSerializer.java Sun Sep 23 22:39:08 2007
@@ -36,8 +36,10 @@
public abstract class AbstractMediatorSerializer implements MediatorSerializer {
protected static final OMFactory fac = OMAbstractFactory.getOMFactory();
- protected static final OMNamespace synNS = fac.createOMNamespace(XMLConfigConstants.SYNAPSE_NAMESPACE, "syn");
- protected static final OMNamespace nullNS = fac.createOMNamespace(XMLConfigConstants.NULL_NAMESPACE, "");
+ protected static final OMNamespace synNS
+ = fac.createOMNamespace(XMLConfigConstants.SYNAPSE_NAMESPACE, "syn");
+ protected static final OMNamespace nullNS
+ = fac.createOMNamespace(XMLConfigConstants.NULL_NAMESPACE, "");
private static final Log log = LogFactory.getLog(AbstractMediatorSerializer.class);
/**
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ConfigurationFactory.java?rev=578664&r1=578663&r2=578664&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ConfigurationFactory.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ConfigurationFactory.java Sun Sep 23 22:39:08 2007
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
package org.apache.synapse.config.xml;
import javax.xml.namespace.QName;
@@ -5,10 +24,32 @@
import org.apache.axiom.om.OMElement;
import org.apache.synapse.config.SynapseConfiguration;
+/**
+ * This interface defines the configuration factories of Synapse
+ */
public interface ConfigurationFactory {
- QName getTagQName();
- SynapseConfiguration getConfiguration(OMElement element);
- Class getSerializerClass();
+ /**
+ * Get the tag QName of the element piece that will be
+ * build using the factory
+ *
+ * @return QName describing the element
+ */
+ QName getTagQName();
+
+ /**
+ * Get (basically builds) the configuration of Synapse built up from
+ * an OMElement using the defined factory
+ *
+ * @param element OMElement describing the configuration to be build
+ * @return SynapseConfiguration build using the relevant factory
+ */
+ SynapseConfiguration getConfiguration(OMElement element);
+ /**
+ * Get the class which serializes the specified element
+ *
+ * @return Class defining the Serializer
+ */
+ Class getSerializerClass();
}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ConfigurationFactoryAndSerializerFinder.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ConfigurationFactoryAndSerializerFinder.java?rev=578664&r1=578663&r2=578664&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ConfigurationFactoryAndSerializerFinder.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ConfigurationFactoryAndSerializerFinder.java Sun Sep 23 22:39:08 2007
@@ -17,7 +17,6 @@
* under the License.
*/
-
package org.apache.synapse.config.xml;
import org.apache.axiom.om.OMElement;
@@ -38,33 +37,29 @@
import java.util.Map;
/**
- *
- *
* This class is based on J2SE Service Provider model
* http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider
- *
+ * <p/>
* It deals with both the problem of turning an XML into a Synapse config and vice-versa
*/
+public class ConfigurationFactoryAndSerializerFinder implements XMLToObjectMapper {
-/**
- * @author paul
- *
- */
-public class ConfigurationFactoryAndSerializerFinder implements XMLToObjectMapper {
-
- private static final Log log = LogFactory.getLog(ConfigurationFactoryAndSerializerFinder.class);
+ private static final Log log = LogFactory
+ .getLog(ConfigurationFactoryAndSerializerFinder.class);
- private static final Class[] configurationFactories = {
- SynapseXMLConfigurationFactory.class,
+ private static final Class[] configurationFactories = {
+ SynapseXMLConfigurationFactory.class,
};
-
+
private static ConfigurationFactoryAndSerializerFinder instance = null;
/**
* A map of mediator QNames to implementation class
*/
- private static Map factoryMap = new HashMap(), serializerMap = new HashMap();
+ private static Map factoryMap = new HashMap();
+
+ private static Map serializerMap = new HashMap();
public static synchronized ConfigurationFactoryAndSerializerFinder getInstance() {
if (instance == null) {
@@ -82,19 +77,19 @@
}
private ConfigurationFactoryAndSerializerFinder() {
-
+
factoryMap = new HashMap();
for (int i = 0; i < configurationFactories.length; i++) {
- Class c = configurationFactories[i];
- try {
+ Class c = configurationFactories[i];
+ try {
ConfigurationFactory fac = (ConfigurationFactory) c.newInstance();
factoryMap.put(fac.getTagQName(), c);
serializerMap.put(fac.getTagQName(), fac.getSerializerClass());
} catch (Exception e) {
- throw new SynapseException("Error instantiating " + c.getName(), e);
- }
- }
+ throw new SynapseException("Error instantiating " + c.getName(), e);
+ }
+ }
// now iterate through the available pluggable mediator factories
registerExtensions();
}
@@ -111,14 +106,12 @@
/**
* Register pluggable mediator factories from the classpath
- *
+ * <p/>
* This looks for JAR files containing a META-INF/services that adheres to the following
* http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider
*/
private void registerExtensions() {
- //log.debug("Registering mediator extensions found in the classpath : " + System.getResource("java.class.path"));
-
// register MediatorFactory extensions
Iterator it = Service.providers(ConfigurationFactory.class);
while (it.hasNext()) {
@@ -133,14 +126,14 @@
}
/**
- * This method returns a Processor given an OMElement. This will be used
- * recursively by the elements which contain processor elements themselves
- * (e.g. rules)
- *
- * @param element
+ * This method returns a Processor given an OMElement. This will be used
+ * recursively by the elements which contain processor elements themselves
+ * (e.g. rules)
+ *
+ * @param element
* @return Processor
- */
- public SynapseConfiguration getConfiguration(OMElement element) {
+ */
+ public SynapseConfiguration getConfiguration(OMElement element) {
String localName = element.getLocalName();
QName qName = null;
@@ -154,17 +147,17 @@
}
Class cls = (Class) factoryMap.get(qName);
-
if (cls == null) {
- String msg = "Unknown Configuration type referenced by configuration element : " + qName;
+ String msg = "Unknown Configuration type " +
+ "referenced by configuration element : " + qName;
log.error(msg);
throw new SynapseException(msg);
}
try {
- ConfigurationFactory cf = (ConfigurationFactory) cls.newInstance();
- return cf.getConfiguration(element);
+ ConfigurationFactory cf = (ConfigurationFactory) cls.newInstance();
+ return cf.getConfiguration(element);
} catch (InstantiationException e) {
String msg = "Error initializing configuration factory : " + cls;
@@ -175,61 +168,77 @@
String msg = "Error initializing configuration factory : " + cls;
log.error(msg);
throw new SynapseException(msg, e);
- }
- }
+ }
+ }
+
+ /**
+ * @param synCfg
+ * @return
+ */
+ public static OMElement serializeConfiguration(SynapseConfiguration synCfg) {
+ if (synCfg.getDefaultQName() == null) {
+ return serializeConfiguration(synCfg, XMLConfigConstants.DEFINITIONS_ELT);
+ } else {
+ return serializeConfiguration(synCfg, synCfg.getDefaultQName());
+ }
+ }
- public static void serializeConfiguration(SynapseConfiguration synCfg, OutputStream outputStream) throws XMLStreamException {
- if (synCfg.getDefaultQName()==null) {
- serializeConfiguration(synCfg, XMLConfigConstants.DEFINITIONS_ELT, outputStream);
- }
- else {
- serializeConfiguration(synCfg, synCfg.getDefaultQName(), outputStream);
- }
- }
-
- /**
- * This method will serialize the config using the supplied QName (looking up the right class to do it)
- * @param synCfg
- * @param qName
- * @param outputStream
- * @throws XMLStreamException
- */
- public static void serializeConfiguration(SynapseConfiguration synCfg, QName qName,
- OutputStream outputStream) throws XMLStreamException {
-
- Class cls = (Class) serializerMap.get(qName);
- if (cls == null) {
- String msg = "Unknown Configuration type referenced by configuration element : " + qName;
- log.error(msg);
- throw new SynapseException(msg);
- }
-
- try {
- ConfigurationSerializer cs = (ConfigurationSerializer) cls.newInstance();
- cs.serializeConfiguration(synCfg, outputStream);
-
- } catch (InstantiationException e) {
- String msg = "Error initializing configuration factory : " + cls;
- log.error(msg);
- throw new SynapseException(msg, e);
-
- } catch (IllegalAccessException e) {
- String msg = "Error initializing configuration factory : " + cls;
- log.error(msg);
- throw new SynapseException(msg, e);
- }
- }
-
- /*
- This method exposes all the MediatorFactories and its Extensions
- */
+ /**
+ * This method will serialize the config using the supplied QName
+ * (looking up the right class to do it)
+ *
+ * @param synCfg
+ * @param qName
+ * @throws XMLStreamException
+ */
+ public static OMElement serializeConfiguration(SynapseConfiguration synCfg, QName qName) {
+
+ Class cls = (Class) serializerMap.get(qName);
+ if (cls == null) {
+ String msg = "Unknown Configuration type " +
+ "referenced by configuration element : " + qName;
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+ try {
+ ConfigurationSerializer cs = (ConfigurationSerializer) cls.newInstance();
+ return cs.serializeConfiguration(synCfg);
+
+ } catch (InstantiationException e) {
+ String msg = "Error initializing configuration factory : " + cls;
+ log.error(msg);
+ throw new SynapseException(msg, e);
+
+ } catch (IllegalAccessException e) {
+ String msg = "Error initializing configuration factory : " + cls;
+ log.error(msg);
+ throw new SynapseException(msg, e);
+ }
+ }
+
+ /**
+ * This method exposes all the ConfigurationFactories and its Extensions
+ *
+ * @return Map of factories
+ */
public Map getFactoryMap() {
return factoryMap;
}
/**
+ * This method exposes all the ConfigurationSerializer and its Extensions
+ *
+ * @return Map of serializers
+ */
+ public static Map getSerializerMap() {
+ return serializerMap;
+ }
+
+ /**
* Allow the mediator factory finder to act as an XMLToObjectMapper for Mediators
- * (i.e. Sequence Mediator) loaded dynamically from a Registry
+ * (i.e. Sequence Mediator) loaded dynamically from a Registry
+ *
* @param om
* @return
*/
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ConfigurationSerializer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ConfigurationSerializer.java?rev=578664&r1=578663&r2=578664&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ConfigurationSerializer.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/ConfigurationSerializer.java Sun Sep 23 22:39:08 2007
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
package org.apache.synapse.config.xml;
import java.io.OutputStream;
@@ -6,11 +25,26 @@
import javax.xml.stream.XMLStreamException;
import org.apache.synapse.config.SynapseConfiguration;
+import org.apache.axiom.om.OMElement;
+/**
+ * This interface defines the configuration serializers of Synapse
+ */
public interface ConfigurationSerializer {
- void serializeConfiguration(SynapseConfiguration synCfg, OutputStream outputStream) throws XMLStreamException;
-
- QName getTagQName();
+ /**
+ * Serializes the given configuraiton to an OMElement
+ *
+ * @param synCfg Configuration to be serialized
+ * @return OMElement describing the configuraiton
+ */
+ OMElement serializeConfiguration(SynapseConfiguration synCfg);
+
+ /**
+ * Get the tag QName of the element
+ *
+ * @return QName describing the element name
+ */
+ QName getTagQName();
}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupFactory.java?rev=578664&r1=578663&r2=578664&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupFactory.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupFactory.java Sun Sep 23 22:39:08 2007
@@ -1,14 +1,54 @@
-package org.apache.synapse.config.xml;
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.synapse.config.xml;
import javax.xml.namespace.QName;
import org.apache.axiom.om.OMElement;
import org.apache.synapse.Startup;
+/**
+ * Defines the factories which builds startups
+ */
public interface StartupFactory {
- public Startup createStartup(OMElement elem);
- public QName getTagQName();
- public Class getSerializerClass();
+
+ /**
+ * Create (build from OM) from the specified OMElement
+ *
+ * @param elem
+ * OMELement describing the Startup
+ * @return Startup build from the given element
+ */
+ public Startup createStartup(OMElement elem);
+
+ /**
+ * Get the tag QName of the element
+ *
+ * @return QName of the element
+ */
+ public QName getTagQName();
+
+ /**
+ * Get the Serializer class for this factory
+ *
+ * @return Class defining the serialization of the startup
+ */
+ public Class getSerializerClass();
}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupFinder.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupFinder.java?rev=578664&r1=578663&r2=578664&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupFinder.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupFinder.java Sun Sep 23 22:39:08 2007
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
package org.apache.synapse.config.xml;
import java.util.HashMap;
@@ -7,8 +26,7 @@
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.SynapseException;
@@ -18,188 +36,207 @@
import sun.misc.Service;
public class StartupFinder {
- private static final Log log = LogFactory
- .getLog(ConfigurationFactoryAndSerializerFinder.class);
-
- private static StartupFinder instance = null;
-
- /**
- * A map of mediator QNames to implementation class
- */
- private static Map factoryMap = new HashMap(),
- serializerMap = new HashMap();
-
- public static synchronized StartupFinder getInstance() {
- if (instance == null) {
- instance = new StartupFinder();
- }
- return instance;
- }
-
- /**
- * Force re initialization next time
- */
- public synchronized void reset() {
- factoryMap.clear();
- instance = null;
- }
-
- private static final Class[] builtins = { SimpleQuartzFactory.class };
-
- private StartupFinder() {
- // preregister any built in
- for (int i = 0; i < builtins.length; i++) {
- Class b = builtins[i];
- StartupFactory sf;
- try {
- sf = (StartupFactory) b.newInstance();
- } catch (Exception e) {
- throw new SynapseException("cannot instantiate " + b.getName(),
- e);
-
- }
- factoryMap.put(sf.getTagQName(), b);
- serializerMap.put(sf.getTagQName(), sf.getSerializerClass());
-
- }
-
- registerExtensions();
- }
-
- private void handleException(String msg) {
- log.error(msg);
- throw new SynapseException(msg);
- }
-
- /**
- * Register pluggable mediator factories from the classpath
- *
- * This looks for JAR files containing a META-INF/services that adheres to
- * the following
- * http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider
- */
- private void registerExtensions() {
-
- // log.debug("Registering mediator extensions found in the classpath : "
- // + System.getResource("java.class.path"));
- // register MediatorFactory extensions
- Iterator it = Service.providers(StartupFactory.class);
- while (it.hasNext()) {
- StartupFactory sf = (StartupFactory) it.next();
- QName tag = sf.getTagQName();
- factoryMap.put(tag, sf.getClass());
- serializerMap.put(tag, sf.getSerializerClass());
- if (log.isDebugEnabled()) {
- log.debug("Added StartupFactory " + sf.getClass()
- + " to handle " + tag);
- }
- }
- }
-
- /**
- * This method returns a Processor given an OMElement. This will be used
- * recursively by the elements which contain processor elements themselves
- * (e.g. rules)
- *
- * @param element
- * @return Processor
- */
- public Startup getStartup(OMElement element) {
+ private static final Log log = LogFactory
+ .getLog(ConfigurationFactoryAndSerializerFinder.class);
- String localName = element.getLocalName();
- QName qName = null;
- if (element.getNamespace() != null) {
- qName = new QName(element.getNamespace().getNamespaceURI(),
- localName);
- } else {
- qName = new QName(localName);
- }
- if (log.isDebugEnabled()) {
- log.debug("getStartup(" + qName + ")");
- }
- Class cls = (Class) factoryMap.get(qName);
-
- if (cls == null) {
- String msg = "Unknown Startup type referenced by startup element : "
- + qName;
- log.error(msg);
- throw new SynapseException(msg);
- }
-
- try {
- StartupFactory sf = (StartupFactory) cls.newInstance();
- return sf.createStartup(element);
-
- } catch (InstantiationException e) {
- String msg = "Error initializing configuration factory : " + cls;
- log.error(msg);
- throw new SynapseException(msg, e);
-
- } catch (IllegalAccessException e) {
- String msg = "Error initializing configuration factory : " + cls;
- log.error(msg);
- throw new SynapseException(msg, e);
- }
- }
-
- /**
- * This method will serialize the config using the supplied QName (looking
- * up the right class to do it)
- *
- * @param parent -
- * Parent OMElement to which the created element will be added if
- * not null
- * @param startup -
- * Startup to be serialized
- * @throws XMLStreamException
- * if the serialization encounter an error
- */
- public void serializeStartup(OMElement parent, Startup startup)
- throws XMLStreamException {
+ private static StartupFinder instance = null;
- Class cls = (Class) serializerMap.get(startup.getTagQName());
- if (cls == null) {
- String msg = "Unknown startup type referenced by startup element : "
- + startup.getTagQName();
- log.error(msg);
- throw new SynapseException(msg);
- }
-
- try {
- StartupSerializer ss = (StartupSerializer) cls.newInstance();
- ss.serializeStartup(parent, startup);
-
- } catch (InstantiationException e) {
- String msg = "Error initializing startup serializer: " + cls;
- log.error(msg);
- throw new SynapseException(msg, e);
-
- } catch (IllegalAccessException e) {
- String msg = "Error initializing startup ser: " + cls;
- log.error(msg);
- throw new SynapseException(msg, e);
- }
- }
-
- /*
- * This method exposes all the MediatorFactories and its Extensions
- */
- public Map getFactoryMap() {
- return factoryMap;
- }
-
- /**
- * Allow the mediator factory finder to act as an XMLToObjectMapper for
- * Mediators (i.e. Sequence Mediator) loaded dynamically from a Registry
- *
- * @param om
- * @return
- */
- public Object getObjectFromOMNode(OMNode om) {
- if (om instanceof OMElement) {
- return getStartup((OMElement) om);
- } else {
+ /**
+ * A map of mediator QNames to implementation class
+ */
+ private static Map factoryMap = new HashMap(),
+ serializerMap = new HashMap();
+
+ public static synchronized StartupFinder getInstance() {
+ if (instance == null) {
+ instance = new StartupFinder();
+ }
+ return instance;
+ }
+
+ /**
+ * Force re initialization next time
+ */
+ public synchronized void reset() {
+ factoryMap.clear();
+ instance = null;
+ }
+
+ private static final Class[] builtins = {SimpleQuartzFactory.class};
+
+ private StartupFinder() {
+ // preregister any built in
+ for (int i = 0; i < builtins.length; i++) {
+ Class b = builtins[i];
+ StartupFactory sf;
+ try {
+ sf = (StartupFactory) b.newInstance();
+ } catch (Exception e) {
+ throw new SynapseException("cannot instantiate " + b.getName(),
+ e);
+
+ }
+ factoryMap.put(sf.getTagQName(), b);
+ serializerMap.put(sf.getTagQName(), sf.getSerializerClass());
+
+ }
+
+ registerExtensions();
+ }
+
+ private void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+ /**
+ * Register pluggable mediator factories from the classpath
+ * <p/>
+ * This looks for JAR files containing a META-INF/services that adheres to
+ * the following
+ * http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider
+ */
+ private void registerExtensions() {
+
+ // log.debug("Registering mediator extensions found in the classpath : "
+ // + System.getResource("java.class.path"));
+
+ // register MediatorFactory extensions
+ Iterator it = Service.providers(StartupFactory.class);
+ while (it.hasNext()) {
+ StartupFactory sf = (StartupFactory) it.next();
+ QName tag = sf.getTagQName();
+ factoryMap.put(tag, sf.getClass());
+ serializerMap.put(tag, sf.getSerializerClass());
+ if (log.isDebugEnabled()) {
+ log.debug("Added StartupFactory " + sf.getClass()
+ + " to handle " + tag);
+ }
+ }
+ }
+
+ /**
+ * This method returns a Processor given an OMElement. This will be used
+ * recursively by the elements which contain processor elements themselves
+ * (e.g. rules)
+ *
+ * @param element
+ * @return Processor
+ */
+ public Startup getStartup(OMElement element) {
+
+ String id = element.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "id"));
+ if (id == null) {
+ String msg = "Id for an startup is required, missing Id in the startup";
+ if (log.isDebugEnabled()) {
+ log.debug(msg);
+ }
+ throw new SynapseException(msg);
+ }
+
+ QName qName = element.getFirstElement().getQName();
+ if (log.isDebugEnabled()) {
+ log.debug("getStartup(" + qName + ")");
+ }
+
+ Class cls = (Class) factoryMap.get(qName);
+ if (cls == null) {
+ String msg = "Unknown Startup type referenced by startup element : "
+ + qName;
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+ try {
+ StartupFactory sf = (StartupFactory) cls.newInstance();
+ Startup startup = sf.createStartup(element.getFirstElement());
+ startup.setId(id);
+ return startup;
+
+ } catch (InstantiationException e) {
+ String msg = "Error initializing configuration factory : " + cls;
+ log.error(msg);
+ throw new SynapseException(msg, e);
+
+ } catch (IllegalAccessException e) {
+ String msg = "Error initializing configuration factory : " + cls;
+ log.error(msg);
+ throw new SynapseException(msg, e);
+ }
+ }
+
+ /**
+ * This method will serialize the config using the supplied QName (looking
+ * up the right class to do it)
+ *
+ * @param parent -
+ * Parent OMElement to which the created element will be added if
+ * not null
+ * @param startup -
+ * Startup to be serialized
+ * @return OMElement startup
+ */
+ public OMElement serializeStartup(OMElement parent, Startup startup) {
+
+ Class cls = (Class) serializerMap.get(startup.getTagQName());
+ if (cls == null) {
+ String msg = "Unknown startup type referenced by startup element : "
+ + startup.getTagQName();
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+ try {
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+ OMElement startupElement = fac.createOMElement(
+ "startup", fac.createOMNamespace(XMLConfigConstants.SYNAPSE_NAMESPACE, "syn"));
+ startupElement.addAttribute("id", startup.getId(), fac.createOMNamespace("", ""));
+ StartupSerializer ss = (StartupSerializer) cls.newInstance();
+ ss.serializeStartup(startupElement, startup);
+ if (parent != null) {
+ parent.addChild(startupElement);
+ }
+
+ return startupElement;
+
+ } catch (InstantiationException e) {
+ String msg = "Error initializing startup serializer: " + cls;
+ log.error(msg);
+ throw new SynapseException(msg, e);
+
+ } catch (IllegalAccessException e) {
+ String msg = "Error initializing startup ser: " + cls;
+ log.error(msg);
+ throw new SynapseException(msg, e);
+ }
+ }
+
+ /*
+ * This method exposes all the StartupFactories and its Extensions
+ */
+ public Map getFactoryMap() {
+ return factoryMap;
+ }
+
+ /*
+ * This method exposes all the StartupSerializers and its Extensions
+ */
+ public Map getSerializerMap() {
+ return serializerMap;
+ }
+
+ /**
+ * Allow the startup finder to act as an XMLToObjectMapper for
+ * Startup (i.e. Startup) loaded dynamically from a Registry
+ *
+ * @param om
+ * @return
+ */
+ public Object getObjectFromOMNode(OMNode om) {
+ if (om instanceof OMElement) {
+ return getStartup((OMElement) om);
+ } else {
handleException("Invalid configuration XML : " + om);
}
return null;
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupSerializer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupSerializer.java?rev=578664&r1=578663&r2=578664&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupSerializer.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupSerializer.java Sun Sep 23 22:39:08 2007
@@ -1,11 +1,40 @@
-package org.apache.synapse.config.xml;
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.synapse.config.xml;
import org.apache.axiom.om.OMElement;
import org.apache.synapse.Startup;
+/**
+ * Defines the serialization of Startups
+ */
public interface StartupSerializer {
- public void serializeStartup(OMElement parent, Startup startup);
+ /**
+ * Serializes the Startup to an OMElement and
+ * attaches as a child to the provided parent OMElement
+ *
+ * @param parent
+ * OMElement to which, serialized startup will be attached
+ * @param startup
+ * Startup to be serialized
+ */
+ public void serializeStartup(OMElement parent, Startup startup);
}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.java?rev=578664&r1=578663&r2=578664&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.java Sun Sep 23 22:39:08 2007
@@ -1,5 +1,23 @@
-package org.apache.synapse.config.xml;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.synapse.config.xml;
import java.util.Iterator;
@@ -12,6 +30,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.Mediator;
import org.apache.synapse.SynapseException;
+import org.apache.synapse.Startup;
import org.apache.synapse.config.Entry;
import org.apache.synapse.config.SynapseConfiguration;
import org.apache.synapse.config.Util;
@@ -23,65 +42,65 @@
import org.apache.synapse.mediators.builtin.SendMediator;
public class SynapseXMLConfigurationFactory implements ConfigurationFactory {
- private static Log log = LogFactory.getLog(SynapseXMLConfigurationFactory.class);
-
- public SynapseConfiguration getConfiguration(OMElement definitions) {
- if (!definitions.getQName().equals(XMLConfigConstants.DEFINITIONS_ELT)) throw new SynapseException("Wrong QName for this config factory "+definitions.getQName());
-
-
- SynapseConfiguration config = new SynapseConfiguration();
- config.setDefaultQName(definitions.getQName());
-
- SequenceMediator rootSequence = new SequenceMediator();
- rootSequence.setName(org.apache.synapse.SynapseConstants.MAIN_SEQUENCE_KEY);
+
+ private static Log log = LogFactory.getLog(SynapseXMLConfigurationFactory.class);
+ public SynapseConfiguration getConfiguration(OMElement definitions) {
+
+ if (!definitions.getQName().equals(XMLConfigConstants.DEFINITIONS_ELT)) {
+ throw new SynapseException(
+ "Wrong QName for this config factory " + definitions.getQName());
+ }
+ SynapseConfiguration config = new SynapseConfiguration();
+ config.setDefaultQName(definitions.getQName());
- Iterator iter = definitions.getChildren();
+ SequenceMediator rootSequence = new SequenceMediator();
+ rootSequence.setName(org.apache.synapse.SynapseConstants.MAIN_SEQUENCE_KEY);
- while (iter.hasNext()) {
- Object o = iter.next();
- if (o instanceof OMElement) {
- OMElement elt = (OMElement) o;
- if (XMLConfigConstants.SEQUENCE_ELT.equals(elt.getQName())) {
- String key = elt.getAttributeValue(
- new QName(XMLConfigConstants.NULL_NAMESPACE, "key"));
- // this could be a sequence def or a mediator of the main sequence
- if (key != null) {
- Mediator m = MediatorFactoryFinder.getInstance().getMediator(elt);
- rootSequence.addChild(m);
- } else {
- defineSequence(config, elt);
- }
- } else if (XMLConfigConstants.ENDPOINT_ELT.equals(elt.getQName())) {
- defineEndpoint(config, elt);
- } else if (XMLConfigConstants.ENTRY_ELT.equals(elt.getQName())) {
- defineEntry(config, elt);
- } else if (XMLConfigConstants.PROXY_ELT.equals(elt.getQName())) {
- defineProxy(config, elt);
- } else if (XMLConfigConstants.REGISTRY_ELT.equals(elt.getQName())) {
- defineRegistry(config, elt);
- } else if (XMLConfigConstants.STARTUP_ELT.equals(elt.getQName())) {
- defineStartup(config, elt);
- }
- else {
- Mediator m = MediatorFactoryFinder.getInstance().getMediator(elt);
- rootSequence.addChild(m);
- }
+ Iterator iter = definitions.getChildren();
+
+ while (iter.hasNext()) {
+ Object o = iter.next();
+ if (o instanceof OMElement) {
+ OMElement elt = (OMElement) o;
+ if (XMLConfigConstants.SEQUENCE_ELT.equals(elt.getQName())) {
+ String key = elt.getAttributeValue(
+ new QName(XMLConfigConstants.NULL_NAMESPACE, "key"));
+ // this could be a sequence def or a mediator of the main sequence
+ if (key != null) {
+ Mediator m = MediatorFactoryFinder.getInstance().getMediator(elt);
+ rootSequence.addChild(m);
+ } else {
+ defineSequence(config, elt);
}
+ } else if (XMLConfigConstants.ENDPOINT_ELT.equals(elt.getQName())) {
+ defineEndpoint(config, elt);
+ } else if (XMLConfigConstants.ENTRY_ELT.equals(elt.getQName())) {
+ defineEntry(config, elt);
+ } else if (XMLConfigConstants.PROXY_ELT.equals(elt.getQName())) {
+ defineProxy(config, elt);
+ } else if (XMLConfigConstants.REGISTRY_ELT.equals(elt.getQName())) {
+ defineRegistry(config, elt);
+ } else if (XMLConfigConstants.STARTUP_ELT.equals(elt.getQName())) {
+ defineStartup(config, elt);
+ } else {
+ Mediator m = MediatorFactoryFinder.getInstance().getMediator(elt);
+ rootSequence.addChild(m);
}
-
-
+ }
+ }
if (config.getLocalRegistry().isEmpty() && config.getProxyServices().isEmpty() &&
rootSequence.getList().isEmpty() && config.getRegistry() != null) {
OMNode remoteConfigNode = config.getRegistry().lookup("synapse.xml");
try {
- config = XMLConfigurationBuilder.getConfiguration(Util.getStreamSource(remoteConfigNode).getInputStream());
+ config = XMLConfigurationBuilder.getConfiguration(
+ Util.getStreamSource(remoteConfigNode).getInputStream());
} catch (XMLStreamException xse) {
- throw new SynapseException("Problem loading remote synapse.xml ",xse);
+ throw new SynapseException("Problem loading remote synapse.xml ", xse);
}
-
+
}
if (config.getMainSequence() == null) {
@@ -109,12 +128,13 @@
}
config.setRegistry(RegistryFactory.createRegistry(elem));
}
-
+
private static void defineStartup(SynapseConfiguration config, OMElement elem) {
- if (config.getStartup() != null) {
- handleException("Only one startup set can be defined within a configuration");
+ Startup startup = StartupFinder.getInstance().getStartup(elem);
+ if (config.getStartup(startup.getId()) != null) {
+ handleException("Duplicate startup with id : " + startup.getId());
}
- config.setStartup(StartupWrapperFactory.createStartup(elem));
+ config.addStartup(startup);
}
private static void defineProxy(SynapseConfiguration config, OMElement elem) {
@@ -199,14 +219,14 @@
throw new SynapseException(msg, e);
}
-
- public QName getTagQName() {
-
- return XMLConfigConstants.DEFINITIONS_ELT;
- }
-
- public Class getSerializerClass() {
- return SynapseXMLConfigurationSerializer.class;
- }
+
+ public QName getTagQName() {
+
+ return XMLConfigConstants.DEFINITIONS_ELT;
+ }
+
+ public Class getSerializerClass() {
+ return SynapseXMLConfigurationSerializer.class;
+ }
}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java?rev=578664&r1=578663&r2=578664&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java Sun Sep 23 22:39:08 2007
@@ -4,6 +4,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.util.Collection;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
@@ -23,129 +24,128 @@
import org.apache.synapse.endpoints.Endpoint;
import org.apache.synapse.Startup;
-public class SynapseXMLConfigurationSerializer implements
- ConfigurationSerializer {
+public class SynapseXMLConfigurationSerializer implements ConfigurationSerializer {
- private static final Log log = LogFactory
- .getLog(XMLConfigurationSerializer.class);
+ private static final Log log = LogFactory
+ .getLog(XMLConfigurationSerializer.class);
- private static final OMFactory fac = OMAbstractFactory.getOMFactory();
+ private static final OMFactory fac = OMAbstractFactory.getOMFactory();
- private static final OMNamespace synNS = fac.createOMNamespace(
- XMLConfigConstants.SYNAPSE_NAMESPACE, "syn");
-
- private static final OMNamespace nullNS = fac.createOMNamespace(
- XMLConfigConstants.NULL_NAMESPACE, "");
-
- /**
- * order of entries is irrelavant, however its nice to have some order
- *
- * @param synCfg
- * @param outputStream
- * @throws XMLStreamException
- */
-
- public void serializeConfiguration(SynapseConfiguration synCfg,
- OutputStream outputStream) throws XMLStreamException {
-
- OMElement definitions = fac.createOMElement("definitions", synNS);
-
- // first process a remote registry if present
- if (synCfg.getRegistry() != null) {
- RegistrySerializer.serializeRegistry(definitions, synCfg
- .getRegistry());
- }
-
- // add proxy services
- Iterator iter = synCfg.getProxyServices().iterator();
- while (iter.hasNext()) {
- ProxyService service = (ProxyService) iter.next();
- ProxyServiceSerializer.serializeProxy(definitions, service);
- }
-
- Map entries = new HashMap();
- Map endpoints = new HashMap();
- Map sequences = new HashMap();
-
- iter = synCfg.getLocalRegistry().keySet().iterator();
- while (iter.hasNext()) {
- Object key = iter.next();
- Object o = synCfg.getLocalRegistry().get(key);
- if (o instanceof Mediator) {
- sequences.put(key, o);
- } else if (o instanceof Endpoint) {
- endpoints.put(key, o);
- } else if (o instanceof Entry) {
- entries.put(key, o);
- } else {
- handleException("Unknown object : " + o.getClass()
- + " for serialization into Synapse configuration");
- }
- }
-
- // process entries
- serializeEntries(definitions, entries);
-
- // process endpoints
- serializeEndpoints(definitions, endpoints);
-
- // process sequences
- serializeSequences(definitions, sequences);
-
- // handle startups
- if (synCfg.getStartup() != null) {
- Iterator it = synCfg.getStartup().iterator();
- while (it.hasNext()) {
- Startup s = (Startup) it.next();
- StartupFinder.getInstance().serializeStartup(definitions, s);
- }
- }
-
- definitions.serialize(outputStream);
- }
-
- private static void serializeEntries(OMElement definitions, Map entries) {
- Iterator iter = entries.keySet().iterator();
- while (iter.hasNext()) {
- String key = (String) iter.next();
- EntrySerializer.serializeEntry((Entry) entries.get(key),
- definitions);
- }
- }
-
- private static void serializeEndpoints(OMElement definitions, Map endpoints) {
- Iterator iter = endpoints.keySet().iterator();
- while (iter.hasNext()) {
- String key = (String) iter.next();
- Object o = endpoints.get(key);
- if (o instanceof Endpoint) {
- Endpoint endpoint = (Endpoint) o;
- OMElement epElement = EndpointAbstractSerializer
- .getEndpointSerializer(endpoint).serializeEndpoint(
- endpoint);
- definitions.addChild(epElement);
- }
-
- }
- }
-
- private static void serializeSequences(OMElement definitions, Map sequences) {
- Iterator iter = sequences.keySet().iterator();
- while (iter.hasNext()) {
- String key = (String) iter.next();
- Mediator mediator = (Mediator) sequences.get(key);
- MediatorSerializerFinder.getInstance().getSerializer(mediator)
- .serializeMediator(definitions, mediator);
- }
- }
-
- private static void handleException(String msg) {
- log.error(msg);
- throw new SynapseException(msg);
- }
+ private static final OMNamespace synNS = fac.createOMNamespace(
+ XMLConfigConstants.SYNAPSE_NAMESPACE, "syn");
+
+ private static final OMNamespace nullNS = fac.createOMNamespace(
+ XMLConfigConstants.NULL_NAMESPACE, "");
+
+ /**
+ * order of entries is irrelavant, however its nice to have some order
+ *
+ * @param synCfg
+ * @throws XMLStreamException
+ */
+
+ public OMElement serializeConfiguration(SynapseConfiguration synCfg) {
+
+ OMElement definitions = fac.createOMElement("definitions", synNS);
+
+ // first process a remote registry if present
+ if (synCfg.getRegistry() != null) {
+ RegistrySerializer.serializeRegistry(definitions, synCfg
+ .getRegistry());
+ }
+
+ // add proxy services
+ Iterator iter = synCfg.getProxyServices().iterator();
+ while (iter.hasNext()) {
+ ProxyService service = (ProxyService) iter.next();
+ ProxyServiceSerializer.serializeProxy(definitions, service);
+ }
+
+ Map entries = new HashMap();
+ Map endpoints = new HashMap();
+ Map sequences = new HashMap();
+
+ iter = synCfg.getLocalRegistry().keySet().iterator();
+ while (iter.hasNext()) {
+ Object key = iter.next();
+ Object o = synCfg.getLocalRegistry().get(key);
+ if (o instanceof Mediator) {
+ sequences.put(key, o);
+ } else if (o instanceof Endpoint) {
+ endpoints.put(key, o);
+ } else if (o instanceof Entry) {
+ entries.put(key, o);
+ } else {
+ handleException("Unknown object : " + o.getClass()
+ + " for serialization into Synapse configuration");
+ }
+ }
+
+ // process entries
+ serializeEntries(definitions, entries);
+
+ // process endpoints
+ serializeEndpoints(definitions, endpoints);
+
+ // process sequences
+ serializeSequences(definitions, sequences);
+
+ // handle startups
+ serializeStartups(definitions, synCfg.getStartups());
+
+ return definitions;
+ }
+
+ private static void serializeEntries(OMElement definitions, Map entries) {
+ Iterator iter = entries.keySet().iterator();
+ while (iter.hasNext()) {
+ String key = (String) iter.next();
+ EntrySerializer.serializeEntry((Entry) entries.get(key),
+ definitions);
+ }
+ }
+
+ private static void serializeStartups(OMElement definitions, Collection startups) {
+ Iterator it = startups.iterator();
+ while (it.hasNext()) {
+ Startup s = (Startup) it.next();
+ StartupFinder.getInstance().serializeStartup(definitions, s);
+ }
+ }
+
+ private static void serializeEndpoints(OMElement definitions, Map endpoints) {
+ Iterator iter = endpoints.keySet().iterator();
+ while (iter.hasNext()) {
+ String key = (String) iter.next();
+ Object o = endpoints.get(key);
+ if (o instanceof Endpoint) {
+ Endpoint endpoint = (Endpoint) o;
+ OMElement epElement = EndpointAbstractSerializer
+ .getEndpointSerializer(endpoint).serializeEndpoint(
+ endpoint);
+ definitions.addChild(epElement);
+ }
+
+ }
+ }
+
+ private static void serializeSequences(OMElement definitions, Map sequences) {
+ Iterator iter = sequences.keySet().iterator();
+ while (iter.hasNext()) {
+ String key = (String) iter.next();
+ Mediator mediator = (Mediator) sequences.get(key);
+ MediatorSerializerFinder.getInstance().getSerializer(mediator)
+ .serializeMediator(definitions, mediator);
+ }
+ }
+
+ private static void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
- public QName getTagQName() {
- return XMLConfigConstants.DEFINITIONS_ELT;
+ public QName getTagQName() {
+ return XMLConfigConstants.DEFINITIONS_ELT;
}
}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigurationBuilder.java?rev=578664&r1=578663&r2=578664&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigurationBuilder.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigurationBuilder.java Sun Sep 23 22:39:08 2007
@@ -29,7 +29,6 @@
import javax.xml.stream.XMLStreamException;
-
/**
* Builds a Synapse Configuration from an XML input stream
*/
@@ -39,15 +38,12 @@
public static SynapseConfiguration getConfiguration(InputStream is) throws XMLStreamException {
-
log.info("Generating the Synapse configuration model by parsing the XML configuration");
- OMElement definitions = null;
- definitions = new StAXOMBuilder(is).getDocumentElement();
+ OMElement definitions = new StAXOMBuilder(is).getDocumentElement();
definitions.build();
-
- SynapseConfiguration config = ConfigurationFactoryAndSerializerFinder.getInstance().getConfiguration(definitions);
- return config;
+
+ return ConfigurationFactoryAndSerializerFinder.getInstance().getConfiguration(definitions);
}
}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigurationSerializer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigurationSerializer.java?rev=578664&r1=578663&r2=578664&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigurationSerializer.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigurationSerializer.java Sun Sep 23 22:39:08 2007
@@ -46,10 +46,6 @@
private static final Log log = LogFactory.getLog(XMLConfigurationSerializer.class);
- private static final OMFactory fac = OMAbstractFactory.getOMFactory();
- private static final OMNamespace synNS = fac.createOMNamespace(XMLConfigConstants.SYNAPSE_NAMESPACE, "syn");
- private static final OMNamespace nullNS = fac.createOMNamespace(XMLConfigConstants.NULL_NAMESPACE, "");
-
/**
* order of entries is irrelavant, however its nice to have some order
* @param synCfg
@@ -59,87 +55,11 @@
public static void serializeConfiguration(SynapseConfiguration synCfg,
OutputStream outputStream) throws XMLStreamException {
- OMElement definitions = fac.createOMElement("definitions", synNS);
-
- // first process a remote registry if present
- if (synCfg.getRegistry() != null) {
- RegistrySerializer.serializeRegistry(definitions, synCfg.getRegistry());
- }
-
- // add proxy services
- Iterator iter = synCfg.getProxyServices().iterator();
- while (iter.hasNext()) {
- ProxyService service = (ProxyService) iter.next();
- ProxyServiceSerializer.serializeProxy(definitions, service);
- }
-
- Map entries = new HashMap();
- Map endpoints = new HashMap();
- Map sequences = new HashMap();
-
- iter = synCfg.getLocalRegistry().keySet().iterator();
- while (iter.hasNext()) {
- Object key = iter.next();
- Object o = synCfg.getLocalRegistry().get(key);
- if (o instanceof Mediator) {
- sequences.put(key, o);
- } else if (o instanceof Endpoint) {
- endpoints.put(key, o);
- } else if (o instanceof Entry) {
- entries.put(key, o);
- } else {
- handleException("Unknown object : " + o.getClass()
- + " for serialization into Synapse configuration");
- }
- }
-
- // process entries
- serializeEntries(definitions, entries);
-
- // process endpoints
- serializeEndpoints(definitions, endpoints);
-
- // process sequences
- serializeSequences(definitions, sequences);
-
+ log.info("Serializing the XML Configuration to the output stream");
+
+ OMElement definitions
+ = ConfigurationFactoryAndSerializerFinder.serializeConfiguration(synCfg);
definitions.serialize(outputStream);
}
-
- private static void serializeEntries(OMElement definitions, Map entries) {
- Iterator iter = entries.keySet().iterator();
- while (iter.hasNext()) {
- String key = (String) iter.next();
- EntrySerializer.serializeEntry((Entry) entries.get(key), definitions);
- }
- }
-
- private static void serializeEndpoints(OMElement definitions, Map endpoints) {
- Iterator iter = endpoints.keySet().iterator();
- while (iter.hasNext()) {
- String key = (String) iter.next();
- Object o = endpoints.get(key);
- if (o instanceof Endpoint) {
- Endpoint endpoint = (Endpoint) o;
- OMElement epElement = EndpointAbstractSerializer.
- getEndpointSerializer(endpoint).serializeEndpoint(endpoint);
- definitions.addChild(epElement);
- }
-
- }
- }
-
- private static void serializeSequences(OMElement definitions, Map sequences) {
- Iterator iter = sequences.keySet().iterator();
- while (iter.hasNext()) {
- String key = (String) iter.next();
- Mediator mediator = (Mediator) sequences.get(key);
- MediatorSerializerFinder.getInstance().getSerializer(mediator)
- .serializeMediator(definitions, mediator);
- }
- }
-
- private static void handleException(String msg) {
- log.error(msg);
- throw new SynapseException(msg);
- }
+
}
Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/AbstractStartup.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/AbstractStartup.java?rev=578664&view=auto
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/AbstractStartup.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/AbstractStartup.java Sun Sep 23 22:39:08 2007
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.synapse.startup;
+
+import org.apache.synapse.Startup;
+
+/**
+ *
+ */
+public abstract class AbstractStartup implements Startup {
+
+ /**
+ * Holds the id of a Startup
+ */
+ private String id = null;
+
+ /**
+ * This will return the id of the startup
+ *
+ * @return String representing the id
+ */
+ public String getId() {
+ return this.id;
+ }
+
+ /**
+ * This will set the id of a Startup
+ *
+ * @param id
+ * String id to be set to the startup
+ */
+ public void setId(String id) {
+ this.id = id;
+ }
+}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartz.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartz.java?rev=578664&r1=578663&r2=578664&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartz.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartz.java Sun Sep 23 22:39:08 2007
@@ -1,3 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
package org.apache.synapse.startup.quartz;
import java.util.HashSet;
@@ -12,6 +31,7 @@
import org.apache.synapse.core.SynapseEnvironment;
import org.apache.synapse.Startup;
import org.apache.synapse.SynapseException;
+import org.apache.synapse.startup.AbstractStartup;
import org.quartz.CronTrigger;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
@@ -28,126 +48,128 @@
* SimpleQuartzJob is there to set the properties and start the actual business-logic class
* It wraps up any properties that the job needs as in the JobDetail and JDMap
*/
-public class SimpleQuartz implements Startup {
- private static final Log log = LogFactory.getLog(SimpleQuartz.class);
- private static final int THREADPOOLSIZE = 5;
-
- private String cron;
-
- private int repeatCount;
-
- private long repeatInterval;
-
- private boolean simple; // true means use repeat, false means use cron
-
- private String className;
-
-// private SynapseEnvironment synapseEnvironment;
-
- private Scheduler sch;
-
- Set xmlProperties = new HashSet();
-
- public QName getTagQName() {
- return SimpleQuartzFactory.JOB;
- }
-
- public void destroy() {
- if (sch != null) {
- try {
- sch.shutdown();
- } catch (SchedulerException e) {
- throw new SynapseException(e);
- }
- }
-
- }
-
- public void init(SynapseEnvironment synapseEnvironment) {
-
- //this.synapseEnvironment = synapseEnvironment;
- try {
- DirectSchedulerFactory.getInstance().createVolatileScheduler(
- THREADPOOLSIZE);
- sch = DirectSchedulerFactory.getInstance().getScheduler();
- Trigger trigger = null;
- if (simple) {
-
- trigger = TriggerUtils.makeImmediateTrigger(repeatCount, repeatInterval);
- } else {
- CronTrigger cronTrig = new CronTrigger();
- cronTrig.setCronExpression(cron);
- trigger = cronTrig;
- }
- // give the trigger a random name
- trigger.setName("Trigger"+String.valueOf((new Random()).nextLong()));
- trigger.setGroup("synapse.simple.quartz");
- trigger.setVolatility(true);
- JobDetail jobDetail = new JobDetail();
- // Give the job a random name
- jobDetail.setName("Job"+String.valueOf((new Random()).nextLong()));
- jobDetail.setGroup("synapse.simple.quartz");
- jobDetail.setJobClass(SimpleQuartzJob.class);
- JobDataMap jdm = new JobDataMap();
- jdm.put(SimpleQuartzJob.SYNAPSEENVIRONMENT, synapseEnvironment);
- jdm.put(SimpleQuartzJob.CLASSNAME, className);
- jdm.put(SimpleQuartzJob.PROPERTIES, xmlProperties);
- jobDetail.setJobDataMap(jdm);
- sch.scheduleJob(jobDetail, trigger);
- sch.start();
- log.info("Scheduled job "+jobDetail.getFullName()+" for class "+className);
-
- } catch (Exception e) {
- throw new SynapseException("Problem with startup of Scheduler ", e);
- }
-
- }
-
- public String getJobClass() {
- return className;
- }
-
- public void setJobClass(String attributeValue) {
- className = attributeValue;
-
- }
-
- public void setSimple(boolean b) {
- simple = b;
- }
-
- public boolean isSimple() {
- return simple;
- }
-
- public void setInterval(long l) {
- repeatInterval = l;
-
- }
- public long getInterval() {
- return repeatInterval;
- }
-
- public void setCount(int i) {
- repeatCount = i;
- }
- public int getCount() {
- return repeatCount;
- }
-
- public void addProperty(OMElement prop) {
- xmlProperties.add(prop);
- }
- public Set getProperties() {
- return xmlProperties;
- }
-
- public void setCron(String attributeValue) {
- cron = attributeValue;
-
- }
- public String getCron() {
- return cron;
- }
+public class SimpleQuartz extends AbstractStartup {
+
+ private static final Log log = LogFactory.getLog(SimpleQuartz.class);
+ private static final int THREADPOOLSIZE = 5;
+
+ private String cron;
+
+ private int repeatCount;
+
+ private long repeatInterval;
+
+ private boolean simple; // true means use repeat, false means use cron
+
+ private String className;
+
+ private Scheduler sch;
+
+ Set xmlProperties = new HashSet();
+
+ public QName getTagQName() {
+ return SimpleQuartzFactory.JOB;
+ }
+
+ public void destroy() {
+ if (sch != null) {
+ try {
+ sch.shutdown();
+ } catch (SchedulerException e) {
+ throw new SynapseException(e);
+ }
+ }
+
+ }
+
+ public void init(SynapseEnvironment synapseEnvironment) {
+
+ try {
+ DirectSchedulerFactory.getInstance().createVolatileScheduler(
+ THREADPOOLSIZE);
+ sch = DirectSchedulerFactory.getInstance().getScheduler();
+ Trigger trigger = null;
+ if (simple) {
+
+ trigger = TriggerUtils.makeImmediateTrigger(repeatCount, repeatInterval);
+ } else {
+ CronTrigger cronTrig = new CronTrigger();
+ cronTrig.setCronExpression(cron);
+ trigger = cronTrig;
+ }
+ // give the trigger a random name
+ trigger.setName("Trigger" + String.valueOf((new Random()).nextLong()));
+ trigger.setGroup("synapse.simple.quartz");
+ trigger.setVolatility(true);
+ JobDetail jobDetail = new JobDetail();
+ // Give the job a random name
+ jobDetail.setName("Job" + String.valueOf((new Random()).nextLong()));
+ jobDetail.setGroup("synapse.simple.quartz");
+ jobDetail.setJobClass(SimpleQuartzJob.class);
+ JobDataMap jdm = new JobDataMap();
+ jdm.put(SimpleQuartzJob.SYNAPSEENVIRONMENT, synapseEnvironment);
+ jdm.put(SimpleQuartzJob.CLASSNAME, className);
+ jdm.put(SimpleQuartzJob.PROPERTIES, xmlProperties);
+ jobDetail.setJobDataMap(jdm);
+ sch.scheduleJob(jobDetail, trigger);
+ sch.start();
+ log.info("Scheduled job " + jobDetail.getFullName() + " for class " + className);
+
+ } catch (Exception e) {
+ throw new SynapseException("Problem with startup of Scheduler ", e);
+ }
+
+ }
+
+ public String getJobClass() {
+ return className;
+ }
+
+ public void setJobClass(String attributeValue) {
+ className = attributeValue;
+
+ }
+
+ public void setSimple(boolean b) {
+ simple = b;
+ }
+
+ public boolean isSimple() {
+ return simple;
+ }
+
+ public void setInterval(long l) {
+ repeatInterval = l;
+
+ }
+
+ public long getInterval() {
+ return repeatInterval;
+ }
+
+ public void setCount(int i) {
+ repeatCount = i;
+ }
+
+ public int getCount() {
+ return repeatCount;
+ }
+
+ public void addProperty(OMElement prop) {
+ xmlProperties.add(prop);
+ }
+
+ public Set getProperties() {
+ return xmlProperties;
+ }
+
+ public void setCron(String attributeValue) {
+ cron = attributeValue;
+
+ }
+
+ public String getCron() {
+ return cron;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org