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 2014/01/28 14:19:58 UTC

[2/2] git commit: CAMEL-7132: quartz/quartz2 component should use avoid null management name if JMX not enabled.

CAMEL-7132: quartz/quartz2 component should use avoid null management name if JMX not enabled.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/eb2596ef
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/eb2596ef
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/eb2596ef

Branch: refs/heads/camel-2.12.x
Commit: eb2596ef431ecfcaaa8c572eabb2c240675ba570
Parents: 0ab8d62
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jan 28 14:20:07 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jan 28 14:20:31 2014 +0100

----------------------------------------------------------------------
 .../camel/component/quartz/QuartzComponent.java |  5 ++-
 .../camel/component/quartz/QuartzEndpoint.java  |  2 +-
 .../camel/component/quartz/QuartzHelper.java    | 34 +++++++++++++++++++
 .../component/quartz2/QuartzComponent.java      |  2 +-
 .../camel/component/quartz2/QuartzEndpoint.java |  2 +-
 .../camel/component/quartz2/QuartzHelper.java   | 35 ++++++++++++++++++++
 6 files changed, 74 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/eb2596ef/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java b/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
index faacab7..eb19c79 100644
--- a/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
+++ b/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzComponent.java
@@ -198,9 +198,8 @@ public class QuartzComponent extends DefaultComponent implements StartupListener
 
     public void onCamelContextStarted(CamelContext camelContext, boolean alreadyStarted) throws Exception {
         if (scheduler != null) {
-            // register current camel context to scheduler so we can look it up when jobs is being triggered
-            // must use management name as it should be unique in the same JVM
-            scheduler.getContext().put(QuartzConstants.QUARTZ_CAMEL_CONTEXT + "-" + getCamelContext().getManagementName(), getCamelContext());
+            String uid = QuartzHelper.getQuartzContextName(camelContext);
+            scheduler.getContext().put(QuartzConstants.QUARTZ_CAMEL_CONTEXT + "-" + uid, camelContext);
         }
 
         // if not configure to auto start then don't start it

http://git-wip-us.apache.org/repos/asf/camel/blob/eb2596ef/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzEndpoint.java b/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzEndpoint.java
index 5c0be0f..e7fd032 100644
--- a/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzEndpoint.java
+++ b/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzEndpoint.java
@@ -73,7 +73,7 @@ public class QuartzEndpoint extends DefaultEndpoint implements ShutdownableServi
         }
         detail.getJobDataMap().put(QuartzConstants.QUARTZ_ENDPOINT_URI, getEndpointUri());
         // must use management name as it should be unique in the same JVM
-        detail.getJobDataMap().put(QuartzConstants.QUARTZ_CAMEL_CONTEXT_NAME, getCamelContext().getManagementName());
+        detail.getJobDataMap().put(QuartzConstants.QUARTZ_CAMEL_CONTEXT_NAME, QuartzHelper.getQuartzContextName(getCamelContext()));
         if (detail.getJobClass() == null) {
             detail.setJobClass(isStateful() ? StatefulCamelJob.class : CamelJob.class);
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/eb2596ef/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzHelper.java b/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzHelper.java
new file mode 100644
index 0000000..676fbb2
--- /dev/null
+++ b/components/camel-quartz/src/main/java/org/apache/camel/component/quartz/QuartzHelper.java
@@ -0,0 +1,34 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.quartz;
+
+import org.apache.camel.CamelContext;
+
+public final class QuartzHelper {
+
+    private QuartzHelper() {
+    }
+
+    public static String getQuartzContextName(CamelContext camelContext) {
+        // favour using the actual management name which was registered in JMX (if JMX is enabled)
+        if (camelContext.getManagementName() != null) {
+            return camelContext.getManagementName();
+        } else {
+            return camelContext.getManagementNameStrategy().getName();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/eb2596ef/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzComponent.java b/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzComponent.java
index 98f0762..db078f9 100644
--- a/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzComponent.java
+++ b/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzComponent.java
@@ -293,7 +293,7 @@ public class QuartzComponent extends DefaultComponent implements StartupListener
 
         // Store CamelContext into QuartzContext space
         SchedulerContext quartzContext = scheduler.getContext();
-        String camelContextName = getCamelContext().getManagementName();
+        String camelContextName = QuartzHelper.getQuartzContextName(getCamelContext());
         LOG.debug("Storing camelContextName={} into Quartz Context space.", camelContextName);
         quartzContext.put(QuartzConstants.QUARTZ_CAMEL_CONTEXT + "-" + camelContextName, getCamelContext());
 

http://git-wip-us.apache.org/repos/asf/camel/blob/eb2596ef/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java b/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java
index 2ea291a..fbc5738 100644
--- a/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java
+++ b/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java
@@ -254,7 +254,7 @@ public class QuartzEndpoint extends DefaultEndpoint {
     private void updateJobDataMap(JobDetail jobDetail) {
         // Store this camelContext name into the job data
         JobDataMap jobDataMap = jobDetail.getJobDataMap();
-        String camelContextName = getCamelContext().getManagementName();
+        String camelContextName = QuartzHelper.getQuartzContextName(getCamelContext());
         String endpointUri = getEndpointUri();
         LOG.debug("Adding camelContextName={}, endpointUri={} into job data map.", camelContextName, endpointUri);
         jobDataMap.put(QuartzConstants.QUARTZ_CAMEL_CONTEXT_NAME, camelContextName);

http://git-wip-us.apache.org/repos/asf/camel/blob/eb2596ef/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzHelper.java b/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzHelper.java
new file mode 100644
index 0000000..0d5c5bc
--- /dev/null
+++ b/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzHelper.java
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.quartz2;
+
+import org.apache.camel.CamelContext;
+
+public final class QuartzHelper {
+
+    private QuartzHelper() {
+    }
+
+    public static String getQuartzContextName(CamelContext camelContext) {
+        // favour using the actual management name which was registered in JMX (if JMX is enabled)
+        if (camelContext.getManagementName() != null) {
+            return camelContext.getManagementName();
+        } else {
+            return camelContext.getManagementNameStrategy().getName();
+        }
+    }
+
+}