Commit in servicemix/tooling/example-client-quartz on MAIN
src/main/java/org/servicemix/demo/QuartzMarshaler.java+40added 1.1
                                 /QuartzComponent.java+209added 1.1
                                 /DefaultQuartzMarshaler.java+80added 1.1
                                 /ServiceMixJob.java+38added 1.1
project.properties+5added 1.1
project.xml+69added 1.1
.cvsignore+3added 1.1
src/main/jbi/META-INF/jbi-spring.xml+22added 1.1
src/main/merge/services.xml+6added 1.1
+472
9 added files
Initial revision of example simple quartz client using the servicemix-client infrastructure.

servicemix/tooling/example-client-quartz/src/main/java/org/servicemix/demo
QuartzMarshaler.java added at 1.1
diff -N QuartzMarshaler.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ QuartzMarshaler.java	18 Aug 2005 17:22:29 -0000	1.1
@@ -0,0 +1,40 @@
+/** 
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * Licensed 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.servicemix.demo;
+
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+
+import javax.jbi.messaging.NormalizedMessage;
+import javax.jbi.messaging.MessagingException;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public interface QuartzMarshaler {
+
+    /**
+     * Populates the given normalized message from the Quartz context
+     *
+     * @param message the normalized message to populate
+     * @param context the Quartz context
+     * @throws JobExecutionException
+     * @throws MessagingException
+     */
+    void populateNormalizedMessage(NormalizedMessage message, JobExecutionContext context) throws JobExecutionException, MessagingException;
+}

servicemix/tooling/example-client-quartz/src/main/java/org/servicemix/demo
QuartzComponent.java added at 1.1
diff -N QuartzComponent.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ QuartzComponent.java	18 Aug 2005 17:22:29 -0000	1.1
@@ -0,0 +1,209 @@
+/** 
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * Licensed 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.servicemix.demo;
+
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.quartz.JobDetail;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+import org.quartz.SchedulerFactory;
+import org.quartz.Trigger;
+import org.quartz.impl.StdSchedulerFactory;
+import org.servicemix.client.ServiceContext;
+import org.servicemix.client.ServiceLifeCycleImplementation;
+
+/**
+ * A <a href="">Quartz</a> component for
+ * triggering components when timer events fire.
+ * 
+ * @version $Revision: 1.1 $
+ */
+public class QuartzComponent implements ServiceLifeCycleImplementation {
+	private static final transient Log log = LogFactory
+			.getLog(QuartzComponent.class);
+
+	public static final String COMPONENT_KEY = "org.servicemix.component";
+
+	private SchedulerFactory factory;
+
+	private Scheduler scheduler;
+
+	private Map triggers;
+
+	private QuartzMarshaler marshaler = new DefaultQuartzMarshaler();
+
+	private ServiceContext serviceContext;
+
+	public void start() throws JBIException {
+		try {
+			scheduler.start();
+		} catch (SchedulerException e) {
+			throw new JBIException(e);
+		}
+	}
+
+	public void stop() throws JBIException {
+		try {
+			scheduler.shutdown();
+		} catch (SchedulerException e) {
+			throw new JBIException(e);
+		}
+	}
+
+	public void addTrigger(Trigger trigger, JobDetail detail)
+			throws JBIException {
+		try {
+			// lets default the trigger name to the job name
+			if (trigger.getName() == null) {
+				trigger.setName(detail.getName());
+			}
+			// lets default the trigger group to the job group
+			if (trigger.getGroup() == null) {
+				trigger.setGroup(detail.getGroup());
+			}
+			// default start time to now if not specified
+			if (trigger.getStartTime() == null) {
+				trigger.setStartTime(new Date());
+			}
+			detail.getJobDataMap().put(COMPONENT_KEY, this);
+			Class jobClass = detail.getJobClass();
+			if (jobClass == null) {
+				detail.setJobClass(ServiceMixJob.class);
+			}
+			scheduler.scheduleJob(detail, trigger);
+		} catch (SchedulerException e) {
+			throw new JBIException("Failed to add trigger: " + trigger
+					+ " with detail: " + detail + ". Reason: " + e, e);
+		}
+	}
+
+	/**
+	 * This method is invoked when a Quartz job is fired.
+	 * 
+	 * @param context
+	 *            the Quartz Job context
+	 */
+	public void onJobExecute(JobExecutionContext context)
+			throws JobExecutionException {
+		if (log.isDebugEnabled()) {
+			log.debug("Firing Quartz Job with context: " + context);
+		}
+		try {
+			QName targetInterface = new QName("http://tempuri.org/quartz",
+					"triggeredNotification");
+			InOnly inOnly = serviceContext.createInOnly(targetInterface);
+			NormalizedMessage message = inOnly.createMessage();
+			getMarshaler().populateNormalizedMessage(message, context);
+			inOnly.setInMessage(message);
+			serviceContext.done(inOnly);
+		} catch (MessagingException e) {
+			throw new JobExecutionException(e);
+		}
+	}
+
+	// Properties
+	// -------------------------------------------------------------------------
+	public SchedulerFactory getFactory() {
+		return factory;
+	}
+
+	public void setFactory(SchedulerFactory factory) {
+		this.factory = factory;
+	}
+
+	public Scheduler getScheduler() {
+		return scheduler;
+	}
+
+	public void setScheduler(Scheduler scheduler) {
+		this.scheduler = scheduler;
+	}
+
+	public Map getTriggers() {
+		return triggers;
+	}
+
+	public void setTriggers(Map triggers) {
+		this.triggers = triggers;
+	}
+
+	public QuartzMarshaler getMarshaler() {
+		return marshaler;
+	}
+
+	public void setMarshaler(QuartzMarshaler marshaler) {
+		this.marshaler = marshaler;
+	}
+
+	// Implementation methods
+	// -------------------------------------------------------------------------
+	public void init(ServiceContext context) throws JBIException {
+		this.serviceContext = context;
+		try {
+			if (scheduler == null) {
+				if (factory == null) {
+					factory = new StdSchedulerFactory();
+				}
+				scheduler = factory.getScheduler();
+			}
+		} catch (SchedulerException e) {
+			throw new JBIException(e);
+		}
+
+		if (triggers != null) {
+			for (Iterator iter = triggers.entrySet().iterator(); iter.hasNext();) {
+				Map.Entry entry = (Map.Entry) iter.next();
+				Object key = entry.getKey();
+				Object value = entry.getValue();
+				if (key == null) {
+					throw new IllegalArgumentException(
+							"Key of the map cannot be null");
+				}
+				if (value == null) {
+					throw new IllegalArgumentException(
+							"Key of the map cannot be null");
+				}
+				if (!(key instanceof Trigger)) {
+					throw new IllegalArgumentException(
+							"Key of the map must be a Trigger but was: "
+									+ key.getClass().getName());
+				}
+				if (!(value instanceof JobDetail)) {
+					throw new IllegalArgumentException(
+							"Key of the map must be a JobDetail but was: "
+									+ value.getClass().getName());
+				}
+				addTrigger((Trigger) key, (JobDetail) value);
+			}
+		}
+	}
+
+}

