cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From egl...@apache.org
Subject svn commit: r510907 - in /incubator/cxf/trunk: common/common/src/main/java/org/apache/cxf/management/ rt/core/src/main/java/org/apache/cxf/workqueue/ rt/management/ rt/management/src/main/java/org/apache/cxf/event/ rt/management/src/main/java/org/apach...
Date Fri, 23 Feb 2007 11:25:59 GMT
Author: eglynn
Date: Fri Feb 23 03:25:58 2007
New Revision: 510907

URL: http://svn.apache.org/viewvc?view=rev&rev=510907
Log:
Comitting fix for CXF-427 "Provide simpler mechanism in CXF for registering MBeans" on behalf of Seumas Soltysik.


Added:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/management/ManagedComponent.java
      - copied, changed from r510580, incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/management/Instrumentation.java
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/management/ManagementConstants.java   (with props)
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/workqueue/WorkQueueManagerImplMBeanWrapper.java
      - copied, changed from r510580, incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/workqueue/WorkQueueInstrumentation.java
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/jmx/InstrumentationManagerImpl.java
      - copied, changed from r510580, incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/jmx/JMXManagedComponentManager.java
    incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorld.java   (with props)
    incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorldMBean.java   (with props)
    incubator/cxf/trunk/rt/management/src/test/resources/
    incubator/cxf/trunk/rt/management/src/test/resources/managed-spring.xml   (with props)
Removed:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/management/Instrumentation.java
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/management/InstrumentationFactory.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/workqueue/WorkQueueInstrumentation.java
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/event/
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/InstrumentationManagerImpl.java
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/jmx/JMXManagedComponentManager.java
    incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/jmx/JMXUtils.java
    incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXUtilsTest.java
Modified:
    incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/management/InstrumentationManager.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/workqueue/WorkQueueManagerImpl.java
    incubator/cxf/trunk/rt/management/pom.xml
    incubator/cxf/trunk/rt/management/src/main/resources/META-INF/bus-extensions.xml
    incubator/cxf/trunk/rt/management/src/main/resources/META-INF/cxf/cxf-extension-management.xml
    incubator/cxf/trunk/rt/management/src/main/resources/META-INF/cxf/cxf-property-editors.xml
    incubator/cxf/trunk/rt/management/src/main/resources/schemas/configuration/instrumentation.xsd
    incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/InstrumentationManagerTest.java
    incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.java
    incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/export/AnnotationTestInstrumentation.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/bus/SpringBusFactoryTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/management/ManagedBusTest.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/management/managed-spring.xml

