You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2010/10/16 10:54:11 UTC

svn commit: r1023215 - in /felix/trunk/ipojo: annotations/src/main/java/org/apache/felix/ipojo/handlers/jmx/ handler/jmx/ handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/

Author: clement
Date: Sat Oct 16 08:54:11 2010
New Revision: 1023215

URL: http://svn.apache.org/viewvc?rev=1023215&view=rev
Log:
Fix FELIX-2633 Rename JMX annotations
The @Conifug annotation is now @JmxBean which make more sense.

Added:
    felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/jmx/JMXBean.java
Modified:
    felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/jmx/Config.java
    felix/trunk/ipojo/handler/jmx/metadata.xml
    felix/trunk/ipojo/handler/jmx/obr.xml
    felix/trunk/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/DynamicMBeanImpl.java
    felix/trunk/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java

Modified: felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/jmx/Config.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/jmx/Config.java?rev=1023215&r1=1023214&r2=1023215&view=diff
==============================================================================
--- felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/jmx/Config.java (original)
+++ felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/jmx/Config.java Sat Oct 16 08:54:11 2010
@@ -27,6 +27,7 @@ import java.lang.annotation.Target;
  * Be aware that despite is it provided in the annotations jar,
  * it refers to an external handler.
  * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ * @deprecated replaced by {@link JMXBean}
  */
 @Target(ElementType.TYPE)
 public @interface Config {

Added: felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/jmx/JMXBean.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/jmx/JMXBean.java?rev=1023215&view=auto
==============================================================================
--- felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/jmx/JMXBean.java (added)
+++ felix/trunk/ipojo/annotations/src/main/java/org/apache/felix/ipojo/handlers/jmx/JMXBean.java Sat Oct 16 08:54:11 2010
@@ -0,0 +1,61 @@
+/*
+ * 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.felix.ipojo.handlers.jmx;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Target;
+
+/**
+ * JMX Handler annotation.
+ * Allows exposing the instances as a JMX MBean.
+ * Be aware that despite is it provided in the annotations jar,
+ * it refers to an external handler.
+ * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
+ */
+@Target(ElementType.TYPE)
+public @interface JMXBean {
+
+    /**
+     * Enables or Disables MOSGi usage.
+     * If MOSGi is used, MBeans are exposed with the MOSGi mechanism.
+     * Otherwise the MBean Platform Server is used.
+     * Default : false
+     */
+    boolean usesMOSGi() default false;
+
+    /**
+     * Sets the MBean object name.
+     * Default : 'package-name:factory-name:instance-name'.
+     */
+    String objectname() default "";
+
+    /**
+     * Sets the MBean domain.
+     * Default : 'package-name'
+     */
+    String domain() default "";
+
+    /**
+     * Sets the MBean name.
+     * Default : 'instance-name'
+     */
+    String name() default "";
+
+
+}

Modified: felix/trunk/ipojo/handler/jmx/metadata.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/handler/jmx/metadata.xml?rev=1023215&r1=1023214&r2=1023215&view=diff
==============================================================================
--- felix/trunk/ipojo/handler/jmx/metadata.xml (original)
+++ felix/trunk/ipojo/handler/jmx/metadata.xml Sat Oct 16 08:54:11 2010
@@ -17,6 +17,6 @@
 	under the License.
 -->
 <ipojo>
-<handler classname="org.apache.felix.ipojo.handlers.jmx.MBeanHandler" name="config" namespace="org.apache.felix.ipojo.handlers.jmx">
-</handler>	
+<handler classname="org.apache.felix.ipojo.handlers.jmx.MBeanHandler" name="config" namespace="org.apache.felix.ipojo.handlers.jmx" />
+<handler classname="org.apache.felix.ipojo.handlers.jmx.MBeanHandler" name="JMXBean" namespace="org.apache.felix.ipojo.handlers.jmx" />
 </ipojo>
\ No newline at end of file

Modified: felix/trunk/ipojo/handler/jmx/obr.xml
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/handler/jmx/obr.xml?rev=1023215&r1=1023214&r2=1023215&view=diff
==============================================================================
--- felix/trunk/ipojo/handler/jmx/obr.xml (original)
+++ felix/trunk/ipojo/handler/jmx/obr.xml Sat Oct 16 08:54:11 2010
@@ -22,4 +22,9 @@
 		<p n="namespace" v="org.apache.felix.ipojo.handlers.jmx"/>
 		<p n="type" v="primitive"/>
 	</capability>
+    <capability name="ipojo.handler">
+        <p n="name" v="JMXBean"/>
+        <p n="namespace" v="org.apache.felix.ipojo.handlers.jmx"/>
+        <p n="type" v="primitive"/>
+    </capability>
 </obr>
\ No newline at end of file

Modified: felix/trunk/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/DynamicMBeanImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/DynamicMBeanImpl.java?rev=1023215&r1=1023214&r2=1023215&view=diff
==============================================================================
--- felix/trunk/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/DynamicMBeanImpl.java (original)
+++ felix/trunk/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/DynamicMBeanImpl.java Sat Oct 16 08:54:11 2010
@@ -1,4 +1,4 @@
-/* 
+/*
  * 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
@@ -393,7 +393,8 @@ public class DynamicMBeanImpl extends No
 
         long timeStamp = System.currentTimeMillis();
 
-        if (newValue.equals(oldValue)) {
+        if ((newValue == null  && oldValue == null)
+        		|| (newValue != null  && newValue.equals(oldValue))) {
             return;
         }
         m_sequenceNumber++;

Modified: felix/trunk/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java?rev=1023215&r1=1023214&r2=1023215&view=diff
==============================================================================
--- felix/trunk/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java (original)
+++ felix/trunk/ipojo/handler/jmx/src/main/java/org/apache/felix/ipojo/handlers/jmx/MBeanHandler.java Sat Oct 16 08:54:11 2010
@@ -76,6 +76,11 @@ public class MBeanHandler extends Primit
     private static final String JMX_CONFIG_ELT = "config";
 
     /**
+     * The name of the global configuration element.
+     */
+    private static final String JMX_CONFIG_ALT_ELT = "JmxBean";
+
+    /**
      * The name of the component object full name attribute.
      */
     private static final String JMX_OBJ_NAME_ELT = "objectName";
@@ -103,7 +108,7 @@ public class MBeanHandler extends Primit
     /**
      * The alternative name of a method element.
      */
-    private static final String JMX_METHOD_ELT_ALT = "method";
+    private static final String JMX_METHOD_ELT_ALT = "JmxMethod";
 
     /**
      * The name of the property or method name attribute.
@@ -123,7 +128,7 @@ public class MBeanHandler extends Primit
     /**
      * The alternative name of a property element.
      */
-    private static final String JMX_PROPERTY_ELT_ALT = "property";
+    private static final String JMX_PROPERTY_ELT_ALT = "JmxProperty";
 
     /**
      * The name of the field attribute.
@@ -222,9 +227,12 @@ public class MBeanHandler extends Primit
 
         // Build the hashmap
         Element[] mbeans = metadata.getElements(JMX_CONFIG_ELT, m_namespace);
+        if (mbeans == null || mbeans.length == 0) {
+            mbeans = metadata.getElements(JMX_CONFIG_ALT_ELT, m_namespace);
+        }
 
         if (mbeans.length != 1) {
-            error("A component must have at most one " + JMX_CONFIG_ELT + ".");
+            error("A component must have exactly one " + JMX_CONFIG_ELT + " or " + JMX_CONFIG_ALT_ELT + " element.");
             error("The JMX handler configuration is ignored.");
             return;
         }
@@ -532,6 +540,21 @@ public class MBeanHandler extends Primit
         PropertyField propertyField = (PropertyField) m_jmxConfigFieldMap
             .getPropertyFromField(fieldName);
         if (propertyField != null) {
+        	// Do we have a value to inject ?
+        	Object v = propertyField.getValue();
+        	if (v == null) {
+        		String type = propertyField.getType();
+    	        if ("boolean".equals(type)) { v = Boolean.FALSE; }
+    	        else if ("byte".equals(type)) { v = new Byte((byte) 0); }
+    	        else if ("short".equals(type)) { v = new Short((short) 0); }
+    	        else if ("int".equals(type)) { v = new Integer(0); }
+    	        else if ("long".equals(type)) { v = new Long(0); }
+    	        else if ("float".equals(type)) { v = new Float(0); }
+    	        else if ("double".equals(type)) { v =new Double(0); }
+    	        else if ("char".equals(type)) { v = new Character((char) 0); }
+
+    	        return v;
+    	    }
             m_instanceManager.onSet(pojo, fieldName, propertyField.getValue());
             return propertyField.getValue();
         }