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/10/12 05:00:38 UTC
svn commit: r584035 - in
/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse:
config/xml/ startup/quartz/
Author: ruwan
Date: Thu Oct 11 20:00:38 2007
New Revision: 584035
URL: http://svn.apache.org/viewvc?rev=584035&view=rev
Log:
Finalizing the Task language syntax
Modified:
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/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/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=584035&r1=584034&r2=584035&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 Thu Oct 11 20:00:38 2007
@@ -126,7 +126,7 @@
String name = element.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
if (name == null) {
- String msg = "Id for an startup is required, missing Id in the startup";
+ String msg = "Name for an startup is required, missing name in the startup";
if (log.isDebugEnabled()) {
log.debug(msg);
}
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=584035&r1=584034&r2=584035&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 Thu Oct 11 20:00:38 2007
@@ -31,10 +31,9 @@
* 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
+ * @param parent - OMElement to which, serialized startup will be attached
+ * @param startup - Startup to be serialized
+ * @return Serialized OMElement
*/
- public void serializeStartup(OMElement parent, Startup startup);
+ public OMElement serializeStartup(OMElement parent, Startup startup);
}
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=584035&r1=584034&r2=584035&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 Thu Oct 11 20:00:38 2007
@@ -54,12 +54,10 @@
private String cron;
- private int repeatCount;
+ private int repeatCount = -1;
private long repeatInterval;
- private boolean simple; // true means use repeat, false means use cron
-
private String className;
private Scheduler sch;
@@ -84,12 +82,10 @@
public void init(SynapseEnvironment synapseEnvironment) {
try {
- DirectSchedulerFactory.getInstance().createVolatileScheduler(
- THREADPOOLSIZE);
+ DirectSchedulerFactory.getInstance().createVolatileScheduler(THREADPOOLSIZE);
sch = DirectSchedulerFactory.getInstance().getScheduler();
Trigger trigger = null;
- if (simple) {
-
+ if (cron == null) {
trigger = TriggerUtils.makeImmediateTrigger(repeatCount, repeatInterval);
} else {
CronTrigger cronTrig = new CronTrigger();
@@ -101,7 +97,7 @@
trigger.setGroup("synapse.simple.quartz");
trigger.setVolatility(true);
JobDetail jobDetail = new JobDetail();
- // Give the job a random name
+ // Give the job a name
jobDetail.setName(name);
jobDetail.setGroup("synapse.simple.quartz");
jobDetail.setJobClass(SimpleQuartzJob.class);
@@ -127,14 +123,6 @@
public void setJobClass(String attributeValue) {
className = attributeValue;
- }
-
- public void setSimple(boolean b) {
- simple = b;
- }
-
- public boolean isSimple() {
- return simple;
}
public void setInterval(long l) {
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzFactory.java?rev=584035&r1=584034&r2=584035&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzFactory.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzFactory.java Thu Oct 11 20:00:38 2007
@@ -33,148 +33,109 @@
import org.apache.synapse.Startup;
import org.apache.synapse.SynapseException;
-/*
- * Namespace = synapse namespace
- *
- * <task class="org.my.synapse.Task">
- * <property name="stringProp" value="String"/>
- * <property name="xmlProp">
- * %lt;somexml>config</somexml>
- * </property>
- * <simpletrigger forever="true" count="10" interval="1000"/>
- * <!-- forever or count not both -->
- * <crontrigger expression="0 * 1 * * ?" />
- * </task>
- *
+/**
+ * <task class="org.my.synapse.Task" name="string">
+ * <property name="stringProp" value="String"/>
+ * <property name="xmlProp">
+ * <somexml>config</somexml>
+ * </property>
+ * <trigger ([[count="10"]? interval="1000"] | [cron="0 * 1 * * ?"])/>
+ * </task>
*/
-
public class SimpleQuartzFactory implements StartupFactory {
- public final static QName TASK = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "task");
-
- private final static QName SIMPLE
- = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "simpletrigger");
+ public final static QName TASK
+ = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "task");
- private final static QName CRON
- = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "crontrigger");
+ private final static QName TRIGGER
+ = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "trigger");
private final static QName PROPERTY
- = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "property");
+ = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "property");
private final static Log log = LogFactory.getLog(SimpleQuartzFactory.class);
public Startup createStartup(OMElement el) {
- if (log.isDebugEnabled())
+
+ if (log.isDebugEnabled()) {
log.debug("Creating SimpleQuartz startup");
+ }
+
if (el.getQName().equals(TASK)) {
+
SimpleQuartz q = new SimpleQuartz();
+
+ // set the task class
OMAttribute classAttr = el.getAttribute(new QName("class"));
- if (classAttr == null) {
- log.error("No class attribute on element. It is required");
- throw new SynapseException(
- "Cannot create Quartz Startup - no class attribute");
+ if (classAttr != null && classAttr.getAttributeValue() != null) {
+ String classname = classAttr.getAttributeValue();
+ try {
+ Class.forName(classname).newInstance();
+ } catch (Exception e) {
+ handleException("Failed to load task class " + classname, e);
+ }
+ q.setJobClass(classname);
+ } else {
+ handleException("Syntax error in the Task : no task class specified");
}
- // test if we can create the task?
- String classname = classAttr.getAttributeValue();
- // if no package specified then prepend "org.apache.synapse.startup.tasks"
- if (classname.indexOf('.') == -1) {
- classname = "org.apache.synapse.startup.tasks." + classname;
- }
- try {
- getClass().getClassLoader().loadClass(classname).newInstance();
- }
- catch (Exception e) {
- throw new SynapseException("Failed to load task class " + classname, e);
- }
- q.setJobClass(classname);
// next sort out the property children
-
Iterator it = el.getChildrenWithName(PROPERTY);
while (it.hasNext()) {
- // simply store the properties for now -
- // they will be loaded when the job is actually run
OMElement prop = (OMElement) it.next();
if (PropertyHelper.isStaticProperty(prop)) {
q.addProperty(prop);
-
} else {
- throw new SynapseException(
- "Task does not support dynamic properties");
+ handleException("Tasks does not support dynamic properties");
}
}
- /* try to handle the simpletrigger approach */
- OMElement trigger = el.getFirstChildWithName(SIMPLE);
+ // setting the trigger to the task
+ OMElement trigger = el.getFirstChildWithName(TRIGGER);
if (trigger != null) {
- q.setSimple(true);
- OMAttribute repeatInterval = trigger.getAttribute(new QName(
- "interval"));
- if (repeatInterval == null) {
- log.error("interval attribute must be specified");
- throw new SynapseException(
- "No interval attribute specified");
- }
- try {
- q.setInterval(Long.parseLong(repeatInterval
- .getAttributeValue()));
- } catch (Exception e) {
- throw new SynapseException(
- "Failed to parse interval as long");
- }
+
OMAttribute count = trigger.getAttribute(new QName("count"));
- if (count == null) {
- // if no count set then forever must be set and set to true
- OMAttribute forever = trigger.getAttribute(new QName(
- "forever"));
-
- if (forever != null) {
- String fValue = forever.getAttributeValue();
- if (fValue.toLowerCase().charAt(0) == 't'
- || fValue.toLowerCase().charAt(0) == '1') {
- q.setCount(-1);
- } else {
- throw new SynapseException(
- "count must be set or forever='true'");
- }
- } else {
- throw new SynapseException(
- "count must be set or forever='true'");
- }
- } // else count is set
- else {
+ if (count != null) {
try {
q.setCount(Integer.parseInt(count.getAttributeValue()));
} catch (Exception e) {
- throw new SynapseException(
- "Failed to parse count as integer");
+ handleException("Failed to parse trigger count as an integer", e);
}
}
- } else // should be cron trigger
- {
- trigger = el.getFirstChildWithName(CRON);
- if (trigger == null) {
- log.error("neither cron nor simpletrigger are set");
- throw new SynapseException(
- "neither crontrigger nor simpletrigger child elements exist");
+ OMAttribute repeatInterval = trigger.getAttribute(new QName("interval"));
+ if (repeatInterval == null && q.getCount() > 0) {
+ handleException("Trigger seems to be " +
+ "a simple trigger, but no interval specified");
+ } else if (repeatInterval != null && repeatInterval.getAttributeValue() != null) {
+ try {
+ q.setInterval(Long.parseLong(repeatInterval.getAttributeValue()));
+ } catch (Exception e) {
+ handleException("Failed to parse trigger interval as a long value", e);
+ }
}
- q.setSimple(false); // cron trigger
- OMAttribute expr = trigger.getAttribute(new QName("expression"));
- if (expr == null) {
- log.error("crontrigger element must have expression attribute");
- throw new SynapseException(
- "crontrigger element must have expression attribute");
+
+ OMAttribute expr = trigger.getAttribute(new QName("cron"));
+ if (expr == null && q.getInterval() == 0) {
+ handleException("Trigger syntax error : " +
+ "trigger do not caontain simple nor cron trigger attributes");
+ } else if (expr != null && q.getInterval() > 0) {
+ handleException("Trigger syntax error : " +
+ "both cron and simple trigger attributes are present");
+ } else if (expr != null && expr.getAttributeValue() != null) {
+ q.setCron(expr.getAttributeValue());
}
- q.setCron(expr.getAttributeValue());
+
+ } else {
+ handleException("Trigger is missing for the task "
+ + el.getAttributeValue(new QName("name")));
}
return q;
} else {
- log.error("wrong QName!");
+ handleException("Syntax error in the task : wrong QName for the task");
return null;
}
-
}
public Class getSerializerClass() {
@@ -183,6 +144,16 @@
public QName getTagQName() {
return TASK;
+ }
+
+ private void handleException(String message, Exception e) {
+ log.error(message);
+ throw new SynapseException(message, e);
+ }
+
+ private void handleException(String message) {
+ log.error(message);
+ throw new SynapseException(message);
}
}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzSerializer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzSerializer.java?rev=584035&r1=584034&r2=584035&view=diff
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzSerializer.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/quartz/SimpleQuartzSerializer.java Thu Oct 11 20:00:38 2007
@@ -19,21 +19,28 @@
package org.apache.synapse.startup.quartz;
-import java.util.Iterator;
-
-import javax.xml.namespace.QName;
-
+import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
-import org.apache.synapse.config.xml.XMLConfigConstants;
-import org.apache.synapse.config.xml.StartupSerializer;
import org.apache.synapse.Startup;
import org.apache.synapse.SynapseException;
+import org.apache.synapse.config.xml.StartupSerializer;
+import org.apache.synapse.config.xml.XMLConfigConstants;
+
+import javax.xml.namespace.QName;
public class SimpleQuartzSerializer implements StartupSerializer {
- public void serializeStartup(OMElement parent, Startup s) {
+ 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 QName PROP_Q
+ = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "property", "syn");
+
+ public OMElement serializeStartup(OMElement parent, Startup s) {
if (!(s instanceof SimpleQuartz)) {
throw new SynapseException("called SimpleQuartzSerializer on some other " +
@@ -41,32 +48,30 @@
}
SimpleQuartz sq = (SimpleQuartz) s;
- OMFactory fac = parent.getOMFactory();
- OMNamespace nullNS = fac.createOMNamespace("", "");
- OMNamespace synNS = fac.createOMNamespace(XMLConfigConstants.SYNAPSE_NAMESPACE, "syn");
OMElement job = fac.createOMElement("task", synNS, parent);
job.addAttribute("class", sq.getJobClass(), nullNS);
- if (sq.isSimple()) {
- OMElement el = fac.createOMElement("simpletrigger", synNS, job);
- if (sq.getCount() == -1) {
- el.addAttribute("forever", "true", nullNS);
- } else {
- el.addAttribute("count", Integer.toString(sq.getCount()), nullNS);
- }
+
+ OMElement el = fac.createOMElement("trigger", synNS, job);
+ if (sq.getCount() != -1) {
+ el.addAttribute("count", Integer.toString(sq.getCount()), nullNS);
+ }
+
+ if (sq.getInterval() != 0) {
el.addAttribute("interval", Long.toString(sq.getInterval()), nullNS);
- } else {
- OMElement el = fac.createOMElement("crontrigger", synNS, job);
- el.addAttribute("expression", sq.getCron(), nullNS);
}
- Iterator it = sq.getProperties().iterator();
- while (it.hasNext()) {
- OMElement prop = (OMElement) it.next();
+ if (sq.getCron() != null) {
+ el.addAttribute("cron", sq.getCron(), nullNS);
+ }
+
+ for (Object o : sq.getProperties()) {
+ OMElement prop = (OMElement) o;
job.addChild(prop.cloneOMElement());
}
+ return job;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org