[jboss-svn-commits] JBL Code SVN: r22352 - in labs/jbossesb/workspace/skeagh: api/service/src/main/java/org/jboss/esb/message and 12 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Sep 3 08:46:48 EDT 2008
Author: tfennelly
Date: 2008-09-03 08:46:48 -0400 (Wed, 03 Sep 2008)
New Revision: 22352
Added:
labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/AssertDeployment.java
labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/DeploymentUnit.java
labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/
labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/AbstractScheduleListener.java
labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/CronSchedule.java
labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/JobScheduler.java
labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/Schedule.java
labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/ScheduleListener.java
labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/SchedulingException.java
labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/SimpleSchedule.java
labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/default-quartz.properties
labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/package.html
labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/
labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/JobSchedulerTest.java
labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/MockScheduledInboundRouter.java
labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/ScheduleListenerTest.java
labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/quartz-01.properties
labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/schedule-listener-01.xml
labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/schedule-listener-02.xml
labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/schedule-listener-03.xml
Removed:
labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/ConfigurationUnit.java
Modified:
labs/jbossesb/workspace/skeagh/api/routing/src/main/java/org/jboss/esb/routing/MessageDispatcher.java
labs/jbossesb/workspace/skeagh/api/service/src/main/java/org/jboss/esb/message/Message.java
labs/jbossesb/workspace/skeagh/commons/src/main/java/org/jboss/esb/classpath/ClassUtil.java
labs/jbossesb/workspace/skeagh/runtime/pom.xml
labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/DeploymentRuntime.java
labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/ConfigurationDigester.java
labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/DefaultConfigurationDigester.java
labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/SetProperty.java
labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/dispatch/LocalDispatcher.java
labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/DefaultConfigurationDigesterTest.java
labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/DeploymentLifecycleTest.java
labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/dispatch/HelloInboundRouter.java
labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/dispatch/LocalDispatcherTest.java
Log:
Added scheduling and AbstractScheduleListener
Modified: labs/jbossesb/workspace/skeagh/api/routing/src/main/java/org/jboss/esb/routing/MessageDispatcher.java
===================================================================
--- labs/jbossesb/workspace/skeagh/api/routing/src/main/java/org/jboss/esb/routing/MessageDispatcher.java 2008-09-03 11:50:44 UTC (rev 22351)
+++ labs/jbossesb/workspace/skeagh/api/routing/src/main/java/org/jboss/esb/routing/MessageDispatcher.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -20,6 +20,7 @@
package org.jboss.esb.routing;
import org.jboss.esb.message.Message;
+import org.jboss.esb.context.InvocationContext;
/**
* Message Dispatcher.
@@ -38,7 +39,8 @@
* Dispatch the message to the target service.
*
* @param message The message to be dispatched.
+ * @param invocationContext The InvocationContext for the message dispatch.
* @throws RoutingException An exception occured while dispatching the message.
*/
- void dispatch(Message message) throws RoutingException;
+ void dispatch(Message message, InvocationContext invocationContext) throws RoutingException;
}
Modified: labs/jbossesb/workspace/skeagh/api/service/src/main/java/org/jboss/esb/message/Message.java
===================================================================
--- labs/jbossesb/workspace/skeagh/api/service/src/main/java/org/jboss/esb/message/Message.java 2008-09-03 11:50:44 UTC (rev 22351)
+++ labs/jbossesb/workspace/skeagh/api/service/src/main/java/org/jboss/esb/message/Message.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -46,6 +46,22 @@
private Map<String, Object> attachments = new LinkedHashMap<String, Object>();
/**
+ * Public default constructor.
+ */
+ public Message()
+ {
+ }
+
+ /**
+ * Public default constructor.
+ * @param payload Message payload.
+ */
+ public Message(final Object payload)
+ {
+ this.payload = payload;
+ }
+
+ /**
* Get the primary payload Object.
*
* @return The primary payload Object.
Modified: labs/jbossesb/workspace/skeagh/commons/src/main/java/org/jboss/esb/classpath/ClassUtil.java
===================================================================
--- labs/jbossesb/workspace/skeagh/commons/src/main/java/org/jboss/esb/classpath/ClassUtil.java 2008-09-03 11:50:44 UTC (rev 22351)
+++ labs/jbossesb/workspace/skeagh/commons/src/main/java/org/jboss/esb/classpath/ClassUtil.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -328,6 +328,31 @@
}
/**
+ * Get the field value on the specified object instance.
+ *
+ * @param field The field to get.
+ * @param targetObject The object instance on which to get.
+ * @throws IllegalAccessException cannot access field.
+ */
+ public static Object getFieldValue(final Field field, final Object targetObject) throws IllegalAccessException
+ {
+ boolean isAccessible = field.isAccessible();
+
+ if (!isAccessible)
+ {
+ field.setAccessible(true);
+ }
+
+ try
+ {
+ return field.get(targetObject);
+ } finally
+ {
+ field.setAccessible(isAccessible);
+ }
+ }
+
+ /**
* Set the field value on the specified object instance.
*
* @param field The field to set.
@@ -363,7 +388,7 @@
*/
public static void setFieldValue(final Object targetObject, final String fieldName, final Object value) throws IllegalAccessException
{
- setFieldValue(targetObject, fieldName, value, value.getClass());
+ setFieldValue(targetObject, fieldName, value, targetObject.getClass());
}
/**
@@ -377,8 +402,9 @@
*/
private static void setFieldValue(final Object targetObject, final String fieldName, final Object value, final Class hierarchyClass) throws IllegalAccessException
{
- // Check all the fields in this class...
- Field[] fields = targetObject.getClass().getDeclaredFields();
+ // Check all the fields declared at the hierarchyClass level in
+ // the inheritance tree...
+ Field[] fields = hierarchyClass.getDeclaredFields();
for (Field field : fields)
{
if (field.getType() == value.getClass() && field.getName().equals(fieldName))
Modified: labs/jbossesb/workspace/skeagh/runtime/pom.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/pom.xml 2008-09-03 11:50:44 UTC (rev 22351)
+++ labs/jbossesb/workspace/skeagh/runtime/pom.xml 2008-09-03 12:46:48 UTC (rev 22352)
@@ -34,6 +34,11 @@
<artifactId>milyn-smooks-javabean</artifactId>
<version>1.1-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>quartz</groupId>
+ <artifactId>quartz</artifactId>
+ <version>1.5.2</version>
+ </dependency>
</dependencies>
<reporting>
Copied: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/AssertDeployment.java (from rev 22294, labs/jbossesb/workspace/skeagh/commons/src/main/java/org/jboss/esb/util/AssertArgument.java)
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/AssertDeployment.java (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/AssertDeployment.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.esb.deploy;
+
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * Deployment assertion utilities.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public abstract class AssertDeployment
+{
+ /**
+ * Private default constructor.
+ */
+ private AssertDeployment()
+ {
+ }
+
+ /**
+ * Assert that the property is not null.
+ *
+ * @param property Property.
+ * @param propertyName Property name.
+ * @return The supplied "property" argument.
+ * @throws IllegalStateException Property is null.
+ */
+ public static Object isNotNull(final Object property, final String propertyName) throws IllegalStateException
+ {
+ if (property == null)
+ {
+ throw new IllegalStateException("null '" + propertyName + "' property. Object not properly deployed. Property '" + propertyName + "' must be set.");
+ }
+ return property;
+ }
+}
\ No newline at end of file
Modified: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/DeploymentRuntime.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/DeploymentRuntime.java 2008-09-03 11:50:44 UTC (rev 22351)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/DeploymentRuntime.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -24,12 +24,13 @@
import org.jboss.esb.annotations.Uninitialize;
import org.jboss.esb.classpath.ClassUtil;
import org.jboss.esb.context.DeploymentContext;
-import org.jboss.esb.deploy.config.ConfigurationUnit;
+import org.jboss.esb.deploy.config.DeploymentUnit;
import org.jboss.esb.deploy.config.InboundRouterConfig;
import org.jboss.esb.deploy.config.OutboundRouterConfig;
import org.jboss.esb.deploy.config.ServiceConfig;
import org.jboss.esb.dispatch.LocalDispatcher;
import org.jboss.esb.message.MessageTransformer;
+import org.jboss.esb.schedule.JobScheduler;
import org.jboss.esb.service.Service;
import org.jboss.esb.service.ServiceName;
import org.jboss.esb.util.AssertArgument;
@@ -63,7 +64,7 @@
/**
* The list of configurations associated with this deployment instance.
*/
- private List<ConfigurationUnit> configurationUnits = new ArrayList<ConfigurationUnit>();
+ private List<DeploymentUnit> deploymentUnits = new ArrayList<DeploymentUnit>();
/**
* Deployed Objects Map.
*/
@@ -116,19 +117,19 @@
*
* @return The deployment configuration units.
*/
- public final List<ConfigurationUnit> getConfigurationUnits()
+ public final List<DeploymentUnit> getConfigurationUnits()
{
- return configurationUnits;
+ return deploymentUnits;
}
/**
* Set the deployment configuration units.
*
- * @param configurationUnits The deployment configuration units.
+ * @param deploymentUnits The deployment configuration units.
*/
- public final void setConfigurationUnits(final List<ConfigurationUnit> configurationUnits)
+ public final void setConfigurationUnits(final List<DeploymentUnit> deploymentUnits)
{
- this.configurationUnits = configurationUnits;
+ this.deploymentUnits = deploymentUnits;
}
/**
@@ -142,14 +143,14 @@
}
/**
- * Add a {@link ConfigurationUnit} to this Runtime.
+ * Add a {@link org.jboss.esb.deploy.config.DeploymentUnit} to this Runtime.
*
- * @param configuration Configuration Unit to be added.
+ * @param deployment Configuration Unit to be added.
*/
- public final void add(final ConfigurationUnit configuration)
+ public final void add(final DeploymentUnit deployment)
{
- AssertArgument.isNotNull(configuration, "configuration");
- configurationUnits.add(configuration);
+ AssertArgument.isNotNull(deployment, "deployment");
+ deploymentUnits.add(deployment);
}
/**
@@ -190,6 +191,8 @@
public final void undeploy() throws DeploymentException
{
logger.info("Starting JBoss ESB undeployment: '" + deploymentName + "'.");
+ // Make sure to undeploy the scheduler first i.e. block scheduled triggers...
+ undeploy(JobScheduler.SCHEDULER_RESOURCE_ID, JobScheduler.getScheduler(context));
// Undeploy any objects manually set in the ESB deployment context...
undeploy(context.getAll());
// Undeploy all objects that were deployed on ESB Startup...
@@ -211,29 +214,41 @@
objectMap.entrySet().toArray(deploymentSet);
for (int i = deploymentSet.length - 1; i >= 0; i--)
{
+ Object key = deploymentSet[i].getKey();
Object object = deploymentSet[i].getValue();
- // Keeping track of Objects as we undeploy them, so as not to
- // undeploy the same object twice...
- if (!undeployedObjects.contains(object))
- {
- try
- {
- ClassUtil.execAnnotatedMethod(object, Uninitialize.class);
- undeployedObjects.add(object);
- } catch (InvocationTargetException e)
- {
- logger.error("Error while undeploying '" + deploymentSet[i].getKey() + "' (" + deploymentSet[i].getValue().getClass().getName() + ").", e.getCause());
- } catch (Throwable t)
- {
- logger.error("Error while undeploying '" + deploymentSet[i].getKey() + "' (" + deploymentSet[i].getValue().getClass().getName() + ").", t);
- }
- }
+ undeploy(key, object);
}
}
}
/**
+ * Undeploy the supplied object.
+ *
+ * @param key Object deploment key.
+ * @param object Deployed object.
+ */
+ private void undeploy(final Object key, final Object object)
+ {
+ // Keeping track of Objects as we undeploy them, so as not to
+ // undeploy the same object twice...
+ if (!undeployedObjects.contains(object))
+ {
+ try
+ {
+ ClassUtil.execAnnotatedMethod(object, Uninitialize.class);
+ undeployedObjects.add(object);
+ } catch (InvocationTargetException e)
+ {
+ logger.error("Error while undeploying '" + key + "' (" + object.getClass().getName() + ").", e.getCause());
+ } catch (Throwable t)
+ {
+ logger.error("Error while undeploying '" + key + "' (" + object.getClass().getName() + ").", t);
+ }
+ }
+ }
+
+ /**
* Deploy all resources.
*
* @throws DeploymentException Error deploying a resource.
@@ -242,31 +257,57 @@
{
Map<String, Object> deployedResources = new LinkedHashMap<String, Object>();
- for (ConfigurationUnit configurationUnit : configurationUnits)
+ // Expose the deployed resources via the DeploymentContext...
+ context.setResources(deployedResources);
+
+ for (DeploymentUnit deploymentUnit : deploymentUnits)
{
- Map<String, Object> resourceMap = configurationUnit.getResources();
+ Map<String, Object> resourceMap = deploymentUnit.getResources();
+
+ // Make sure we deploy the JobScheduler resource before deploying any
+ // other resources...
+ JobScheduler scheduler = (JobScheduler) resourceMap.get(JobScheduler.SCHEDULER_RESOURCE_ID);
+ if (scheduler == null)
+ {
+ scheduler = new JobScheduler();
+ }
+ deployResource(JobScheduler.SCHEDULER_RESOURCE_ID, scheduler, deployedResources);
+
+ // Now deploy the other resources...
Set<Map.Entry<String, Object>> resources = resourceMap.entrySet();
-
for (Map.Entry<String, Object> resource : resources)
{
- try
- {
- deployObject(resource.getValue(), null);
- logger.debug("Deployed resource '" + resource.getKey() + "' (" + resource.getValue().getClass().getName() + ").");
- deployedObjects.put(resource.getKey(), resource.getValue());
- deployedResources.put(resource.getKey(), resource.getValue());
- } catch (InvocationTargetException e)
- {
- throw new DeploymentException("Unable to deploy resource '" + resource.getKey() + "' (" + resource.getValue().getClass().getName() + ").", e.getCause());
- } catch (Exception e)
- {
- throw new DeploymentException("Unable to deploy resource '" + resource.getKey() + "' (" + resource.getValue().getClass().getName() + ").", e);
- }
+ deployResource(resource.getKey(), resource.getValue(), deployedResources);
}
}
+ }
- // Expose the deployed resources via the DeploymentContext...
- context.setResources(deployedResources);
+ /**
+ * Deploy resource.
+ *
+ * @param key Resource key.
+ * @param resource Resource object instance.
+ * @param deployedResources The list of already deployed resources.
+ * @throws DeploymentException Unable to deploy resource.
+ */
+ private void deployResource(final String key, final Object resource, final Map<String, Object> deployedResources) throws DeploymentException
+ {
+ if (!deployedObjects.containsValue(resource))
+ {
+ try
+ {
+ deployObject(resource, key, null);
+ logger.debug("Deployed resource '" + key + "' (" + resource.getClass().getName() + ").");
+ deployedObjects.put(key, resource);
+ deployedResources.put(key, resource);
+ } catch (InvocationTargetException e)
+ {
+ throw new DeploymentException("Unable to deploy resource '" + key + "' (" + resource.getClass().getName() + ").", e.getCause());
+ } catch (Exception e)
+ {
+ throw new DeploymentException("Unable to deploy resource '" + key + "' (" + resource.getClass().getName() + ").", e);
+ }
+ }
}
/**
@@ -276,16 +317,16 @@
*/
private void deployServices() throws DeploymentException
{
- for (ConfigurationUnit configurationUnit : configurationUnits)
+ for (DeploymentUnit deploymentUnit : deploymentUnits)
{
- Map<ServiceName, ServiceConfig> serviceMap = configurationUnit.getServices();
+ Map<ServiceName, ServiceConfig> serviceMap = deploymentUnit.getServices();
Set<Map.Entry<ServiceName, ServiceConfig>> services = serviceMap.entrySet();
for (Map.Entry<ServiceName, ServiceConfig> service : services)
{
try
{
- deployObject(service.getValue().getService(), service.getKey());
+ deployObject(service.getValue().getService(), null, service.getKey());
logger.debug("Deployed service '" + service.getKey() + "' (" + service.getValue().getClass().getName() + ").");
deployedObjects.put(service.getKey(), service.getValue().getService());
} catch (InvocationTargetException e)
@@ -306,9 +347,9 @@
*/
private void deployInboundRouters() throws DeploymentException
{
- for (ConfigurationUnit configurationUnit : configurationUnits)
+ for (DeploymentUnit deploymentUnit : deploymentUnits)
{
- Map<ServiceName, List<InboundRouterConfig>> routerMap = configurationUnit.getInboundRouters();
+ Map<ServiceName, List<InboundRouterConfig>> routerMap = deploymentUnit.getInboundRouters();
Set<Map.Entry<ServiceName, List<InboundRouterConfig>>> routers = routerMap.entrySet();
for (Map.Entry<ServiceName, List<InboundRouterConfig>> routerConfigMap : routers)
@@ -326,14 +367,14 @@
// Create a dispatcher and hook it into the inRouter...
LocalDispatcher dispatcher = new LocalDispatcher(context);
dispatcher.setServiceName(serviceName);
- dispatcher.setService(getService(configurationUnit, serviceName));
+ dispatcher.setService(getService(deploymentUnit, serviceName));
dispatcher.setTransformers(routerConfig.getTransformers());
- dispatcher.setOutboundRouters(configurationUnit.getOutboundRouters().get(serviceName));
+ dispatcher.setOutboundRouters(deploymentUnit.getOutboundRouters().get(serviceName));
dispatcher.initialize();
routerConfig.getRouter().setDispatcher(dispatcher);
// Now deploy the router...
- deployObject(routerConfig.getRouter(), serviceName);
+ deployObject(routerConfig.getRouter(), routerConfig.getName(), serviceName);
logger.debug("Deployed InboundRouter '" + routerConfig.getName() + "' (" + routerConfig.getRouter().getClass().getName() + ").");
deployedObjects.put(routerConfig.getName(), routerConfig.getRouter());
} catch (InvocationTargetException e)
@@ -349,15 +390,15 @@
}
/**
- * Get the named Service instance from the specified {@link ConfigurationUnit}.
+ * Get the named Service instance from the specified {@link org.jboss.esb.deploy.config.DeploymentUnit}.
*
- * @param configurationUnit The configuration unit.
+ * @param deploymentUnit The configuration unit.
* @param serviceName The ServiceName.
* @return The Service.
*/
- private Service getService(final ConfigurationUnit configurationUnit, final ServiceName serviceName)
+ private Service getService(final DeploymentUnit deploymentUnit, final ServiceName serviceName)
{
- ServiceConfig serviceConfig = configurationUnit.getServices().get(serviceName);
+ ServiceConfig serviceConfig = deploymentUnit.getServices().get(serviceName);
if (serviceConfig != null)
{
return serviceConfig.getService();
@@ -372,9 +413,9 @@
*/
private void deployOutboundRouters() throws DeploymentException
{
- for (ConfigurationUnit configurationUnit : configurationUnits)
+ for (DeploymentUnit deploymentUnit : deploymentUnits)
{
- Map<ServiceName, List<OutboundRouterConfig>> routerMap = configurationUnit.getOutboundRouters();
+ Map<ServiceName, List<OutboundRouterConfig>> routerMap = deploymentUnit.getOutboundRouters();
Set<Map.Entry<ServiceName, List<OutboundRouterConfig>>> routers = routerMap.entrySet();
for (Map.Entry<ServiceName, List<OutboundRouterConfig>> routerConfigMap : routers)
@@ -388,7 +429,7 @@
deployTransformers(routerConfigMap.getKey(), routerConfig.getTransformers(), routerConfig.getName());
// Now deploy the router...
- deployObject(routerConfig.getRouter(), routerConfigMap.getKey());
+ deployObject(routerConfig.getRouter(), routerConfig.getName(), routerConfigMap.getKey());
logger.debug("Deployed OutboundRouter '" + routerConfig.getName() + "' (" + routerConfig.getRouter().getClass().getName() + ").");
deployedObjects.put(routerConfig.getName(), routerConfig.getRouter());
} catch (InvocationTargetException e)
@@ -409,8 +450,9 @@
* @param serviceName The service with which the transformer set is associated.
* @param transformers The transformer list.
* @param routerConfigName The name of the owning router. @throws DeploymentException Error deploying transformers.
+ * @throws DeploymentException Error deploying transformers.
*/
- private void deployTransformers(ServiceName serviceName, final List<MessageTransformer> transformers, final String routerConfigName) throws DeploymentException
+ private void deployTransformers(final ServiceName serviceName, final List<MessageTransformer> transformers, final String routerConfigName) throws DeploymentException
{
if (transformers != null)
{
@@ -418,7 +460,7 @@
{
try
{
- deployObject(transformer, serviceName);
+ deployObject(transformer, null, serviceName);
logger.debug("Deployed transformer for router '" + routerConfigName + "' (" + transformer.getClass().getName() + ").");
deployedObjects.put(transformer, transformer);
} catch (InvocationTargetException e)
@@ -436,13 +478,20 @@
* Deploy the specified object.
*
* @param object The Object to be deployed.
+ * @param serviceName The name of the service for which the object is being deployed, or null if the
+ * object is not associated with a service.
* @throws InvocationTargetException Exception during object deployment.
* @throws IllegalAccessException Unable to invoke initialize method on object.
*/
- private void deployObject(final Object object, final ServiceName serviceName) throws InvocationTargetException, IllegalAccessException
+ private void deployObject(final Object object, final String objectName, final ServiceName serviceName) throws InvocationTargetException, IllegalAccessException
{
// Set the deployment context on the object, if specified...
ClassUtil.setFieldValue(object, "deploymentContext", context);
+ if (objectName != null)
+ {
+ // If supplied, set the "objectName" on the object...
+ ClassUtil.setFieldValue(object, "objectName", objectName);
+ }
if (serviceName != null)
{
// If supplied, set the ServiceName on the object...
@@ -459,7 +508,7 @@
*/
private void assertConfigurationsAdded() throws DeploymentException
{
- if (configurationUnits.isEmpty())
+ if (deploymentUnits.isEmpty())
{
throw new DeploymentException("DeploymentRuntime not yet configured. Unable to deploy.");
}
Deleted: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/ConfigurationUnit.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/ConfigurationUnit.java 2008-09-03 11:50:44 UTC (rev 22351)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/ConfigurationUnit.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -1,187 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright XXXX, Red Hat Middleware LLC, and others contributors as indicated
- * by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * (C) 2005-2008, JBoss Inc.
- */
-package org.jboss.esb.deploy.config;
-
-import org.jboss.esb.service.ServiceName;
-import org.jboss.esb.util.AssertArgument;
-
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * JBoss ESB Deployment Configuration Unit.
- *
- * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
- */
-public class ConfigurationUnit
-{
- /**
- * List of deployment resource objects.
- */
- private Map<String, Object> resources = new LinkedHashMap<String, Object>();
- /**
- * List of Inbound routers defined in the configuration.
- */
- private Map<ServiceName, List<InboundRouterConfig>> inboundRouters = new LinkedHashMap<ServiceName, List<InboundRouterConfig>>();
- /**
- * List of Services defined in the configuration.
- */
- private Map<ServiceName, ServiceConfig> services = new LinkedHashMap<ServiceName, ServiceConfig>();
- /**
- * List of Outbound routers defined in the configuration.
- */
- private Map<ServiceName, List<OutboundRouterConfig>> outboundRouters = new LinkedHashMap<ServiceName, List<OutboundRouterConfig>>();
-
- /**
- * Add an inbounder router for a service.
- *
- * @param id The resource ID.
- * @param resource The resource.
- */
- public final void addResource(final String id, final Object resource)
- {
- AssertArgument.isNotNull(id, "id");
- AssertArgument.isNotNull(resource, "resource");
- resources.put(id, resource);
- }
-
- /**
- * Get the list of resources associated with this deployment configuration unit (mapped by id).
- *
- * @return The list of resources associated with this deployment configuration unit.
- */
- public final Map<String, Object> getResources()
- {
- return resources;
- }
-
- /**
- * Get the List of Inbound routers defined in the configuration (mapped by ServiceName).
- *
- * @return The List of Inbound routers defined in the configuration.
- */
- public final Map<ServiceName, List<InboundRouterConfig>> getInboundRouters()
- {
- return inboundRouters;
- }
-
- /**
- * Get the named InboundRouterConfig from the specified service.
- *
- * @param service The service name.
- * @param configName The configuration name.
- * @return The router configuration, or null if no such router is
- * specified.
- */
- public final InboundRouterConfig getInboundRouter(final ServiceName service, final String configName)
- {
- List<InboundRouterConfig> inboundRouterList = inboundRouters.get(service);
-
- if (inboundRouterList != null)
- {
- for (InboundRouterConfig inboundRouterConfig : inboundRouterList)
- {
- if (configName.equals(inboundRouterConfig.getName()))
- {
- return inboundRouterConfig;
- }
- }
- }
-
- return null;
- }
-
- /**
- * Get the List of Inbound routers defined in the configuration (mapped by ServiceName).
- *
- * @param inboundRouters The List of Inbound routers defined in the configuration.
- */
- public final void setInboundRouters(final Map<ServiceName, List<InboundRouterConfig>> inboundRouters)
- {
- this.inboundRouters = inboundRouters;
- }
-
- /**
- * Get the List of Services defined in the configuration (mapped by ServiceName).
- *
- * @return The List of Services defined in the configuration.
- */
- public final Map<ServiceName, ServiceConfig> getServices()
- {
- return services;
- }
-
- /**
- * Get the List of Services defined in the configuration (mapped by ServiceName).
- *
- * @param services The List of Services defined in the configuration.
- */
- public final void setServices(final Map<ServiceName, ServiceConfig> services)
- {
- this.services = services;
- }
-
- /**
- * Get the List of Outbound routers defined in the configuration (mapped by ServiceName).
- *
- * @return The List of Outbound routers defined in the configuration.
- */
- public final Map<ServiceName, List<OutboundRouterConfig>> getOutboundRouters()
- {
- return outboundRouters;
- }
-
- /**
- * Get the named OutboundRouterConfig from the specified service.
- *
- * @param service The service name.
- * @param configName The configuration name.
- * @return The router configuration, or null if no such router is
- * specified.
- */
- public final OutboundRouterConfig getOutboundRouter(final ServiceName service, final String configName)
- {
- List<OutboundRouterConfig> outboundRouterList = outboundRouters.get(service);
-
- if (outboundRouterList != null)
- {
- for (OutboundRouterConfig outboundRouterConfig : outboundRouterList)
- {
- if (configName.equals(outboundRouterConfig.getName()))
- {
- return outboundRouterConfig;
- }
- }
- }
-
- return null;
- }
-
- /**
- * Set the List of Outbound routers defined in the configuration (mapped by ServiceName).
- *
- * @param outboundRouters The List of Outbound routers defined in the configuration.
- */
- public final void setOutboundRouters(final Map<ServiceName, List<OutboundRouterConfig>> outboundRouters)
- {
- this.outboundRouters = outboundRouters;
- }
-}
Copied: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/DeploymentUnit.java (from rev 22294, labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/ConfigurationUnit.java)
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/DeploymentUnit.java (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/DeploymentUnit.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -0,0 +1,187 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.esb.deploy.config;
+
+import org.jboss.esb.service.ServiceName;
+import org.jboss.esb.util.AssertArgument;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * JBoss ESB Deployment Configuration Unit.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class DeploymentUnit
+{
+ /**
+ * List of deployment resource objects.
+ */
+ private Map<String, Object> resources = new LinkedHashMap<String, Object>();
+ /**
+ * List of Inbound routers defined in the configuration.
+ */
+ private Map<ServiceName, List<InboundRouterConfig>> inboundRouters = new LinkedHashMap<ServiceName, List<InboundRouterConfig>>();
+ /**
+ * List of Services defined in the configuration.
+ */
+ private Map<ServiceName, ServiceConfig> services = new LinkedHashMap<ServiceName, ServiceConfig>();
+ /**
+ * List of Outbound routers defined in the configuration.
+ */
+ private Map<ServiceName, List<OutboundRouterConfig>> outboundRouters = new LinkedHashMap<ServiceName, List<OutboundRouterConfig>>();
+
+ /**
+ * Add an inbounder router for a service.
+ *
+ * @param id The resource ID.
+ * @param resource The resource.
+ */
+ public final void addResource(final String id, final Object resource)
+ {
+ AssertArgument.isNotNull(id, "id");
+ AssertArgument.isNotNull(resource, "resource");
+ resources.put(id, resource);
+ }
+
+ /**
+ * Get the list of resources associated with this deployment configuration unit (mapped by id).
+ *
+ * @return The list of resources associated with this deployment configuration unit.
+ */
+ public final Map<String, Object> getResources()
+ {
+ return resources;
+ }
+
+ /**
+ * Get the List of Inbound routers defined in the configuration (mapped by ServiceName).
+ *
+ * @return The List of Inbound routers defined in the configuration.
+ */
+ public final Map<ServiceName, List<InboundRouterConfig>> getInboundRouters()
+ {
+ return inboundRouters;
+ }
+
+ /**
+ * Get the named InboundRouterConfig from the specified service.
+ *
+ * @param service The service name.
+ * @param configName The configuration name.
+ * @return The router configuration, or null if no such router is
+ * specified.
+ */
+ public final InboundRouterConfig getInboundRouter(final ServiceName service, final String configName)
+ {
+ List<InboundRouterConfig> inboundRouterList = inboundRouters.get(service);
+
+ if (inboundRouterList != null)
+ {
+ for (InboundRouterConfig inboundRouterConfig : inboundRouterList)
+ {
+ if (configName.equals(inboundRouterConfig.getName()))
+ {
+ return inboundRouterConfig;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Get the List of Inbound routers defined in the configuration (mapped by ServiceName).
+ *
+ * @param inboundRouters The List of Inbound routers defined in the configuration.
+ */
+ public final void setInboundRouters(final Map<ServiceName, List<InboundRouterConfig>> inboundRouters)
+ {
+ this.inboundRouters = inboundRouters;
+ }
+
+ /**
+ * Get the List of Services defined in the configuration (mapped by ServiceName).
+ *
+ * @return The List of Services defined in the configuration.
+ */
+ public final Map<ServiceName, ServiceConfig> getServices()
+ {
+ return services;
+ }
+
+ /**
+ * Get the List of Services defined in the configuration (mapped by ServiceName).
+ *
+ * @param services The List of Services defined in the configuration.
+ */
+ public final void setServices(final Map<ServiceName, ServiceConfig> services)
+ {
+ this.services = services;
+ }
+
+ /**
+ * Get the List of Outbound routers defined in the configuration (mapped by ServiceName).
+ *
+ * @return The List of Outbound routers defined in the configuration.
+ */
+ public final Map<ServiceName, List<OutboundRouterConfig>> getOutboundRouters()
+ {
+ return outboundRouters;
+ }
+
+ /**
+ * Get the named OutboundRouterConfig from the specified service.
+ *
+ * @param service The service name.
+ * @param configName The configuration name.
+ * @return The router configuration, or null if no such router is
+ * specified.
+ */
+ public final OutboundRouterConfig getOutboundRouter(final ServiceName service, final String configName)
+ {
+ List<OutboundRouterConfig> outboundRouterList = outboundRouters.get(service);
+
+ if (outboundRouterList != null)
+ {
+ for (OutboundRouterConfig outboundRouterConfig : outboundRouterList)
+ {
+ if (configName.equals(outboundRouterConfig.getName()))
+ {
+ return outboundRouterConfig;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Set the List of Outbound routers defined in the configuration (mapped by ServiceName).
+ *
+ * @param outboundRouters The List of Outbound routers defined in the configuration.
+ */
+ public final void setOutboundRouters(final Map<ServiceName, List<OutboundRouterConfig>> outboundRouters)
+ {
+ this.outboundRouters = outboundRouters;
+ }
+}
Property changes on: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/DeploymentUnit.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/ConfigurationDigester.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/ConfigurationDigester.java 2008-09-03 11:50:44 UTC (rev 22351)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/ConfigurationDigester.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -20,7 +20,7 @@
package org.jboss.esb.deploy.config.digest;
import org.jboss.esb.deploy.DeploymentException;
-import org.jboss.esb.deploy.config.ConfigurationUnit;
+import org.jboss.esb.deploy.config.DeploymentUnit;
import java.io.IOException;
import java.io.Reader;
@@ -41,12 +41,12 @@
/**
* Digest the supplied configuration stream.
* <p/>
- * Produces a {@link org.jboss.esb.deploy.config.ConfigurationUnit} that can be added to a {@link org.jboss.esb.deploy.DeploymentRuntime}.
+ * Produces a {@link org.jboss.esb.deploy.config.DeploymentUnit} that can be added to a {@link org.jboss.esb.deploy.DeploymentRuntime}.
*
* @param configStream The configuration Stream.
* @return A configuration unit.
* @throws IOException Error reading the configuration stream.
* @throws DeploymentException Error in the supplied configuration data.
*/
- ConfigurationUnit digest(final Reader configStream) throws IOException, DeploymentException;
+ DeploymentUnit digest(final Reader configStream) throws IOException, DeploymentException;
}
Modified: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/DefaultConfigurationDigester.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/DefaultConfigurationDigester.java 2008-09-03 11:50:44 UTC (rev 22351)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/DefaultConfigurationDigester.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -21,7 +21,7 @@
import org.jboss.esb.deploy.DeploymentException;
import org.jboss.esb.deploy.DeploymentResource;
-import org.jboss.esb.deploy.config.ConfigurationUnit;
+import org.jboss.esb.deploy.config.DeploymentUnit;
import org.jboss.esb.deploy.config.InboundRouterConfig;
import org.jboss.esb.deploy.config.OutboundRouterConfig;
import org.jboss.esb.deploy.config.ServiceConfig;
@@ -56,14 +56,14 @@
/**
* Digest the supplied configuration stream.
* <p/>
- * Produces a {@link org.jboss.esb.deploy.config.ConfigurationUnit} that can be added to a {@link org.jboss.esb.deploy.DeploymentRuntime}.
+ * Produces a {@link org.jboss.esb.deploy.config.DeploymentUnit} that can be added to a {@link org.jboss.esb.deploy.DeploymentRuntime}.
*
* @param configStream The configuration Stream.
* @return A configuration unit.
* @throws IOException Error reading the configuration stream.
* @throws DeploymentException Error in the supplied configuration data.
*/
- public final ConfigurationUnit digest(final InputStream configStream) throws IOException, DeploymentException
+ public final DeploymentUnit digest(final InputStream configStream) throws IOException, DeploymentException
{
AssertArgument.isNotNull(configStream, "configStream");
return digest(new InputStreamReader(configStream));
@@ -72,14 +72,14 @@
/**
* Digest the supplied configuration stream.
* <p/>
- * Produces a {@link ConfigurationUnit} that can be added to a {@link org.jboss.esb.deploy.DeploymentRuntime}.
+ * Produces a {@link org.jboss.esb.deploy.config.DeploymentUnit} that can be added to a {@link org.jboss.esb.deploy.DeploymentRuntime}.
*
* @param configStream The configuration Stream.
* @return A configuration unit.
* @throws IOException Error reading the configuration stream.
* @throws DeploymentException Error in the supplied configuration data.
*/
- public final ConfigurationUnit digest(final Reader configStream) throws IOException, DeploymentException
+ public final DeploymentUnit digest(final Reader configStream) throws IOException, DeploymentException
{
AssertArgument.isNotNull(configStream, "configStream");
@@ -104,7 +104,7 @@
* @throws SAXException Error digesting document.
* @throws DeploymentException Error in the supplied configuration data.
*/
- private ConfigurationUnit digest(final Document configDoc) throws SAXException, DeploymentException
+ private DeploymentUnit digest(final Document configDoc) throws SAXException, DeploymentException
{
XsdDOMValidator validator = new XsdDOMValidator(configDoc);
@@ -123,8 +123,8 @@
}
// It's a valid configuration, so lets extract the resources, routers (in/out) and services from it
- // and create a ConfigurationUnit ...
- ConfigurationUnit configurationtUnit = new ConfigurationUnit();
+ // and create a DeploymentUnit ...
+ DeploymentUnit configurationtUnit = new DeploymentUnit();
digestResources(configDoc, configurationtUnit);
digestRouters(configDoc, configurationtUnit);
@@ -140,7 +140,7 @@
* @param configurationtUnit The configuration unit to which the resources are to be added.
* @throws DeploymentException Error in the supplied configuration data.
*/
- private void digestResources(final Document configDoc, final ConfigurationUnit configurationtUnit) throws DeploymentException
+ private void digestResources(final Document configDoc, final DeploymentUnit configurationtUnit) throws DeploymentException
{
NodeList resourcesNodeList = configDoc.getElementsByTagName("resources");
@@ -176,7 +176,7 @@
* @param configurationtUnit The configuration unit to which the routers are to be added.
* @throws DeploymentException Error in the supplied configuration data.
*/
- private void digestRouters(final Document configDoc, final ConfigurationUnit configurationtUnit) throws DeploymentException
+ private void digestRouters(final Document configDoc, final DeploymentUnit configurationtUnit) throws DeploymentException
{
NodeList routingNodeList = configDoc.getElementsByTagName("routing");
@@ -204,7 +204,7 @@
* @param inRoutersNodeList The inRouters DOM node tree.
* @throws DeploymentException Error in the supplied configuration data.
*/
- private void digestInRouters(final ConfigurationUnit configurationtUnit, final NodeList inRoutersNodeList) throws DeploymentException
+ private void digestInRouters(final DeploymentUnit configurationtUnit, final NodeList inRoutersNodeList) throws DeploymentException
{
int inRoutersCount = inRoutersNodeList.getLength();
Map<ServiceName, List<InboundRouterConfig>> inboundRouters = new LinkedHashMap<ServiceName, List<InboundRouterConfig>>();
@@ -241,7 +241,7 @@
* @param outRoutersNodeList The outRouters DOM node tree.
* @throws DeploymentException Error in the supplied configuration data.
*/
- private void digestOutRouters(final ConfigurationUnit configurationtUnit, final NodeList outRoutersNodeList) throws DeploymentException
+ private void digestOutRouters(final DeploymentUnit configurationtUnit, final NodeList outRoutersNodeList) throws DeploymentException
{
int outRoutersCount = outRoutersNodeList.getLength();
Map<ServiceName, List<OutboundRouterConfig>> outboundRouters = new LinkedHashMap<ServiceName, List<OutboundRouterConfig>>();
@@ -278,7 +278,7 @@
* @param configurationtUnit The configuration unit to which the Services are to be added.
* @throws DeploymentException Error in the supplied configuration data.
*/
- private void digestServices(final Document configDoc, final ConfigurationUnit configurationtUnit) throws DeploymentException
+ private void digestServices(final Document configDoc, final DeploymentUnit configurationtUnit) throws DeploymentException
{
NodeList servicesNodeList = configDoc.getElementsByTagName("services");
Modified: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/SetProperty.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/SetProperty.java 2008-09-03 11:50:44 UTC (rev 22351)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/deploy/config/digest/SetProperty.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -19,6 +19,7 @@
*/
package org.jboss.esb.deploy.config.digest;
+import org.jboss.esb.classpath.ClassUtil;
import org.milyn.SmooksException;
import org.milyn.cdr.annotation.ConfigParam;
import org.milyn.container.ExecutionContext;
@@ -27,9 +28,10 @@
import org.milyn.javabean.repository.BeanRepositoryManager;
import org.milyn.xml.DomUtils;
import org.w3c.dom.Element;
-import org.jboss.esb.classpath.ClassUtil;
import java.lang.reflect.Field;
+import java.util.Map;
+import java.util.Properties;
/**
* Set the value of a property of a bean (from the Smooks bean repository).
@@ -76,19 +78,28 @@
Object instance = getObject(executionContext);
Class objectClass = instance.getClass();
String propertyName = getPropertyName(element);
+ String value = getPropertyValue(element);
- try
+ if (instance instanceof Map)
{
- Field field = getPropertyField(propertyName, objectClass);
- String value = getPropertyValue(element);
-
- setPropertyValue(field, instance, value);
- } catch (NoSuchFieldException e)
+ ((Map) instance).put(propertyName, value);
+ } else
{
- throw new SmooksException("Property '" + propertyName + "' unknown on class '" + objectClass + "' (or super class).", e);
- } catch (IllegalAccessException e)
- {
- throw new SmooksException("Property '" + propertyName + "' cannot be set on class '" + objectClass + "'.", e);
+ try
+ {
+ Field field = getPropertyField(propertyName, objectClass);
+ setPropertyValue(field, instance, value);
+ } catch (NoSuchFieldException e)
+ {
+ if (!attemptPropertiesFieldSet(instance, propertyName, value))
+ {
+ // Throw the original exception...
+ throw new SmooksException("Property '" + propertyName + "' unknown on class '" + objectClass + "' (or super class).", e);
+ }
+ } catch (IllegalAccessException e)
+ {
+ throw new SmooksException("Property '" + propertyName + "' cannot be set on class '" + objectClass + "'.", e);
+ }
}
}
@@ -109,6 +120,43 @@
}
/**
+ * Attempt to set the property value on a "properties" field (type {@link Properties})
+ * on the object, if such a field exists.
+ *
+ * @param instance The object instance.
+ * @param propertyName The property name.
+ * @param value The property value.
+ * @return True if the property was successfully set, otherwise false.
+ */
+ private boolean attemptPropertiesFieldSet(final Object instance, final String propertyName, final String value)
+ {
+ try
+ {
+ Class objectClass = instance.getClass();
+ Field field = getPropertyField("properties", objectClass);
+
+ if (Properties.class.isAssignableFrom(field.getType()))
+ {
+ Properties properties = (Properties) ClassUtil.getFieldValue(field, instance);
+ if (properties == null)
+ {
+ properties = new Properties();
+ ClassUtil.setFieldValue(field, instance, properties);
+ }
+ properties.put(propertyName, value);
+ return true;
+ }
+ } catch (NoSuchFieldException e1)
+ {
+ // Ignore... fall through...
+ } catch (IllegalAccessException e1)
+ {
+ // Ignore... fall through...
+ }
+ return false;
+ }
+
+ /**
* Get the {@link Field} for the specified property of the specified class.
*
* @param propertyName The property name.
Modified: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/dispatch/LocalDispatcher.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/dispatch/LocalDispatcher.java 2008-09-03 11:50:44 UTC (rev 22351)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/dispatch/LocalDispatcher.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -19,9 +19,9 @@
*/
package org.jboss.esb.dispatch;
+import org.jboss.esb.context.AddressingContext;
import org.jboss.esb.context.DeploymentContext;
import org.jboss.esb.context.InvocationContext;
-import org.jboss.esb.context.AddressingContext;
import org.jboss.esb.deploy.config.OutboundRouterConfig;
import org.jboss.esb.message.Message;
import org.jboss.esb.message.MessageTransformationException;
@@ -31,6 +31,7 @@
import org.jboss.esb.service.Service;
import org.jboss.esb.service.ServiceException;
import org.jboss.esb.service.ServiceName;
+import org.jboss.esb.util.AssertArgument;
import java.util.List;
@@ -109,13 +110,16 @@
* the Service, takes back the Service result and passes to the
* outbound routers.
*
- * @param message The message to be dispatched.
+ * @param message The message to be dispatched.
+ * @param invocationContext The InvocationContext for the message dispatch.
* @throws RoutingException Error dispatching message.
*/
- public final void dispatch(final Message message) throws RoutingException
+ public final void dispatch(final Message message, final InvocationContext invocationContext) throws RoutingException
{
+ AssertArgument.isNotNull(message, "message");
+ AssertArgument.isNotNull(invocationContext, "invocationContext");
+
Message outMessage;
-
DeploymentContext.setContext(deploymentContext);
try
{
@@ -125,8 +129,7 @@
AddressingContext.setContext(addressingContext);
try
{
- // TODO: The inbound router should have access to the InvocationContext
- InvocationContext.setContext(new InvocationContext());
+ InvocationContext.setContext(invocationContext);
try
{
applyInboundTransforms(message);
Added: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/AbstractScheduleListener.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/AbstractScheduleListener.java (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/AbstractScheduleListener.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -0,0 +1,130 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.esb.schedule;
+
+import org.jboss.esb.annotations.Initialize;
+import org.jboss.esb.context.DeploymentContext;
+import org.jboss.esb.deploy.AssertDeployment;
+
+/**
+ * Abstract {@link ScheduleListener}.
+ * <p/>
+ * This abstract implementation registers the listener implementation with the
+ * {@link JobScheduler} associated with the deployment context. The schedule
+ * instance is looked up based on the config property named "scheduleResourceId".
+ * See {@link JobScheduler#addScheduleListener(ScheduleListener, String, String, org.jboss.esb.context.DeploymentContext)}.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public abstract class AbstractScheduleListener implements ScheduleListener
+{
+ /**
+ * The objectName of the listener.
+ */
+ private String objectName;
+ /**
+ * Deployment context.
+ */
+ private DeploymentContext deploymentContext;
+ /**
+ * The scheduleResourceId of the listener.
+ */
+ private String scheduleResourceId;
+
+ /**
+ * Register the ScheduleListener instance with the {@link org.jboss.esb.schedule.JobScheduler}.
+ */
+ @Initialize
+ public final void registerListener() throws SchedulingException
+ {
+ AssertDeployment.isNotNull(objectName, "objectName");
+ AssertDeployment.isNotNull(deploymentContext, "deploymentContext");
+ AssertDeployment.isNotNull(scheduleResourceId, "scheduleResourceId");
+
+ JobScheduler.addScheduleListener(this, objectName, scheduleResourceId, deploymentContext);
+ }
+
+ /**
+ * On schedule event processor.
+ *
+ * @throws SchedulingException Exception processing schedule event.
+ */
+ public abstract void onSchedule() throws SchedulingException;
+
+ /**
+ * Get the listener object name.
+ *
+ * @return The listener object name.
+ */
+ public String getObjectName()
+ {
+ return objectName;
+ }
+
+ /**
+ * Set the listener object name.
+ *
+ * @param objectName The listener object name.
+ */
+ public void setObjectName(String objectName)
+ {
+ this.objectName = objectName;
+ }
+
+ /**
+ * Get the DeploymentContext with which this object is a associated.
+ *
+ * @return The DeploymentContext.
+ */
+ public DeploymentContext getDeploymentContext()
+ {
+ return deploymentContext;
+ }
+
+ /**
+ * Set the DeploymentContext with which this object is a associated.
+ *
+ * @param deploymentContext The DeploymentContext.
+ */
+ public void setDeploymentContext(DeploymentContext deploymentContext)
+ {
+ this.deploymentContext = deploymentContext;
+ }
+
+ /**
+ * Get the schedule resourceId..
+ *
+ * @return The schedule resourceId..
+ */
+ public String getScheduleResourceId()
+ {
+ return scheduleResourceId;
+ }
+
+ /**
+ * Set the schedule resourceId..
+ *
+ * @param scheduleResourceId The schedule resourceId..
+ */
+ public void setScheduleResourceId(String scheduleResourceId)
+ {
+ this.scheduleResourceId = scheduleResourceId;
+ }
+}
Property changes on: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/AbstractScheduleListener.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/CronSchedule.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/CronSchedule.java (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/CronSchedule.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -0,0 +1,88 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.esb.schedule;
+
+import org.quartz.Trigger;
+import org.quartz.CronTrigger;
+import org.jboss.esb.annotations.Initialize;
+
+import java.text.ParseException;
+
+/**
+ * Cron Schedule value object.
+ * <p/>
+ * Example of cron expression configuration:
+ * <pre>
+ * <property name="cronExpression" value="0/20 * * * * ?"/>
+ * <property name="startDate" value="yy-MM-dd HH:mm:ss"/>
+ * <property name="endDate" value="yy-MM-dd HH:mm:ss"/>
+ * </pre>
+ *
+ * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class CronSchedule extends Schedule
+{
+
+ /**
+ * Cron scheduling expression (see Quartz docs).
+ */
+ private String cronExpression;
+
+ /**
+ * Get Cron Expression.
+ *
+ * @return The Cron expression.
+ */
+ public final String getCronExpression()
+ {
+ return cronExpression;
+ }
+
+ /**
+ * Set Cron expression.
+ *
+ * @param cronExpression The Cron schedule expression.
+ */
+ public final void setCronExpression(final String cronExpression)
+ {
+ this.cronExpression = cronExpression;
+ }
+
+ /**
+ * Create a Trigger from the Schedule instance.
+ *
+ * @return A Trigger instance.
+ * @throws SchedulingException Unable to create Trigger.
+ */
+ public Trigger toTrigger() throws SchedulingException
+ {
+ CronTrigger trigger = new CronTrigger();
+
+ setTimes(trigger);
+ try {
+ trigger.setCronExpression(cronExpression);
+ } catch (ParseException e) {
+ throw new SchedulingException("Invalid schedule CRON expression '" + cronExpression + "'.", e);
+ }
+
+ return trigger;
+ }
+}
\ No newline at end of file
Property changes on: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/CronSchedule.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/JobScheduler.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/JobScheduler.java (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/JobScheduler.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -0,0 +1,229 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.esb.schedule;
+
+import org.jboss.esb.annotations.Initialize;
+import org.jboss.esb.annotations.Uninitialize;
+import org.jboss.esb.classpath.ClassUtil;
+import org.jboss.esb.context.DeploymentContext;
+import org.quartz.*;
+import org.quartz.impl.StdSchedulerFactory;
+
+import java.io.IOException;
+import java.util.Properties;
+import java.util.UUID;
+
+/**
+ * Basic Job Scheduler, scoped around an ESB deployment.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class JobScheduler
+{
+ /**
+ * Deployment scheduler resource ID.
+ */
+ public static final String SCHEDULER_RESOURCE_ID = "scheduler";
+ /**
+ * Generate a random UUID to act as the scheduler instance name.
+ */
+ private String schedulerId = UUID.randomUUID().toString();
+ /**
+ * Quartz scheduler instance.
+ */
+ private org.quartz.Scheduler quartzScheduler;
+ /**
+ * Configured scheduler properties. Populated by the config framework.
+ */
+ private Properties properties;
+
+ /**
+ * Set the scheduler properties.
+ *
+ * @param properties The scheduler properties.
+ */
+ public final void setProperties(final Properties properties)
+ {
+ this.properties = properties;
+ }
+
+ /**
+ * Get the scheduler for the supplied deployment context.
+ *
+ * @param context The deployment context.
+ * @return The scheduler.
+ */
+ public static JobScheduler getScheduler(final DeploymentContext context)
+ {
+ return (JobScheduler) context.getResource(SCHEDULER_RESOURCE_ID);
+ }
+
+ /**
+ * Start the scheduler.
+ *
+ * @throws SchedulerException Exception while starting scheduler.
+ */
+ @Initialize
+ public final void initialize() throws SchedulerException
+ {
+ Properties defaultProperties = new Properties();
+
+ try
+ {
+ defaultProperties.load(ClassUtil.getResourceAsStream("default-quartz.properties", getClass()));
+ } catch (IOException e)
+ {
+ throw new IllegalStateException("Unexpected IOEXception while reading default quartz config from local classpath.", e);
+ }
+
+ if (properties != null)
+ {
+ defaultProperties.putAll(properties);
+ }
+ defaultProperties.setProperty(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, schedulerId);
+ quartzScheduler = (new StdSchedulerFactory(defaultProperties)).getScheduler();
+ try
+ {
+ quartzScheduler.start();
+ } catch (Throwable t)
+ {
+ quartzScheduler = null;
+ }
+ }
+
+ /**
+ * Get the Quartz Scheduler.
+ *
+ * @return The Quartz Scheduler.
+ */
+ public final Scheduler getQuartzScheduler()
+ {
+ return quartzScheduler;
+ }
+
+ /**
+ * Shutdown the scheduler.
+ *
+ * @throws SchedulerException Exception while shuting down scheduler.
+ */
+ @Uninitialize
+ public final void shutdown() throws SchedulerException
+ {
+ if (quartzScheduler != null)
+ {
+ quartzScheduler.shutdown();
+ }
+ }
+
+ /**
+ * Add a schedule listener.
+ *
+ * @param listener The listener.
+ * @param listenerName The name of the listener (objectName).
+ * @param scheduleId The schedule Id.
+ * @param deploymentContext The deployment context against which the listener is to be bound..
+ * @throws SchedulingException Error adding listener to schedule.
+ */
+ public static void addScheduleListener(final ScheduleListener listener, final String listenerName, final String scheduleId, final DeploymentContext deploymentContext) throws SchedulingException
+ {
+ JobScheduler scheduler = JobScheduler.getScheduler(deploymentContext);
+ Object resource = deploymentContext.getResource(scheduleId);
+ Schedule schedule;
+
+ if (resource == null)
+ {
+ throw new SchedulingException("Unknown schedule resource ID '" + scheduleId + "'.");
+ }
+
+ try
+ {
+ schedule = (Schedule) resource;
+ } catch (ClassCastException e)
+ {
+ throw new SchedulingException("Resource '" + scheduleId + "' must implement '" + Schedule.class.getName() + "' (see SimpleSchedule and CronSchedule). Is of type '" + resource.getClass().getName() + "'.");
+ }
+
+ // And add the listener against the schedule...
+ scheduler.addScheduleListener(listener, scheduleId + ":" + listenerName, schedule);
+ }
+
+ /**
+ * Add a schedule listener.
+ *
+ * @param listener The listener.
+ * @param scheduleName The schedule name.
+ * @param schedule The schedule.
+ * @throws SchedulingException Error adding listener to schedule.
+ */
+ public void addScheduleListener(final ScheduleListener listener, final String scheduleName, final Schedule schedule) throws SchedulingException
+ {
+ JobDetail jobDetail = new JobDetail(scheduleName, schedulerId, ESBScheduledJob.class);
+ JobDataMap jobDataMap = new JobDataMap();
+ Trigger trigger = schedule.toTrigger();
+
+ trigger.setName(scheduleName);
+ trigger.setGroup(schedulerId);
+
+ jobDataMap.put(ScheduleListener.class.getName(), listener);
+ jobDataMap.put(ClassLoader.class.getName(), Thread.currentThread().getContextClassLoader());
+ jobDetail.setJobDataMap(jobDataMap);
+ try
+ {
+ quartzScheduler.scheduleJob(jobDetail, trigger);
+ } catch (SchedulerException e)
+ {
+ throw new SchedulingException("Failed to schedule job.", e);
+ }
+ }
+
+ /**
+ * Quartz Stateful Job.
+ */
+ public static class ESBScheduledJob implements StatefulJob
+ {
+ public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException
+ {
+ final JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
+ ScheduleListener listener = (ScheduleListener) jobDataMap.get(ScheduleListener.class.getName());
+ final ClassLoader tcc = (ClassLoader) jobDataMap.get(ClassLoader.class.getName());
+
+ final Thread thread = Thread.currentThread();
+ final ClassLoader currentClassLoader = thread.getContextClassLoader();
+ thread.setContextClassLoader(tcc);
+ try
+ {
+ listener.onSchedule();
+ } catch (SchedulingException e)
+ {
+ JobExecutionException jobException = new JobExecutionException("Scheduling exception on " + jobExecutionContext.getJobDetail().getName());
+ jobException.initCause(e);
+ throw jobException;
+ } catch (final Throwable th)
+ {
+ JobExecutionException jobException = new JobExecutionException("Unexpected exception on " + jobExecutionContext.getJobDetail().getName());
+ jobException.initCause(th);
+ throw jobException;
+ } finally
+ {
+ thread.setContextClassLoader(currentClassLoader);
+ }
+ }
+ }
+}
Property changes on: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/JobScheduler.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/Schedule.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/Schedule.java (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/Schedule.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -0,0 +1,139 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.esb.schedule;
+
+import org.quartz.Trigger;
+import org.jboss.esb.annotations.Initialize;
+
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * Schedule value object.
+ * <p/>
+ * The scheduling can be configured by:
+ * <ol>
+ * <li> {@link SimpleSchedule}.
+ * <li> {@link CronSchedule}
+ * </ol>
+ * <p/>
+ * Note tha startDate and endDate are optional:
+ * <ul>
+ * <li> If a startDate is not specified thenthe time will start immedietly.
+ * <li> If endDate is not specified the it will run indefinetly.
+ * </ul>
+ *
+ * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public abstract class Schedule
+{
+ /**
+ * Start date for job.
+ */
+ private Calendar startDate;
+ /**
+ * End date for job.
+ */
+ private Calendar endDate;
+
+ /**
+ * Assert that the schedule configuration is OK.
+ * @throws SchedulingException Invalid schedule resource configuration.
+ */
+ @Initialize
+ public void assertScheduleOK() throws SchedulingException
+ {
+ // Just make sure we can create a trigger from the schedule
+ // without generating an exception...
+ toTrigger();
+ }
+
+ /**
+ * Get job start date.
+ *
+ * @return The job start date.
+ */
+ public final Calendar getStartDate()
+ {
+ return startDate;
+ }
+
+ /**
+ * Set job start date.
+ *
+ * @param startDate The job start date.
+ */
+ public final void setStartDate(final Calendar startDate)
+ {
+ this.startDate = startDate;
+ }
+
+ /**
+ * Get job end date.
+ *
+ * @return The job end date.
+ */
+ public final Calendar getEndDate()
+ {
+ return endDate;
+ }
+
+ /**
+ * Set job end date.
+ *
+ * @param endDate The job end date.
+ */
+ public final void setEndDate(final Calendar endDate)
+ {
+ this.endDate = endDate;
+ }
+
+ /**
+ * Create a Trigger from the Schedule instance.
+ *
+ * @return A Trigger instance.
+ * @throws SchedulingException Unable to create Trigger.
+ */
+ public abstract Trigger toTrigger() throws SchedulingException;
+
+ /**
+ * Set the Tigger start and end times.
+ * <p/>
+ * Utility method for Schedule implementations.
+ *
+ * @param trigger The Trigger instance.
+ */
+ protected final void setTimes(final Trigger trigger)
+ {
+ // Set the start and end times, if configured....
+ if (startDate != null)
+ {
+ trigger.setStartTime(startDate.getTime());
+ } else
+ {
+ trigger.setStartTime(new Date(0));
+ }
+ if (endDate != null)
+ {
+ trigger.setEndTime(endDate.getTime());
+ }
+ }
+}
\ No newline at end of file
Property changes on: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/Schedule.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/ScheduleListener.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/ScheduleListener.java (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/ScheduleListener.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -0,0 +1,39 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.esb.schedule;
+
+/**
+ * Schedule Listener.
+ * <p/>
+ * A schedule listener listens for scheduling events.
+ *
+ * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public interface ScheduleListener
+{
+
+ /**
+ * On schedule event processor.
+ *
+ * @throws SchedulingException Exception processing schedule event.
+ */
+ void onSchedule() throws SchedulingException;
+}
Property changes on: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/ScheduleListener.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/SchedulingException.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/SchedulingException.java (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/SchedulingException.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.esb.schedule;
+
+import org.jboss.esb.JBossESBException;
+
+/**
+ * Scheduling Exception.
+ *
+ * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class SchedulingException extends JBossESBException
+{
+
+ /**
+ * Public Constructor.
+ *
+ * @param message Exception message.
+ */
+ public SchedulingException(final String message)
+ {
+ super(message);
+ }
+
+ /**
+ * Public Constructor.
+ *
+ * @param message Exception message.
+ * @param cause Exception cause.
+ */
+ public SchedulingException(final String message, final Throwable cause)
+ {
+ super(message, cause);
+ }
+}
Property changes on: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/SchedulingException.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/SimpleSchedule.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/SimpleSchedule.java (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/SimpleSchedule.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -0,0 +1,118 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.esb.schedule;
+
+import org.quartz.SimpleTrigger;
+import org.quartz.Trigger;
+
+/**
+ * Simple Schedule value object.
+ * <p/>
+ * Example of simple configuration:
+ * <pre>
+ * <property name="frequency" value="10"/>
+ * <property name="execCount" value="10"/>
+ * <property name="startDate" value="yy-MM-dd HH:mm:ss"/>
+ * <property name="endDate" value="yy-MM-dd HH:mm:ss"/>
+ * </pre>
+ *
+ * @author <a href="daniel.bevenius at redpill.se">Daniel Bevenius</a>
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class SimpleSchedule extends Schedule
+{
+ /**
+ * Poll frequency in milliseconds.
+ */
+ private long frequency;
+ /**
+ * Number of times to execute (default - execute indefinitely).
+ */
+ private int execCount = -1;
+
+ /**
+ * Get schedule frequency.
+ *
+ * @return The schedule frequency.
+ */
+ public final long getFrequency()
+ {
+ return frequency;
+ }
+
+ /**
+ * Set schedule frequency.
+ *
+ * @param frequency The schedule frequency (in milliseconds).
+ */
+ public final void setFrequency(final long frequency)
+ {
+ this.frequency = frequency;
+ }
+
+ /**
+ * Get schedule execution count.
+ *
+ * @return The schedule execution count.
+ */
+ public final int getExecCount()
+ {
+ return execCount;
+ }
+
+ /**
+ * Set schedule execution count.
+ *
+ * @param execCount The schedule execution count.
+ */
+ public final void setExecCount(final int execCount)
+ {
+ this.execCount = execCount;
+ }
+
+ /**
+ * Create a Trigger from the Schedule instance.
+ *
+ * @return A Trigger instance.
+ * @throws SchedulingException Unable to create Trigger.
+ */
+ public Trigger toTrigger() throws SchedulingException
+ {
+ SimpleTrigger trigger = new SimpleTrigger();
+
+ setTimes(trigger);
+ trigger.setRepeatInterval(frequency);
+
+ if (execCount == 0)
+ {
+ throw new SchedulingException("Invalid schedule configuration. Cannot define a SimpleSchedule with an execution count of 0.");
+ } else if (execCount == -1)
+ {
+ // Repeat forever ....
+ trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
+ } else
+ {
+ // So the repeatCount = execCount - 1 ....
+ trigger.setRepeatCount(execCount - 1);
+ }
+
+ return trigger;
+ }
+}
Property changes on: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/SimpleSchedule.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/default-quartz.properties
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/default-quartz.properties (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/default-quartz.properties 2008-09-03 12:46:48 UTC (rev 22352)
@@ -0,0 +1,16 @@
+# Default ESB Quartz Properties file.
+# org.quartz.scheduler.instanceName set by JobScheduler
+
+org.quartz.scheduler.rmi.export = false
+org.quartz.scheduler.rmi.proxy = false
+org.quartz.scheduler.wrapJobExecutionInUserTransaction = false
+
+org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
+org.quartz.threadPool.threadCount = 2
+org.quartz.threadPool.threadPriority = 5
+org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true
+
+org.quartz.jobStore.misfireThreshold = 60000
+
+org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
+
Property changes on: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/default-quartz.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/package.html
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/package.html (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/main/java/org/jboss/esb/schedule/package.html 2008-09-03 12:46:48 UTC (rev 22352)
@@ -0,0 +1,8 @@
+<html>
+<head></head>
+<body>
+Scheduling.
+
+<h2>Package Specification</h2>
+</body>
+</html>
\ No newline at end of file
Modified: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/DefaultConfigurationDigesterTest.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/DefaultConfigurationDigesterTest.java 2008-09-03 11:50:44 UTC (rev 22351)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/DefaultConfigurationDigesterTest.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -46,7 +46,7 @@
public void test_resources_01() throws IOException, DeploymentException
{
- ConfigurationUnit configUnit = digest("jbossesb-resources_01.xml");
+ DeploymentUnit configUnit = digest("jbossesb-resources_01.xml");
Map<String, Object> resources = configUnit.getResources();
XProtDeploymentResource xprotRes = (XProtDeploymentResource) resources.get("xprotRes1");
@@ -68,18 +68,18 @@
public void test_inandoutrouters_01() throws IOException, DeploymentException
{
- ConfigurationUnit configUnit = digest("jbossesb-inandoutrouters_01.xml");
+ DeploymentUnit configUnit = digest("jbossesb-inandoutrouters_01.xml");
test_inrouters(configUnit);
test_outrouters(configUnit);
}
private void test_inrouters(String config) throws IOException, DeploymentException
{
- ConfigurationUnit configUnit = digest(config);
+ DeploymentUnit configUnit = digest(config);
test_inrouters(configUnit);
}
- private void test_inrouters(ConfigurationUnit configUnit)
+ private void test_inrouters(DeploymentUnit configUnit)
{
Map<ServiceName, List<InboundRouterConfig>> inRouters = configUnit.getInboundRouters();
@@ -124,11 +124,11 @@
private void test_outrouters(String config) throws IOException, DeploymentException
{
- ConfigurationUnit configUnit = digest(config);
+ DeploymentUnit configUnit = digest(config);
test_outrouters(configUnit);
}
- private void test_outrouters(ConfigurationUnit configUnit)
+ private void test_outrouters(DeploymentUnit configUnit)
{
Map<ServiceName, List<OutboundRouterConfig>> inRouters = configUnit.getOutboundRouters();
@@ -173,7 +173,7 @@
public void test_services_01() throws DeploymentException, IOException
{
- ConfigurationUnit configUnit = digest("jbossesb-services_01.xml");
+ DeploymentUnit configUnit = digest("jbossesb-services_01.xml");
Map<ServiceName, ServiceConfig> services = configUnit.getServices();
ServiceConfig serviceAConfig = services.get(new ServiceName("service-cat", "service-a"));
@@ -191,7 +191,7 @@
assertEquals("propValueB", serviceB.getProp1());
}
- private ConfigurationUnit digest(String config) throws IOException, DeploymentException
+ private DeploymentUnit digest(String config) throws IOException, DeploymentException
{
DefaultConfigurationDigester digester = new DefaultConfigurationDigester();
return digester.digest(getClass().getResourceAsStream(config));
Modified: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/DeploymentLifecycleTest.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/DeploymentLifecycleTest.java 2008-09-03 11:50:44 UTC (rev 22351)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/deploy/config/DeploymentLifecycleTest.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -43,7 +43,7 @@
public void test_deploy_01_noexception() throws DeploymentException, IOException
{
DeploymentRuntime runtime = new DeploymentRuntime();
- ConfigurationUnit configUnit = digest("jbossesb-deploy-01.xml");
+ DeploymentUnit configUnit = digest("jbossesb-deploy-01.xml");
runtime.add(configUnit);
assertDeployed(false);
@@ -56,7 +56,7 @@
public void test_deploy_01_exception() throws DeploymentException, IOException
{
DeploymentRuntime runtime = new DeploymentRuntime();
- ConfigurationUnit configUnit = digest("jbossesb-deploy-01.xml");
+ DeploymentUnit configUnit = digest("jbossesb-deploy-01.xml");
runtime.add(configUnit);
assertDeployed(false);
@@ -81,7 +81,7 @@
assertEquals(deployed, MyTestService.initialised);
}
- private ConfigurationUnit digest(String config) throws IOException, DeploymentException
+ private DeploymentUnit digest(String config) throws IOException, DeploymentException
{
DefaultConfigurationDigester digester = new DefaultConfigurationDigester();
return digester.digest(getClass().getResourceAsStream(config));
Modified: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/dispatch/HelloInboundRouter.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/dispatch/HelloInboundRouter.java 2008-09-03 11:50:44 UTC (rev 22351)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/dispatch/HelloInboundRouter.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -43,6 +43,6 @@
{
Message esbMessage = new Message();
esbMessage.setPayload(message);
- dispatcher.dispatch(esbMessage);
+ dispatcher.dispatch(esbMessage, new InvocationContext());
}
}
Modified: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/dispatch/LocalDispatcherTest.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/dispatch/LocalDispatcherTest.java 2008-09-03 11:50:44 UTC (rev 22351)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/dispatch/LocalDispatcherTest.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -22,7 +22,7 @@
import junit.framework.TestCase;
import org.jboss.esb.deploy.DeploymentRuntime;
import org.jboss.esb.deploy.DeploymentException;
-import org.jboss.esb.deploy.config.ConfigurationUnit;
+import org.jboss.esb.deploy.config.DeploymentUnit;
import org.jboss.esb.deploy.config.digest.DefaultConfigurationDigester;
import org.jboss.esb.service.ServiceName;
import org.jboss.esb.routing.RoutingException;
@@ -41,7 +41,7 @@
ServiceName service = new ServiceName("hello", "hello");
DeploymentRuntime runtime = new DeploymentRuntime();
DefaultConfigurationDigester digester = new DefaultConfigurationDigester();
- ConfigurationUnit configUnit = digester.digest(getClass().getResourceAsStream("jbossesb-dispatch-no-service.xml"));
+ DeploymentUnit configUnit = digester.digest(getClass().getResourceAsStream("jbossesb-dispatch-no-service.xml"));
runtime.add(configUnit);
@@ -63,7 +63,7 @@
ServiceName service = new ServiceName("hello", "hello");
DeploymentRuntime runtime = new DeploymentRuntime();
DefaultConfigurationDigester digester = new DefaultConfigurationDigester();
- ConfigurationUnit configUnit = digester.digest(getClass().getResourceAsStream("jbossesb-dispatch-with-service.xml"));
+ DeploymentUnit configUnit = digester.digest(getClass().getResourceAsStream("jbossesb-dispatch-with-service.xml"));
runtime.add(configUnit);
@@ -90,7 +90,7 @@
ServiceName service = new ServiceName("hello", "hello");
DeploymentRuntime runtime = new DeploymentRuntime();
DefaultConfigurationDigester digester = new DefaultConfigurationDigester();
- ConfigurationUnit configUnit = digester.digest(getClass().getResourceAsStream("jbossesb-dispatch-with-intransform.xml"));
+ DeploymentUnit configUnit = digester.digest(getClass().getResourceAsStream("jbossesb-dispatch-with-intransform.xml"));
runtime.add(configUnit);
@@ -137,7 +137,7 @@
ServiceName service = new ServiceName("hello", "hello");
DeploymentRuntime runtime = new DeploymentRuntime();
DefaultConfigurationDigester digester = new DefaultConfigurationDigester();
- ConfigurationUnit configUnit = digester.digest(getClass().getResourceAsStream("jbossesb-dispatch-with-outtransform.xml"));
+ DeploymentUnit configUnit = digester.digest(getClass().getResourceAsStream("jbossesb-dispatch-with-outtransform.xml"));
runtime.add(configUnit);
Added: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/JobSchedulerTest.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/JobSchedulerTest.java (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/JobSchedulerTest.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -0,0 +1,173 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.esb.schedule;
+
+import junit.framework.TestCase;
+import org.quartz.SchedulerException;
+
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class JobSchedulerTest extends TestCase
+{
+ // See setUp...
+ private JobScheduler scheduler1;
+ private JobScheduler scheduler2;
+ private TestListener listener1 = new TestListener();
+ private TestListener listener2 = new TestListener();
+ private TestListener listener3 = new TestListener();
+ private TestListener listener4 = new TestListener();
+
+ public void test_simple_schedule() throws IOException, SchedulerException, SchedulingException, InterruptedException
+ {
+ SimpleSchedule simpleSchedule = new SimpleSchedule();
+ simpleSchedule.setExecCount(-1);
+ simpleSchedule.setFrequency(100);
+ test(simpleSchedule);
+ }
+
+ public void test_cron_schedule() throws IOException, SchedulerException, SchedulingException, InterruptedException
+ {
+ CronSchedule cronSchedule = new CronSchedule();
+ cronSchedule.setCronExpression("0/1 * * * * ?");
+
+ scheduler1.addScheduleListener(listener1, "schedule1", cronSchedule);
+
+ long lastT1 = listener1.callCount;
+ long start = System.currentTimeMillis();
+ while (System.currentTimeMillis() < start + 6000)
+ {
+ Thread.sleep(2000);
+ // All listeners are active...
+ assertTrue(lastT1 < listener1.callCount);
+ lastT1 = listener1.callCount;
+ }
+
+ scheduler1.shutdown();
+ lastT1 = listener1.callCount;
+ start = System.currentTimeMillis();
+ while (System.currentTimeMillis() < start + 6000)
+ {
+ Thread.sleep(2000);
+ // All listeners are active...
+ assertTrue(lastT1 == listener1.callCount);
+ lastT1 = listener1.callCount;
+ }
+ }
+
+ private void test(Schedule schedule) throws SchedulingException, InterruptedException, SchedulerException
+ {
+ scheduler1.addScheduleListener(listener1, "schedule1", schedule);
+ scheduler1.addScheduleListener(listener2, "schedule2", schedule);
+ scheduler2.addScheduleListener(listener3, "schedule1", schedule);
+ scheduler2.addScheduleListener(listener4, "schedule2", schedule);
+
+ long lastT1 = listener1.callCount;
+ long lastT2 = listener2.callCount;
+ long lastT3 = listener3.callCount;
+ long lastT4 = listener4.callCount;
+ long start = System.currentTimeMillis();
+ while (System.currentTimeMillis() < start + 3000)
+ {
+ Thread.sleep(500);
+ // All listeners are active...
+ assertTrue(lastT1 < listener1.callCount);
+ assertTrue(lastT2 < listener2.callCount);
+ assertTrue(lastT3 < listener3.callCount);
+ assertTrue(lastT4 < listener4.callCount);
+ lastT1 = listener1.callCount;
+ lastT2 = listener2.callCount;
+ lastT3 = listener3.callCount;
+ lastT4 = listener4.callCount;
+ }
+
+ scheduler1.shutdown();
+ lastT1 = listener1.callCount;
+ lastT2 = listener2.callCount;
+ lastT3 = listener3.callCount;
+ lastT4 = listener4.callCount;
+ start = System.currentTimeMillis();
+ while (System.currentTimeMillis() < start + 3000)
+ {
+ Thread.sleep(500);
+ // The listeners on scheduler1 should now be stopped...
+ assertTrue(lastT1 == listener1.callCount);
+ assertTrue(lastT2 == listener2.callCount);
+ assertTrue(lastT3 < listener3.callCount);
+ assertTrue(lastT4 < listener4.callCount);
+ lastT1 = listener1.callCount;
+ lastT2 = listener2.callCount;
+ lastT3 = listener3.callCount;
+ lastT4 = listener4.callCount;
+ }
+
+ scheduler2.shutdown();
+ lastT1 = listener1.callCount;
+ lastT2 = listener2.callCount;
+ lastT3 = listener3.callCount;
+ lastT4 = listener4.callCount;
+ start = System.currentTimeMillis();
+ while (System.currentTimeMillis() < start + 3000)
+ {
+ Thread.sleep(500);
+ // The listeners both schedulers should now be stopped...
+ assertTrue(lastT1 == listener1.callCount);
+ assertTrue(lastT2 == listener2.callCount);
+ assertTrue(lastT3 == listener3.callCount);
+ assertTrue(lastT4 == listener4.callCount);
+ lastT1 = listener1.callCount;
+ lastT2 = listener2.callCount;
+ lastT3 = listener3.callCount;
+ lastT4 = listener4.callCount;
+ }
+ }
+
+ private class TestListener implements ScheduleListener
+ {
+
+ private long callCount;
+
+ public void onSchedule() throws SchedulingException
+ {
+ callCount++;
+ }
+ }
+
+ protected void setUp() throws Exception
+ {
+ scheduler1 = new JobScheduler();
+ scheduler1.initialize();
+ scheduler2 = new JobScheduler();
+ scheduler2.initialize();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ try
+ {
+ scheduler1.shutdown();
+ } finally
+ {
+ scheduler2.shutdown();
+ }
+ }
+}
Property changes on: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/JobSchedulerTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/MockScheduledInboundRouter.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/MockScheduledInboundRouter.java (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/MockScheduledInboundRouter.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.esb.schedule;
+
+import org.jboss.esb.message.Message;
+import org.jboss.esb.routing.InboundRouter;
+import org.jboss.esb.routing.MessageDispatcher;
+import org.jboss.esb.routing.RoutingException;
+import org.jboss.esb.annotations.Initialize;
+import org.jboss.esb.deploy.AssertDeployment;
+import org.jboss.esb.context.InvocationContext;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class MockScheduledInboundRouter extends AbstractScheduleListener implements InboundRouter
+{
+ public static Message inMessage;
+ private MessageDispatcher dispatcher;
+
+ public void setDispatcher(MessageDispatcher dispatcher)
+ {
+ this.dispatcher = dispatcher;
+ }
+
+ public void onSchedule() throws SchedulingException
+ {
+ try
+ {
+ dispatcher.dispatch(inMessage, new InvocationContext());
+ } catch (RoutingException e)
+ {
+ throw new SchedulingException("Unable to route message.", e);
+ }
+ }
+
+ @Initialize
+ public void assertConfigured()
+ {
+ AssertDeployment.isNotNull(inMessage, "inMessage");
+ }
+}
Property changes on: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/MockScheduledInboundRouter.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/ScheduleListenerTest.java
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/ScheduleListenerTest.java (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/ScheduleListenerTest.java 2008-09-03 12:46:48 UTC (rev 22352)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright XXXX, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2008, JBoss Inc.
+ */
+package org.jboss.esb.schedule;
+
+import junit.framework.TestCase;
+import org.jboss.esb.deploy.DeploymentException;
+import org.jboss.esb.deploy.DeploymentRuntime;
+import org.jboss.esb.deploy.config.digest.DefaultConfigurationDigester;
+import org.jboss.esb.deploy.config.DeploymentUnit;
+import org.jboss.esb.routing.RoutingException;
+import org.jboss.esb.service.ServiceName;
+import org.jboss.esb.dispatch.HelloWorldService;
+import org.jboss.esb.message.Message;
+
+import java.io.IOException;
+
+/**
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class ScheduleListenerTest extends TestCase
+{
+
+ public void test_OK() throws DeploymentException, IOException, RoutingException, InterruptedException
+ {
+ ServiceName service = new ServiceName("hello", "hello");
+ DeploymentRuntime runtime = new DeploymentRuntime();
+ DefaultConfigurationDigester digester = new DefaultConfigurationDigester();
+ DeploymentUnit deploymentUnit = digester.digest(getClass().getResourceAsStream("schedule-listener-01.xml"));
+
+ runtime.add(deploymentUnit);
+
+ // Set the mock router's message before deploying...
+ MockScheduledInboundRouter.inMessage = new Message("Hi, this is the mock scheduled inRouter!");
+
+ runtime.deploy();
+
+ // Sleep for a second in order to all the message to be delivered by the mock router...
+ Thread.sleep(1000);
+ try {
+ HelloWorldService helloService = (HelloWorldService) deploymentUnit.getServices().get(service).getService();
+ assertEquals("Hi, this is the mock scheduled inRouter!", helloService.getHelloMessage());
+ } finally {
+ runtime.undeploy();
+ }
+ }
+
+ public void test_no_schedule() throws DeploymentException, IOException, RoutingException, InterruptedException
+ {
+ DeploymentRuntime runtime = new DeploymentRuntime();
+ DefaultConfigurationDigester digester = new DefaultConfigurationDigester();
+ DeploymentUnit deploymentUnit = digester.digest(getClass().getResourceAsStream("schedule-listener-02.xml"));
+
+ runtime.add(deploymentUnit);
+
+ // Set the mock router's message before deploying...
+ MockScheduledInboundRouter.inMessage = new Message("Hi, this is the mock scheduled inRouter!");
+
+ try {
+ runtime.deploy();
+ } catch(DeploymentException e) {
+ assertEquals("Unable to deploy InboundRouter 'inrouter1' (org.jboss.esb.schedule.MockScheduledInboundRouter).", e.getMessage());
+ assertEquals("Unknown schedule resource ID 'schedule1'.", e.getCause().getMessage());
+ }
+ }
+
+ public void test_not_a_schedule() throws DeploymentException, IOException, RoutingException, InterruptedException
+ {
+ DeploymentRuntime runtime = new DeploymentRuntime();
+ DefaultConfigurationDigester digester = new DefaultConfigurationDigester();
+ DeploymentUnit deploymentUnit = digester.digest(getClass().getResourceAsStream("schedule-listener-03.xml"));
+
+ runtime.add(deploymentUnit);
+
+ // Set the mock router's message before deploying...
+ MockScheduledInboundRouter.inMessage = new Message("Hi, this is the mock scheduled inRouter!");
+
+ try {
+ runtime.deploy();
+ } catch(DeploymentException e) {
+ assertEquals("Unable to deploy InboundRouter 'inrouter1' (org.jboss.esb.schedule.MockScheduledInboundRouter).", e.getMessage());
+ assertEquals("Resource 'schedule1' must implement 'org.jboss.esb.schedule.Schedule' (see SimpleSchedule and CronSchedule). Is of type 'java.lang.Object'.", e.getCause().getMessage());
+ }
+ }
+}
Property changes on: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/ScheduleListenerTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/quartz-01.properties
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/quartz-01.properties (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/quartz-01.properties 2008-09-03 12:46:48 UTC (rev 22352)
@@ -0,0 +1,17 @@
+# Default ESB Quartz Properties file.
+#
+
+org.quartz.scheduler.instanceName = DefaultQuartzScheduler
+org.quartz.scheduler.rmi.export = false
+org.quartz.scheduler.rmi.proxy = false
+org.quartz.scheduler.wrapJobExecutionInUserTransaction = false
+
+org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
+org.quartz.threadPool.threadCount = 2
+org.quartz.threadPool.threadPriority = 5
+org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread = true
+
+org.quartz.jobStore.misfireThreshold = 60000
+
+org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
+
Property changes on: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/quartz-01.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Copied: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/schedule-listener-01.xml (from rev 22294, labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/dispatch/jbossesb-dispatch-with-service.xml)
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/schedule-listener-01.xml (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/schedule-listener-01.xml 2008-09-03 12:46:48 UTC (rev 22352)
@@ -0,0 +1,21 @@
+<jbossesb xmlns="http://www.jboss.org/jbossesb/xsd/jbossesb-5.0.xsd" xmlns:xprot="http://www.jboss.org/jbossesb/xsd/xprot/xprot.xsd">
+
+ <resources>
+ <resource id="schedule1" class="org.jboss.esb.schedule.SimpleSchedule">
+ <property name="frequency">100</property>
+ <property name="execCount">1</property>
+ </resource>
+ </resources>
+
+ <services>
+ <service serviceCategory="hello" serviceName="hello" serviceDescription="A Service" class="org.jboss.esb.dispatch.HelloWorldService" />
+ </services>
+
+ <routing>
+ <inRouters serviceCategory="hello" serviceName="hello">
+ <inRouter name="inrouter1" class="org.jboss.esb.schedule.MockScheduledInboundRouter">
+ <property name="scheduleResourceId">schedule1</property>
+ </inRouter>
+ </inRouters>
+ </routing>
+</jbossesb>
\ No newline at end of file
Added: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/schedule-listener-02.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/schedule-listener-02.xml (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/schedule-listener-02.xml 2008-09-03 12:46:48 UTC (rev 22352)
@@ -0,0 +1,15 @@
+<jbossesb xmlns="http://www.jboss.org/jbossesb/xsd/jbossesb-5.0.xsd" xmlns:xprot="http://www.jboss.org/jbossesb/xsd/xprot/xprot.xsd">
+
+ <!--
+ Invalid config... no "schedule1" for scheduled router.
+ -->
+
+ <routing>
+ <inRouters serviceCategory="hello" serviceName="hello">
+ <inRouter name="inrouter1" class="org.jboss.esb.schedule.MockScheduledInboundRouter">
+ <property name="scheduleResourceId">schedule1</property>
+ </inRouter>
+ </inRouters>
+ </routing>
+
+</jbossesb>
\ No newline at end of file
Property changes on: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/schedule-listener-02.xml
___________________________________________________________________
Name: svn:mime-type
+ text/xml
Name: svn:eol-style
+ native
Added: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/schedule-listener-03.xml
===================================================================
--- labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/schedule-listener-03.xml (rev 0)
+++ labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/schedule-listener-03.xml 2008-09-03 12:46:48 UTC (rev 22352)
@@ -0,0 +1,18 @@
+<jbossesb xmlns="http://www.jboss.org/jbossesb/xsd/jbossesb-5.0.xsd" xmlns:xprot="http://www.jboss.org/jbossesb/xsd/xprot/xprot.xsd">
+
+ <!--
+ Invalid config - schedule1 does not impement org.jboss.esb.schedule.Schedule
+ -->
+
+ <resources>
+ <resource id="schedule1" class="java.lang.Object" />
+ </resources>
+
+ <routing>
+ <inRouters serviceCategory="hello" serviceName="hello">
+ <inRouter name="inrouter1" class="org.jboss.esb.schedule.MockScheduledInboundRouter">
+ <property name="scheduleResourceId">schedule1</property>
+ </inRouter>
+ </inRouters>
+ </routing>
+</jbossesb>
\ No newline at end of file
Property changes on: labs/jbossesb/workspace/skeagh/runtime/src/test/java/org/jboss/esb/schedule/schedule-listener-03.xml
___________________________________________________________________
Name: svn:mime-type
+ text/xml
Name: svn:eol-style
+ native
More information about the jboss-svn-commits
mailing list