camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r956772 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/impl/ main/java/org/apache/camel/management/ main/java/org/apache/camel/management/mbean/ main/java/org/apache/camel/spi/ test/java/org/apache/camel/management/
Date Tue, 22 Jun 2010 04:44:47 GMT
Author: ningjiang
Date: Tue Jun 22 04:44:46 2010
New Revision: 956772

URL: http://svn.apache.org/viewvc?rev=956772&view=rev
Log:
CAMEL-2753 JMX notification for events

Added:
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/JmxNotificationBroadcasterAware.java
  (with props)
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/JmxNotificationEventNotifier.java
  (with props)
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEventNotifier.java
  (with props)
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEventNotifierMBean.java
  (with props)
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxNotificationEventNotifierTest.java
  (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedThreadPool.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTracer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ManagementNamingStrategy.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTracerTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedDualCamelContextTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=956772&r1=956771&r2=956772&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Tue
Jun 22 04:44:46 2010
@@ -33,6 +33,7 @@ import java.util.concurrent.atomic.Atomi
 import javax.naming.Context;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
 import org.apache.camel.Component;
 import org.apache.camel.Consumer;
 import org.apache.camel.ConsumerTemplate;
@@ -72,6 +73,7 @@ import org.apache.camel.spi.ComponentRes
 import org.apache.camel.spi.DataFormat;
 import org.apache.camel.spi.DataFormatResolver;
 import org.apache.camel.spi.EndpointStrategy;
+import org.apache.camel.spi.EventNotifier;
 import org.apache.camel.spi.ExecutorServiceStrategy;
 import org.apache.camel.spi.FactoryFinder;
 import org.apache.camel.spi.FactoryFinderResolver;
@@ -134,6 +136,7 @@ public class DefaultCamelContext extends
     private AtomicBoolean managementStrategyInitialized = new AtomicBoolean(false);
     private final List<RouteDefinition> routeDefinitions = new ArrayList<RouteDefinition>();
     private List<InterceptStrategy> interceptStrategies = new ArrayList<InterceptStrategy>();
+    
     private boolean firstStartDone;
     private Boolean autoStartup = Boolean.TRUE;
     private Boolean trace = Boolean.FALSE;
@@ -605,7 +608,7 @@ public class DefaultCamelContext extends
         }
         startServices(object);
     }
-
+   
     public boolean hasService(Object object) {
         if (object instanceof Service) {
             return servicesToClose.contains(object);
@@ -1010,6 +1013,17 @@ public class DefaultCamelContext extends
             }
         }
 
+        // start notifiers as services
+        for (EventNotifier notifier : getManagementStrategy().getEventNotifiers()) {
+            if (notifier instanceof Service) {
+                Service service = (Service) notifier;
+                for (LifecycleStrategy strategy : lifecycleStrategies) {
+                    strategy.onServiceAdd(this, service, null);
+                }
+            }
+            startServices(notifier);
+        }
+
         // must let some bootstrap service be started before we can notify the starting event
         EventHelper.notifyCamelContextStarting(this);
 
@@ -1068,6 +1082,11 @@ public class DefaultCamelContext extends
 
         // must notify that we are stopped before stopping the management strategy
         EventHelper.notifyCamelContextStopped(this);
+        
+        // stop the notifier service
+        for (EventNotifier notifier : getManagementStrategy().getEventNotifiers()) {
+            shutdownServices(notifier);
+        }
 
         // shutdown management as the last one
         shutdownServices(managementStrategy);
@@ -1629,6 +1648,12 @@ public class DefaultCamelContext extends
             answer = new DefaultManagementStrategy();
         }
 
+        // inject CamelContext
+        if (answer instanceof CamelContextAware) {
+            CamelContextAware aware = (CamelContextAware) answer;
+            aware.setCamelContext(this);
+        }
+
         return answer;
     }
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java?rev=956772&r1=956771&r2=956772&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
Tue Jun 22 04:44:46 2010
@@ -20,11 +20,8 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.concurrent.ThreadPoolExecutor;
 import javax.management.JMException;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.CamelContextAware;
@@ -48,6 +45,7 @@ import org.apache.camel.management.mbean
 import org.apache.camel.management.mbean.ManagedDelayer;
 import org.apache.camel.management.mbean.ManagedEndpoint;
 import org.apache.camel.management.mbean.ManagedErrorHandler;
+import org.apache.camel.management.mbean.ManagedEventNotifier;
 import org.apache.camel.management.mbean.ManagedPerformanceCounter;
 import org.apache.camel.management.mbean.ManagedProcessor;
 import org.apache.camel.management.mbean.ManagedProducer;
@@ -73,6 +71,7 @@ import org.apache.camel.processor.SendPr
 import org.apache.camel.processor.Throttler;
 import org.apache.camel.processor.interceptor.Tracer;
 import org.apache.camel.spi.BrowsableEndpoint;
+import org.apache.camel.spi.EventNotifier;
 import org.apache.camel.spi.LifecycleStrategy;
 import org.apache.camel.spi.ManagementAware;
 import org.apache.camel.spi.ManagementStrategy;
@@ -297,6 +296,11 @@ public class DefaultManagementLifecycleS
             ManagedTracer mt = new ManagedTracer(context, (Tracer) service);
             mt.init(getManagementStrategy());
             return mt;
+        } else if (service instanceof EventNotifier) {
+            // special for event notifier
+            ManagedEventNotifier men = new ManagedEventNotifier(context, (EventNotifier)
service);
+            men.init(getManagementStrategy());
+            return men;            
         } else if (service instanceof Producer) {
             answer = new ManagedProducer(context, (Producer) service);
         } else if (service instanceof ScheduledPollConsumer) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java?rev=956772&r1=956771&r2=956772&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementNamingStrategy.java
Tue Jun 22 04:44:46 2010
@@ -33,6 +33,7 @@ import org.apache.camel.Service;
 import org.apache.camel.builder.ErrorHandlerBuilder;
 import org.apache.camel.builder.ErrorHandlerBuilderRef;
 import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.spi.EventNotifier;
 import org.apache.camel.spi.InterceptStrategy;
 import org.apache.camel.spi.ManagementNamingStrategy;
 import org.apache.camel.spi.RouteContext;
@@ -54,6 +55,7 @@ public class DefaultManagementNamingStra
     public static final String TYPE_ROUTE = "routes";
     public static final String TYPE_COMPONENT = "components";
     public static final String TYPE_TRACER = "tracer";
+    public static final String TYPE_EVENT_NOTIFIER = "eventnotifiers";
     public static final String TYPE_ERRORHANDLER = "errorhandlers";
     public static final String TYPE_THREAD_POOL = "threadpools";
     public static final String TYPE_SERVICE = "services";
@@ -207,6 +209,24 @@ public class DefaultManagementNamingStra
         return createObjectName(buffer);
     }
 