servicemix/tooling/example-client-quartz/src/main/java/org/servicemix/demo
DefaultQuartzMarshaler.java added at 1.1
diff -N DefaultQuartzMarshaler.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ DefaultQuartzMarshaler.java	18 Aug 2005 17:22:29 -0000	1.1
@@ -0,0 +1,80 @@
+/**
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * Licensed 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.servicemix.demo;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.dom.DOMSource;
+
+import org.quartz.JobDataMap;
+import org.quartz.JobDetail;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.servicemix.components.util.MarshalerSupport;
+import org.servicemix.jbi.util.DOMUtil;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * The default implementation of the Quartz marshaler
+ * 
+ * @version $Revision: 1.1 $
+ */
+public class DefaultQuartzMarshaler extends MarshalerSupport implements
+		QuartzMarshaler {
+	public static final String CONTEXT_KEY = "org.servicemix.quartz.context";
+
+	public static final String DETAIL_KEY = "org.servicemix.quartz.detail";
+
+	public void populateNormalizedMessage(NormalizedMessage message,
+			JobExecutionContext context) throws JobExecutionException,
+			MessagingException {
+		message.setProperty(CONTEXT_KEY, context);
+		JobDetail detail = context.getJobDetail();
+		message.setProperty(DETAIL_KEY, detail);
+
+		JobDataMap dataMap = detail.getJobDataMap();
+		for (Iterator iter = dataMap.entrySet().iterator(); iter.hasNext();) {
+			Map.Entry entry = (Map.Entry) iter.next();
+			String key = (String) entry.getKey();
+			Object value = entry.getValue();
+			message.setProperty(key, value);
+		}
+
+		try {
+			Document document = getTransformer().createDocument();
+			Element root = document.createElement("timer");
+			document.appendChild(root);
+			DOMUtil.addChildElement(root, "name", detail.getName());
+			DOMUtil.addChildElement(root, "group", detail.getGroup());
+			DOMUtil.addChildElement(root, "fullname", detail.getFullName());
+			DOMUtil.addChildElement(root, "description", detail
+					.getDescription());
+			DOMUtil.addChildElement(root, "fireTime", context.getFireTime());
+
+			message.setContent(new DOMSource(document));
+		} catch (ParserConfigurationException e) {
+			throw new MessagingException("Failed to create content: " + e, e);
+		}
+	}
+
+}

servicemix/tooling/example-client-quartz/src/main/java/org/servicemix/demo
ServiceMixJob.java added at 1.1
diff -N ServiceMixJob.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ServiceMixJob.java	18 Aug 2005 17:22:29 -0000	1.1
@@ -0,0 +1,38 @@
+/** 
+ * 
+ * Copyright 2005 LogicBlaze, Inc. http://www.logicblaze.com
+ * 
+ * Licensed 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.servicemix.demo;
+
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.servicemix.components.util.ComponentSupport;
+
+/**
+ * A Quartz Job which dispatches a message to a component.
+ *
+ * @version $Revision: 1.1 $
+ */
+public class ServiceMixJob implements Job {
+    public void execute(JobExecutionContext context) throws JobExecutionException {
+        QuartzComponent component = (QuartzComponent) context.getJobDetail().getJobDataMap().get(QuartzComponent.COMPONENT_KEY);
+        if (component == null) {
+            throw new JobExecutionException("No quartz JBI component available for key: " + QuartzComponent.COMPONENT_KEY + ". Bad job data map");
+        }
+        component.onJobExecute(context);
+    }
+}

