You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by cs...@apache.org on 2011/10/05 09:56:44 UTC

svn commit: r1179088 - in /camel/trunk/camel-core/src/main/java/org/apache/camel: api/management/ management/

Author: cschneider
Date: Wed Oct  5 07:56:43 2011
New Revision: 1179088

URL: http://svn.apache.org/viewvc?rev=1179088&view=rev
Log:
CAMEL-4516 Adding notification support for jmx mbean assembler

Added:
    camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/ManagedNotification.java   (with props)
    camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/ManagedNotifications.java   (with props)
    camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/NotificationSender.java   (with props)
    camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/NotificationSenderAware.java   (with props)
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/NotificationSenderAdapter.java   (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementMBeanAssembler.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/MBeanInfoAssembler.java

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/ManagedNotification.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/ManagedNotification.java?rev=1179088&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/ManagedNotification.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/ManagedNotification.java Wed Oct  5 07:56:43 2011
@@ -0,0 +1,38 @@
+/**
+ * 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;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Inherited
+@Documented
+public @interface ManagedNotification {
+
+        String name();
+
+        String description() default "";
+
+        String[] notificationTypes();
+
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/ManagedNotification.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/ManagedNotifications.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/ManagedNotifications.java?rev=1179088&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/ManagedNotifications.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/ManagedNotifications.java Wed Oct  5 07:56:43 2011
@@ -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.api.management;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target(ElementType.TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+@Inherited
+@Documented
+public @interface ManagedNotifications {
+
+        ManagedNotification[] value();
+
+}
\ No newline at end of file

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/ManagedNotifications.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/NotificationSender.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/NotificationSender.java?rev=1179088&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/NotificationSender.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/NotificationSender.java Wed Oct  5 07:56:43 2011
@@ -0,0 +1,26 @@
+/**
+ * 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;
+
+import javax.management.Notification;
+
+/**
+ * To be implemented by classes that can send out notifications
+ */
+public interface NotificationSender {
+    void sendNotification(Notification notification);
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/NotificationSender.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/NotificationSenderAware.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/NotificationSenderAware.java?rev=1179088&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/NotificationSenderAware.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/NotificationSenderAware.java Wed Oct  5 07:56:43 2011
@@ -0,0 +1,25 @@
+/**
+ * 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;
+
+/**
+ * To be implemented by the user class to get a NotificationSender injected
+ *
+ */
+public interface NotificationSenderAware {
+    void setNotificationSender(NotificationSender sender);
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/NotificationSenderAware.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementMBeanAssembler.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementMBeanAssembler.java?rev=1179088&r1=1179087&r2=1179088&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementMBeanAssembler.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementMBeanAssembler.java Wed Oct  5 07:56:43 2011
@@ -26,6 +26,7 @@ import javax.management.modelmbean.Requi
 
 import org.apache.camel.api.management.ManagedInstance;
 import org.apache.camel.api.management.ManagedResource;
+import org.apache.camel.api.management.NotificationSenderAware;
 import org.apache.camel.spi.ManagementMBeanAssembler;
 import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
@@ -75,6 +76,11 @@ public class DefaultManagementMBeanAssem
         } catch (InvalidTargetObjectTypeException e) {
             throw new JMException(e.getMessage());
         }
+        
+        // Allows the managed object to send notifications
+        if (obj instanceof NotificationSenderAware) {
+            ((NotificationSenderAware)obj).setNotificationSender(new NotificationSenderAdapter(mbean));
+        }
 
         return mbean;
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/MBeanInfoAssembler.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/MBeanInfoAssembler.java?rev=1179088&r1=1179087&r2=1179088&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/MBeanInfoAssembler.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/MBeanInfoAssembler.java Wed Oct  5 07:56:43 2011
@@ -27,9 +27,12 @@ import javax.management.JMException;
 import javax.management.modelmbean.ModelMBeanAttributeInfo;
 import javax.management.modelmbean.ModelMBeanInfo;
 import javax.management.modelmbean.ModelMBeanInfoSupport;
+import javax.management.modelmbean.ModelMBeanNotificationInfo;
 import javax.management.modelmbean.ModelMBeanOperationInfo;
 
 import org.apache.camel.api.management.ManagedAttribute;
+import org.apache.camel.api.management.ManagedNotification;
+import org.apache.camel.api.management.ManagedNotifications;
 import org.apache.camel.api.management.ManagedOperation;
 import org.apache.camel.api.management.ManagedResource;
 import org.apache.camel.util.IntrospectionSupport;
@@ -59,23 +62,37 @@ public class MBeanInfoAssembler {
         List<ManagedOperationInfo> operations = new ArrayList<ManagedOperationInfo>();
         List<ModelMBeanAttributeInfo> mBeanAttributes = new ArrayList<ModelMBeanAttributeInfo>();
         List<ModelMBeanOperationInfo> mBeanOperations = new ArrayList<ModelMBeanOperationInfo>();
+        
 
         // extract details
         extractAttributesAndOperations(managedBean, attributes, operations);
         extractMbeanAttributes(managedBean, attributes, mBeanAttributes, mBeanOperations);
         extractMbeanOperations(managedBean, operations, mBeanOperations);
+        List<ModelMBeanNotificationInfo> mBeanNotifications = extractMbeanNotifiations(managedBean);
 
         // create the ModelMBeanInfo
         String name = getName(managedBean, objectName);
         String description = getDescription(managedBean, objectName);
         ModelMBeanAttributeInfo[] arrayAttributes = mBeanAttributes.toArray(new ModelMBeanAttributeInfo[mBeanAttributes.size()]);
         ModelMBeanOperationInfo[] arrayOperations = mBeanOperations.toArray(new ModelMBeanOperationInfo[mBeanOperations.size()]);
+        ModelMBeanNotificationInfo[] arrayNotifications = mBeanNotifications.toArray(new ModelMBeanNotificationInfo[mBeanNotifications.size()]);
 
-        ModelMBeanInfo info = new ModelMBeanInfoSupport(name, description, arrayAttributes, null, arrayOperations, null);
+        ModelMBeanInfo info = new ModelMBeanInfoSupport(name, description, arrayAttributes, null, arrayOperations, arrayNotifications);
         LOG.trace("Created ModelMBeanInfo {}", info);
         return info;
     }
 
+    private List<ModelMBeanNotificationInfo> extractMbeanNotifiations(Object managedBean) {
+        List<ModelMBeanNotificationInfo> mBeanNotifications = new ArrayList<ModelMBeanNotificationInfo>();
+        ManagedNotifications notifications = managedBean.getClass().getAnnotation(ManagedNotifications.class);
+        if (notifications != null) {
+            for (ManagedNotification notification : notifications.value()) {
+                mBeanNotifications.add(new ModelMBeanNotificationInfo(notification.notificationTypes(), notification.name(), notification.description()));
+            }
+        }
+        return mBeanNotifications;
+    }
+
     private void extractAttributesAndOperations(Object managedBean, Map<String, ManagedAttributeInfo> attributes, List<ManagedOperationInfo> operations) {
         for (Method method : managedBean.getClass().getMethods()) {
 

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/management/NotificationSenderAdapter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/NotificationSenderAdapter.java?rev=1179088&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/NotificationSenderAdapter.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/NotificationSenderAdapter.java Wed Oct  5 07:56:43 2011
@@ -0,0 +1,39 @@
+/**
+ * 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;
+
+import javax.management.Notification;
+import javax.management.modelmbean.ModelMBeanNotificationBroadcaster;
+
+import org.apache.camel.api.management.NotificationSender;
+
+final class NotificationSenderAdapter implements NotificationSender {
+    ModelMBeanNotificationBroadcaster broadcaster;
+
+    public NotificationSenderAdapter(ModelMBeanNotificationBroadcaster broadcaster) {
+        this.broadcaster = broadcaster;
+    }
+
+    @Override
+    public void sendNotification(Notification notification) {
+        try {
+            broadcaster.sendNotification(notification);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+}
\ No newline at end of file

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/management/NotificationSenderAdapter.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain