You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2013/01/25 09:15:53 UTC
svn commit: r1438381 - in /camel/branches/camel-2.10.x: ./
components/camel-quartz/src/main/java/org/apache/camel/component/quartz/CamelJob.java
components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzCronRouteWithSmallCacheTest.java
Author: davsclaus
Date: Fri Jan 25 08:15:53 2013
New Revision: 1438381
URL: http://svn.apache.org/viewvc?rev=1438381&view=rev
Log:
CAMEL-5994: Quartz trigger should reuse endpoint from route to use the same as the consumer. Thanks to Alexis Kinsella and Denis Delangle for code with fix and test case.
Added:
camel/branches/camel-2.10.x/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzCronRouteWithSmallCacheTest.java
- copied unchanged from r1438380, camel/trunk/components/camel-quartz/src/test/java/org/apache/camel/component/quartz/QuartzCronRouteWithSmallCacheTest.java
Modified:
camel/branches/camel-2.10.x/ (props changed)
camel/branches/camel-2.10.x/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/CamelJob.java
Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Merged /camel/trunk:r1438380
Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: camel/branches/camel-2.10.x/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/CamelJob.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/CamelJob.java?rev=1438381&r1=1438380&r2=1438381&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/CamelJob.java (original)
+++ camel/branches/camel-2.10.x/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/CamelJob.java Fri Jan 25 08:15:53 2013
@@ -19,17 +19,23 @@ package org.apache.camel.component.quart
import java.io.Serializable;
import org.apache.camel.CamelContext;
+import org.apache.camel.Route;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.SchedulerContext;
import org.quartz.SchedulerException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import static org.apache.camel.util.URISupport.normalizeUri;
/**
* @version
*/
public class CamelJob implements Job, Serializable {
+ private static final transient Logger LOG = LoggerFactory.getLogger(CamelJob.class);
private static final long serialVersionUID = 26L;
public void execute(JobExecutionContext context) throws JobExecutionException {
@@ -47,11 +53,38 @@ public class CamelJob implements Job, Se
if (camelContext == null) {
throw new JobExecutionException("No CamelContext could be found with name: " + camelContextName);
}
- QuartzEndpoint endpoint = camelContext.getEndpoint(endpointUri, QuartzEndpoint.class);
+
+ QuartzEndpoint endpoint = lookupQuartzEndpoint(camelContext, endpointUri);
if (endpoint == null) {
throw new JobExecutionException("No QuartzEndpoint could be found with uri: " + endpointUri);
}
endpoint.onJobExecute(context);
}
+ private QuartzEndpoint lookupQuartzEndpoint(CamelContext camelContext, String endpointUri) throws JobExecutionException {
+ try {
+ String targetUri = normalizeUri(endpointUri);
+
+ // check all active routes for the quartz endpoint this task matches
+ // as we prefer to use the existing endpoint from the routes
+ for (Route route : camelContext.getRoutes()) {
+ if (route.getEndpoint() instanceof QuartzEndpoint) {
+ if (normalizeUri(route.getEndpoint().getEndpointUri()).equals(targetUri)) {
+ return (QuartzEndpoint) route.getEndpoint();
+ }
+ }
+ }
+ } catch (Exception e) {
+ throw new JobExecutionException("Error lookup up existing QuartzEndpoint with uri: " + endpointUri, e);
+ }
+
+ // fallback and lookup existing from registry (eg maybe a @Consume POJO with a quartz endpoint, and thus not from a route)
+ if (camelContext.hasEndpoint(endpointUri) != null) {
+ return camelContext.getEndpoint(endpointUri, QuartzEndpoint.class);
+ } else {
+ LOG.warn("Cannot find existing QuartzEndpoint with uri: {}. Creating new endpoint instance.", endpointUri);
+ return camelContext.getEndpoint(endpointUri, QuartzEndpoint.class);
+ }
+ }
+
}
\ No newline at end of file