camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [3/8] camel git commit: CAMEL-9157: JMX - Add dataformat as mbean category
Date Thu, 24 Sep 2015 11:36:16 GMT
CAMEL-9157: JMX - Add dataformat as mbean category


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

Branch: refs/heads/master
Commit: ca7fd9a833ffa5a8895159564f18a4d7cff8f950
Parents: 5f399e6
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Sep 24 11:29:19 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Sep 24 11:29:19 2015 +0200

----------------------------------------------------------------------
 .../mbean/ManagedDataFormatMBean.java           | 41 +++++++++
 .../DefaultManagementLifecycleStrategy.java     |  3 +
 .../DefaultManagementObjectStrategy.java        | 13 +++
 .../management/ManagedManagementStrategy.java   | 12 ++-
 .../management/mbean/ManagedDataFormat.java     | 91 ++++++++++++++++++++
 .../camel/spi/ManagementObjectStrategy.java     |  2 +
 6 files changed, 155 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ca7fd9a8/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedDataFormatMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedDataFormatMBean.java
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedDataFormatMBean.java
new file mode 100644
index 0000000..c5ed0e0
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedDataFormatMBean.java
@@ -0,0 +1,41 @@
+/**
+ * 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 javax.management.openmbean.TabularData;
+
+import org.apache.camel.api.management.ManagedAttribute;
+import org.apache.camel.api.management.ManagedOperation;
+
+public interface ManagedDataFormatMBean {
+
+    @ManagedAttribute(description = "Camel ID")
+    String getCamelId();
+
+    @ManagedAttribute(description = "Camel ManagementName")
+    String getCamelManagementName();
+
+    @ManagedAttribute(description = "DataFormat State")
+    String getState();
+
+    @ManagedOperation(description = "DataFormat information as JSon")
+    String informationJson();
+
+    @ManagedOperation(description = "Explain how this data format is configured")
+    TabularData explain(boolean allOptions);
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/ca7fd9a8/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 ab4db16..1c52d2a 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
@@ -81,6 +81,7 @@ import org.apache.camel.processor.interceptor.BacklogDebugger;
 import org.apache.camel.processor.interceptor.BacklogTracer;
 import org.apache.camel.processor.interceptor.Tracer;
 import org.apache.camel.spi.AsyncProcessorAwaitManager;
+import org.apache.camel.spi.DataFormat;
 import org.apache.camel.spi.EventNotifier;
 import org.apache.camel.spi.InflightRepository;
 import org.apache.camel.spi.LifecycleStrategy;
@@ -449,6 +450,8 @@ public class DefaultManagementLifecycleStrategy extends ServiceSupport
implement
                 managedBacklogDebuggers.put(backlogDebugger, md);
             }
             return md;
+        } else if (service instanceof DataFormat) {
+            answer = getManagementObjectStrategy().getManagedObjectForDataFormat(context,
(DataFormat) service);
         } else if (service instanceof Producer) {
             answer = getManagementObjectStrategy().getManagedObjectForProducer(context, (Producer)
service);
         } else if (service instanceof Consumer) {

http://git-wip-us.apache.org/repos/asf/camel/blob/ca7fd9a8/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
index 95d2a0f..d30e4fe 100644
--- a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementObjectStrategy.java
@@ -42,6 +42,7 @@ import org.apache.camel.management.mbean.ManagedComponent;
 import org.apache.camel.management.mbean.ManagedConsumer;
 import org.apache.camel.management.mbean.ManagedConvertBody;
 import org.apache.camel.management.mbean.ManagedCustomLoadBalancer;
+import org.apache.camel.management.mbean.ManagedDataFormat;
 import org.apache.camel.management.mbean.ManagedDelayer;
 import org.apache.camel.management.mbean.ManagedDynamicRouter;
 import org.apache.camel.management.mbean.ManagedEndpoint;
@@ -153,6 +154,7 @@ import org.apache.camel.processor.loadbalancer.TopicLoadBalancer;
 import org.apache.camel.processor.loadbalancer.WeightedLoadBalancer;
 import org.apache.camel.processor.validation.PredicateValidatingProcessor;
 import org.apache.camel.spi.BrowsableEndpoint;
+import org.apache.camel.spi.DataFormat;
 import org.apache.camel.spi.EventNotifier;
 import org.apache.camel.spi.ManagementObjectStrategy;
 import org.apache.camel.spi.RouteContext;
@@ -180,6 +182,17 @@ public class DefaultManagementObjectStrategy implements ManagementObjectStrategy
     }
 
     @SuppressWarnings({"deprecation", "unchecked"})
+    public Object getManagedObjectForDataFormat(CamelContext context, DataFormat dataFormat)
{
+        if (dataFormat instanceof org.apache.camel.spi.ManagementAware) {
+            return ((org.apache.camel.spi.ManagementAware<DataFormat>) dataFormat).getManagedObject(dataFormat);
+        } else {
+            ManagedDataFormat md = new ManagedDataFormat(context, dataFormat);
+            md.init(context.getManagementStrategy());
+            return md;
+        }
+    }
+
+    @SuppressWarnings({"deprecation", "unchecked"})
     public Object getManagedObjectForEndpoint(CamelContext context, Endpoint endpoint) {
         // we only want to manage singleton endpoints
         if (!endpoint.isSingleton()) {

http://git-wip-us.apache.org/repos/asf/camel/blob/ca7fd9a8/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java
b/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java
index 942df5f..58a6982 100644
--- a/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java
@@ -25,6 +25,7 @@ import org.apache.camel.management.mbean.ManagedBacklogTracer;
 import org.apache.camel.management.mbean.ManagedCamelContext;
 import org.apache.camel.management.mbean.ManagedComponent;
 import org.apache.camel.management.mbean.ManagedConsumer;
+import org.apache.camel.management.mbean.ManagedDataFormat;
 import org.apache.camel.management.mbean.ManagedEndpoint;
 import org.apache.camel.management.mbean.ManagedErrorHandler;
 import org.apache.camel.management.mbean.ManagedEventNotifier;
@@ -35,7 +36,6 @@ import org.apache.camel.management.mbean.ManagedService;
 import org.apache.camel.management.mbean.ManagedThreadPool;
 import org.apache.camel.management.mbean.ManagedTracer;
 import org.apache.camel.model.ProcessorDefinition;
-import org.apache.camel.spi.DataFormat;
 import org.apache.camel.spi.ManagementAgent;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -92,6 +92,9 @@ public class ManagedManagementStrategy extends DefaultManagementStrategy
{
         } else if (managedObject instanceof ManagedComponent) {
             ManagedComponent mc = (ManagedComponent) managedObject;
             objectName = getManagementNamingStrategy().getObjectNameForComponent(mc.getComponent(),
mc.getComponentName());
+        } else if (managedObject instanceof ManagedDataFormat) {
+            ManagedDataFormat md = (ManagedDataFormat) managedObject;
+            objectName = getManagementNamingStrategy().getObjectNameForDataFormat(md.getContext(),
md.getDataFormat());
         } else if (managedObject instanceof ManagedEndpoint) {
             ManagedEndpoint me = (ManagedEndpoint) managedObject;
             objectName = getManagementNamingStrategy().getObjectNameForEndpoint(me.getEndpoint());
@@ -134,12 +137,7 @@ public class ManagedManagementStrategy extends DefaultManagementStrategy
{
             if (ms.getService() instanceof Endpoint) {
                 return null;
             }
-            if (ms.getService() instanceof DataFormat) {
-                DataFormat df = (DataFormat) ms.getService();
-                objectName = getManagementNamingStrategy().getObjectNameForDataFormat(ms.getContext(),
df);
-            } else {
-                objectName = getManagementNamingStrategy().getObjectNameForService(ms.getContext(),
ms.getService());
-            }
+            objectName = getManagementNamingStrategy().getObjectNameForService(ms.getContext(),
ms.getService());
         }
 
         return nameType.cast(objectName);

http://git-wip-us.apache.org/repos/asf/camel/blob/ca7fd9a8/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedDataFormat.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedDataFormat.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedDataFormat.java
new file mode 100644
index 0000000..dcb5e09
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedDataFormat.java
@@ -0,0 +1,91 @@
+/**
+ * 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 javax.management.openmbean.TabularData;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ServiceStatus;
+import org.apache.camel.StatefulService;
+import org.apache.camel.api.management.ManagedInstance;
+import org.apache.camel.api.management.ManagedResource;
+import org.apache.camel.api.management.mbean.ManagedDataFormatMBean;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.spi.ManagementStrategy;
+
+@ManagedResource(description = "Managed DataFormat")
+public class ManagedDataFormat implements ManagedInstance, ManagedDataFormatMBean {
+    private final CamelContext camelContext;
+    private final DataFormat dataFormat;
+
+    public ManagedDataFormat(CamelContext camelContext, DataFormat dataFormat) {
+        this.camelContext = camelContext;
+        this.dataFormat = dataFormat;
+    }
+
+    public void init(ManagementStrategy strategy) {
+        // noop
+    }
+
+    public DataFormat getDataFormat() {
+        return dataFormat;
+    }
+
+    public CamelContext getContext() {
+        return camelContext;
+    }
+
+    @Override
+    public String getCamelId() {
+        return camelContext.getName();
+    }
+
+    @Override
+    public String getCamelManagementName() {
+        return camelContext.getManagementName();
+    }
+
+    @Override
+    public String getState() {
+        // must use String type to be sure remote JMX can read the attribute without requiring
Camel classes.
+        if (dataFormat instanceof StatefulService) {
+            ServiceStatus status = ((StatefulService) dataFormat).getStatus();
+            return status.name();
+        }
+
+        // assume started if not a ServiceSupport instance
+        return ServiceStatus.Started.name();
+    }
+
+    @Override
+    public String informationJson() {
+        // TODO: not yet implemented
+        return null;
+    }
+
+    @Override
+    public TabularData explain(boolean allOptions) {
+        // TODO: not yet implemented
+        return null;
+    }
+
+    @Override
+    public DataFormat getInstance() {
+        return dataFormat;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/ca7fd9a8/camel-core/src/main/java/org/apache/camel/spi/ManagementObjectStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/ManagementObjectStrategy.java b/camel-core/src/main/java/org/apache/camel/spi/ManagementObjectStrategy.java
index 5190cd6..b6acc7f 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/ManagementObjectStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/ManagementObjectStrategy.java
@@ -38,6 +38,8 @@ public interface ManagementObjectStrategy {
 
     Object getManagedObjectForComponent(CamelContext context, Component component, String
name);
 
+    Object getManagedObjectForDataFormat(CamelContext context, DataFormat dataFormat);
+
     Object getManagedObjectForEndpoint(CamelContext context, Endpoint endpoint);
 
     Object getManagedObjectForErrorHandler(CamelContext context, RouteContext routeContext,


Mime
View raw message