Modified: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/management/InstrumentationManager.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/management/InstrumentationManager.java?view=diff&rev=510907&r1=510906&r2=510907
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/management/InstrumentationManager.java (original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/management/InstrumentationManager.java Fri Feb 23 03:25:58 2007
@@ -19,39 +19,72 @@
 
 package org.apache.cxf.management;
 
-import java.util.List;
-
+import javax.management.JMException;
 import javax.management.MBeanServer;
+import javax.management.ObjectName;
 
 /** 
  *  InstrumentationManager interface for the instrumentations query, register 
  *  and unregister
  */
 public interface InstrumentationManager {
+    /**
+     * Register a component with management infrastructure. Component will supply registration name.
+     * @param component
+     * @return name used to register the component
+     * @throws JMException
+     */
+    ObjectName register(ManagedComponent component) throws JMException;
     
     /**
-     * register the instrumentation instance to the instrumentation manager      
+     * Register a component with management infrastructure. Component will supply registration name.
+     * @param component
+     * @param forceRegistration if set to true, then component will be registered despite existing component.
+     * @return name used to register the component
+     * @throws JMException
      */
-    void register(Instrumentation instrumentation);
+    ObjectName register(ManagedComponent component, boolean forceRegistration) throws JMException;
 
     /**
-     * unregister the instrumentation instance from the instrumentation manager  
+     * Registers object with management infrastructure with a specific name. Object must be annotated or 
+     * implement standard MBean interface.
+     * @param obj
+     * @param name
+     * @throws JMException
      */
-    void unregister(Object component);
-
+    void register(Object obj, ObjectName name) throws JMException;
+    
+    /**
+     * Registers object with management infrastructure with a specific name. Object must be annotated or 
+     * implement standard MBean interface.
+     * @param obj
+     * @param name
+     * @param forceRegistration if set to true, then component will be registered despite existing component.
+     * @throws JMException
+     */
+    void register(Object obj, ObjectName name, boolean forceRegistration) throws JMException;
+    
+    /**
+     * Unregisters component with management infrastructure
+     * @param component
+     * @throws JMException
+     */
+    void unregister(ManagedComponent component) throws JMException;
+    
     /**
-     * get all instrumentation from the instrumentation manager
-     * @return the instrumentation list 
+     * Unregisters component based upon registered name
+     * @param name
+     * @throws JMException
      */
-    List<Instrumentation> getAllInstrumentation();
+    void unregister(ObjectName name) throws JMException;
 
     /**
-     * provide a clean up method for instrumentation manager to stop
+     * Cleans up and shutsdown management infrastructure.
      */
     void shutdown();
     
     /**
-     * get the MBeanServer which will host the cxf runtime component MBeans
+     * Get the MBeanServer which hosts managed components
      * NOTE: if the configuration is not set the JMXEnabled to be true, this method
      * will return null
      * @return the MBeanServer 

Copied: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/management/ManagedComponent.java (from r510580, incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/management/Instrumentation.java)
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/management/ManagedComponent.java?view=diff&rev=510907&p1=incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/management/Instrumentation.java&r1=510580&p2=incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/management/ManagedComponent.java&r2=510907
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/management/Instrumentation.java (original)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/management/ManagedComponent.java Fri Feb 23 03:25:58 2007
@@ -19,31 +19,14 @@
 
 package org.apache.cxf.management;
 
-
+import javax.management.JMException;
+import javax.management.ObjectName;
 /**
  * Basic interface for representing a Instrumented object.
  * 
  */
-public interface Instrumentation {
-
-    /**
-     * get the Instrumentation Name, this name is base on class 
-     * which implement instrumentation interface
-     * @return the instrumentation name      
-     */
-    String getInstrumentationName();    
+public interface ManagedComponent {
     
-    /**
-     * get the instrumentation managed component  
-     * @return the Component object reference 
-     */
-    Object getComponent();
+    ObjectName getObjectName() throws JMException;
     
-    /**
-     * get the unique Instrumentation Name, this name is base on class instance
-     * which implement instrumentation interface
-     * @return the instrumentation name and instance number  
-     */
-    String getUniqueInstrumentationName();
-       
 }

Added: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/management/ManagementConstants.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/management/ManagementConstants.java?view=auto&rev=510907
==============================================================================
--- incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/management/ManagementConstants.java (added)
+++ incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/management/ManagementConstants.java Fri Feb 23 03:25:58 2007
@@ -0,0 +1,33 @@
+/**
+ * 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.cxf.management;
+
+public final class ManagementConstants {
+    
+    public static final String DEFAULT_DOMAIN_NAME = "org.apache.cxf";
+    public static final String BUS_ID_PROP = "bus.id";
+    public static final String NAME_PROP = "name";
+    public static final String TYPE_PROP = "type";
+    public static final String DESCRIPTION_PROP = "description";
+    
+    private ManagementConstants() {
+        
+    }
+}

Propchange: incubator/cxf/trunk/common/common/src/main/java/org/apache/cxf/management/ManagementConstants.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/workqueue/WorkQueueManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/workqueue/WorkQueueManagerImpl.java?view=diff&rev=510907&r1=510906&r2=510907
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/workqueue/WorkQueueManagerImpl.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/workqueue/WorkQueueManagerImpl.java Fri Feb 23 03:25:58 2007
@@ -19,21 +19,17 @@
 
 package org.apache.cxf.workqueue;
 
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.annotation.PostConstruct;
 import javax.annotation.Resource;
-import javax.xml.namespace.QName;
+import javax.management.JMException;
 
 import org.apache.cxf.Bus;
-import org.apache.cxf.event.ComponentEventFilter;
-import org.apache.cxf.event.Event;
-import org.apache.cxf.event.EventProcessor;
-import org.apache.cxf.management.Instrumentation;
-import org.apache.cxf.management.InstrumentationFactory;
+import org.apache.cxf.management.InstrumentationManager;
 
-
-public class WorkQueueManagerImpl implements WorkQueueManager, InstrumentationFactory {
+public class WorkQueueManagerImpl implements WorkQueueManager {
 
     private static final Logger LOG =
         Logger.getLogger(WorkQueueManagerImpl.class.getName());
@@ -62,13 +58,16 @@
     public synchronized AutomaticWorkQueue getAutomaticWorkQueue() {
         if (autoQueue == null) {
             autoQueue = createAutomaticWorkQueue();
-            EventProcessor ep = bus.getExtension(EventProcessor.class);
-            //setup the QName
-            QName eventID = new QName(ComponentEventFilter.COMPONENT_CREATED_EVENT);
-            if (null != ep) {                
-                ep.sendEvent(new Event(this, eventID));
+            InstrumentationManager manager = bus.getExtension(InstrumentationManager.class);
+            if (null != manager) {
+                try {
+                    manager.register(new WorkQueueManagerImplMBeanWrapper(this));
+                } catch (JMException jmex) {
+                    LOG.log(Level.WARNING , jmex.getMessage(), jmex);
+                }
             }
         }
+        
         return autoQueue;
     }
 
@@ -86,12 +85,6 @@
             autoQueue.shutdown(processRemainingTasks);
         }
 
-        //sent out remove event.
-        EventProcessor ep = bus.getExtension(EventProcessor.class);
-        QName eventID = new QName(ComponentEventFilter.COMPONENT_REMOVED_EVENT);
-        if (null != ep) {
-            ep.sendEvent(new Event(this, eventID));        
-        }
         synchronized (this) {
             notifyAll();
         }
@@ -117,9 +110,6 @@
         for (java.util.logging.Handler h : LOG.getHandlers())  {
             h.flush();
         }
-
-        //sent out creation event.        
-        
         
     }
 
@@ -146,7 +136,4 @@
                
     }
     
-    public Instrumentation createInstrumentation() {
-        return  new WorkQueueInstrumentation(this);
-    }
 }

Copied: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/workqueue/WorkQueueManagerImplMBeanWrapper.java (from r510580, incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/workqueue/WorkQueueInstrumentation.java)
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/workqueue/WorkQueueManagerImplMBeanWrapper.java?view=diff&rev=510907&p1=incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/workqueue/WorkQueueInstrumentation.java&r1=510580&p2=incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/workqueue/WorkQueueManagerImplMBeanWrapper.java&r2=510907
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/workqueue/WorkQueueInstrumentation.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/workqueue/WorkQueueManagerImplMBeanWrapper.java Fri Feb 23 03:25:58 2007
@@ -19,8 +19,15 @@
 
 package org.apache.cxf.workqueue;
 
+import java.util.Hashtable;
+import java.util.Map;
 
-import org.apache.cxf.management.Instrumentation;
+import javax.management.JMException;
+import javax.management.ObjectName;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.management.ManagedComponent;
+import org.apache.cxf.management.ManagementConstants;
 import org.apache.cxf.management.annotation.ManagedAttribute;
 import org.apache.cxf.management.annotation.ManagedOperation;
 import org.apache.cxf.management.annotation.ManagedResource;
@@ -30,16 +37,17 @@
                  description = "The CXF internal thread pool for manangement ", 
                  currencyTimeLimit = 15, persistPolicy = "OnUpdate", persistPeriod = 200)
                  
-public class WorkQueueInstrumentation implements Instrumentation {    
-    private static final String INSTRUMENTED_NAME = "Bus.WorkQueue";
+public class WorkQueueManagerImplMBeanWrapper implements ManagedComponent {    
+    private static final String NAME_VALUE = "Bus.WorkQueue";
+    private static final String TYPE_VALUE = "WorkQueueMBean";
     
-    private String objectName;
     private WorkQueueManagerImpl wqManager;
     private AutomaticWorkQueueImpl aWorkQueue;
+    private Bus bus;
     
-    public WorkQueueInstrumentation(WorkQueueManagerImpl wq) {
+    public WorkQueueManagerImplMBeanWrapper(WorkQueueManagerImpl wq) {
         wqManager = wq;        
-        objectName = "WorkQueue";
+        bus = wq.getBus();
         if (wqManager.autoQueue != null 
             && AutomaticWorkQueueImpl.class.isAssignableFrom(wqManager.autoQueue.getClass())) {
             aWorkQueue = (AutomaticWorkQueueImpl)wqManager.autoQueue;
@@ -110,18 +118,17 @@
     public void setLowWaterMark(int lwm) {
         aWorkQueue.setLowWaterMark(lwm);
     }
-    
-    
-    public Object getComponent() {        
-        return wqManager;
-    }
 
-    public String getInstrumentationName() {        
-        return INSTRUMENTED_NAME;
-    }
-
-    public String getUniqueInstrumentationName() {       
-        return objectName;
-    }   
+    public ObjectName getObjectName() throws JMException {
+        Map<String, String> table = new Hashtable<String, String>();
+        String busId = bus.getId() == null ? Integer.toString(bus.hashCode()) : bus.getId();
+
+        table.put(ManagementConstants.BUS_ID_PROP, busId);
+        table.put(ManagementConstants.NAME_PROP, NAME_VALUE);
+        table.put(ManagementConstants.TYPE_PROP, TYPE_VALUE);
 
+        //Use default domain name of server
+        return new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME, (Hashtable)table);
+    }
+    
 }

Modified: incubator/cxf/trunk/rt/management/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/pom.xml?view=diff&rev=510907&r1=510906&r2=510907
==============================================================================
--- incubator/cxf/trunk/rt/management/pom.xml (original)
+++ incubator/cxf/trunk/rt/management/pom.xml Fri Feb 23 03:25:58 2007
@@ -59,11 +59,18 @@
         </dependency>
 
         <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring</artifactId>
+            <version>${spring.version}</version>
+        </dependency>
+
+        <dependency>
             <groupId>org.apache.cxf</groupId>
             <artifactId>cxf-testutils</artifactId>
             <version>${project.version}</version>
             <scope>test</scope>
         </dependency>
+
         <dependency>
             <groupId>org.easymock</groupId>
             <artifactId>easymockclassextension</artifactId>

Copied: incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/jmx/InstrumentationManagerImpl.java (from r510580, incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/jmx/JMXManagedComponentManager.java)
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/jmx/InstrumentationManagerImpl.java?view=diff&rev=510907&p1=incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/jmx/JMXManagedComponentManager.java&r1=510580&p2=incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/jmx/InstrumentationManagerImpl.java&r2=510907
==============================================================================
--- incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/jmx/JMXManagedComponentManager.java (original)
+++ incubator/cxf/trunk/rt/management/src/main/java/org/apache/cxf/management/jmx/InstrumentationManagerImpl.java Fri Feb 23 03:25:58 2007
@@ -19,170 +19,217 @@
 
 package org.apache.cxf.management.jmx;
 
-
-
 import java.io.IOException;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
 import javax.management.InstanceAlreadyExistsException;
-import javax.management.InstanceNotFoundException;
 import javax.management.JMException;
-import javax.management.MBeanException;
-import javax.management.MBeanRegistrationException;
 import javax.management.MBeanServer;
 import javax.management.MBeanServerFactory;
 
-
 import javax.management.NotCompliantMBeanException;
+import javax.management.ObjectInstance;
 import javax.management.ObjectName;
-import javax.management.ReflectionException;
 import javax.management.modelmbean.InvalidTargetObjectTypeException;
 import javax.management.modelmbean.ModelMBeanInfo;
 import javax.management.modelmbean.RequiredModelMBean;
 
+import org.apache.cxf.Bus;
+import org.apache.cxf.buslifecycle.BusLifeCycleListener;
+import org.apache.cxf.buslifecycle.BusLifeCycleManager;
 import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.management.Instrumentation;
+import org.apache.cxf.management.InstrumentationManager;
 import org.apache.cxf.management.JMXConnectorPolicyType;
+import org.apache.cxf.management.ManagedComponent;
+import org.apache.cxf.management.ManagementConstants;
 import org.apache.cxf.management.jmx.export.runtime.ModelMBeanAssembler;
 
 
 /**
  * The manager class for the JMXManagedComponent which hosts the JMXManagedComponents.
  */
-public class JMXManagedComponentManager {
-    private static final Logger LOG = LogUtils.getL7dLogger(JMXManagedComponentManager.class);
-   
-    private boolean platformMBeanServer;    
-    private ModelMBeanAssembler mbAssembler; 
+public class InstrumentationManagerImpl extends JMXConnectorPolicyType 
+    implements InstrumentationManager, BusLifeCycleListener {
+    private static final Logger LOG = LogUtils.getL7dLogger(InstrumentationManagerImpl.class);
+
+    private Bus bus;
     private MBServerConnectorFactory mcf;    
     private MBeanServer mbs;
+    private Set<ObjectName> busMBeans = new HashSet<ObjectName>();
+    private ModelMBeanAssembler assembler;
     
-    public JMXManagedComponentManager() {        
-        mbAssembler = new ModelMBeanAssembler();    
+    public InstrumentationManagerImpl() {        
+        assembler = new ModelMBeanAssembler();
     }
     
-       
-    public void init(JMXConnectorPolicyType cp) {
+    public Bus getBus() {
+        return bus;
+    }
+    
+    @Resource(name = "bus")
+    public void setBus(Bus bus) {        
+        this.bus = bus;
+    }
+
+
+    @PostConstruct     
+    public void register() {    
+        if (null != bus) {
+            bus.setExtension(this, InstrumentationManager.class);
+            BusLifeCycleManager blcm = bus.getExtension(BusLifeCycleManager.class);
+            blcm.registerLifeCycleListener(this);
+        }
+    }
+    
+    @PostConstruct     
+    public void init() {    
+        if (isEnabled()) {        
+            if (LOG.isLoggable(Level.INFO)) {
+                LOG.info("Setting up MBeanServer ");
+            }
+
+            List servers = MBeanServerFactory.findMBeanServer(ManagementConstants.DEFAULT_DOMAIN_NAME);
+            if (servers.size() <= 1) {
+                mbs = MBeanServerFactory.createMBeanServer(ManagementConstants.DEFAULT_DOMAIN_NAME);
+            } else {
+                mbs = (MBeanServer)servers.get(0);
+            }
+            mcf = MBServerConnectorFactory.getInstance();
+            mcf.setMBeanServer(mbs);
+            mcf.setThreaded(isThreaded());
+            mcf.setDaemon(isDaemon());
+            mcf.setServiceUrl(getJMXServiceURL());
+            try {            
+                mcf.createConnector();
+            } catch (IOException ex) {
+                LOG.log(Level.SEVERE, "START_CONNECTOR_FAILURE_MSG", new Object[]{ex});
+            }                
+        }
+    }
+
+    public void register(Object obj, ObjectName name) throws JMException {
+        register(obj, name, false);        
+    }
+    
+    public void register(Object obj, ObjectName name, boolean forceRegistration) throws JMException {
+        if (!isEnabled()) {
+            return;           
+        }
+        //Try to register as a Standard MBean
+        try {
+            registerMBeanWithServer(obj, name, forceRegistration);           
+        } catch (NotCompliantMBeanException e) {        
+            //If this is not a "normal" MBean, then try to deploy it using JMX annotations
+            assembler = new ModelMBeanAssembler();
+            ModelMBeanInfo mbi = assembler.getModelMbeanInfo(obj.getClass());
+            register(obj, name, mbi, forceRegistration);
+        }                
+    }
+
+    public ObjectName register(ManagedComponent i) throws JMException {
+        ObjectName name = register(i, false);
+        
+        return name;
+    }
+    
+    public ObjectName register(ManagedComponent i, boolean forceRegistration) throws JMException {
+        ObjectName name = i.getObjectName();
+        register(i, name, forceRegistration);
         
-        // get the init information from configuration
+        return name;
+    }    
+
+    
+    public void unregister(ManagedComponent component) throws JMException {
+        ObjectName name = component.getObjectName();
+        unregister(name);
+    }
+    
+    public void unregister(ObjectName name) throws JMException {  
+        if (!isEnabled()) {
+            return;           
+        }
         
-        if (LOG.isLoggable(Level.INFO)) {
-            LOG.info("Setting up MBeanServer ");
+        busMBeans.remove(name);       
+        mbs.unregisterMBean(name);                    
+    }  
+    
+    public MBeanServer getMBeanServer() {        
+        return mbs;
+    }
+    
+    public void shutdown() {
+        if (!isEnabled()) {
+            return;           
         }
         
-        mbs = MBeanServerFactory.createMBeanServer(JMXUtils.DOMAIN_STRING);            
-        mcf = MBServerConnectorFactory.getInstance();
-        mcf.setMBeanServer(mbs);
-        mcf.setThreaded(cp.isThreaded());
-        mcf.setDaemon(cp.isDaemon());
-        mcf.setServiceUrl(cp.getJMXServiceURL());
-        try {            
-            mcf.createConnector();
+        try {
+            mcf.destroy();
         } catch (IOException ex) {
-            LOG.log(Level.SEVERE, "START_CONNECTOR_FAILURE_MSG", new Object[]{ex});
-        }        
+            LOG.log(Level.SEVERE, "STOP_CONNECTOR_FAILURE_MSG", new Object[]{ex});
+        }   
+    }
+
+    public void initComplete() {
         
     }
     
-    public MBeanServer getMBeanServer() {
-        return mbs;
+    public void preShutdown() {
+                
     }
-    
-    public void shutdown() { 
-        if (!platformMBeanServer) {
+
+    public void postShutdown() {
+        Iterator<ObjectName> it = busMBeans.iterator();
+        while (it.hasNext()) {
+            ObjectName name = it.next();
+            busMBeans.remove(name);
             try {
-                mcf.destroy();
-            } catch (IOException ex) {
-                LOG.log(Level.SEVERE, "STOP_CONNECTOR_FAILURE_MSG", new Object[]{ex});
+                unregister(name);
+            } catch (JMException jmex) {
+                LOG.log(Level.SEVERE, "UNREGISTER_FAILURE_MSG", new Object[]{name, jmex});
             }
         }
     }
-   
-    public void registerMBean(Object object, ObjectName name) {        
+    
+    private void register(Object obj, ObjectName name, ModelMBeanInfo mbi, boolean forceRegistration) 
+        throws JMException {                  
+        RequiredModelMBean rtMBean = 
+            (RequiredModelMBean)mbs.instantiate("javax.management.modelmbean.RequiredModelMBean");
+        rtMBean.setModelMBeanInfo(mbi);
         try {
-            mbs.registerMBean(object, name);           
-        } catch (InstanceAlreadyExistsException e) {            
-            try { 
-                mbs.unregisterMBean(name);                
-                mbs.registerMBean(object, name);
-            } catch (Exception e1) {
-                LOG.log(Level.SEVERE, "REGISTER_FAILURE_MSG", new Object[]{name, e1});
-            }
-        } catch (MBeanRegistrationException e) {
-            LOG.log(Level.SEVERE, "REGISTER_FAILURE_MSG", new Object[]{name, e});          
-        } catch (NotCompliantMBeanException e) {
-            LOG.log(Level.SEVERE, "REGISTER_FAILURE_MSG", new Object[]{name, e});
+            rtMBean.setManagedResource(obj, "ObjectReference");
+        } catch (InvalidTargetObjectTypeException itotex) {
+            throw new JMException(itotex.getMessage());
         }
+        registerMBeanWithServer(rtMBean, name, forceRegistration);
     }
-    
-    public void unregisterMBean(ObjectName name) {      
+
+    private void registerMBeanWithServer(Object obj, ObjectName name, boolean forceRegistration) 
+        throws JMException {
+        ObjectInstance instance = null;
         try {
-            mbs.unregisterMBean(name);            
-        } catch (JMException e) {
-            LOG.log(Level.SEVERE, "UNREGISTER_FAILURE_MSG", new Object[]{name, e});
+            instance = mbs.registerMBean(obj, name);           
+        } catch (InstanceAlreadyExistsException e) {            
+            if (forceRegistration) {
+                mbs.unregisterMBean(name);                
+                instance = mbs.registerMBean(obj, name);
+            } else {
+                throw e;
+            }
         }
-    }
-    
-    /**
-     * Create the related JMX component and register it.
-     * @param instrumentation
-     */
-    public void registerMBean(Instrumentation instrumentation) {
-        ModelMBeanInfo mbi = mbAssembler.getModelMbeanInfo(instrumentation.getClass());
         
-        if (mbi != null) {                    
-            RequiredModelMBean rtMBean;
-            try {
-                                        
-                rtMBean = (RequiredModelMBean)mbs.instantiate(
-                    "javax.management.modelmbean.RequiredModelMBean");
-                               
-                rtMBean.setModelMBeanInfo(mbi);
-                
-                rtMBean.setManagedResource(instrumentation, "ObjectReference");
-                                       
-                registerMBean(rtMBean,
-                    JMXUtils.getObjectName(instrumentation.getInstrumentationName(),
-                                           instrumentation.getUniqueInstrumentationName()));
-                                       
-                if (LOG.isLoggable(Level.INFO)) {
-                    LOG.info("registered the object to MBserver " 
-                                       + instrumentation.getUniqueInstrumentationName());
-                } 
-                    
-                   
-            } catch (ReflectionException e) {
-                LOG.log(Level.SEVERE, "INSTANTIANTE_FAILURE_MSG", new Object[]{e});
-            } catch (MBeanException e) {
-                LOG.log(Level.SEVERE, "MBEAN_FAILURE_MSG", new Object[]{e});
-            } catch (InstanceNotFoundException e) {
-                LOG.log(Level.SEVERE, "SET_MANAGED_RESOURCE_FAILURE_MSG", new Object[]{e});
-            } catch (InvalidTargetObjectTypeException e) {
-                LOG.log(Level.SEVERE, "SET_MANAGED_RESOURCE_FAILURE_MSG", new Object[]{e});
-            }
-        } else {
-            LOG.log(Level.SEVERE, "GET_MANAGED_INFORMATION_FAILURE_MSG", 
-                    new Object[]{instrumentation.getInstrumentationName()});
-        }                
+        if (instance != null) {
+            busMBeans.add(name);
+        }
     }
     
-    /**
-     * Identify the related JMX component and unregister it.
-     * @param instrumentation
-     */
-    public void unregisterMBean(Instrumentation instrumentation) {
-        ObjectName name;                 
-        name = JMXUtils.getObjectName(instrumentation.getInstrumentationName(),
-            instrumentation.getUniqueInstrumentationName());               
-        unregisterMBean(name);
-        if (LOG.isLoggable(Level.INFO)) {
-            LOG.info("unregistered the object to MBserver" 
-                               + instrumentation.getUniqueInstrumentationName());
-        }   
-    }
-
-   
 
 }
 

Modified: incubator/cxf/trunk/rt/management/src/main/resources/META-INF/bus-extensions.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/main/resources/META-INF/bus-extensions.xml?view=diff&rev=510907&r1=510906&r2=510907
==============================================================================
--- incubator/cxf/trunk/rt/management/src/main/resources/META-INF/bus-extensions.xml (original)
+++ incubator/cxf/trunk/rt/management/src/main/resources/META-INF/bus-extensions.xml Fri Feb 23 03:25:58 2007
@@ -17,11 +17,7 @@
   specific language governing permissions and limitations
   under the License.
 -->
-<extensions xmlns="http://cxf.apache.org/bus/extension">
-   
-    <extension class="org.apache.cxf.event.EventProcessorImpl"
-           interface="org.apache.cxf.event.EventProcessor"/>
-    <extension class="org.apache.cxf.management.InstrumentationManagerImpl"
-           interface="org.apache.cxf.management.InstrumentationManager"/>       
-    
+<extensions xmlns="http://cxf.apache.org/bus/extension">   
+    <extension class="org.apache.cxf.management.jmx.InstrumentationManagerImpl"
+           interface="org.apache.cxf.management.InstrumentationManager"/>           
 </extensions>

Modified: incubator/cxf/trunk/rt/management/src/main/resources/META-INF/cxf/cxf-extension-management.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/main/resources/META-INF/cxf/cxf-extension-management.xml?view=diff&rev=510907&r1=510906&r2=510907
==============================================================================
--- incubator/cxf/trunk/rt/management/src/main/resources/META-INF/cxf/cxf-extension-management.xml (original)
+++ incubator/cxf/trunk/rt/management/src/main/resources/META-INF/cxf/cxf-extension-management.xml Fri Feb 23 03:25:58 2007
@@ -22,13 +22,12 @@
        xmlns:foo="http://cxf.apache.org/configuration/foo"
        xsi:schemaLocation="
 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
-    
-    <bean id="org.apache.cxf.event.EventProcessor" class="org.apache.cxf.event.EventProcessorImpl">
-        <property name="bus" ref="cxf"/>
-    </bean>
-    
-    <bean id="org.apache.cxf.management.InstrumentationManager" class="org.apache.cxf.management.InstrumentationManagerImpl">
+        
+    <bean id="org.apache.cxf.management.jmx.InstrumentationManagerImpl" class="org.apache.cxf.management.jmx.InstrumentationManagerImpl">
         <property name="bus" ref="cxf"/>
+        <property name="enabled" value="false"/>
+        <property name="threaded" value="false"/>        
+        <property name="daemon" value="false"/>        
     </bean>
     
 </beans>

Modified: incubator/cxf/trunk/rt/management/src/main/resources/META-INF/cxf/cxf-property-editors.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/main/resources/META-INF/cxf/cxf-property-editors.xml?view=diff&rev=510907&r1=510906&r2=510907
==============================================================================
--- incubator/cxf/trunk/rt/management/src/main/resources/META-INF/cxf/cxf-property-editors.xml (original)
+++ incubator/cxf/trunk/rt/management/src/main/resources/META-INF/cxf/cxf-property-editors.xml Fri Feb 23 03:25:58 2007
@@ -30,7 +30,6 @@
                     <property name="packageName" value="org.apache.cxf.management"/>
                     <property name="propertyClassNames">
                         <list>
-                            <value>InstrumentationType</value>
                             <value>JMXConnectorPolicyType</value>
                         </list>
                     </property>

Modified: incubator/cxf/trunk/rt/management/src/main/resources/schemas/configuration/instrumentation.xsd
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/main/resources/schemas/configuration/instrumentation.xsd?view=diff&rev=510907&r1=510906&r2=510907
==============================================================================
--- incubator/cxf/trunk/rt/management/src/main/resources/schemas/configuration/instrumentation.xsd (original)
+++ incubator/cxf/trunk/rt/management/src/main/resources/schemas/configuration/instrumentation.xsd Fri Feb 23 03:25:58 2007
@@ -25,26 +25,14 @@
     elementFormDefault="qualified" 
     attributeFormDefault="unqualified"
     jaxb:version="2.0">
-    
-    <xs:complexType name="InstrumentationType">
-        <xs:attribute name="Enabled" type="xs:boolean" default="true"/>
-        <xs:attribute name="JMXEnabled" type="xs:boolean" default="false"/>        
-    </xs:complexType>
-    
+        
     <xs:complexType name="JMXConnectorPolicyType">
-        <xs:attribute name="Threaded" type="xs:boolean" default="false"/>
-        <xs:attribute name="Daemon" type="xs:boolean" default="false"/>
+        <xs:attribute name="Enabled" type="xs:boolean" use="required" />        
+        <xs:attribute name="Threaded" type="xs:boolean" use="required" />        
+        <xs:attribute name="Daemon" type="xs:boolean" use="required" />        
         <xs:attribute name="JMXServiceURL" type="xs:string" default="service:jmx:rmi:///jndi/rmi://localhost:9913/jmxrmi"/>        
     </xs:complexType>
     
-    <xs:element name="instrumentation" type="tns:InstrumentationType"/>
     <xs:element name="JMXConnectorPolicy" type="tns:JMXConnectorPolicyType"/>   
-
-     <xs:complexType name="InstrumentationManagerConfigBean">  
-        <xs:sequence>
-            <xs:element ref="tns:instrumentation" minOccurs="0"/>
-            <xs:element ref="tns:JMXConnectorPolicy" minOccurs="0"/>
-        </xs:sequence>
-    </xs:complexType>
 
 </xs:schema>

Modified: incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/InstrumentationManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/InstrumentationManagerTest.java?view=diff&rev=510907&r1=510906&r2=510907
==============================================================================
--- incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/InstrumentationManagerTest.java (original)
+++ incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/InstrumentationManagerTest.java Fri Feb 23 03:25:58 2007
@@ -18,19 +18,15 @@
  */
 package org.apache.cxf.management;
 
-import java.util.List;
+import java.util.Iterator;
+import java.util.Set;
 
-import javax.xml.namespace.QName;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
 
 import junit.framework.TestCase;
-
-
 import org.apache.cxf.Bus;
-import org.apache.cxf.BusFactory;
-import org.apache.cxf.event.ComponentEventFilter;
-import org.apache.cxf.event.Event;
-import org.apache.cxf.event.EventProcessor;
-import org.apache.cxf.workqueue.WorkQueueInstrumentation;
+import org.apache.cxf.bus.spring.SpringBusFactory;
 import org.apache.cxf.workqueue.WorkQueueManagerImpl;
 
 public class InstrumentationManagerTest extends TestCase {
@@ -38,10 +34,7 @@
     Bus bus;
     
     public void setUp() throws Exception {
-        BusFactory bf = BusFactory.newInstance();
-        bus =  bf.createBus();
-        BusFactory.setDefaultBus(bus);
-        im = bus.getExtension(InstrumentationManager.class);
+
     }
     
     public void tearDown() throws Exception {
@@ -49,46 +42,40 @@
         bus.shutdown(true);
     }
     
+    public void testInstrumentationNotEnabled() {
+        SpringBusFactory factory = new SpringBusFactory();
+        bus =  factory.createBus();
+        im = bus.getExtension(InstrumentationManager.class);
+        assertTrue("Instrumentation Manager should not be null", im != null);
+        MBeanServer mbs = im.getMBeanServer();
+        assertNull("MBeanServer should not be available.", mbs);
+    }
+    
     // try to get WorkQueue information
     public void testWorkQueueInstrumentation() throws Exception {
+        SpringBusFactory factory = new SpringBusFactory();
+        bus =  factory.createBus("managed-spring.xml", true);
+        im = bus.getExtension(InstrumentationManager.class);
         assertTrue("Instrumentation Manager should not be null", im != null);
-        //im.getAllInstrumentation();
         WorkQueueManagerImpl wqm = new WorkQueueManagerImpl();
         wqm.setBus(bus);
-        EventProcessor ep = bus.getExtension(EventProcessor.class);
-        QName eventID = new QName(ComponentEventFilter.COMPONENT_CREATED_EVENT);
-        if (null != ep) {         
-            ep.sendEvent(new Event(wqm, eventID));
-        }        
+        wqm.getAutomaticWorkQueue();
         
-        //NOTE: now the bus WorkQueueManager is lazy load , if WorkQueueManager
-        //create with bus , this test could be failed.
-        List<Instrumentation> list = im.getAllInstrumentation();
-        //NOTE: change for the BindingManager and TransportFactoryManager instrumentation
-        // create with the bus.
-        assertEquals("Too many instrumented items", 1, list.size());
-        Instrumentation it1 = list.get(0);
-        //Instrumentation it2 = list.get(3);
-        assertTrue("Item 1 not a WorkQueueInstrumentation",
-                   WorkQueueInstrumentation.class.isAssignableFrom(it1.getClass()));
-        
-        // not check for the instrumentation unique name
-        // sleep for the MBServer connector thread startup
-        try {
-            Thread.sleep(100);
-        } catch (InterruptedException e) {
-            // do nothing
+        MBeanServer mbs = im.getMBeanServer();
+        assertNotNull("MBeanServer should be available.", mbs);
+        ObjectName name = new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME 
+                                         + ":type=WorkQueueMBean,*");
+        Set s = mbs.queryNames(name, null);
+        assertTrue(s.size() == 1);
+        Iterator it = s.iterator();
+        while (it.hasNext()) {
+            ObjectName n = (ObjectName)it.next();            
+            Long result = 
+                (Long)mbs.invoke(n, "getWorkQueueMaxSize", new Object[0], new String[0]);            
+            assertEquals(result, Long.valueOf(250));
         }
-        eventID = new QName(ComponentEventFilter.COMPONENT_REMOVED_EVENT);
-        if (null != ep) {
-            ep.sendEvent(new Event(wqm, eventID));
-        }    
-        assertEquals("Instrumented stuff not removed from list", 0, list.size());
+
         bus.shutdown(true);
-        assertEquals("Instrumented stuff not removed from list", 0, list.size());
     }
-
-
-
 
 }

Added: incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorld.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorld.java?view=auto&rev=510907
==============================================================================
--- incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorld.java (added)
+++ incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorld.java Fri Feb 23 03:25:58 2007
@@ -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.cxf.management.jmx;
+
+public class HelloWorld implements HelloWorldMBean {
+    public String sayHi() {
+        return "Wazzzuuup!";
+    }
+}

Propchange: incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorld.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorldMBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorldMBean.java?view=auto&rev=510907
==============================================================================
--- incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorldMBean.java (added)
+++ incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorldMBean.java Fri Feb 23 03:25:58 2007
@@ -0,0 +1,24 @@
+/**
+ * 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.cxf.management.jmx;
+
+public interface HelloWorldMBean {
+    String sayHi();
+}

Propchange: incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/HelloWorldMBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.java?view=diff&rev=510907&r1=510906&r2=510907
==============================================================================
--- incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.java (original)
+++ incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/JMXManagedComponentManagerTest.java Fri Feb 23 03:25:58 2007
@@ -19,63 +19,88 @@
 
 package org.apache.cxf.management.jmx;
 
+import javax.management.JMException;
 import javax.management.ObjectName;
 
 import junit.framework.TestCase;
 
-import org.apache.cxf.BusException;
-import org.apache.cxf.management.JMXConnectorPolicyType;
 import org.apache.cxf.management.jmx.export.AnnotationTestInstrumentation;
 
-
 public class JMXManagedComponentManagerTest extends TestCase {
        
     private static final String NAME_ATTRIBUTE = "Name";    
-    private JMXManagedComponentManager manager;
+    private InstrumentationManagerImpl manager;
     
-    public void setUp() throws BusException {
-        manager = new JMXManagedComponentManager(); 
+    public void setUp() throws Exception {
+        manager = new InstrumentationManagerImpl(); 
+        manager.setDaemon(false);
+        manager.setThreaded(true);
+        manager.setEnabled(true);
+        manager.setJMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9913/jmxrmi");
+        manager.init();
+        //Wait for MBeanServer connector to be initialized on separate thread.
+        Thread.sleep(2000);
     }
         
-    public void testJMXManagerInit() {
-        JMXConnectorPolicyType connector = new JMXConnectorPolicyType();        
-        connector.setDaemon(false);
-        connector.setThreaded(true);
-        connector.setJMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9913/jmxrmi");
-        try {
-            manager.init(connector); 
-            Thread.sleep(300);
-            manager.shutdown();
-        } catch (Exception ex) {
-            assertTrue("JMX Manager init with NewMBeanServer error", false);
-            ex.printStackTrace();
-        }
+    public void tearDown() throws Exception {
+        manager.shutdown();
     }
     
-    public void testRegisterInstrumentation() {
-        JMXConnectorPolicyType connector = new JMXConnectorPolicyType();        
-        connector.setDaemon(false);
-        connector.setThreaded(false);
-        connector.setJMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9913/jmxrmi");
-        manager.init(connector);
-        // setup the fack instrumentation
+    public void testRegisterInstrumentation() throws Exception {
+        manager.setDaemon(false);
+        manager.setThreaded(false);
+        manager.setJMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:9913/jmxrmi");
+        manager.init();
+
         AnnotationTestInstrumentation im = new AnnotationTestInstrumentation();
-        ObjectName name = JMXUtils.getObjectName(im.getUniqueInstrumentationName(), 
-                                                 im.getInstrumentationName());
-       
+        ObjectName name = new ObjectName("org.apache.cxf:type=foo,name=bar");        
         im.setName("John Smith");          
-        manager.registerMBean(im);
+        manager.register(im, name);
+        
+        Object val = manager.getMBeanServer().getAttribute(name, NAME_ATTRIBUTE);
+        assertEquals("Incorrect result", "John Smith", val);
         
-        try {            
-            Object val = manager.getMBeanServer().getAttribute(name, NAME_ATTRIBUTE);
-            assertEquals("Incorrect result", "John Smith", val);
-            Thread.sleep(300);
-        } catch (Exception ex) {            
-            ex.printStackTrace();
-            assertTrue("get instrumentation attribute error", false);
+        try {
+            manager.register(im, name);
+            fail("Registering with existing name should fail.");
+        } catch (JMException jmex) {
+            //Expected
         }
-        manager.unregisterMBean(im);
-        manager.shutdown();
+        
+        manager.register(im, name, true);                
+        
+        val = manager.getMBeanServer().getAttribute(name, NAME_ATTRIBUTE);
+        assertEquals("Incorrect result", "John Smith", val);
+        manager.unregister(name);
+        
+        im.setName("Foo Bar");  
+        name = manager.register(im);
+
+        val = manager.getMBeanServer().getAttribute(name, NAME_ATTRIBUTE);
+        assertEquals("Incorrect result", "Foo Bar", val);
+        
+        try {
+            manager.register(im);
+            fail("Registering with existing name should fail.");
+        } catch (JMException jmex) {
+            //Expected
+        }        
+        
+        name = manager.register(im, true);
+        
+        val = manager.getMBeanServer().getAttribute(name, NAME_ATTRIBUTE);
+        assertEquals("Incorrect result", "Foo Bar", val);
+        
+        manager.unregister(im);
     }
 
+    public void testRegisterStandardMBean() throws Exception {
+        HelloWorld hw = new HelloWorld();
+        ObjectName name = new ObjectName("org.apache.cxf:type=foo,name=bar");
+        manager.register(hw, name);
+        String result = 
+            (String)manager.getMBeanServer().invoke(name, "sayHi", new Object[0], new String[0]);    
+        assertEquals("Wazzzuuup!", result);
+    }
+    
 }

Modified: incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/export/AnnotationTestInstrumentation.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/export/AnnotationTestInstrumentation.java?view=diff&rev=510907&r1=510906&r2=510907
==============================================================================
--- incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/export/AnnotationTestInstrumentation.java (original)
+++ incubator/cxf/trunk/rt/management/src/test/java/org/apache/cxf/management/jmx/export/AnnotationTestInstrumentation.java Fri Feb 23 03:25:58 2007
@@ -19,8 +19,10 @@
 
 package org.apache.cxf.management.jmx.export;
 
-import org.apache.cxf.management.Instrumentation;
-import org.apache.cxf.management.InstrumentationFactory;
+import javax.management.JMException;
+import javax.management.ObjectName;
+
+import org.apache.cxf.management.ManagedComponent;
 import org.apache.cxf.management.annotation.ManagedAttribute;
 import org.apache.cxf.management.annotation.ManagedNotification;
 import org.apache.cxf.management.annotation.ManagedNotifications;
@@ -36,7 +38,7 @@
                  persistLocation = "/local/work", persistName = "bar.jmx")
 @ManagedNotifications({@ManagedNotification(name = "My Notification",
                                             notificationTypes = {"type.foo", "type.bar" }) })
-public class AnnotationTestInstrumentation implements Instrumentation, InstrumentationFactory {
+public class AnnotationTestInstrumentation implements ManagedComponent {
 
     private String name; 
 
@@ -101,20 +103,8 @@
         return x + y;
     }
 
-    public String getInstrumentationName() {        
-        return "AnnotationTestInstrumentation";
-    }
-
-    public Object getComponent() {        
-        return this;
-    }
-
-    public String getUniqueInstrumentationName() {       
-        return "AnnotationTestInstrumentation";
-    }
-
-    public Instrumentation createInstrumentation() {
-        //        return  new AnnotationTestInstrumentation(this);
-        return this;
+    public ObjectName getObjectName() throws JMException {
+        return new ObjectName("org.apache.cxf:type=AnnotationTestInstrumentation");
     }
+    
 }

Added: incubator/cxf/trunk/rt/management/src/test/resources/managed-spring.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/management/src/test/resources/managed-spring.xml?view=auto&rev=510907
==============================================================================
--- incubator/cxf/trunk/rt/management/src/test/resources/managed-spring.xml (added)
+++ incubator/cxf/trunk/rt/management/src/test/resources/managed-spring.xml Fri Feb 23 03:25:58 2007
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:im="http://cxf.apache.org/management"
+       xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
+  
+    <bean id="org.apache.cxf.management.InstrumentationManager" class="org.apache.cxf.management.jmx.InstrumentationManagerImpl">
+        <property name="bus" ref="cxf" />
+        <property name="enabled" value="true"/>
+        <property name="threaded" value="false"/>        
+        <property name="daemon" value="false"/>            
+        <property name="JMXServiceURL" value="service:jmx:rmi:///jndi/rmi://localhost:9914/jmxrmi" />
+    </bean> 
+ 
+</beans>
\ No newline at end of file

Propchange: incubator/cxf/trunk/rt/management/src/test/resources/managed-spring.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/management/src/test/resources/managed-spring.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/bus/SpringBusFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/bus/SpringBusFactoryTest.java?view=diff&rev=510907&r1=510906&r2=510907
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/bus/SpringBusFactoryTest.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/bus/SpringBusFactoryTest.java Fri Feb 23 03:25:58 2007
@@ -27,7 +27,6 @@
 import org.apache.cxf.bus.spring.SpringBusFactory;
 import org.apache.cxf.buslifecycle.BusLifeCycleManager;
 import org.apache.cxf.endpoint.ServerRegistry;
-import org.apache.cxf.event.EventProcessor;
 import org.apache.cxf.management.InstrumentationManager;
 import org.apache.cxf.phase.PhaseManager;
 import org.apache.cxf.transport.ConduitInitiatorManager;
@@ -53,8 +52,6 @@
         assertNotNull("No lifecycle manager", bus.getExtension(BusLifeCycleManager.class));
         assertNotNull("No service registry", bus.getExtension(ServerRegistry.class));
         assertNotNull("No instrumentation manager", bus.getExtension(InstrumentationManager.class));
-        assertNotNull("No event processor", bus.getExtension(EventProcessor.class));
-        
         
         try {
             bfm.getBindingFactory("http://cxf.apache.org/unknown");

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/management/ManagedBusTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/management/ManagedBusTest.java?view=diff&rev=510907&r1=510906&r2=510907
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/management/ManagedBusTest.java (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/management/ManagedBusTest.java Fri Feb 23 03:25:58 2007
@@ -19,38 +19,65 @@
 
 package org.apache.cxf.systest.management;
 
-import java.util.HashMap;
-import java.util.Map;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
 
 import junit.framework.TestCase;
 
 import org.apache.cxf.Bus;
-import org.apache.cxf.bus.CXFBusFactory;
 import org.apache.cxf.bus.spring.SpringBusFactory;
-import org.apache.cxf.configuration.Configurer;
 import org.apache.cxf.management.InstrumentationManager;
-import org.apache.cxf.management.InstrumentationManagerImpl;
-import org.apache.cxf.management.InstrumentationType;
+import org.apache.cxf.management.ManagementConstants;
+import org.apache.cxf.management.jmx.InstrumentationManagerImpl;
+import org.apache.cxf.workqueue.WorkQueueManager;
 
 public class ManagedBusTest extends TestCase {
 
-    public void xtestManagedCXFBus() {
-        CXFBusFactory factory = new CXFBusFactory();
-        Map<String, Object> properties = new HashMap<String, Object>();
-        properties.put(Configurer.USER_CFG_FILE_PROPERTY_NAME, 
-                       "org/apache/cxf/systest/management/managed-cxf.xml");
-        Bus bus = factory.createBus(null, properties);
+    public void testManagedSpringBus() throws Exception {
+        SpringBusFactory factory = new SpringBusFactory();
+        Bus bus = factory.createBus();        
+        InstrumentationManager im = bus.getExtension(InstrumentationManager.class);
+        assertNotNull(im);
+                
+        InstrumentationManagerImpl imi = (InstrumentationManagerImpl)im;
+        assertEquals("service:jmx:rmi:///jndi/rmi://localhost:9913/jmxrmi", imi.getJMXServiceURL());
+        assertTrue(!imi.isEnabled());
+        assertNull(imi.getMBeanServer());
+        
+        //Test that registering without an MBeanServer is a no-op
+        im.register(imi, new ObjectName("org.apache.cxf:foo=bar"));                        
+        
         bus.shutdown(true);
     }
-
-    public void testManagedSpringBus() {
+    
+    public void testManagedBusWithConfig() throws Exception {
         SpringBusFactory factory = new SpringBusFactory();
         Bus bus = factory.createBus("org/apache/cxf/systest/management/managed-spring.xml", true);
         InstrumentationManager im = bus.getExtension(InstrumentationManager.class);
         assertNotNull(im);
         InstrumentationManagerImpl imi = (InstrumentationManagerImpl)im;
-        InstrumentationType i = imi.getInstrumentation();
-        assertNotNull(i);
+        assertEquals("service:jmx:rmi:///jndi/rmi://localhost:9914/jmxrmi", imi.getJMXServiceURL());
+        assertTrue(imi.isEnabled());
+        assertNotNull(imi.getMBeanServer());
+
+        WorkQueueManager manager = bus.getExtension(WorkQueueManager.class);
+        manager.getAutomaticWorkQueue();
+        
+        MBeanServer mbs = im.getMBeanServer();        
+        ObjectName name = new ObjectName(ManagementConstants.DEFAULT_DOMAIN_NAME 
+                                         + ":type=WorkQueueMBean,*");
+        Set s = mbs.queryNames(name, null);
+        assertTrue(s.size() == 1);
+        Iterator it = s.iterator();
+        while (it.hasNext()) {
+            ObjectName n = (ObjectName)it.next();            
+            Long result = 
+                (Long)mbs.invoke(n, "getWorkQueueMaxSize", new Object[0], new String[0]);            
+            assertEquals(result, Long.valueOf(250));
+        }
 
         bus.shutdown(true);
     }

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/management/managed-spring.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/management/managed-spring.xml?view=diff&rev=510907&r1=510906&r2=510907
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/management/managed-spring.xml (original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/management/managed-spring.xml Fri Feb 23 03:25:58 2007
@@ -23,21 +23,10 @@
        xsi:schemaLocation="
 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
   
-    <bean id="org.apache.cxf.management.InstrumentationManager" class="org.apache.cxf.management.InstrumentationManagerImpl">
-        <property name="bus" ref="cxf"/>
-        <property name="instrumentation">
-            <value>
-                <im:instrumentation Enabled="true" JMXEnabled="true"/>
-            </value>
-        </property>
-        <property name="JMXConnectorPolicy">
-            <value>
-                <im:JMXConnectorPolicy 
-                    Threaded="true" 
-                    Daemon="false"
-                    JMXServiceURL="service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi/server"/>
-            </value>
-        </property>
+    <bean id="org.apache.cxf.management.InstrumentationManager" class="org.apache.cxf.management.jmx.InstrumentationManagerImpl">
+        <property name="bus" ref="cxf" />
+        <property name="enabled" value="true" />
+        <property name="JMXServiceURL" value="service:jmx:rmi:///jndi/rmi://localhost:9914/jmxrmi" />
     </bean> 
  
 </beans>



Mime
View raw message