[jboss-cvs] JBossAS SVN: r85228 - in projects/jboss-osgi/trunk: runtime/deployer/src/main/resources and 9 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Mar 4 10:04:48 EST 2009
Author: thomas.diesler at jboss.com
Date: 2009-03-04 10:04:47 -0500 (Wed, 04 Mar 2009)
New Revision: 85228
Added:
projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleManagementDeployer.java
projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/Constants.java
projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/
projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/MBeanProxy.java
projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/MBeanProxyException.java
projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java
projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedBundleMBean.java
projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedFramework.java
projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedFrameworkMBean.java
projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ObjectNameFactory.java
Removed:
projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/jmx/
projects/jboss-osgi/trunk/runtime/spi/src/main/resources/
Modified:
projects/jboss-osgi/trunk/runtime/deployer/src/main/resources/osgi-deployers-jboss-beans.xml
projects/jboss-osgi/trunk/service/http/pom.xml
projects/jboss-osgi/trunk/service/http/src/main/java/org/jboss/osgi/service/http/GenericEndpointServlet.java
projects/jboss-osgi/trunk/service/http/src/main/java/org/jboss/osgi/service/http/HttpEndpointDeployer.java
projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/jbosgi36/junit/OSGI36TestCase.java
projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/jbosgi36/mbean/FooMBean.java
projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/service/microcontainer/MBeanTestService.java
projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/service/microcontainer/junit/MicrocontainerServiceTestCase.java
Log:
Add a bundle management view
Added: projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleManagementDeployer.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleManagementDeployer.java (rev 0)
+++ projects/jboss-osgi/trunk/runtime/deployer/src/main/java/org/jboss/osgi/deployer/BundleManagementDeployer.java 2009-03-04 15:04:47 UTC (rev 85228)
@@ -0,0 +1,84 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.deployer;
+
+// $Id: $
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.osgi.spi.management.ManagedBundle;
+import org.osgi.framework.Bundle;
+
+/**
+ * Register the bundle for management
+ *
+ * @author Thomas.Diesler at jboss.com
+ * @since 04-Mar-2009
+ */
+public class BundleManagementDeployer extends AbstractSimpleRealDeployer<Bundle>
+{
+ private MBeanServer mbeanServer;
+
+ public BundleManagementDeployer()
+ {
+ super(Bundle.class);
+ }
+
+ public void setMbeanServer(MBeanServer mbeanServer)
+ {
+ this.mbeanServer = mbeanServer;
+ }
+
+ public void deploy(DeploymentUnit unit, Bundle bundle) throws DeploymentException
+ {
+ ManagedBundle mb = new ManagedBundle(bundle);
+ ObjectName oname = mb.getObjectName();
+ try
+ {
+ mbeanServer.registerMBean(mb, oname);
+ unit.addAttachment(ManagedBundle.class, mb);
+ }
+ catch (Exception ex)
+ {
+ DeploymentException.rethrowAsDeploymentException(ex.getMessage(), ex);
+ }
+ }
+
+ @Override
+ public void undeploy(DeploymentUnit unit, Bundle bundle)
+ {
+ try
+ {
+ ManagedBundle mb = unit.getAttachment(ManagedBundle.class);
+ if (mb != null && mbeanServer.isRegistered(mb.getObjectName()))
+ mbeanServer.unregisterMBean(mb.getObjectName());
+ }
+ catch (Exception ex)
+ {
+ log.warn("Cannot unregister: " + bundle, ex);
+ }
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/runtime/deployer/src/main/resources/osgi-deployers-jboss-beans.xml
===================================================================
--- projects/jboss-osgi/trunk/runtime/deployer/src/main/resources/osgi-deployers-jboss-beans.xml 2009-03-04 15:02:25 UTC (rev 85227)
+++ projects/jboss-osgi/trunk/runtime/deployer/src/main/resources/osgi-deployers-jboss-beans.xml 2009-03-04 15:04:47 UTC (rev 85228)
@@ -33,7 +33,7 @@
org.jboss.osgi.service,
org.jboss.osgi.spi,
org.jboss.osgi.spi.framework,
- org.jboss.osgi.spi.jmx,
+ org.jboss.osgi.spi.management,
org.jboss.system.server.jmx,
org.jboss.web,
org.jboss.virtual,
@@ -59,6 +59,11 @@
</property>
</bean>
+ <!-- The Framework Management -->
+ <bean name="jboss.osgi:service=ManagedFramework" class="org.jboss.osgi.spi.management.ManagedFramework">
+ <property name="mbeanServer"><inject bean="JMXKernel" property="mbeanServer"/></property>
+ </bean>
+
<!-- A Service that gives access to the Microcontainer Kernel -->
<bean name="jboss.osgi:service=Microcontainer" class="org.jboss.osgi.service.MicrocontainerService">
<property name="bundleContext"><inject bean="jboss.osgi:service=Framework" property="systemBundleContext"/></property>
@@ -80,6 +85,11 @@
<property name="systemContext"><inject bean="jboss.osgi:service=Framework" property="systemBundleContext" /></property>
</bean>
+ <!-- The Bundle Management Deployer -->
+ <bean name="jboss.osgi:service=BundleManagementDeployer" class="org.jboss.osgi.deployer.BundleManagementDeployer">
+ <property name="mbeanServer"><inject bean="JMXKernel" property="mbeanServer"/></property>
+ </bean>
+
<!-- The Bundle Start/Stop Deployer -->
<bean name="jboss.osgi:service=BundleStartStopDeployer" class="org.jboss.osgi.deployer.BundleStartStopDeployer">
<property name="systemContext"><inject bean="jboss.osgi:service=Framework" property="systemBundleContext" /></property>
Added: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/Constants.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/Constants.java (rev 0)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/Constants.java 2009-03-04 15:04:47 UTC (rev 85228)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.spi;
+
+// $Id$
+
+/**
+ * An JBossOSGi Constants
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 04-Mar-2009
+ */
+public abstract class Constants
+{
+ /** The JBossOSGi domain 'jboss.osgi' */
+ public static final String DOMAIN_NAME = "jboss.osgi";
+}
Property changes on: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/Constants.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/MBeanProxy.java (from rev 85213, projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/jmx/MBeanProxy.java)
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/MBeanProxy.java (rev 0)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/MBeanProxy.java 2009-03-04 15:04:47 UTC (rev 85228)
@@ -0,0 +1,392 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.spi.management;
+
+// $Id$
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.HashMap;
+
+import javax.management.Attribute;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+import javax.management.RuntimeErrorException;
+import javax.management.RuntimeMBeanException;
+import javax.management.RuntimeOperationsException;
+
+
+/**
+ * A simple MBeanProxy
+ *
+ * @author Thomas.Diesler at jboss.com
+ * @since 24-Feb-2009
+ */
+public class MBeanProxy
+{
+ @SuppressWarnings( { "unchecked" })
+ public static Object get(Class interf, ObjectName name, MBeanServerConnection server) throws MBeanProxyException
+ {
+ return get(new Class[] { interf }, name, server);
+ }
+
+ @SuppressWarnings( { "unchecked" })
+ public static Object get(Class[] interfaces, ObjectName name, MBeanServerConnection server) throws MBeanProxyException
+ {
+ return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces, new JMXInvocationHandler(server, name));
+ }
+
+ /**
+ * Invocation handler for MBean proxies.
+ *
+ * @author <a href="mailto:juha at jboss.org">Juha Lindfors</a>
+ * @author Thomas.Diesler at jboss.com
+ * @since 24-Feb-2009
+ */
+ static class JMXInvocationHandler implements InvocationHandler, Serializable
+ {
+ private static final long serialVersionUID = 3714728148040623702L;
+
+ // Attributes -------------------------------------------------
+
+ /*
+ * Reference to the MBean server this proxy connects to.
+ */
+ protected MBeanServerConnection server = null;
+
+ /*
+ * The object name of the MBean this proxy represents.
+ */
+ protected ObjectName objectName = null;
+
+ /*
+ * MBean attribute meta data.
+ */
+ private HashMap<String, MBeanAttributeInfo> attributeMap = new HashMap<String, MBeanAttributeInfo>();
+
+ /*
+ * Indicates whether Object.toString() should be delegated to the resource or handled by the proxy.
+ */
+ private boolean delegateToStringToResource = false;
+
+ /*
+ * Indicates whether Object.equals() should be delegated to the resource or handled by the proxy.
+ */
+ private boolean delegateEqualsToResource = false;
+
+ /*
+ * Indicates whether Object.hashCode() should be delegated to the resource or handled by the proxy.
+ */
+ private boolean delegateHashCodeToResource = false;
+
+ // Constructors -----------------------------------------------
+
+ /*
+ * Constructs a new JMX MBean Proxy invocation handler.
+ * @param server reference to the MBean server this proxy connects to
+ * @param name object name of the MBean this proxy represents
+ * @throws MBeanProxyCreationException wraps underlying JMX exceptions in case the proxy creation fails
+ */
+ public JMXInvocationHandler(MBeanServerConnection server, ObjectName name) throws MBeanProxyException
+ {
+ try
+ {
+ if (server == null)
+ throw new MBeanProxyException("null agent reference");
+
+ this.server = server;
+ this.objectName = name;
+
+ MBeanInfo info = server.getMBeanInfo(objectName);
+ MBeanAttributeInfo[] attributes = info.getAttributes();
+ MBeanOperationInfo[] operations = info.getOperations();
+
+ // collect the MBean attribute metadata for standard mbean proxies
+ for (int i = 0; i < attributes.length; ++i)
+ attributeMap.put(attributes[i].getName(), attributes[i]);
+
+ // Check whether the target resource exposes the common object methods.
+ // Dynamic Proxy will delegate these methods automatically to the
+ // invoke() implementation.
+ for (int i = 0; i < operations.length; ++i)
+ {
+ if (operations[i].getName().equals("toString") && operations[i].getReturnType().equals("java.lang.String") && operations[i].getSignature().length == 0)
+ {
+ delegateToStringToResource = true;
+ }
+
+ else if (operations[i].getName().equals("equals") && operations[i].getReturnType().equals(Boolean.TYPE.getName())
+ && operations[i].getSignature().length == 1 && operations[i].getSignature()[0].getType().equals("java.lang.Object"))
+ {
+ delegateEqualsToResource = true;
+ }
+
+ else if (operations[i].getName().equals("hashCode") && operations[i].getReturnType().equals(Integer.TYPE.getName())
+ && operations[i].getSignature().length == 0)
+ {
+ delegateHashCodeToResource = true;
+ }
+ }
+ }
+ catch (InstanceNotFoundException e)
+ {
+ throw new MBeanProxyException("Object name " + name + " not found: " + e.toString());
+ }
+ catch (Exception ex)
+ {
+ throw new MBeanProxyException(ex.toString());
+ }
+ }
+
+ // InvocationHandler implementation ---------------------------
+
+ @SuppressWarnings("unchecked")
+ public Object invoke(Object proxy, Method method, Object[] args) throws Exception
+ {
+ Class<?> declaringClass = method.getDeclaringClass();
+
+ // Handle methods from Object class. If the target resource exposes
+ // operation metadata with same signature then the invocations will be
+ // delegated to the target. Otherwise this instance of invocation handler
+ // will execute them.
+ if (declaringClass == Object.class)
+ return handleObjectMethods(method, args);
+
+ try
+ {
+ String methodName = method.getName();
+
+ // Assume a get/setAttribute convention on the typed proxy interface.
+ // If the MBean metadata exposes a matching attribute then use the
+ // MBeanServer attribute accessors to read/modify the value. If not,
+ // fallback to MBeanServer.invoke() assuming this is an operation
+ // invocation despite the accessor naming convention.
+
+ // getter
+ if (methodName.startsWith("get") && args == null)
+ {
+ String attrName = methodName.substring(3, methodName.length());
+
+ // check that the metadata exists
+ MBeanAttributeInfo info = (MBeanAttributeInfo)attributeMap.get(attrName);
+ if (info != null)
+ {
+ String retType = method.getReturnType().getName();
+
+ // check for correct return type on the getter
+ if (retType.equals(info.getType()))
+ {
+ return server.getAttribute(objectName, attrName);
+ }
+ }
+ }
+
+ // boolean getter
+ else if (methodName.startsWith("is") && args == null)
+ {
+ String attrName = methodName.substring(2, methodName.length());
+
+ // check that the metadata exists
+ MBeanAttributeInfo info = (MBeanAttributeInfo)attributeMap.get(attrName);
+ if (info != null && info.isIs())
+ {
+ Class<?> retType = method.getReturnType();
+
+ // check for correct return type on the getter
+ if (retType.equals(Boolean.class) || retType.equals(Boolean.TYPE))
+ {
+ return server.getAttribute(objectName, attrName);
+ }
+ }
+ }
+
+ // setter
+ else if (methodName.startsWith("set") && args != null && args.length == 1)
+ {
+ String attrName = methodName.substring(3, methodName.length());
+
+ // check that the metadata exists
+ MBeanAttributeInfo info = (MBeanAttributeInfo)attributeMap.get(attrName);
+ if (info != null && method.getReturnType().equals(Void.TYPE))
+ {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+
+ Class<?> signatureClass = null;
+ String classType = info.getType();
+
+ if (isPrimitive(classType))
+ signatureClass = getPrimitiveClass(classType);
+ else
+ signatureClass = cl.loadClass(info.getType());
+
+ if (signatureClass.isAssignableFrom(args[0].getClass()))
+ {
+ server.setAttribute(objectName, new Attribute(attrName, args[0]));
+ return null;
+ }
+ }
+ }
+
+ String[] signature = null;
+
+ if (args != null)
+ {
+ signature = new String[args.length];
+ Class[] sign = method.getParameterTypes();
+
+ for (int i = 0; i < sign.length; ++i)
+ signature[i] = sign[i].getName();
+ }
+
+ return server.invoke(objectName, methodName, args, signature);
+ }
+ catch (Exception ex)
+ {
+ throw (Exception)decodeJMXException(ex);
+ }
+ }
+
+ /*
+ * Attempt to decode the given Throwable.
+ * If it is a container JMX exception, then the target is returned.
+ * Otherwise the argument is returned.
+ */
+ private Throwable decodeJMXException(final Exception ex)
+ {
+ Throwable result = ex;
+
+ while (true)
+ {
+ if (result instanceof MBeanException)
+ result = ((MBeanException)result).getTargetException();
+ else if (result instanceof ReflectionException)
+ result = ((ReflectionException)result).getTargetException();
+ else if (result instanceof RuntimeOperationsException)
+ result = ((RuntimeOperationsException)result).getTargetException();
+ else if (result instanceof RuntimeMBeanException)
+ result = ((RuntimeMBeanException)result).getTargetException();
+ else if (result instanceof RuntimeErrorException)
+ result = ((RuntimeErrorException)result).getTargetError();
+ else
+ // can't decode
+ break;
+ }
+
+ return result;
+ }
+
+ private Object handleObjectMethods(Method method, Object[] args) throws Exception
+ {
+ if (method.getName().equals("toString"))
+ {
+ if (delegateToStringToResource)
+ return server.invoke(objectName, "toString", null, null);
+ else
+ return toString();
+ }
+
+ else if (method.getName().equals("equals"))
+ {
+ if (delegateEqualsToResource)
+ {
+ return server.invoke(objectName, "equals", new Object[] { args[0] }, new String[] { "java.lang.Object" });
+ }
+ else if (Proxy.isProxyClass(args[0].getClass()))
+ {
+ Proxy prxy = (Proxy)args[0];
+ return new Boolean(this.equals(Proxy.getInvocationHandler(prxy)));
+ }
+ else
+ {
+ return new Boolean(this.equals(args[0]));
+ }
+ }
+
+ else if (method.getName().equals("hashCode"))
+ {
+ if (delegateHashCodeToResource)
+ return server.invoke(objectName, "hashCode", null, null);
+ else
+ return new Integer(this.hashCode());
+ }
+
+ else
+ throw new Error("Unexpected method invocation!");
+ }
+
+ private boolean isPrimitive(String type)
+ {
+ if (type.equals(Integer.TYPE.getName()))
+ return true;
+ if (type.equals(Long.TYPE.getName()))
+ return true;
+ if (type.equals(Boolean.TYPE.getName()))
+ return true;
+ if (type.equals(Byte.TYPE.getName()))
+ return true;
+ if (type.equals(Character.TYPE.getName()))
+ return true;
+ if (type.equals(Short.TYPE.getName()))
+ return true;
+ if (type.equals(Float.TYPE.getName()))
+ return true;
+ if (type.equals(Double.TYPE.getName()))
+ return true;
+ if (type.equals(Void.TYPE.getName()))
+ return true;
+
+ return false;
+ }
+
+ private Class<?> getPrimitiveClass(String type)
+ {
+ if (type.equals(Integer.TYPE.getName()))
+ return Integer.TYPE;
+ if (type.equals(Long.TYPE.getName()))
+ return Long.TYPE;
+ if (type.equals(Boolean.TYPE.getName()))
+ return Boolean.TYPE;
+ if (type.equals(Byte.TYPE.getName()))
+ return Byte.TYPE;
+ if (type.equals(Character.TYPE.getName()))
+ return Character.TYPE;
+ if (type.equals(Short.TYPE.getName()))
+ return Short.TYPE;
+ if (type.equals(Float.TYPE.getName()))
+ return Float.TYPE;
+ if (type.equals(Double.TYPE.getName()))
+ return Double.TYPE;
+ if (type.equals(Void.TYPE.getName()))
+ return Void.TYPE;
+
+ return null;
+ }
+ }
+}
Copied: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/MBeanProxyException.java (from rev 85213, projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/jmx/MBeanProxyException.java)
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/MBeanProxyException.java (rev 0)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/MBeanProxyException.java 2009-03-04 15:04:47 UTC (rev 85228)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.spi.management;
+
+// $Id: $
+
+import javax.management.JMException;
+
+public class MBeanProxyException extends JMException
+{
+ private static final long serialVersionUID = 2796580582557329145L;
+
+ public MBeanProxyException()
+ {
+ }
+
+ public MBeanProxyException(String msg)
+ {
+ super(msg);
+ }
+}
Added: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java (rev 0)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java 2009-03-04 15:04:47 UTC (rev 85228)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.spi.management;
+
+//$Id$
+
+import javax.management.ObjectName;
+
+import org.jboss.osgi.spi.Constants;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleException;
+
+/**
+ * The managed view of an OSGi Bundle
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 23-Jan-2009
+ */
+public class ManagedBundle implements ManagedBundleMBean
+{
+ private Bundle bundle;
+ private ObjectName oname;
+
+ public ManagedBundle(Bundle bundle)
+ {
+ this.bundle = bundle;
+ this.oname = ObjectNameFactory.create(Constants.DOMAIN_NAME + ":bundle=" + bundle.getSymbolicName() + ",id=" + bundle.getBundleId());
+ }
+
+ public ObjectName getObjectName()
+ {
+ return oname;
+ }
+
+ public int getState()
+ {
+ return bundle.getState();
+ }
+
+ public String getSymbolicName()
+ {
+ return bundle.getSymbolicName();
+ }
+
+ public void start() throws BundleException
+ {
+ bundle.start();
+ }
+
+ public void stop() throws BundleException
+ {
+ bundle.stop();
+ }
+
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedBundle.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedBundleMBean.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedBundleMBean.java (rev 0)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedBundleMBean.java 2009-03-04 15:04:47 UTC (rev 85228)
@@ -0,0 +1,59 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.spi.management;
+
+import org.osgi.framework.BundleException;
+
+//$Id$
+
+
+/**
+ * The managed view of an OSGi Bundle
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 04-Mar-2009
+ */
+public interface ManagedBundleMBean
+{
+ /**
+ * Returns this bundle's current state.
+ * A bundle can be in only one state at any time.
+ *
+ * @return An element of UNINSTALLED,INSTALLED, RESOLVED,STARTING, STOPPING,ACTIVE.
+ */
+ int getState();
+
+ /**
+ * Returns the symbolic name of this bundle as specified by its Bundle-SymbolicName manifest header
+ */
+ String getSymbolicName();
+
+ /**
+ * Starts this bundle with no options
+ */
+ void start() throws BundleException;
+
+ /**
+ * Stops this bundle with no options.
+ */
+ void stop() throws BundleException;
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedBundleMBean.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedFramework.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedFramework.java (rev 0)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedFramework.java 2009-03-04 15:04:47 UTC (rev 85228)
@@ -0,0 +1,94 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.spi.management;
+
+//$Id$
+
+import java.util.Set;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.QueryExp;
+
+import org.jboss.logging.Logger;
+import org.jboss.osgi.spi.Constants;
+
+/**
+ * The managed view of an OSGi Framework
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 04-Mar-2009
+ */
+public class ManagedFramework implements ManagedFrameworkMBean
+{
+ private static final String OBJECT_NAME = "jboss.osgi:service=ManagedFramework";
+
+ // Provide logging
+ final Logger log = Logger.getLogger(ManagedFramework.class);
+
+ private MBeanServer mbeanServer;
+
+ public void setMbeanServer(MBeanServer server)
+ {
+ this.mbeanServer = server;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Set<ObjectName> getBundles()
+ {
+ // [JBAS-6571] JMX filtering does not work with wildcards
+ // ObjectName pattern = ObjectNameFactory.create(Constants.DOMAIN_NAME + ":bundle=*,*");
+ // Set<ObjectName> names = mbeanServer.queryNames(pattern, null);
+
+ ObjectName pattern = ObjectNameFactory.create(Constants.DOMAIN_NAME + ":*");
+ Set<ObjectName> names = mbeanServer.queryNames(pattern, new IsBundleQueryExp());
+ return names;
+ }
+
+ // Accept names like "jboss.osgi:bundle=*"
+ static class IsBundleQueryExp implements QueryExp
+ {
+ private static final long serialVersionUID = 1L;
+
+ public boolean apply(ObjectName name)
+ {
+ return name.getKeyProperty("bundle") != null;
+ }
+
+ public void setMBeanServer(MBeanServer server)
+ {
+ }
+ }
+
+ public void start()
+ {
+ try
+ {
+ if (mbeanServer != null)
+ mbeanServer.registerMBean(this, ObjectNameFactory.create(OBJECT_NAME));
+ }
+ catch (Exception ex)
+ {
+ log.warn("Cannot register: " + OBJECT_NAME);
+ }
+ }
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedFramework.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedFrameworkMBean.java
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedFrameworkMBean.java (rev 0)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedFrameworkMBean.java 2009-03-04 15:04:47 UTC (rev 85228)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.spi.management;
+
+//$Id$
+
+import java.util.Set;
+
+import javax.management.ObjectName;
+
+/**
+ * The managed view of an OSGi Framework
+ *
+ * @author thomas.diesler at jboss.com
+ * @since 04-Mar-2009
+ */
+public interface ManagedFrameworkMBean
+{
+ /**
+ * Get the list of all installed bundles
+ */
+ Set<ObjectName> getBundles();
+}
\ No newline at end of file
Property changes on: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ManagedFrameworkMBean.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Copied: projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ObjectNameFactory.java (from rev 85213, projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/jmx/ObjectNameFactory.java)
===================================================================
--- projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ObjectNameFactory.java (rev 0)
+++ projects/jboss-osgi/trunk/runtime/spi/src/main/java/org/jboss/osgi/spi/management/ObjectNameFactory.java 2009-03-04 15:04:47 UTC (rev 85228)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.osgi.spi.management;
+
+// $Id$
+
+import java.util.Hashtable;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+/**
+ * A simple factory for creating safe object names.
+ *
+ * @author Thomas.Diesler at jboss.org
+ * @since 08-May-2006
+ */
+public class ObjectNameFactory
+{
+ public static ObjectName create(String name)
+ {
+ try
+ {
+ return new ObjectName(name);
+ }
+ catch (MalformedObjectNameException e)
+ {
+ throw new Error("Invalid ObjectName: " + name + "; " + e);
+ }
+ }
+
+ public static ObjectName create(String domain, String key, String value)
+ {
+ try
+ {
+ return new ObjectName(domain, key, value);
+ }
+ catch (MalformedObjectNameException e)
+ {
+ throw new Error("Invalid ObjectName: " + domain + "," + key + "," + value + "; " + e);
+ }
+ }
+
+ public static ObjectName create(String domain, Hashtable<String, String> table)
+ {
+ try
+ {
+ return new ObjectName(domain, table);
+ }
+ catch (MalformedObjectNameException e)
+ {
+ throw new Error("Invalid ObjectName: " + domain + "," + table + "; " + e);
+ }
+ }
+}
Modified: projects/jboss-osgi/trunk/service/http/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/service/http/pom.xml 2009-03-04 15:02:25 UTC (rev 85227)
+++ projects/jboss-osgi/trunk/service/http/pom.xml 2009-03-04 15:04:47 UTC (rev 85228)
@@ -102,7 +102,7 @@
org.jboss.osgi.service,
org.jboss.osgi.spi,
org.jboss.osgi.spi.framework,
- org.jboss.osgi.spi.jmx,
+ org.jboss.osgi.spi.management,
org.jboss.virtual,
org.jboss.web,
org.osgi.framework,
Modified: projects/jboss-osgi/trunk/service/http/src/main/java/org/jboss/osgi/service/http/GenericEndpointServlet.java
===================================================================
--- projects/jboss-osgi/trunk/service/http/src/main/java/org/jboss/osgi/service/http/GenericEndpointServlet.java 2009-03-04 15:02:25 UTC (rev 85227)
+++ projects/jboss-osgi/trunk/service/http/src/main/java/org/jboss/osgi/service/http/GenericEndpointServlet.java 2009-03-04 15:04:47 UTC (rev 85228)
@@ -36,7 +36,7 @@
import org.jboss.mx.util.MBeanProxy;
import org.jboss.mx.util.MBeanProxyCreationException;
-import org.jboss.osgi.spi.jmx.ObjectNameFactory;
+import org.jboss.osgi.spi.management.ObjectNameFactory;
import org.jboss.system.server.jmx.JMXKernel;
import org.jboss.virtual.VFSUtils;
Modified: projects/jboss-osgi/trunk/service/http/src/main/java/org/jboss/osgi/service/http/HttpEndpointDeployer.java
===================================================================
--- projects/jboss-osgi/trunk/service/http/src/main/java/org/jboss/osgi/service/http/HttpEndpointDeployer.java 2009-03-04 15:02:25 UTC (rev 85227)
+++ projects/jboss-osgi/trunk/service/http/src/main/java/org/jboss/osgi/service/http/HttpEndpointDeployer.java 2009-03-04 15:04:47 UTC (rev 85228)
@@ -39,7 +39,7 @@
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.metadata.web.jboss.JBossWebMetaData;
import org.jboss.osgi.service.MicrocontainerService;
-import org.jboss.osgi.spi.jmx.ObjectNameFactory;
+import org.jboss.osgi.spi.management.ObjectNameFactory;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
Modified: projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/jbosgi36/junit/OSGI36TestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/jbosgi36/junit/OSGI36TestCase.java 2009-03-04 15:02:25 UTC (rev 85227)
+++ projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/jbosgi36/junit/OSGI36TestCase.java 2009-03-04 15:04:47 UTC (rev 85228)
@@ -28,10 +28,10 @@
import org.jboss.osgi.spi.framework.NamedInstanceProvider;
import org.jboss.osgi.spi.framework.OSGiBootstrap;
import org.jboss.osgi.spi.framework.OSGiBootstrapProvider;
-import org.jboss.osgi.spi.jmx.MBeanProxy;
-import org.jboss.osgi.spi.jmx.MBeanProxyException;
import org.jboss.osgi.spi.junit.IntegrationTest;
import org.jboss.osgi.spi.junit.IntegrationTestSetup;
+import org.jboss.osgi.spi.management.MBeanProxy;
+import org.jboss.osgi.spi.management.MBeanProxyException;
import org.jboss.test.osgi.jbosgi36.mbean.FooMBean;
/**
Modified: projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/jbosgi36/mbean/FooMBean.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/jbosgi36/mbean/FooMBean.java 2009-03-04 15:02:25 UTC (rev 85227)
+++ projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/jbosgi36/mbean/FooMBean.java 2009-03-04 15:04:47 UTC (rev 85228)
@@ -25,7 +25,7 @@
import javax.management.ObjectName;
-import org.jboss.osgi.spi.jmx.ObjectNameFactory;
+import org.jboss.osgi.spi.management.ObjectNameFactory;
public interface FooMBean
{
Modified: projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/service/microcontainer/MBeanTestService.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/service/microcontainer/MBeanTestService.java 2009-03-04 15:02:25 UTC (rev 85227)
+++ projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/service/microcontainer/MBeanTestService.java 2009-03-04 15:04:47 UTC (rev 85228)
@@ -27,7 +27,7 @@
import javax.management.ObjectName;
import org.jboss.osgi.service.MicrocontainerService;
-import org.jboss.osgi.spi.jmx.ObjectNameFactory;
+import org.jboss.osgi.spi.management.ObjectNameFactory;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceListener;
Modified: projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/service/microcontainer/junit/MicrocontainerServiceTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/service/microcontainer/junit/MicrocontainerServiceTestCase.java 2009-03-04 15:02:25 UTC (rev 85227)
+++ projects/jboss-osgi/trunk/testsuite/src/test/java/org/jboss/test/osgi/service/microcontainer/junit/MicrocontainerServiceTestCase.java 2009-03-04 15:04:47 UTC (rev 85228)
@@ -25,9 +25,9 @@
import junit.framework.Test;
-import org.jboss.osgi.spi.jmx.MBeanProxy;
import org.jboss.osgi.spi.junit.IntegrationTest;
import org.jboss.osgi.spi.junit.IntegrationTestSetup;
+import org.jboss.osgi.spi.management.MBeanProxy;
import org.jboss.test.osgi.service.microcontainer.FooMBean;
import org.jboss.test.osgi.service.microcontainer.MBeanTestService;
More information about the jboss-cvs-commits
mailing list