servicemix/tooling/example-client-quartz
project.properties added at 1.1
diff -N project.properties
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ project.properties	18 Aug 2005 17:22:29 -0000	1.1
@@ -0,0 +1,5 @@
+#------------------------------------------------------------------
+# J B I   I N S T A L L E R    P R O P E R T I E S
+#------------------------------------------------------------------
+jbi.component.class.name=org.servicemix.client.SpringComponent
+#jbi.bootstrap.class.name=org.servicemix.client.SpringBootstrap
\ No newline at end of file

servicemix/tooling/example-client-quartz
project.xml added at 1.1
diff -N project.xml
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ project.xml	18 Aug 2005 17:22:29 -0000	1.1
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+	<pomVersion>2</pomVersion>
+	<name>ServiceMix Client Quartz Example</name>
+	<id>example-client-quartz</id>
+	<currentVersion>1.0</currentVersion>
+	<package>org.servicemix.demo</package>
+	<shortDescription>
+		This is an example of a simple quartz scheduler component
+		written using the ServiceMix Client infrastructure
+	</shortDescription>
+	<description>
+		This is an example of a simple quartz scheduler component
+		written using the ServiceMix Client infrastructure
+	</description>
+
+	<developers>
+		<developer>
+			<name>Philip Dodds</name>
+			<id>pdodds</id>
+			<email>[EMAIL PROTECTED]</email>
+			<organization>Unity Systems</organization>
+		</developer>
+	</developers>
+	
+	<dependencies>
+		<dependency>
+			<id>servicemix</id>
+			<version>1.0</version>
+			<type>jar</type>
+			<url>http://www.servicemix.org</url>
+		</dependency>
+		<dependency>
+			<groupId>servicemix</groupId>
+			<artifactId>jaxp</artifactId>
+			<version>1.3</version>
+		</dependency>
+		<dependency>
+			<groupId>mx4j</groupId>
+			<artifactId>mx4j-jmx</artifactId>
+			<version>2.1.1</version>
+		</dependency>
+		<dependency>
+			<groupId>commons-logging</groupId>
+			<artifactId>commons-logging</artifactId>
+			<version>1.0.3</version>
+			<url>http://jakarta.apache.org/commons/logging/</url>
+		</dependency>
+		<dependency>
+			<groupId>servicemix</groupId>
+			<artifactId>servicemix-client</artifactId>
+			<version>1.0-SNAPSHOT</version>
+			<properties>
+				<jbi.bundle>true</jbi.bundle>
+			</properties>
+		</dependency>
+		<dependency>
+			<id>quartz</id>
+			<version>1.4.0</version>
+			<properties>
+				<jbi.bundle>true</jbi.bundle>
+			</properties>
+		</dependency>
+	</dependencies>
+	<build>
+		<sourceDirectory>src/main/java</sourceDirectory>
+		<unitTestSourceDirectory>src/test/java</unitTestSourceDirectory>
+	</build>
+</project>

servicemix/tooling/example-client-quartz
.cvsignore added at 1.1
diff -N .cvsignore
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ .cvsignore	18 Aug 2005 17:22:29 -0000	1.1
@@ -0,0 +1,3 @@
+target
+.classpath
+.project

servicemix/tooling/example-client-quartz/src/main/jbi/META-INF
jbi-spring.xml added at 1.1
diff -N jbi-spring.xml
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ jbi-spring.xml	18 Aug 2005 17:22:29 -0000	1.1
@@ -0,0 +1,22 @@
+<beans>
+	<bean id="myQuartzService"
+		class="org.servicemix.demo.QuartzComponent">
+		<property name="triggers">
+			<map>
+				<entry>
+					<key>
+						<bean class="org.quartz.SimpleTrigger">
+							<property name="repeatInterval"
+								value="5000" />
+							<property name="repeatCount" value="-1" />
+						</bean>
+					</key>
+					<bean class="org.quartz.JobDetail">
+						<property name="name" value="My Example Job" />
+						<property name="group" value="ServiceMix" />
+					</bean>
+				</entry>
+			</map>
+		</property>
+	</bean>
+</beans>
\ No newline at end of file

servicemix/tooling/example-client-quartz/src/main/merge
services.xml added at 1.1
diff -N services.xml
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ services.xml	18 Aug 2005 17:22:29 -0000	1.1
@@ -0,0 +1,6 @@
+<services binding-component="false"
+	xmlns:quartz="http://tempuri.org/quartz"
+	xmlns:logger="http://tempuri.org/logger.wsdl">
+	<consumes interface-name="quartz:triggeredNotification"
+		service-name="logger:example" />
+</services>
\ No newline at end of file
CVSspam 0.2.8



Reply via email to