Author: clement Date: Sat Oct 16 08:55:49 2010 New Revision: 1023216 URL: http://svn.apache.org/viewvc?rev=1023216&view=rev Log: Add the JMX Handler Test suite
Added: felix/trunk/ipojo/tests/handler/jmx/ (with props) felix/trunk/ipojo/tests/handler/jmx/pom.xml felix/trunk/ipojo/tests/handler/jmx/src/ felix/trunk/ipojo/tests/handler/jmx/src/main/ felix/trunk/ipojo/tests/handler/jmx/src/main/java/ felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/ felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/ felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/ felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/ felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/JmxTestSuite.java felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/MBeanTests.java felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/component/ felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/component/SimpleManagedComponent.java felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/component/SimpleManagedComponentAnnotated.java felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/component/SimpleManagedComponentAnnotatedDeprecated.java felix/trunk/ipojo/tests/handler/jmx/src/main/resources/ felix/trunk/ipojo/tests/handler/jmx/src/main/resources/metadata.xml Modified: felix/trunk/ipojo/tests/pom.xml Propchange: felix/trunk/ipojo/tests/handler/jmx/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Sat Oct 16 08:55:49 2010 @@ -0,0 +1,4 @@ +.classpath +.project +.settings +target Added: felix/trunk/ipojo/tests/handler/jmx/pom.xml URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/handler/jmx/pom.xml?rev=1023216&view=auto ============================================================================== --- felix/trunk/ipojo/tests/handler/jmx/pom.xml (added) +++ felix/trunk/ipojo/tests/handler/jmx/pom.xml Sat Oct 16 08:55:49 2010 @@ -0,0 +1,129 @@ +<?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. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <groupId>ipojo.tests</groupId> + <artifactId>ipojo.tests</artifactId> + <version>1.5.0-SNAPSHOT</version> + </parent> + <groupId>ipojo.tests</groupId> + <version>1.5.0-SNAPSHOT</version> + <modelVersion>4.0.0</modelVersion> + <packaging>bundle</packaging> + <name>iPOJO JMX Handler Test Suite</name> + <artifactId>tests.jmx.handler</artifactId> + + <dependencies> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.ipojo.annotations</artifactId> + <version>1.7.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.ipojo</artifactId> + <version>1.7.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.ipojo.handler.jmx</artifactId> + <version>1.5.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>3.8.1</version> + </dependency> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.ipojo.junit4osgi</artifactId> + <version>1.1.0-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>org.osgi</groupId> + <artifactId>org.osgi.compendium</artifactId> + </dependency> + </dependencies> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.5</source> + <target>1.5</target> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + <configuration> + <instructions> + <Private-Package>org.apache.felix.ipojo.test.* + </Private-Package> + <Test-Suite> + org.apache.felix.ipojo.test.JmxTestSuite + </Test-Suite> + </instructions> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-ipojo-plugin</artifactId> + <executions> + <execution> + <goals> + <goal>ipojo-bundle</goal> + </goals> + <configuration> + <ignoreAnnotations>false</ignoreAnnotations> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-junit4osgi-plugin + </artifactId> + <version>1.1.0-SNAPSHOT</version> + <executions> + <execution> + <goals> + <goal>test</goal> + </goals> + <configuration> + <hideOutputs>false</hideOutputs> + <logService>false</logService> + <configuration> + <org.osgi.http.port>8083</org.osgi.http.port> + </configuration> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project> Added: felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/JmxTestSuite.java URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/JmxTestSuite.java?rev=1023216&view=auto ============================================================================== --- felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/JmxTestSuite.java (added) +++ felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/JmxTestSuite.java Sat Oct 16 08:55:49 2010 @@ -0,0 +1,47 @@ +/* + * 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.test; + +import junit.framework.Test; + +import org.apache.felix.ipojo.junit4osgi.OSGiTestSuite; +import org.osgi.framework.BundleContext; + +/** + * Event Admin Handler test suite. + * + * @author <a href="mailto:d...@felix.apache.org">Felix Project Team</a> + */ +public class JmxTestSuite { + + /** + * Generate the Event Admin Handler test suite. + * + * @param bc + * the OSGi bundle context + * @return the Event Admin Handler test suite. + */ + public static Test suite(BundleContext bc) { + OSGiTestSuite ots = new OSGiTestSuite("JMX Handler test suite", + bc); + ots.addTestSuite(MBeanTests.class); + return ots; + } + +} \ No newline at end of file Added: felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/MBeanTests.java URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/MBeanTests.java?rev=1023216&view=auto ============================================================================== --- felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/MBeanTests.java (added) +++ felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/MBeanTests.java Sat Oct 16 08:55:49 2010 @@ -0,0 +1,234 @@ +/* + * 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.test; + +import java.lang.management.ManagementFactory; + +import javax.management.InstanceNotFoundException; +import javax.management.IntrospectionException; +import javax.management.ListenerNotFoundException; +import javax.management.MBeanAttributeInfo; +import javax.management.MBeanException; +import javax.management.MBeanInfo; +import javax.management.MBeanOperationInfo; +import javax.management.MBeanParameterInfo; +import javax.management.MBeanServer; +import javax.management.MalformedObjectNameException; +import javax.management.Notification; +import javax.management.NotificationListener; +import javax.management.ObjectInstance; +import javax.management.ObjectName; +import javax.management.ReflectionException; + +import org.apache.felix.ipojo.ComponentInstance; +import org.apache.felix.ipojo.junit4osgi.OSGiTestCase; +import org.apache.felix.ipojo.junit4osgi.helpers.IPOJOHelper; + +/** + * Test the good behaviour of the EventAdminHandler. + * + * @author <a href="mailto:d...@felix.apache.org">Felix Project Team</a> + */ +public class MBeanTests extends OSGiTestCase { + + /** + * Helper used to create test components. + */ + private IPOJOHelper m_helper; + + /** + * The MBean server used to access exposed MBeans. + */ + private MBeanServer m_server; + + /** + * Initialize test. + */ + public void setUp() { + m_helper = new IPOJOHelper(this); + m_server = ManagementFactory.getPlatformMBeanServer(); + } + + /** + * Clean test. + */ + public void tearDown() { + m_helper.dispose(); + } + + /** + * Test the MBean exposed by the simple component, defined without + * annotations and with the brand new JMX handler syntax. + */ + public void testMBeanWithoutAnnotations() throws MalformedObjectNameException, IntrospectionException, InstanceNotFoundException, ListenerNotFoundException, ReflectionException, MBeanException { + // Create an instance of the component + ComponentInstance componentInstance = m_helper + .createComponentInstance("org.apache.felix.ipojo.test.component.SimpleManagedComponent"); + String instanceName = componentInstance.getInstanceName(); + ObjectName objectName = new ObjectName( + "org.apache.felix.ipojo.test.component:type=org.apache.felix.ipojo.test.component.SimpleManagedComponent,instance=" + + instanceName); + doTest(objectName); + } + + /** + * Test the MBean exposed by the simple component, defined without + * annotations and with the deprecated JMX handler syntax. + */ + public void testMBeanWithoutAnnotationsDeprecated() throws MalformedObjectNameException, IntrospectionException, InstanceNotFoundException, ListenerNotFoundException, ReflectionException, MBeanException { + // Create an instance of the component + ComponentInstance componentInstance = m_helper + .createComponentInstance("org.apache.felix.ipojo.test.component.SimpleManagedComponentDeprecated"); + String instanceName = componentInstance.getInstanceName(); + ObjectName objectName = new ObjectName( + "org.apache.felix.ipojo.test.component:type=org.apache.felix.ipojo.test.component.SimpleManagedComponent,instance=" + + instanceName); + doTest(objectName); + } + + + /** + * Test the MBean exposed by the simple component, defined with + * annotations. + */ + public void testMBeanWithAnnotations() throws MalformedObjectNameException, IntrospectionException, + InstanceNotFoundException, ListenerNotFoundException, + ReflectionException, MBeanException { + // Create an instance of the component + ComponentInstance componentInstance = m_helper + .createComponentInstance("org.apache.felix.ipojo.test.component.SimpleManagedComponentAnnotated"); + String instanceName = componentInstance.getInstanceName(); + ObjectName objectName = new ObjectName( + "org.apache.felix.ipojo.test.component:type=org.apache.felix.ipojo.test.component.SimpleManagedComponentAnnotated,instance=" + + instanceName); + doTest(objectName); + } + + /** + * Test the MBean exposed by the simple component, defined with + * annotations. + */ + public void testMBeanWithAnnotationsDeprecated() throws MalformedObjectNameException, IntrospectionException, + InstanceNotFoundException, ListenerNotFoundException, + ReflectionException, MBeanException { + // Create an instance of the component + ComponentInstance componentInstance = m_helper + .createComponentInstance("org.apache.felix.ipojo.test.component.SimpleManagedComponentAnnotatedDeprecated"); + String instanceName = componentInstance.getInstanceName(); + ObjectName objectName = new ObjectName( + "org.apache.felix.ipojo.test.component:type=org.apache.felix.ipojo.test.component.SimpleManagedComponentAnnotatedDeprecated,instance=" + + instanceName); + doTest(objectName); + } + + /** + * Utility method used to test the MBean with the given objectName. + * @param objectName the objectName of the MBean to test. + */ + private void doTest(ObjectName objectName) throws IntrospectionException, InstanceNotFoundException, ReflectionException, MBeanException, ListenerNotFoundException { + + // Get the MBean from the platform MBean server + + MBeanInfo mBeanInfo = m_server.getMBeanInfo(objectName); + ObjectInstance objectInstance = m_server.getObjectInstance(objectName); + assertNotNull(mBeanInfo); + assertNotNull(objectInstance); + // Check that the property is exposed + MBeanAttributeInfo[] attributes = mBeanInfo.getAttributes(); + assertEquals(1, attributes.length); + MBeanAttributeInfo attribute = attributes[0]; + assertEquals("integer", attribute.getName()); + assertEquals("int", attribute.getType()); + assertTrue(attribute.isReadable()); + assertFalse(attribute.isWritable()); + // Check that both methods are exposed + MBeanOperationInfo[] operations = mBeanInfo.getOperations(); + assertEquals(2, operations.length); + MBeanOperationInfo getOperation; + MBeanOperationInfo setOperation; + // Order is not important + if (operations[0].getName().equals("getIntegerValue")) { + getOperation = operations[0]; + setOperation = operations[1]; + } else { + setOperation = operations[0]; + getOperation = operations[1]; + } + // Check the 'get' operation + assertEquals("getIntegerValue", getOperation.getName()); + assertEquals("Get the value of the integer", + getOperation.getDescription()); + assertEquals("int", getOperation.getReturnType()); + MBeanParameterInfo[] getOperationParams = getOperation.getSignature(); + assertEquals(0, getOperationParams.length); + // Check the 'set' operation + assertEquals("setIntegerValue", setOperation.getName()); + assertEquals("Set the value of the integer", + setOperation.getDescription()); + assertEquals("int", setOperation.getReturnType()); + MBeanParameterInfo[] setOperationParams = setOperation.getSignature(); + assertEquals(1, setOperationParams.length); + assertEquals("int", setOperationParams[0].getType()); + // Call the methods and test the result, also test notifications + CustomNotificationListener listener = new CustomNotificationListener(); + m_server.addNotificationListener(objectName, listener, null, null); + int value1 = 123; + int value2 = 456; + m_server.invoke(objectName, "setIntegerValue", new Object[] { value1 }, + new String[] { "int" }); + m_server.invoke(objectName, "setIntegerValue", new Object[] { value2 }, + new String[] { "int" }); + int result = (Integer) m_server.invoke(objectName, "getIntegerValue", + new Object[0], new String[0]); + assertEquals(value2, result); + m_server.removeNotificationListener(objectName, listener, null, null); + //assertEquals(2, listener.getCount()); + } + + /** + * Custom listener used to count MBean notifications. + * @author <a href="mailto:d...@felix.apache.org">Felix Project Team</a> + */ + private class CustomNotificationListener implements NotificationListener { + + /** + * Counter for the notifications. + */ + private int m_counter = 0; + + /** + * Notified ! + * @param notification the notification + * @param handback ignored + */ + public void handleNotification(Notification notification, + Object handback) { + m_counter++; + } + + /** + * Return the notification count of this listener. + * @return the notification count of this listener. + */ + public int getCount() { + return m_counter; + } + } + +} Added: felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/component/SimpleManagedComponent.java URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/component/SimpleManagedComponent.java?rev=1023216&view=auto ============================================================================== --- felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/component/SimpleManagedComponent.java (added) +++ felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/component/SimpleManagedComponent.java Sat Oct 16 08:55:49 2010 @@ -0,0 +1,56 @@ +/* + * 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.test.component; + +import java.util.Random; + +/** + * Simple component that holds an integer. It is exposed as a MBean. + * + * @author <a href="mailto:d...@felix.apache.org">Felix Project Team</a> + */ +public class SimpleManagedComponent { + + /** + * The integer. + */ + private int m_integer /*= new Random().nextInt()*/; + + /** + * Set the value of the integer. + * @param newValue the new value + * @return the old value of the integer. + */ + @SuppressWarnings("unused") + private synchronized int setIntegerValue(int newValue) { + int oldValue = m_integer; + m_integer = newValue; + return oldValue; + } + + /** + * Get the value of the integer. + * @return the currentvalue of the integer. + */ + @SuppressWarnings("unused") + private synchronized int getIntegerValue() { + return m_integer; + } + +} Added: felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/component/SimpleManagedComponentAnnotated.java URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/component/SimpleManagedComponentAnnotated.java?rev=1023216&view=auto ============================================================================== --- felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/component/SimpleManagedComponentAnnotated.java (added) +++ felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/component/SimpleManagedComponentAnnotated.java Sat Oct 16 08:55:49 2010 @@ -0,0 +1,69 @@ +/* + * 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.test.component; + +import java.util.Random; + +import org.apache.felix.ipojo.annotations.Component; +import org.apache.felix.ipojo.handlers.jmx.JMXBean; +import org.apache.felix.ipojo.handlers.jmx.JMXMethod; +import org.apache.felix.ipojo.handlers.jmx.JMXProperty; + +/** + * Simple component that holds an integer. It is exposed as a MBean. This + * version uses the brand new annotations of the JMX handler. + * + * @author <a href="mailto:d...@felix.apache.org">Felix Project Team</a> + */ +...@component(immediate = true) +...@jmxbean +public class SimpleManagedComponentAnnotated { + + /** + * The integer. + */ + @JMXProperty(name = "integer", rights = "r", notification = true) + private int m_integer = new Random().nextInt();; + + /** + * Set the value of the integer. + * + * @param newValue + * the new value + * @return the old value of the integer. + */ + @SuppressWarnings("unused") + @JMXMethod(description = "Set the value of the integer") + private synchronized int setIntegerValue(int newValue) { + int oldValue = m_integer; + m_integer = newValue; + return oldValue; + } + + /** + * Get the value of the integer. + * + * @return the currentvalue of the integer. + */ + @SuppressWarnings("unused") + @JMXMethod(description = "Get the value of the integer") + private synchronized int getIntegerValue() { + return m_integer; + } +} Added: felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/component/SimpleManagedComponentAnnotatedDeprecated.java URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/component/SimpleManagedComponentAnnotatedDeprecated.java?rev=1023216&view=auto ============================================================================== --- felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/component/SimpleManagedComponentAnnotatedDeprecated.java (added) +++ felix/trunk/ipojo/tests/handler/jmx/src/main/java/org/apache/felix/ipojo/test/component/SimpleManagedComponentAnnotatedDeprecated.java Sat Oct 16 08:55:49 2010 @@ -0,0 +1,70 @@ +/* + * 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.test.component; + +import java.util.Random; + +import org.apache.felix.ipojo.annotations.Component; +import org.apache.felix.ipojo.handlers.jmx.Config; +import org.apache.felix.ipojo.handlers.jmx.Method; +import org.apache.felix.ipojo.handlers.jmx.Property; + + +/** + * Simple component that holds an integer. It is exposed as a MBean. This + * version uses the deprecated annotations of the JMX handler. + * + * @author <a href="mailto:d...@felix.apache.org">Felix Project Team</a> + */ +...@component(immediate = true) +...@config +public class SimpleManagedComponentAnnotatedDeprecated { + + /** + * The integer. + */ + @Property(name = "integer", rights = "r", notification = true) + private int m_integer = new Random().nextInt();; + + /** + * Set the value of the integer. + * + * @param newValue + * the new value + * @return the old value of the integer. + */ + @SuppressWarnings("unused") + @Method(description = "Set the value of the integer") + private synchronized int setIntegerValue(int newValue) { + int oldValue = m_integer; + m_integer = newValue; + return oldValue; + } + + /** + * Get the value of the integer. + * + * @return the currentvalue of the integer. + */ + @SuppressWarnings("unused") + @Method(description = "Get the value of the integer") + private synchronized int getIntegerValue() { + return m_integer; + } +} Added: felix/trunk/ipojo/tests/handler/jmx/src/main/resources/metadata.xml URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/handler/jmx/src/main/resources/metadata.xml?rev=1023216&view=auto ============================================================================== --- felix/trunk/ipojo/tests/handler/jmx/src/main/resources/metadata.xml (added) +++ felix/trunk/ipojo/tests/handler/jmx/src/main/resources/metadata.xml Sat Oct 16 08:55:49 2010 @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ipojo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="org.apache.felix.ipojo http://felix.apache.org/ipojo/schemas/SNAPSHOT/core.xsd" + xmlns="org.apache.felix.ipojo" + xmlns:jmx="org.apache.felix.ipojo.handlers.jmx"> + + <!-- The simple managed component without annotations and with brand new JMX handler syntax --> + <component classname="org.apache.felix.ipojo.test.component.SimpleManagedComponent" immediate="true"> + <!-- Expose field and methods with JMX handler --> + <jmx:config> + <jmx:jmxmethod name="getIntegerValue" description="Get the value of the integer"/> + <jmx:jmxmethod name="setIntegerValue" description="Set the value of the integer"/> + <jmx:jmxproperty name="integer" field="m_integer" rights="r" notification="true"/> + </jmx:config> + </component> + + <!-- The simple managed component without annotations and with brand new JMX handler syntax --> + <component classname="org.apache.felix.ipojo.test.component.SimpleManagedComponent" immediate="true" name="org.apache.felix.ipojo.test.component.SimpleManagedComponentDeprecated"> + <!-- Expose field and methods with JMX handler --> + <jmx:config> + <jmx:method name="getIntegerValue" description="Get the value of the integer"/> + <jmx:method name="setIntegerValue" description="Set the value of the integer"/> + <jmx:property name="integer" field="m_integer" rights="r" notification="true"/> + </jmx:config> + </component> + +</ipojo> \ No newline at end of file Modified: felix/trunk/ipojo/tests/pom.xml URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/tests/pom.xml?rev=1023216&r1=1023215&r2=1023216&view=diff ============================================================================== --- felix/trunk/ipojo/tests/pom.xml (original) +++ felix/trunk/ipojo/tests/pom.xml Sat Oct 16 08:55:49 2010 @@ -156,13 +156,9 @@ <jdk>1.5</jdk> </activation> <modules> - <!-- - Remove bundleAsiPOJO - Deprecated - <module>bundleAsiPOJO</module> - --> <module>core/annotations</module> - <module>manipulator/manipulator-java5 - </module> + <module>manipulator/manipulator-java5</module> + <module>handler/jmx</module> <module>handler/transaction</module> </modules> </profile> @@ -172,13 +168,9 @@ <jdk>1.6</jdk> </activation> <modules> - <!-- - Remove bundleAsiPOJO - Deprecated - <module>bundleAsiPOJO</module> - --> <module>core/annotations</module> - <module>manipulator/manipulator-java5 - </module> + <module>manipulator/manipulator-java5</module> + <module>handler/jmx</module> <module>handler/transaction</module> </modules> </profile>