Author: alesj
Date: 2010-02-05 08:25:00 -0500 (Fri, 05 Feb 2010)
New Revision: 100484
Added:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractDictionaryFactory.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/JMXDictionaryFactory.java
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/pom.xml
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/KernelDictionaryFactory.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ServiceManagerPluginImpl.java
Log:
[JBOSGI-141]; add JMX based dictionary factory.
Remove enableMDR usage flag.
Depend on Kernel 2.2.x snapshot for JMX bug fix.
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/pom.xml 2010-02-05 13:11:03 UTC
(rev 100483)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/pom.xml 2010-02-05 13:25:00 UTC
(rev 100484)
@@ -137,24 +137,26 @@
<groupId>org.jboss.deployers</groupId>
<artifactId>jboss-deployers-jmx</artifactId>
<version>${version.jboss.deployers}</version>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.kernel</groupId>
<artifactId>jboss-kernel</artifactId>
<version>${version.jboss.kernel}</version>
</dependency>
+ <dependency>
+ <groupId>org.jboss.kernel</groupId>
+ <artifactId>jboss-jmx-mc-int</artifactId>
+ <version>${version.jboss.kernel}</version>
+ </dependency>
<dependency>
<groupId>org.jboss.kernel</groupId>
<artifactId>jboss-jmx-aop-mc-int</artifactId>
<version>${version.jboss.kernel}</version>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.kernel</groupId>
- <artifactId>jboss-jmx-mc-int</artifactId>
- <version>${version.jboss.kernel}</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.kernel</groupId>
<artifactId>jboss-dependency</artifactId>
<version>${version.jboss.kernel}</version>
</dependency>
Added:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractDictionaryFactory.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractDictionaryFactory.java
(rev 0)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/AbstractDictionaryFactory.java 2010-02-05
13:25:00 UTC (rev 100484)
@@ -0,0 +1,167 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.framework.bundle;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.kernel.spi.config.KernelConfigurator;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.system.microcontainer.ServiceControllerContext;
+import org.jboss.util.collection.Iterators;
+import org.osgi.framework.Constants;
+
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Abstract dictionary factory.
+ *
+ * @author <a href="ales.justin(a)jboss.org">Ales Justin</a>
+ */
+public abstract class AbstractDictionaryFactory<T extends ControllerContext>
implements DictionaryFactory<T>
+{
+ protected static final String NAME = "bean.name";
+ protected static final String[] EMPTY = new String[0];
+ private KernelConfigurator configurator;
+ private final ClassInfo OBJECT;
+
+ public AbstractDictionaryFactory(KernelConfigurator configurator)
+ {
+ if (configurator == null)
+ throw new IllegalArgumentException("Null configurator");
+
+ this.configurator = configurator;
+ OBJECT = getClassInfo(Object.class);
+ }
+
+ protected ClassInfo getClassInfo(Class<?> clazz)
+ {
+ try
+ {
+ return configurator.getClassInfo(clazz);
+ }
+ catch (Throwable t)
+ {
+ throw new RuntimeException(t);
+ }
+ }
+
+ protected abstract class AbstractDictionary extends Dictionary<String, Object>
+ {
+ private Map<Object, Object> map;
+ private ControllerContext context;
+
+ protected AbstractDictionary(ControllerContext context)
+ {
+ this.context = context;
+ this.map = new ConcurrentHashMap<Object, Object>(2);
+ map.put(NAME, getName(context));
+ map.put(Constants.OBJECTCLASS, EMPTY);
+ }
+
+ protected abstract Object getName(ControllerContext context);
+
+ public int size()
+ {
+ return map.size();
+ }
+
+ public boolean isEmpty()
+ {
+ return size() == 0;
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public Enumeration<String> keys()
+ {
+ return Iterators.toEnumeration(map.keySet().iterator());
+ }
+
+ @SuppressWarnings({"unchecked"})
+ public Enumeration<Object> elements()
+ {
+ return Iterators.toEnumeration(map.values().iterator());
+ }
+
+ public Object get(Object key)
+ {
+ Object value = map.get(key);
+ if (value != EMPTY)
+ return value;
+
+ ClassInfo clazz;
+ Object target = context.getTarget();
+ if (target != null)
+ {
+ clazz = getClassInfo(target.getClass());
+ }
+ else
+ clazz = getFromNullTarget(context);
+
+ String[] classes = EMPTY;
+ if (clazz != null)
+ {
+ Set<String> clazzes = new HashSet<String>();
+ traverseClass(clazz, clazzes);
+ classes = clazzes.toArray(new String[clazzes.size()]);
+ map.put(Constants.OBJECTCLASS, classes);
+ }
+ return classes;
+ }
+
+ protected ClassInfo getFromNullTarget(ControllerContext context)
+ {
+ return null;
+ }
+
+ public Object put(String key, Object value)
+ {
+ return map.put(key, value);
+ }
+
+ public Object remove(Object key)
+ {
+ return map.remove(key);
+ }
+
+ protected void traverseClass(ClassInfo clazz, Set<String> classes)
+ {
+ if (clazz == null || clazz == OBJECT)
+ {
+ return;
+ }
+
+ classes.add(clazz.getName());
+
+ // traverse superclass
+ traverseClass(clazz.getSuperclass(), classes);
+ ClassInfo[] interfaces = clazz.getInterfaces();
+ if (interfaces != null)
+ {
+ // traverse interfaces
+ for(ClassInfo intface : interfaces)
+ {
+ traverseClass(intface, classes);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
Copied:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/JMXDictionaryFactory.java
(from rev 100475,
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/KernelDictionaryFactory.java)
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/JMXDictionaryFactory.java
(rev 0)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/JMXDictionaryFactory.java 2010-02-05
13:25:00 UTC (rev 100484)
@@ -0,0 +1,65 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.framework.bundle;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.kernel.spi.config.KernelConfigurator;
+import org.jboss.system.microcontainer.ServiceControllerContext;
+
+import java.util.Dictionary;
+
+/**
+ * JMX dictionary factory.
+ * TODO - expose all classes, or just explicit target class and its mbean interface?
+ *
+ * @author <a href="ales.justin(a)jboss.org">Ales Justin</a>
+ */
+public class JMXDictionaryFactory extends
AbstractDictionaryFactory<ServiceControllerContext>
+{
+ public JMXDictionaryFactory(KernelConfigurator configurator)
+ {
+ super(configurator);
+ }
+
+ public Class<ServiceControllerContext> getContextType()
+ {
+ return ServiceControllerContext.class;
+ }
+
+ public Dictionary<String, Object> getDictionary(ServiceControllerContext
context)
+ {
+ return null;
+ }
+
+ private class JMXDictionary extends AbstractDictionary
+ {
+ private JMXDictionary(ServiceControllerContext context)
+ {
+ super(context);
+ }
+
+ protected Object getName(ControllerContext context)
+ {
+ return
ServiceControllerContext.class.cast(context).getObjectName().getCanonicalName();
+ }
+ }
+}
\ No newline at end of file
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/KernelDictionaryFactory.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/KernelDictionaryFactory.java 2010-02-05
13:11:03 UTC (rev 100483)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/KernelDictionaryFactory.java 2010-02-05
13:25:00 UTC (rev 100484)
@@ -29,6 +29,7 @@
import java.util.concurrent.ConcurrentHashMap;
import org.jboss.beans.info.spi.BeanInfo;
+import org.jboss.dependency.spi.ControllerContext;
import org.jboss.kernel.spi.config.KernelConfigurator;
import org.jboss.kernel.spi.dependency.KernelControllerContext;
import org.jboss.reflect.spi.ClassInfo;
@@ -40,34 +41,13 @@
*
* @author <a href="ales.justin(a)jboss.org">Ales Justin</a>
*/
-public class KernelDictionaryFactory implements
DictionaryFactory<KernelControllerContext>
+public class KernelDictionaryFactory extends
AbstractDictionaryFactory<KernelControllerContext>
{
- private static final String NAME = "bean.name";
- private static final String[] EMPTY = new String[0];
- private KernelConfigurator configurator;
- private final ClassInfo OBJECT;
-
public KernelDictionaryFactory(KernelConfigurator configurator)
{
- if (configurator == null)
- throw new IllegalArgumentException("Null configurator");
-
- this.configurator = configurator;
- OBJECT = getClassInfo(Object.class);
+ super(configurator);
}
- private ClassInfo getClassInfo(Class<?> clazz)
- {
- try
- {
- return configurator.getClassInfo(clazz);
- }
- catch (Throwable t)
- {
- throw new RuntimeException(t);
- }
- }
-
public Class<KernelControllerContext> getContextType()
{
return KernelControllerContext.class;
@@ -78,100 +58,24 @@
return new KernelDictionary(context);
}
- private class KernelDictionary extends Dictionary<String, Object>
+ private class KernelDictionary extends AbstractDictionary
{
- private Map<Object, Object> map;
- private KernelControllerContext context;
-
private KernelDictionary(KernelControllerContext context)
{
- this.context = context;
- this.map = new ConcurrentHashMap<Object, Object>(2);
- map.put(NAME, context.getName());
- map.put(Constants.OBJECTCLASS, EMPTY);
+ super(context);
}
- public int size()
+ protected Object getName(ControllerContext context)
{
- return map.size();
+ return KernelControllerContext.class.cast(context).getName();
}
- public boolean isEmpty()
+ @Override
+ protected ClassInfo getFromNullTarget(ControllerContext context)
{
- return size() == 0;
+ KernelControllerContext kcc = KernelControllerContext.class.cast(context);
+ BeanInfo beanInfo = kcc.getBeanInfo();
+ return beanInfo != null ? beanInfo.getClassInfo() : null;
}
-
- @SuppressWarnings({"unchecked"})
- public Enumeration<String> keys()
- {
- return Iterators.toEnumeration(map.keySet().iterator());
- }
-
- @SuppressWarnings({"unchecked"})
- public Enumeration<Object> elements()
- {
- return Iterators.toEnumeration(map.values().iterator());
- }
-
- public Object get(Object key)
- {
- Object value = map.get(key);
- if (value != EMPTY)
- return value;
-
- ClassInfo clazz = null;
- Object target = context.getTarget();
- BeanInfo info = context.getBeanInfo();
- if (target != null)
- {
- clazz = getClassInfo(target.getClass());
- }
- else if (info != null)
- {
- clazz = info.getClassInfo();
- }
-
- String[] classes = EMPTY;
- if (clazz != null)
- {
- Set<String> clazzes = new HashSet<String>();
- traverseClass(clazz, clazzes);
- classes = clazzes.toArray(new String[clazzes.size()]);
- map.put(Constants.OBJECTCLASS, classes);
- }
- return classes;
- }
-
- public Object put(String key, Object value)
- {
- return map.put(key, value);
- }
-
- public Object remove(Object key)
- {
- return map.remove(key);
- }
-
- protected void traverseClass(ClassInfo clazz, Set<String> classes)
- {
- if (clazz == null || clazz == OBJECT)
- {
- return;
- }
-
- classes.add(clazz.getName());
-
- // traverse superclass
- traverseClass(clazz.getSuperclass(), classes);
- ClassInfo[] interfaces = clazz.getInterfaces();
- if (interfaces != null)
- {
- // traverse interfaces
- for(ClassInfo intface : interfaces)
- {
- traverseClass(intface, classes);
- }
- }
- }
}
}
\ No newline at end of file
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ServiceManagerPluginImpl.java
===================================================================
---
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ServiceManagerPluginImpl.java 2010-02-05
13:11:03 UTC (rev 100483)
+++
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/ServiceManagerPluginImpl.java 2010-02-05
13:25:00 UTC (rev 100484)
@@ -72,36 +72,35 @@
public class ServiceManagerPluginImpl extends AbstractPlugin implements
ServiceManagerPlugin
{
// Provide logging
- final Logger log = Logger.getLogger(ServiceManagerPluginImpl.class);
+ private final Logger log = Logger.getLogger(ServiceManagerPluginImpl.class);
/** The kernel */
private Kernel kernel;
+ /** The mdr factory */
+ private MetaDataRetrievalFactory factory;
/** The previous context tracker */
private ContextTracker previousTracker;
- /** Enable MDR usage */
- private boolean enableMDRUsage = true;
-
+
public ServiceManagerPluginImpl(OSGiBundleManager bundleManager)
{
super(bundleManager);
}
+ @Deprecated
public void setEnableMDRUsage(boolean mdrUsage)
{
- this.enableMDRUsage = mdrUsage;
+ log.warn("This flag is no longer supported.");
}
public void start()
{
kernel = getBundleManager().getKernel();
- if (enableMDRUsage == true)
- applyMDRUsage(true);
+ applyMDRUsage(true);
}
public void stop()
{
- if (enableMDRUsage == true)
- applyMDRUsage(false);
+ applyMDRUsage(false);
}
public ServiceReference[] getRegisteredServices(AbstractBundleState bundleState)
@@ -312,12 +311,15 @@
private MetaDataRetrievalFactory getMetaDataRetrievalFactory()
{
- MetaDataRetrievalFactory mdrFactory;
- InstanceMetaDataRetrievalFactory imdrf = new
InstanceMetaDataRetrievalFactory(kernel);
- imdrf.addFactory(new OSGiServiceStateDictionaryFactory());
- imdrf.addFactory(new KernelDictionaryFactory(kernel.getConfigurator()));
- // TODO - JMX?
- mdrFactory = imdrf;
+ MetaDataRetrievalFactory mdrFactory = factory;
+ if (mdrFactory == null)
+ {
+ InstanceMetaDataRetrievalFactory imdrf = new
InstanceMetaDataRetrievalFactory(kernel);
+ imdrf.addFactory(new OSGiServiceStateDictionaryFactory());
+ imdrf.addFactory(new KernelDictionaryFactory(kernel.getConfigurator()));
+ // add JMX via configuration, as we don't wanna depend on JMX code
+ mdrFactory = imdrf;
+ }
return mdrFactory;
}
@@ -402,7 +404,7 @@
*/
private boolean hasPermission(ControllerContext context)
{
- // TODO - make thisa generic, w/o casting
+ // TODO - make this generic, w/o casting
if (context instanceof OSGiServiceState)
{
OSGiServiceState serviceState = (OSGiServiceState)context;
@@ -410,4 +412,14 @@
}
return true;
}
+
+ /**
+ * Set mdr factory.
+ *
+ * @param factory the factory
+ */
+ public void setFactory(MetaDataRetrievalFactory factory)
+ {
+ this.factory = factory;
+ }
}
\ No newline at end of file