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 2016/12/19 15:35:15 UTC
[3/8] camel git commit: CAMEL-10599: Add ReloadStrategy to allow
watching for file changes and reload routes on the fly.
CAMEL-10599: Add ReloadStrategy to allow watching for file changes and reload routes on the fly.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/417c57d7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/417c57d7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/417c57d7
Branch: refs/heads/master
Commit: 417c57d7feeccafd15403f4ad1c1969bf6e1f096
Parents: d9fb32e
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Dec 19 14:00:50 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Dec 19 16:34:46 2016 +0100
----------------------------------------------------------------------
.../mbean/ManagedReloadStrategyMBean.java | 32 +++++++++++++
.../DefaultManagementLifecycleStrategy.java | 4 ++
.../management/mbean/ManagedReloadStrategy.java | 50 ++++++++++++++++++++
.../org/apache/camel/spi/ReloadStrategy.java | 11 ++++-
.../camel/support/ReloadStrategySupport.java | 23 +++++++++
5 files changed, 119 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/417c57d7/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedReloadStrategyMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedReloadStrategyMBean.java b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedReloadStrategyMBean.java
new file mode 100644
index 0000000..80065ce
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedReloadStrategyMBean.java
@@ -0,0 +1,32 @@
+/**
+ * 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.api.management.mbean;
+
+import org.apache.camel.api.management.ManagedAttribute;
+
+public interface ManagedReloadStrategyMBean extends ManagedServiceMBean {
+
+ @ManagedAttribute(description = "Strategy")
+ String getStrategy();
+
+ @ManagedAttribute(description = "Number of reloads succeeded")
+ int getReloadCounter();
+
+ @ManagedAttribute(description = "Number of reloads failed")
+ int getFailedCounter();
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/417c57d7/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
index 34c8d5e..1df3a7e 100644
--- a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
@@ -61,6 +61,7 @@ import org.apache.camel.management.mbean.ManagedEndpoint;
import org.apache.camel.management.mbean.ManagedEndpointRegistry;
import org.apache.camel.management.mbean.ManagedInflightRepository;
import org.apache.camel.management.mbean.ManagedProducerCache;
+import org.apache.camel.management.mbean.ManagedReloadStrategy;
import org.apache.camel.management.mbean.ManagedRestRegistry;
import org.apache.camel.management.mbean.ManagedRoute;
import org.apache.camel.management.mbean.ManagedRuntimeEndpointRegistry;
@@ -91,6 +92,7 @@ import org.apache.camel.spi.ManagementAware;
import org.apache.camel.spi.ManagementNameStrategy;
import org.apache.camel.spi.ManagementObjectStrategy;
import org.apache.camel.spi.ManagementStrategy;
+import org.apache.camel.spi.ReloadStrategy;
import org.apache.camel.spi.RestRegistry;
import org.apache.camel.spi.RouteContext;
import org.apache.camel.spi.RuntimeEndpointRegistry;
@@ -487,6 +489,8 @@ public class DefaultManagementLifecycleStrategy extends ServiceSupport implement
answer = new ManagedStreamCachingStrategy(context, (StreamCachingStrategy) service);
} else if (service instanceof EventNotifier) {
answer = getManagementObjectStrategy().getManagedObjectForEventNotifier(context, (EventNotifier) service);
+ } else if (service instanceof ReloadStrategy) {
+ answer = new ManagedReloadStrategy(context, (ReloadStrategy) service);
} else if (service != null) {
// fallback as generic service
answer = getManagementObjectStrategy().getManagedObjectForService(context, service);
http://git-wip-us.apache.org/repos/asf/camel/blob/417c57d7/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedReloadStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedReloadStrategy.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedReloadStrategy.java
new file mode 100644
index 0000000..3635c7c
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedReloadStrategy.java
@@ -0,0 +1,50 @@
+/**
+ * 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.management.mbean;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.api.management.ManagedResource;
+import org.apache.camel.api.management.mbean.ManagedReloadStrategyMBean;
+import org.apache.camel.spi.ReloadStrategy;
+
+/**
+ * @version
+ */
+@ManagedResource(description = "Managed ReloadStrategy")
+public class ManagedReloadStrategy extends ManagedService implements ManagedReloadStrategyMBean {
+ private final ReloadStrategy reloadStrategy;
+
+ public ManagedReloadStrategy(CamelContext context, ReloadStrategy reloadStrategy) {
+ super(context, reloadStrategy);
+ this.reloadStrategy = reloadStrategy;
+ }
+
+ @Override
+ public String getStrategy() {
+ return reloadStrategy.getClass().getSimpleName();
+ }
+
+ @Override
+ public int getReloadCounter() {
+ return reloadStrategy.getReloadCounter();
+ }
+
+ @Override
+ public int getFailedCounter() {
+ return reloadStrategy.getFailedCounter();
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/417c57d7/camel-core/src/main/java/org/apache/camel/spi/ReloadStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/ReloadStrategy.java b/camel-core/src/main/java/org/apache/camel/spi/ReloadStrategy.java
index 7f30552..3c74dac 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/ReloadStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/ReloadStrategy.java
@@ -29,7 +29,6 @@ import org.apache.camel.StaticService;
public interface ReloadStrategy extends Service, StaticService, CamelContextAware {
// TODO: naming of this SPI?
- // TODO: Add JMX mbean
/**
* A reload is triggered and the {@link CamelContext} is expected to do a re-start
@@ -46,4 +45,14 @@ public interface ReloadStrategy extends Service, StaticService, CamelContextAwar
* @param resource the changed resource
*/
void onReloadRoutes(CamelContext camelContext, String name, InputStream resource);
+
+ /**
+ * Number of reloads succeeded.
+ */
+ int getReloadCounter();
+
+ /**
+ * Number of reloads failed.
+ */
+ int getFailedCounter();
}
http://git-wip-us.apache.org/repos/asf/camel/blob/417c57d7/camel-core/src/main/java/org/apache/camel/support/ReloadStrategySupport.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/support/ReloadStrategySupport.java b/camel-core/src/main/java/org/apache/camel/support/ReloadStrategySupport.java
index 355f19d..e0957d7 100644
--- a/camel-core/src/main/java/org/apache/camel/support/ReloadStrategySupport.java
+++ b/camel-core/src/main/java/org/apache/camel/support/ReloadStrategySupport.java
@@ -33,6 +33,9 @@ public abstract class ReloadStrategySupport extends ServiceSupport implements Re
protected final Logger log = LoggerFactory.getLogger(getClass());
private CamelContext camelContext;
+ private int succeeded;
+ private int failed;
+
@Override
public CamelContext getCamelContext() {
return camelContext;
@@ -50,21 +53,41 @@ public abstract class ReloadStrategySupport extends ServiceSupport implements Re
ServiceHelper.stopService(camelContext);
ServiceHelper.startService(camelContext);
} catch (Exception e) {
+ failed++;
throw ObjectHelper.wrapRuntimeCamelException(e);
}
log.info("Reloaded CamelContext: {}", camelContext.getName());
+
+ succeeded++;
}
@Override
public void onReloadRoutes(CamelContext camelContext, String name, InputStream resource) {
+
+ // load the stream in as DOM and find out if its <routes> <route> or <camelContext>
+ // and if its <blueprint> <beans> etc and then find inside the <camelContext> and grab what we support re-loading
+
log.debug("Reloading CamelContext: {} routes from resource: {}", camelContext.getName(), name);
// assume the resource is XML routes
try {
RoutesDefinition routes = camelContext.loadRoutesDefinition(resource);
camelContext.addRouteDefinitions(routes.getRoutes());
} catch (Exception e) {
+ failed++;
throw ObjectHelper.wrapRuntimeCamelException(e);
}
log.info("Reloaded CamelContext: {} routes from resource: {}", camelContext.getName(), name);
+
+ succeeded++;
+ }
+
+ @Override
+ public int getReloadCounter() {
+ return succeeded;
+ }
+
+ @Override
+ public int getFailedCounter() {
+ return failed;
}
}