+    public ObjectName getObjectNameForEventNotifier(CamelContext context, EventNotifier eventNotifier)
throws MalformedObjectNameException {
+        StringBuilder buffer = new StringBuilder();
+        buffer.append(domainName).append(":");
+        buffer.append(KEY_CONTEXT + "=").append(getContextId(context)).append(",");
+        buffer.append(KEY_TYPE + "=" + TYPE_EVENT_NOTIFIER + ",");
+
+        if (eventNotifier instanceof JmxNotificationEventNotifier) {
+            // JMX notifier shall have an easy to use name
+            buffer.append(KEY_NAME + "=").append("JmxEventNotifier");
+        } else {
+            // others can be per instance
+            buffer.append(KEY_NAME + "=")
+                .append("EventNotifier")
+                .append("(").append(ObjectHelper.getIdentityHashCode(eventNotifier)).append(")");
+        }
+        return createObjectName(buffer);
+    }
+
     public ObjectName getObjectNameForRoute(Route route) throws MalformedObjectNameException
{
         Endpoint ep = route.getEndpoint();
         String id = route.getId();

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementStrategy.java?rev=956772&r1=956771&r2=956772&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementStrategy.java
Tue Jun 22 04:44:46 2010
@@ -20,6 +20,8 @@ import java.util.ArrayList;
 import java.util.EventObject;
 import java.util.List;
 
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
 import org.apache.camel.ManagementStatisticsLevel;
 import org.apache.camel.model.ProcessorDefinition;
 import org.apache.camel.spi.EventFactory;
@@ -43,7 +45,7 @@ import org.fusesource.commons.management
  * @see ManagedManagementStrategy
  * @version $Revision$
  */
-public class DefaultManagementStrategy implements ManagementStrategy {
+public class DefaultManagementStrategy implements ManagementStrategy, CamelContextAware {
 
     private List<EventNotifier> eventNotifiers = new ArrayList<EventNotifier>();
     private EventFactory eventFactory = new DefaultEventFactory();
@@ -51,6 +53,7 @@ public class DefaultManagementStrategy i
     private boolean onlyManageProcessorWithCustomId;
     private ManagementAgent managementAgent;
     private ManagementStatisticsLevel statisticsLevel = ManagementStatisticsLevel.All;
+    private CamelContext camelContext;
 
     public List<EventNotifier> getEventNotifiers() {
         return eventNotifiers;
@@ -129,6 +132,14 @@ public class DefaultManagementStrategy i
         return false;
     }
 
+    public CamelContext getCamelContext() {
+        return camelContext;
+    }
+
+    public void setCamelContext(CamelContext camelContext) {
+        this.camelContext = camelContext;
+    }
+
     public void notify(EventObject event) throws Exception {
         if (eventNotifiers != null && !eventNotifiers.isEmpty()) {
             for (EventNotifier notifier : eventNotifiers) {

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/management/JmxNotificationBroadcasterAware.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/JmxNotificationBroadcasterAware.java?rev=956772&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/JmxNotificationBroadcasterAware.java
(added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/JmxNotificationBroadcasterAware.java
Tue Jun 22 04:44:46 2010
@@ -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.management;
+
+import javax.management.NotificationBroadcasterSupport;
+
+public interface JmxNotificationBroadcasterAware {
+    
+    void setNotificationBroadcaster(NotificationBroadcasterSupport broadcaseter);
+
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/management/JmxNotificationBroadcasterAware.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/management/JmxNotificationBroadcasterAware.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/management/JmxNotificationEventNotifier.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/JmxNotificationEventNotifier.java?rev=956772&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/JmxNotificationEventNotifier.java
(added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/JmxNotificationEventNotifier.java
Tue Jun 22 04:44:46 2010
@@ -0,0 +1,86 @@
+/**
+ * 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 java.util.ArrayList;
+import java.util.EventObject;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicLong;
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.DynamicMBean;
+import javax.management.InvalidAttributeValueException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanConstructorInfo;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanNotificationInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.Notification;
+import javax.management.NotificationBroadcasterSupport;
+import javax.management.ReflectionException;
+
+import org.apache.camel.Service;
+import org.apache.camel.spi.EventNotifier;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * A JMX based {@link EventNotifier} which broadcasts JMX {@link Notification}s.
+ *
+ * @version $Revision$
+ */
+public class JmxNotificationEventNotifier extends EventNotifierSupport implements JmxNotificationBroadcasterAware
{
+
+    private static final Log LOG = LogFactory.getLog(JmxNotificationEventNotifier.class);
+    private final AtomicLong counter = new AtomicLong();
+    private NotificationBroadcasterSupport notificationBroadcaseter;
+    
+    
+    public void setNotificationBroadcaster(NotificationBroadcasterSupport broadcaseter) {
+        notificationBroadcaseter = broadcaseter;
+    }
+
+    public void notify(EventObject event) throws Exception {
+        // use simple class name as the type
+        String type = event.getClass().getSimpleName();
+        Notification notification = new Notification(type, event, counter.getAndIncrement());
+
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("Broadcasting JMX notification " + notification);
+        }
+        if (notificationBroadcaseter != null) {
+            notificationBroadcaseter.sendNotification(notification);
+        }
+    }
+
+    public boolean isEnabled(EventObject event) {
+        return true;
+    }
+
+    @Override
+    protected void doStart() throws Exception {
+        counter.set(0);
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        // TODO Auto-generated method stub
+        
+    }
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/management/JmxNotificationEventNotifier.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/management/JmxNotificationEventNotifier.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java?rev=956772&r1=956771&r2=956772&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/ManagedManagementStrategy.java
Tue Jun 22 04:44:46 2010
@@ -25,6 +25,7 @@ import org.apache.camel.management.mbean
 import org.apache.camel.management.mbean.ManagedConsumer;
 import org.apache.camel.management.mbean.ManagedEndpoint;
 import org.apache.camel.management.mbean.ManagedErrorHandler;
+import org.apache.camel.management.mbean.ManagedEventNotifier;
 import org.apache.camel.management.mbean.ManagedProcessor;
 import org.apache.camel.management.mbean.ManagedProducer;
 import org.apache.camel.management.mbean.ManagedRoute;
@@ -32,6 +33,7 @@ import org.apache.camel.management.mbean
 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.EventNotifier;
 import org.apache.camel.spi.ManagementAgent;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -110,10 +112,13 @@ public class ManagedManagementStrategy e
             objectName = getManagementNamingStrategy().getObjectNameForProducer(ms.getContext(),
ms.getProducer());
         } else if (managedObject instanceof ManagedTracer) {
             ManagedTracer mt = (ManagedTracer) managedObject;
-            objectName = getManagementNamingStrategy().getObjectNameForTracer(mt.getCamelContext(),
mt.getTracer());
+            objectName = getManagementNamingStrategy().getObjectNameForTracer(mt.getContext(),
mt.getTracer());
+        } else if (managedObject instanceof ManagedEventNotifier) {
+            ManagedEventNotifier men = (ManagedEventNotifier) managedObject;
+            objectName = getManagementNamingStrategy().getObjectNameForEventNotifier(men.getContext(),
men.getEventNotifier());
         } else if (managedObject instanceof ManagedThreadPool) {
             ManagedThreadPool mes = (ManagedThreadPool) managedObject;
-            objectName = getManagementNamingStrategy().getObjectNameForThreadPool(mes.getCamelContext(),
mes.getThreadPool());
+            objectName = getManagementNamingStrategy().getObjectNameForThreadPool(mes.getContext(),
mes.getThreadPool());
         } else if (managedObject instanceof ManagedService) {
             // check for managed service should be last
             ManagedService ms = (ManagedService) managedObject;

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEventNotifier.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEventNotifier.java?rev=956772&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEventNotifier.java
(added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEventNotifier.java
Tue Jun 22 04:44:46 2010
@@ -0,0 +1,140 @@
+/**
+ * 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 java.util.ArrayList;
+import java.util.List;
+
+import javax.management.MBeanNotificationInfo;
+import javax.management.NotificationBroadcasterSupport;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.management.JmxNotificationBroadcasterAware;
+import org.apache.camel.spi.EventNotifier;
+import org.apache.camel.spi.ManagementStrategy;
+
+/**
+ * @version $Revision$
+ */
+public class ManagedEventNotifier extends NotificationBroadcasterSupport implements ManagedEventNotifierMBean
{
+
+    private CamelContext context;
+    private EventNotifier eventNotifier;
+
+    public ManagedEventNotifier(CamelContext context, EventNotifier eventNotifier) {
+        this.context = context;
+        this.eventNotifier = eventNotifier;
+        if (eventNotifier instanceof JmxNotificationBroadcasterAware) {
+            ((JmxNotificationBroadcasterAware)eventNotifier).setNotificationBroadcaster(this);
+        }
+    }
+
+    public void init(ManagementStrategy strategy) {
+        // do nothing
+    }
+
+    public CamelContext getContext() {
+        return context;
+    }
+
+    public EventNotifier getEventNotifier() {
+        return eventNotifier;
+    }
+    
+    public boolean isIgnoreCamelContextEvents() {
+        return getEventNotifier().isIgnoreCamelContextEvents();
+    }
+    
+    public void setIgnoreCamelContextEvents(boolean ignoreCamelContextEvents) {
+        getEventNotifier().setIgnoreCamelContextEvents(ignoreCamelContextEvents);
+    }
+    
+    public boolean isIgnoreRouteEvents() {
+        return getEventNotifier().isIgnoreRouteEvents();
+    }
+    
+    public void setIgnoreRouteEvents(boolean ignoreRouteEvents) {
+        getEventNotifier().setIgnoreRouteEvents(ignoreRouteEvents);
+    }
+    
+    public boolean isIgnoreServiceEvents() {
+        return getEventNotifier().isIgnoreServiceEvents();
+    }
+   
+    public void setIgnoreServiceEvents(boolean ignoreServiceEvents) {
+        getEventNotifier().setIgnoreServiceEvents(ignoreServiceEvents);
+    }
+   
+    public boolean isIgnoreExchangeEvents() {
+        return getEventNotifier().isIgnoreExchangeEvents();
+    }
+    
+    public void setIgnoreExchangeEvents(boolean ignoreExchangeEvents) {
+        getEventNotifier().setIgnoreExchangeEvents(ignoreExchangeEvents);
+    }
+    
+    public boolean isIgnoreExchangeCreatedEvent() {
+        return getEventNotifier().isIgnoreExchangeCreatedEvent();
+    }
+   
+    public void setIgnoreExchangeCreatedEvent(boolean ignoreExchangeCreatedEvent) {
+        getEventNotifier().setIgnoreExchangeCreatedEvent(ignoreExchangeCreatedEvent);
+    }
+    
+    public boolean isIgnoreExchangeCompletedEvent() {
+        return getEventNotifier().isIgnoreExchangeCompletedEvent();
+    }
+    
+    public void setIgnoreExchangeCompletedEvent(boolean ignoreExchangeCompletedEvent) {
+        getEventNotifier().setIgnoreExchangeCompletedEvent(ignoreExchangeCompletedEvent);
+    }
+    
+    public boolean isIgnoreExchangeFailureEvents() {
+        return getEventNotifier().isIgnoreExchangeFailureEvents();
+    }
+    
+    public void setIgnoreExchangeFailureEvents(boolean ignoreExchangeFailureEvents) {
+        getEventNotifier().setIgnoreExchangeFailureEvents(ignoreExchangeFailureEvents);
+    }
+
+    public boolean isIgnoreExchangeSentEvents() {
+        return getEventNotifier().isIgnoreExchangeSentEvents();
+    }
+ 
+    public void setIgnoreExchangeSentEvents(boolean ignoreExchangeSentEvents) {
+        getEventNotifier().setIgnoreExchangeSentEvents(ignoreExchangeSentEvents);
+    }
+    
+    public MBeanNotificationInfo[] getNotificationInfo() {
+        // all the class names in the event package
+        String[] names = {"CamelContextStartedEvent", "CamelContextStartingEvent", "CamelContextStartupFailureEvent"
+                , "CamelContextStopFailureEvent", "CamelContextStoppedEvent", "CamelContextStoppingEvent"
+                , "ExchangeCompletedEvent", "ExchangeCreatedEvent", "ExchangeFailureEvent"
+                , "ExchangeFailureHandledEvent", "ExchangeSentEvent", "RouteStartedEvent"
+                , "RouteStoppedEvent", "ServiceStartupFailureEvent", "ServiceStopFailureEvent"};
+
+        List<MBeanNotificationInfo> infos = new ArrayList<MBeanNotificationInfo>();
+        for (String name : names) {
+            MBeanNotificationInfo info = new MBeanNotificationInfo(new String[]{"org.apache.camel.management.event"},
+                    "org.apache.camel.management.event." + name, "The event " + name + "
occurred");
+            infos.add(info);
+        }
+
+        return infos.toArray(new MBeanNotificationInfo[infos.size()]);
+    }
+
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEventNotifier.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEventNotifier.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEventNotifierMBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEventNotifierMBean.java?rev=956772&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEventNotifierMBean.java
(added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEventNotifierMBean.java
Tue Jun 22 04:44:46 2010
@@ -0,0 +1,53 @@
+/**
+ * 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;
+
+public interface ManagedEventNotifierMBean {
+    
+    boolean isIgnoreCamelContextEvents();
+
+    void setIgnoreCamelContextEvents(boolean ignoreCamelContextEvents);
+
+    boolean isIgnoreRouteEvents();
+
+    void setIgnoreRouteEvents(boolean ignoreRouteEvents);
+
+    boolean isIgnoreServiceEvents();
+
+    void setIgnoreServiceEvents(boolean ignoreServiceEvents);
+
+    boolean isIgnoreExchangeEvents();
+
+    void setIgnoreExchangeEvents(boolean ignoreExchangeEvents);
+
+    boolean isIgnoreExchangeCreatedEvent();
+
+    void setIgnoreExchangeCreatedEvent(boolean ignoreExchangeCreatedEvent);
+
+    boolean isIgnoreExchangeCompletedEvent();
+
+    void setIgnoreExchangeCompletedEvent(boolean ignoreExchangeCompletedEvent);
+
+    boolean isIgnoreExchangeFailureEvents();
+
+    void setIgnoreExchangeFailureEvents(boolean ignoreExchangeFailureEvents);
+
+    boolean isIgnoreExchangeSentEvents();
+
+    void setIgnoreExchangeSentEvents(boolean ignoreExchangeSentEvents);
+
+}

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEventNotifierMBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedEventNotifierMBean.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedThreadPool.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedThreadPool.java?rev=956772&r1=956771&r2=956772&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedThreadPool.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedThreadPool.java
Tue Jun 22 04:44:46 2010
@@ -42,7 +42,7 @@ public class ManagedThreadPool {
         // do nothing
     }
 
-    public CamelContext getCamelContext() {
+    public CamelContext getContext() {
         return camelContext;
     }
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTracer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTracer.java?rev=956772&r1=956771&r2=956772&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTracer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTracer.java
Tue Jun 22 04:44:46 2010
@@ -42,7 +42,7 @@ public class ManagedTracer {
         // do nothing
     }
 
-    public CamelContext getCamelContext() {
+    public CamelContext getContext() {
         return camelContext;
     }
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ManagementNamingStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ManagementNamingStrategy.java?rev=956772&r1=956771&r2=956772&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ManagementNamingStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/spi/ManagementNamingStrategy.java
Tue Jun 22 04:44:46 2010
@@ -60,4 +60,5 @@ public interface ManagementNamingStrateg
 
     ObjectName getObjectNameForThreadPool(CamelContext context, ThreadPoolExecutor threadPool)
throws MalformedObjectNameException;
 
+    ObjectName getObjectNameForEventNotifier(CamelContext context, EventNotifier eventNotifier)
throws MalformedObjectNameException;
 }

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxNotificationEventNotifierTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxNotificationEventNotifierTest.java?rev=956772&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxNotificationEventNotifierTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxNotificationEventNotifierTest.java
Tue Jun 22 04:44:46 2010
@@ -0,0 +1,134 @@
+/**
+ * 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 java.util.Set;
+
+import javax.management.Notification;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.util.CastUtils;
+
+/**
+ * @version $Revision$
+ */
+public class JmxNotificationEventNotifierTest extends ContextTestSupport {
+
+    private JmxNotificationEventNotifier notifier;
+
+    @Override
+    protected boolean useJmx() {
+        return true;
+    }
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        notifier = new JmxNotificationEventNotifier();
+        notifier.setIgnoreCamelContextEvents(true);
+        notifier.setIgnoreRouteEvents(true);
+        notifier.setIgnoreServiceEvents(true);
+
+        CamelContext context = new DefaultCamelContext(createRegistry());
+        context.getManagementStrategy().addEventNotifier(notifier);
+
+        DefaultManagementNamingStrategy naming = (DefaultManagementNamingStrategy) context.getManagementStrategy().getManagementNamingStrategy();
+        naming.setHostName("localhost");
+        naming.setDomainName("org.apache.camel");
+
+        return context;
+    }
+
+    public void testExchangeDone() throws Exception {
+        ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=eventnotifiers,name=JmxEventNotifier");
+        MyNotificationListener listener = new MyNotificationListener();   
+        context.getManagementStrategy().getManagementAgent().getMBeanServer().addNotificationListener(on,
+            listener,                                                                   
                     
+            new NotificationFilter() {
+                public boolean isNotificationEnabled(Notification notification) {
+                    return true;
+                }
+            }, null);
+
+        getMockEndpoint("mock:result").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+        
+        assertEquals("Get a wrong number of events", 5, listener.getEventCounter());
+
+        context.stop();
+    }
+
+    public void testExchangeFailed() throws Exception {
+        ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=eventnotifiers,name=JmxEventNotifier");
+        
+        MyNotificationListener listener = new MyNotificationListener();   
+        context.getManagementStrategy().getManagementAgent().getMBeanServer().addNotificationListener(on,
+            listener, new NotificationFilter() {
+                public boolean isNotificationEnabled(Notification notification) {
+                    return true;
+                }
+            }, null);
+        
+        try {
+            template.sendBody("direct:fail", "Hello World");
+            fail("Should have thrown an exception");
+        } catch (Exception e) {
+            // expected
+            assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+        }
+        
+        assertEquals("Get a wrong number of events", 3, listener.getEventCounter());
+
+        context.stop();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").to("log:foo").to("mock:result");
+
+                from("direct:fail").throwException(new IllegalArgumentException("Damn"));
+            }
+        };
+    }
+    
+    private class MyNotificationListener implements NotificationListener {
+        
+        private int eventCounter;
+
+        public void handleNotification(Notification notification, Object handback) {
+            log.debug("Get the notification : " + notification);
+            eventCounter++;            
+        }
+        
+        public int getEventCounter() {
+            return eventCounter;
+        }
+        
+    }
+
+}
\ No newline at end of file

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxNotificationEventNotifierTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxNotificationEventNotifierTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTracerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTracerTest.java?rev=956772&r1=956771&r2=956772&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTracerTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTracerTest.java
Tue Jun 22 04:44:46 2010
@@ -46,8 +46,7 @@ public class ManagedCamelContextTracerTe
         naming.setDomainName("org.apache.camel");
         return context;
     }
-
-    @SuppressWarnings("unchecked")
+    
     public void testCamelContextTracing() throws Exception {
         MBeanServer mbeanServer = context.getManagementStrategy().getManagementAgent().getMBeanServer();
 

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedDualCamelContextTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedDualCamelContextTest.java?rev=956772&r1=956771&r2=956772&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedDualCamelContextTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedDualCamelContextTest.java
Tue Jun 22 04:44:46 2010
@@ -39,8 +39,7 @@ public class ManagedDualCamelContextTest
         context.addRoutes(createRouteBuilder());
         return context;
     }
-
-    @SuppressWarnings("unchecked")
+    
     public void testDualCamelContext() throws Exception {
         CamelContext camel1 = createCamelContext();
         camel1.start();



Mime
View raw message