JBoss-OSGI SVN: r97168 - projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle.
by jboss-osgi-commits@lists.jboss.org
Author: alesj
Date: 2009-11-30 10:38:43 -0500 (Mon, 30 Nov 2009)
New Revision: 97168
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/DescribeAction.java
Log:
javadocs
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/DescribeAction.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/DescribeAction.java 2009-11-30 15:37:44 UTC (rev 97167)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/DescribeAction.java 2009-11-30 15:38:43 UTC (rev 97168)
@@ -33,7 +33,7 @@
/**
* Describe osgi service.
- * Put it's properties into MDR.
+ * Put its properties into MDR.
*
* @author <a href="ales.justin(a)jboss.org">Ales Justin</a>
*/
14 years, 7 months
JBoss-OSGI SVN: r97167 - projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle.
by jboss-osgi-commits@lists.jboss.org
Author: alesj
Date: 2009-11-30 10:37:44 -0500 (Mon, 30 Nov 2009)
New Revision: 97167
Added:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/ContextComparator.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/MDRUtils.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/PreInstallAction.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/ServiceRefDictionary.java
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/DescribeAction.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/GenericServiceReferenceWrapper.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiControllerContextActions.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceAction.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java
Log:
[JBOSGi-141]; remove direct OSGi service usage.
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java 2009-11-30 14:38:21 UTC (rev 97166)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java 2009-11-30 15:37:44 UTC (rev 97167)
@@ -303,7 +303,7 @@
*
* @param context the context
*/
- void addRegisteredService(org.jboss.dependency.spi.ControllerContext context)
+ void addRegisteredService(ControllerContext context)
{
addUsedBy(context, this);
}
@@ -313,7 +313,7 @@
*
* @param context the context
*/
- void removeRegisteredService(OSGiServiceState context)
+ void removeRegisteredService(ControllerContext context)
{
removeUsedBy(context, this);
}
Copied: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/ContextComparator.java (from rev 97142, projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/ContextComparator.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/ContextComparator.java 2009-11-30 15:37:44 UTC (rev 97167)
@@ -0,0 +1,57 @@
+/*
+* 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 java.util.Comparator;
+
+import org.jboss.dependency.spi.ControllerContext;
+
+/**
+ * Compare controller contexts.
+ *
+ * @author <a href="ales.justin(a)jboss.org">Ales Justin</a>
+ */
+class ContextComparator implements Comparator<ControllerContext>
+{
+ public static final Comparator<ControllerContext> INSTANCE = new ContextComparator();
+
+ public int compare(ControllerContext c1, ControllerContext c2)
+ {
+ Integer ranking1 = MDRUtils.getRanking(c1);
+ Integer ranking2 = MDRUtils.getRanking(c2);
+ int diff = ranking2 - ranking1;
+ if (diff == 0)
+ {
+ Long id1 = MDRUtils.getId(c1);
+ Long id2 = MDRUtils.getId(c2);
+ if (id1 == null || id2 == null)
+ return 0;
+ if (id1 != null && id2 == null)
+ return -1;
+ if (id2 != null && id1 == null)
+ return 1;
+
+ return (id2 > id1) ? -1 : 1;
+ }
+ return diff;
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/DescribeAction.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/DescribeAction.java 2009-11-30 14:38:21 UTC (rev 97166)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/DescribeAction.java 2009-11-30 15:37:44 UTC (rev 97167)
@@ -21,35 +21,41 @@
*/
package org.jboss.osgi.framework.bundle;
-import org.jboss.dependency.spi.Controller;
-import org.jboss.kernel.Kernel;
-import org.jboss.kernel.spi.dependency.KernelController;
+import java.util.Dictionary;
+
import org.jboss.kernel.spi.metadata.KernelMetaDataRepository;
+import org.jboss.metadata.spi.loader.MutableMetaDataLoader;
+import org.jboss.metadata.spi.repository.MutableMetaDataRepository;
+import org.jboss.metadata.spi.retrieval.MetaDataRetrieval;
+import org.jboss.metadata.spi.scope.CommonLevels;
+import org.jboss.metadata.spi.scope.Scope;
+import org.jboss.metadata.spi.scope.ScopeKey;
/**
- * Describe osgi service, its metadata.
+ * Describe osgi service.
+ * Put it's properties into MDR.
*
* @author <a href="ales.justin(a)jboss.org">Ales Justin</a>
*/
-class DescribeAction extends SimpleOSGiServiceAction
+class DescribeAction extends OSGiServiceAction
{
- protected void handleContext(OSGiServiceState context, boolean install)
+ protected void installAction(OSGiServiceState context) throws Throwable
{
- Controller controller = context.getController();
- if (controller instanceof KernelController)
+ KernelMetaDataRepository repository = getRepository(context);
+ ScopeKey contextScopeKey = context.getScopeInfo().getMutableScope();
+ Scope scope = contextScopeKey.getScope(CommonLevels.INSTANCE);
+ ScopeKey key = new ScopeKey(scope);
+ MutableMetaDataRepository mutable = repository.getMetaDataRepository();
+ MetaDataRetrieval retrieval = mutable.getMetaDataRetrieval(key);
+ if (retrieval instanceof MutableMetaDataLoader)
{
- KernelController kc = (KernelController)controller;
- Kernel kernel = kc.getKernel();
- KernelMetaDataRepository repository = kernel.getMetaDataRepository();
- if (install)
- {
- repository.addMetaData(context);
- repository.getMetaData(context); // TODO - remove this once we fix it in MC core
- }
- else
- {
- repository.removeMetaData(context);
- }
+ MutableMetaDataLoader mmdl = (MutableMetaDataLoader)retrieval;
+ Dictionary<String, Object> dictionary = new ServiceRefDictionary(context);
+ mmdl.addMetaData(dictionary, Dictionary.class);
}
}
+
+ protected void uninstallAction(OSGiServiceState context)
+ {
+ }
}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/GenericServiceReferenceWrapper.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/GenericServiceReferenceWrapper.java 2009-11-30 14:38:21 UTC (rev 97166)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/GenericServiceReferenceWrapper.java 2009-11-30 15:37:44 UTC (rev 97167)
@@ -21,6 +21,8 @@
*/
package org.jboss.osgi.framework.bundle;
+import java.util.Dictionary;
+import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;
@@ -55,14 +57,20 @@
return context;
}
- public Object getProperty(String s)
+ public Object getProperty(String key)
{
- return null; // TODO
+ return MDRUtils.getProperty(context, key, Object.class);
}
public String[] getPropertyKeys()
{
- return null; // TODO
+ Dictionary<String, Object> dictionary = MDRUtils.getProperties(context);
+ String[] keys = new String[dictionary.size()];
+ int i = 0;
+ Enumeration<String> e = dictionary.keys();
+ while (e.hasMoreElements())
+ keys[i++] = e.nextElement();
+ return keys;
}
public Bundle getBundle()
@@ -95,14 +103,14 @@
return null;
}
- public boolean isAssignableTo(Bundle bundle, String s)
+ public boolean isAssignableTo(Bundle bundle, String className)
{
- return false; // TODO
+ return MDRUtils.isAssignableTo(context, bundleState, bundle, className);
}
- public int compareTo(Object o)
+ public int compareTo(Object obj)
{
- return 0; // TODO
+ return MDRUtils.compareTo(context, obj);
}
public int hashCode()
Copied: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/MDRUtils.java (from rev 97142, projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/MDRUtils.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/MDRUtils.java 2009-11-30 15:37:44 UTC (rev 97167)
@@ -0,0 +1,349 @@
+/*
+* 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 java.util.Arrays;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.logging.Logger;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.metadata.spi.scope.CommonLevels;
+import org.jboss.metadata.spi.scope.ScopeLevel;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+
+/**
+ * MetaDataRepository utils.
+ *
+ * @author <a href="ales.justin(a)jboss.org">Ales Justin</a>
+ */
+public class MDRUtils
+{
+ /** The log */
+ private static final Logger log = Logger.getLogger(MDRUtils.class);
+
+ /** The empty dictionary */
+ private static final Dictionary<String, Object> EMPTY = new Hashtable<String, Object>();
+
+ /**
+ * Get metadata.
+ *
+ * @param context the context
+ * @param level the scope level
+ * @return metadata
+ */
+ private static MetaData getMetaData(ControllerContext context, ScopeLevel level)
+ {
+ if (context == null)
+ throw new IllegalArgumentException("Null context");
+
+ MetaData metaData = context.getScopeInfo().getMetaData();
+ if (level != null && metaData != null)
+ metaData = metaData.getScopeMetaData(level);
+ return metaData;
+ }
+
+ /**
+ * Get context's properties.
+ *
+ * @param context the context
+ * @return the properties
+ */
+ @SuppressWarnings({"unchecked"})
+ static Dictionary<String, Object> getProperties(ControllerContext context)
+ {
+ MetaData metaData = getMetaData(context, CommonLevels.INSTANCE);
+ if (metaData != null)
+ {
+ Dictionary<String, Object> properties = metaData.getMetaData(Dictionary.class);
+ if (properties != null)
+ return properties;
+ }
+ return EMPTY;
+ }
+
+ /**
+ * Get property.
+ *
+ * @param context the context
+ * @param key the property key
+ * @param expectedType the expected type
+ * @return found property or null
+ */
+ static <T> T getProperty(ControllerContext context, String key, Class<T> expectedType)
+ {
+ return getProperty(context, key, expectedType, null);
+ }
+
+ /**
+ * Get property.
+ *
+ * @param context the context
+ * @param key the property key
+ * @param expectedType the expected type
+ * @param defaultValue the default value
+ * @return found property or null
+ */
+ static <T> T getProperty(ControllerContext context, String key, Class<T> expectedType, T defaultValue)
+ {
+ if (key == null)
+ throw new IllegalArgumentException("Null key");
+ if (expectedType == null)
+ throw new IllegalArgumentException("Null expected type");
+
+ Dictionary<String, Object> properties = getProperties(context);
+ Object result = properties.get(key);
+ if (result != null && expectedType.isInstance(result) == false)
+ {
+ if (defaultValue == null)
+ throw new IllegalArgumentException("Illegal result type: " + result + ", expected: " + expectedType);
+ else
+ result = defaultValue;
+ }
+
+ if (result == null)
+ result = defaultValue;
+
+ return expectedType.cast(result);
+ }
+
+ /**
+ * Is assignable to bundle.
+ *
+ * @param context the context
+ * @param bundleState the bundle state
+ * @param otherBundle the other bundle
+ * @param className the class name
+ * @return true if assignable, false otherwise
+ */
+ private static boolean isAssignableTo(ControllerContext context, AbstractBundleState bundleState, AbstractBundleState otherBundle, String className)
+ {
+ if (bundleState == otherBundle)
+ return true;
+
+ if (OSGiBundleManager.isUnregistered(context))
+ return false;
+
+ return isAssignableTo(bundleState, otherBundle, className);
+ }
+
+ /**
+ * Is assignable.
+ *
+ * @param bundleState the bundle state
+ * @param other the other bundle
+ * @param className the class name
+ * @return true if assignable, false otherwise
+ */
+ private static boolean isAssignableTo(AbstractBundleState bundleState, AbstractBundleState other, String className)
+ {
+ Object source = bundleState.getSource(className);
+ if (source == null)
+ throw new IllegalStateException("Cannot load '" + className + "' from: " + bundleState);
+
+ Object otherSource = other.getSource(className);
+ if (otherSource == null)
+ {
+ log.debug("Cannot load '" + className + "' from: " + other);
+ return false;
+ }
+
+ boolean equals = source.equals(otherSource);
+ if (equals == false)
+ {
+ ClassLoader otherLoader = otherSource.getClass().getClassLoader();
+ ClassLoader sourceLoader = source.getClass().getClassLoader();
+ StringBuffer buffer = new StringBuffer("Cannot assign '" + className + "' comming from different exporters");
+ buffer.append("\n service: ").append(sourceLoader);
+ buffer.append("\n request: ").append(otherLoader);
+ log.warn(buffer.toString());
+ }
+ return equals;
+ }
+
+ /**
+ * Match class.
+ *
+ * @param context the context
+ * @param clazz the class to match
+ * @return true if the class matches any of the classes
+ */
+ public static boolean matchClass(ControllerContext context, String clazz)
+ {
+ String[] classes = getProperty(context, Constants.OBJECTCLASS, String[].class);
+ return classes != null && Arrays.asList(classes).contains(clazz);
+ }
+
+ /**
+ * Get service ranking.
+ *
+ * @param context the context
+ * @return the ranking or null
+ */
+ public static Integer getRanking(ControllerContext context)
+ {
+ return getProperty(context, Constants.SERVICE_RANKING, Integer.class, 0);
+ }
+
+ /**
+ * Get service id.
+ *
+ * @param context the context
+ * @return the id or null
+ */
+ public static Long getId(ControllerContext context)
+ {
+ return getProperty(context, Constants.SERVICE_ID, Long.class);
+ }
+
+ /**
+ * Is context assignable to bundle.
+ *
+ * @param context the context
+ * @param bundleState the bundle state
+ * @return true if assignable, false otherwise
+ */
+ public static boolean isAssignableTo(ControllerContext context, AbstractBundleState bundleState)
+ {
+ if (context == null)
+ throw new IllegalArgumentException("Null context");
+ if (bundleState == null)
+ throw new IllegalArgumentException("Null bundle state");
+
+ OSGiBundleManager manager = bundleState.getBundleManager();
+ // context's bundle
+ AbstractBundleState other = manager.getBundleForContext(context);
+ if (bundleState == other)
+ return true;
+ if (OSGiBundleManager.isUnregistered(context))
+ return false;
+
+ String[] classes = getProperty(context, Constants.OBJECTCLASS, String[].class);
+ if (classes == null)
+ return false;
+
+ for (String className : classes)
+ {
+ if (isAssignableTo(bundleState, other, className) == false)
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Is assignable to bundle.
+ *
+ * @param context the context
+ * @param bundleState the bundle state
+ * @param className the class name
+ * @return true if assignable, false otherwise
+ */
+ public static boolean isAssignableTo(ControllerContext context, AbstractBundleState bundleState, String className)
+ {
+ if (context == null)
+ throw new IllegalArgumentException("Null context");
+ if (bundleState == null)
+ throw new IllegalArgumentException("Null bundle state");
+ if (className == null)
+ throw new IllegalArgumentException("Null class name");
+
+ OSGiBundleManager manager = bundleState.getBundleManager();
+ // context's bundle
+ AbstractBundleState other = manager.getBundleForContext(context);
+ return isAssignableTo(context, bundleState, other, className);
+ }
+
+ /**
+ * Is assignable to bundle.
+ *
+ * @param context the context
+ * @param bundleState the bundle state
+ * @param bundle the other bundle
+ * @param className the class name
+ * @return true if assignable, false otherwise
+ */
+ public static boolean isAssignableTo(ControllerContext context, AbstractBundleState bundleState, Bundle bundle, String className)
+ {
+ if (context == null)
+ throw new IllegalArgumentException("Null context");
+ if (bundleState == null)
+ throw new IllegalArgumentException("Null bundle state");
+ if (bundle == null)
+ throw new IllegalArgumentException("Null bundle");
+ if (className == null)
+ throw new IllegalArgumentException("Null class name");
+
+ AbstractBundleState otherBundle;
+ if (bundle instanceof AbstractBundleState)
+ otherBundle = (AbstractBundleState)bundle;
+ else if (bundle instanceof OSGiBundleWrapper)
+ otherBundle = ((OSGiBundleWrapper)bundle).getBundleState();
+ else
+ throw new IllegalArgumentException("Illegal bundle type: " + bundle);
+
+ return isAssignableTo(context, bundleState, otherBundle, className);
+ }
+
+ /**
+ * Compare to.
+ *
+ * @param context the context
+ * @param reference the other reference
+ * @return compare value
+ */
+ public static int compareTo(ControllerContext context, Object reference)
+ {
+ if (context == null)
+ throw new IllegalArgumentException("Null context");
+ if (reference == null)
+ throw new IllegalArgumentException("Null reference");
+
+ ControllerContext other;
+ if (reference instanceof ControllerContext)
+ other = (ControllerContext)reference;
+ else if (reference instanceof ControllerContextHandle)
+ other = ((ControllerContextHandle)reference).getContext();
+ else
+ throw new IllegalArgumentException(reference + " is not a service reference");
+
+ Long thisServiceId = getId(context);
+ Long otherServiceId = getId(other);
+ if (thisServiceId == null && otherServiceId == null)
+ return 0;
+ if (otherServiceId == null)
+ return -1; // TODO?
+ if (thisServiceId == null)
+ return 1; // TODO?
+ if (thisServiceId - otherServiceId == 0)
+ return 0;
+
+ int thisRanking = getRanking(context);
+ int otherRanking = getRanking(other);
+ int ranking = thisRanking - otherRanking;
+ if (ranking != 0)
+ return ranking;
+
+ return (thisServiceId > otherServiceId) ? -1 : 1;
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-30 14:38:21 UTC (rev 97166)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-30 15:37:44 UTC (rev 97167)
@@ -32,7 +32,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.Comparator;
import java.util.Dictionary;
import java.util.HashSet;
import java.util.LinkedHashMap;
@@ -40,6 +39,7 @@
import java.util.Locale;
import java.util.Map;
import java.util.Set;
+import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -97,8 +97,8 @@
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceReference;
-import org.osgi.framework.Version;
import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.Version;
import org.osgi.service.packageadmin.PackageAdmin;
/**
@@ -1155,6 +1155,43 @@
}
/**
+ * Load class from a bundle.
+ * If it cannot be loaded, return null.
+ *
+ * @param bundle the bundle to load from
+ * @param clazz the class
+ * @return class or null
+ */
+ private Class<?> loadClass(Bundle bundle, String clazz)
+ {
+ try
+ {
+ return bundle.loadClass(clazz);
+ }
+ catch (ClassNotFoundException e)
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Do we have a permission to use context.
+ *
+ * @param context the context
+ * @return true if allowed to use context, false otherwise
+ */
+ private boolean hasPermission(ControllerContext context)
+ {
+ // TODO - make thisa generic, w/o casting
+ if (context instanceof OSGiServiceState)
+ {
+ OSGiServiceState serviceState = (OSGiServiceState)context;
+ return serviceState.hasPermission();
+ }
+ return true;
+ }
+
+ /**
* Get services
*
* @param bundle the referencing bundle
@@ -1163,7 +1200,7 @@
* @param checkAssignable whether to check isAssignable
* @return the services
*/
- Collection<OSGiServiceState> getServices(AbstractBundleState bundle, String clazz, Filter filter, boolean checkAssignable)
+ Collection<ControllerContext> getServices(AbstractBundleState bundle, String clazz, Filter filter, boolean checkAssignable)
{
Set<ControllerContext> contexts;
KernelController controller = kernel.getController();
@@ -1193,23 +1230,20 @@
if (filter == null)
filter = NoFilter.INSTANCE;
- // review: optimise this, e.g. index by class
// Use a sorted set to order services according to spec
- Set<OSGiServiceState> result = new TreeSet<OSGiServiceState>(ServiceComparator.INSTANCE);
+ SortedSet<ControllerContext> result = new TreeSet<ControllerContext>(ContextComparator.INSTANCE);
for (ControllerContext context : contexts)
{
- // TODO - fix filtering
- if (context instanceof OSGiServiceState)
+ if (isUnregistered(context) == false)
{
- OSGiServiceState service = OSGiServiceState.class.cast(context);
- // Check the state, filter and permission
- if (service.isUnregistered() == false && filter.match(service) && service.hasPermission())
+ ServiceReference ref = getServiceReferenceForContext(context);
+ if (filter.match(ref) && hasPermission(context))
{
- if (clazz == null || isSystemBundle == false || service.matchClass(clazz))
+ if (clazz == null || isSystemBundle == false || MDRUtils.matchClass(context, clazz))
{
// Check the assignability
- if (checkAssignable == false || service.isAssignable(bundle))
- result.add(service);
+ if (checkAssignable == false || MDRUtils.isAssignableTo(context, bundle))
+ result.add(context);
}
}
}
@@ -1218,26 +1252,6 @@
}
/**
- * Load class from a bundle.
- * If it cannot be loaded, return null.
- *
- * @param bundle the bundle to load from
- * @param clazz the class
- * @return class or null
- */
- private Class<?> loadClass(Bundle bundle, String clazz)
- {
- try
- {
- return bundle.loadClass(clazz);
- }
- catch (ClassNotFoundException e)
- {
- return null;
- }
- }
-
- /**
* Get service reference
*
* @param bundle the referencing bundle
@@ -1246,30 +1260,12 @@
*/
ServiceReference getServiceReference(AbstractBundleState bundle, String clazz)
{
- Collection<OSGiServiceState> services = getServices(bundle, clazz, null, true);
- if (services == null || services.isEmpty())
+ Collection<ControllerContext> contexts = getServices(bundle, clazz, null, true);
+ if (contexts == null || contexts.isEmpty())
return null;
- // If multiple such services exist, the service with the highest ranking (as specified in its SERVICE_RANKING property) is returned.
- // If there is a tie in ranking, the service with the lowest service ID (as specified in its SERVICE_ID property);
- // that is, the service that was registered first is returned.
-
- long bestId = 0;
- int bestRanking = 0;
- ServiceReference bestMatch = null;
- for (OSGiServiceState service : services)
- {
- long id = service.getServiceId();
- int ranking = service.getServiceRanking();
- if (bestMatch == null || ranking > bestRanking || (ranking == bestRanking && id < bestId))
- {
- bestMatch = service.getReferenceInternal();
- bestRanking = ranking;
- bestId = id;
- }
- }
-
- return bestMatch;
+ ControllerContext context = contexts.iterator().next();
+ return getServiceReferenceForContext(context);
}
/**
@@ -1283,15 +1279,15 @@
*/
ServiceReference[] getServiceReferences(AbstractBundleState bundle, String clazz, Filter filter, boolean checkAssignable)
{
- Collection<OSGiServiceState> services = getServices(bundle, clazz, filter, checkAssignable);
- if (services == null || services.isEmpty())
+ Collection<ControllerContext> contexts = getServices(bundle, clazz, filter, checkAssignable);
+ if (contexts == null || contexts.isEmpty())
return null;
- ServiceReference[] result = new ServiceReference[services.size()];
+ ServiceReference[] result = new ServiceReference[contexts.size()];
int i = 0;
- for (OSGiServiceState service : services)
- result[i++] = service.getReferenceInternal();
+ for (ControllerContext context : contexts)
+ result[i++] = getServiceReferenceForContext(context);
return result;
}
@@ -1389,14 +1385,25 @@
{
ControllerContextHandle handle = (ControllerContextHandle)reference;
ControllerContext context = handle.getContext();
- Controller controller = context.getController();
- if (controller == null || controller.getStates().isBeforeState(context.getState(), ControllerState.INSTALLED))
- return null; // we're probably not installed anymore
+ if (isUnregistered(context)) // we're probably not installed anymore
+ return null;
return bundleState.addContextInUse(context);
}
/**
+ * Is the context undergisted.
+ *
+ * @param context the context
+ * @return true if the context is unregisted, false otherwise
+ */
+ static boolean isUnregistered(ControllerContext context)
+ {
+ Controller controller = context.getController();
+ return controller == null || controller.getStates().isBeforeState(context.getState(), ControllerState.INSTALLED);
+ }
+
+ /**
* Unget a service
*
* @param bundleState the bundle state
@@ -1620,17 +1627,4 @@
else
plugin.fireFrameworkEvent(systemBundle, FrameworkEvent.WARNING, new BundleException("Error " + context, t));
}
-
- /**
- * ServiceComparator, reverses the order of compareTo
- */
- static class ServiceComparator implements Comparator<OSGiServiceState>
- {
- public static ServiceComparator INSTANCE = new ServiceComparator();
-
- public int compare(OSGiServiceState o1, OSGiServiceState o2)
- {
- return -o1.compareTo(o2);
- }
- }
}
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiControllerContextActions.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiControllerContextActions.java 2009-11-30 14:38:21 UTC (rev 97166)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiControllerContextActions.java 2009-11-30 15:37:44 UTC (rev 97167)
@@ -51,6 +51,7 @@
private static Map<ControllerState, ControllerContextAction> getActions()
{
Map<ControllerState, ControllerContextAction> map = new HashMap<ControllerState, ControllerContextAction>(2);
+ map.put(ControllerState.PRE_INSTALL, new PreInstallAction());
map.put(ControllerState.DESCRIBED, new DescribeAction());
map.put(ControllerState.INSTANTIATED, new ContextRegistryAction());
return map;
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceAction.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceAction.java 2009-11-30 14:38:21 UTC (rev 97166)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceAction.java 2009-11-30 15:37:44 UTC (rev 97167)
@@ -22,6 +22,9 @@
package org.jboss.osgi.framework.bundle;
import org.jboss.dependency.plugins.action.SimpleControllerContextAction;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.spi.metadata.KernelMetaDataRepository;
import org.jboss.logging.Logger;
/**
@@ -33,13 +36,38 @@
{
protected Logger log = Logger.getLogger(getClass());
- protected OSGiServiceState contextCast(org.jboss.dependency.spi.ControllerContext context)
+ protected OSGiServiceState contextCast(ControllerContext context)
{
return OSGiServiceState.class.cast(context);
}
- protected boolean validateContext(org.jboss.dependency.spi.ControllerContext context)
+ protected boolean validateContext(ControllerContext context)
{
return (context instanceof OSGiServiceState);
}
+
+ /**
+ * Get kernel.
+ *
+ * @param context the context
+ * @return MC kernel
+ */
+ protected Kernel getKernel(OSGiServiceState context)
+ {
+ AbstractBundleState bundleState = context.getBundleState();
+ OSGiBundleManager manager = bundleState.getBundleManager();
+ return manager.getKernel();
+ }
+
+ /**
+ * Get metadata repository.
+ *
+ * @param context the context
+ * @return kernel metadata repository
+ */
+ protected KernelMetaDataRepository getRepository(OSGiServiceState context)
+ {
+ Kernel kernel = getKernel(context);
+ return kernel.getMetaDataRepository();
+ }
}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java 2009-11-30 14:38:21 UTC (rev 97166)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java 2009-11-30 15:37:44 UTC (rev 97167)
@@ -35,6 +35,7 @@
import org.jboss.beans.info.spi.BeanInfo;
import org.jboss.dependency.plugins.AbstractControllerContext;
+import org.jboss.dependency.spi.ControllerContext;
import org.jboss.dependency.spi.ScopeInfo;
import org.jboss.dependency.spi.dispatch.InvokeDispatchContext;
import org.jboss.dependency.spi.tracker.ContextTracker;
@@ -448,102 +449,9 @@
public boolean isAssignableTo(Bundle bundle, String className)
{
- if (bundle == null)
- throw new IllegalArgumentException("Null bundle");
- if (className == null)
- throw new IllegalArgumentException("Null class name");
-
- if (bundle instanceof OSGiBundleWrapper == false)
- throw new IllegalArgumentException("Unknown bundle: " + bundle);
-
- OSGiBundleWrapper wrapper = (OSGiBundleWrapper)bundle;
- AbstractBundleState bundleState = wrapper.getBundleState();
- return isAssignableTo(bundleState, className);
+ return MDRUtils.isAssignableTo(this, bundleState, bundle, className);
}
- /**
- * Check the isAssignableTo
- *
- * @param other the bundle state
- * @param className the class name
- * @return true when assignable
- */
- boolean isAssignableTo(AbstractBundleState other, String className)
- {
- if (className == null)
- throw new IllegalArgumentException("Null class name");
-
- if (other == bundleState)
- return true;
-
- if (isUnregistered())
- return false;
-
- Class<?> source = (Class<?>)bundleState.getSource(className);
- if (source == null)
- throw new IllegalStateException("Cannot load '" + className + "' from: " + bundleState);
-
- Class<?> otherSource = (Class<?>)other.getSource(className);
- if (otherSource == null)
- {
- log.debug("Cannot load '" + className + "' from: " + other);
- return false;
- }
-
- boolean equals = source.equals(otherSource);
- if (equals == false)
- {
- ClassLoader otherLoader = otherSource.getClassLoader();
- ClassLoader sourceLoader = source.getClassLoader();
- StringBuffer buffer = new StringBuffer("Cannot assign '" + className + "' comming from different exporters");
- buffer.append("\n service: ").append(sourceLoader);
- buffer.append("\n request: ").append(otherLoader);
- log.warn(buffer.toString());
- }
- return equals;
- }
-
- /**
- * Check the isAssignable
- *
- * @param bundle the bundle state
- * @return true when assignable
- */
- boolean isAssignable(AbstractBundleState bundle)
- {
- if (bundle == bundleState)
- return true;
-
- if (isUnregistered())
- return false;
-
- for (String clazz : getClasses())
- {
- if (isAssignableTo(bundle, clazz) == false)
- return false;
- }
- return true;
- }
-
- /**
- * Match the class
- *
- * @param className the class name
- * @return true when the class name matches
- */
- boolean matchClass(String className)
- {
- if (clazzes == null || clazzes.length == 0)
- return false;
-
- for (String clazz : clazzes)
- {
- if (className.equals(clazz))
- return true;
- }
- return false;
- }
-
public void unregister()
{
checkUnregistered();
@@ -566,21 +474,24 @@
if (reference == null)
throw new IllegalArgumentException("Null reference");
- OSGiServiceState other;
- if (reference instanceof OSGiServiceState)
- other = (OSGiServiceState)reference;
- else if (reference instanceof OSGiServiceReferenceWrapper)
- other = ((OSGiServiceReferenceWrapper)reference).getServiceState();
- else // TODO - handle generic service ref wrapper via MDR?
+ ControllerContext other;
+ if (reference instanceof ControllerContext)
+ other = (ControllerContext)reference;
+ else if (reference instanceof ControllerContextHandle)
+ other = ((ControllerContextHandle)reference).getContext();
+ else
throw new IllegalArgumentException(reference + " is not a service reference");
+ Long otherServiceId = MDRUtils.getId(other);
+ if (otherServiceId == null)
+ return -1; // TODO?
+
long thisServiceId = getServiceId();
- long otherServiceId = other.getServiceId();
if (thisServiceId == otherServiceId)
return 0;
+ Integer otherRanking = MDRUtils.getRanking(other);
int thisRanking = getServiceRanking();
- int otherRanking = other.getServiceRanking();
int ranking = thisRanking - otherRanking;
if (ranking != 0)
return ranking;
Copied: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/PreInstallAction.java (from rev 97111, projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/DescribeAction.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/PreInstallAction.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/PreInstallAction.java 2009-11-30 15:37:44 UTC (rev 97167)
@@ -0,0 +1,46 @@
+/*
+* 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.kernel.spi.metadata.KernelMetaDataRepository;
+
+/**
+ * PreInstall osgi service, its metadata.
+ *
+ * @author <a href="ales.justin(a)jboss.org">Ales Justin</a>
+ */
+class PreInstallAction extends SimpleOSGiServiceAction
+{
+ protected void handleContext(OSGiServiceState context, boolean install)
+ {
+ KernelMetaDataRepository repository = getRepository(context);
+ if (install)
+ {
+ repository.addMetaData(context);
+ repository.getMetaData(context); // TODO - remove this once we fix it in MC core
+ }
+ else
+ {
+ repository.removeMetaData(context);
+ }
+ }
+}
\ No newline at end of file
Copied: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/ServiceRefDictionary.java (from rev 97142, projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java)
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/ServiceRefDictionary.java (rev 0)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/ServiceRefDictionary.java 2009-11-30 15:37:44 UTC (rev 97167)
@@ -0,0 +1,111 @@
+/*
+* 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 java.util.Dictionary;
+import java.util.Enumeration;
+
+import org.osgi.framework.ServiceReference;
+
+/**
+ * Service reference based dictionary.
+ *
+ * @author <a href="ales.justin(a)jboss.org">Ales Justin</a>
+ */
+class ServiceRefDictionary extends Dictionary<String, Object>
+{
+ private ServiceReference ref;
+
+ ServiceRefDictionary(ServiceReference ref)
+ {
+ if (ref == null)
+ throw new IllegalArgumentException("Null ref");
+ this.ref = ref;
+ }
+
+ public int size()
+ {
+ String[] keys = ref.getPropertyKeys();
+ return (keys != null) ? keys.length : 0;
+ }
+
+ public boolean isEmpty()
+ {
+ return size() == 0;
+ }
+
+ public Enumeration<String> keys()
+ {
+ return new Enumeration<String>()
+ {
+ String[] keys = ref.getPropertyKeys();
+ int index = 0;
+
+ public boolean hasMoreElements()
+ {
+ return index < size();
+ }
+
+ public String nextElement()
+ {
+ return keys[index++];
+ }
+ };
+ }
+
+ public Enumeration<Object> elements()
+ {
+ return new Enumeration<Object>()
+ {
+ String[] keys = ref.getPropertyKeys();
+ int index = 0;
+
+ public boolean hasMoreElements()
+ {
+ return index < size();
+ }
+
+ public Object nextElement()
+ {
+ return get(keys[index++]);
+ }
+ };
+ }
+
+ public Object get(Object key)
+ {
+ if (key == null)
+ return null;
+
+ return ref.getProperty(key.toString());
+ }
+
+ public Object put(String key, Object value)
+ {
+ return null;
+ }
+
+ public Object remove(Object key)
+ {
+ return null;
+ }
+}
\ No newline at end of file
14 years, 7 months
JBoss-OSGI SVN: r97156 - in projects/jboss-osgi/projects/bundles: jboss-xml-binding/trunk and 1 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-30 03:17:04 -0500 (Mon, 30 Nov 2009)
New Revision: 97156
Modified:
projects/jboss-osgi/projects/bundles/jboss-reflect/trunk/pom.xml
projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/pom.xml
projects/jboss-osgi/projects/bundles/microcontainer/trunk/pom.xml
Log:
jbossxb exports - wip
Modified: projects/jboss-osgi/projects/bundles/jboss-reflect/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/jboss-reflect/trunk/pom.xml 2009-11-30 08:01:38 UTC (rev 97155)
+++ projects/jboss-osgi/projects/bundles/jboss-reflect/trunk/pom.xml 2009-11-30 08:17:04 UTC (rev 97156)
@@ -40,6 +40,7 @@
<!-- Properties -->
<properties>
<version.javassist>3.9.0.GA</version.javassist>
+ <version.jboss.osgi.common.core>2.2.13.GA</version.jboss.osgi.common.core>
<version.jboss.reflect>2.0.2.GA</version.jboss.reflect>
</properties>
@@ -58,7 +59,19 @@
<groupId>org.jboss</groupId>
<artifactId>jboss-reflect</artifactId>
<version>${version.jboss.reflect}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-common-core</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
+ <dependency>
+ <groupId>org.jboss.osgi.bundles</groupId>
+ <artifactId>jboss-osgi-common-core</artifactId>
+ <version>${version.jboss.osgi.common.core}</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
<build>
@@ -87,6 +100,7 @@
javassist;inline=false,
</Embed-Dependency>
<_exportcontents>
+ javassist*;version=${version.javassist},
org.jboss.beans.info*;version=${version.jboss.reflect},
org.jboss.classadapter.spi*;version=${version.jboss.reflect},
org.jboss.config*;version=${version.jboss.reflect},
Modified: projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/pom.xml 2009-11-30 08:01:38 UTC (rev 97155)
+++ projects/jboss-osgi/projects/bundles/jboss-xml-binding/trunk/pom.xml 2009-11-30 08:17:04 UTC (rev 97156)
@@ -186,8 +186,7 @@
</Embed-Dependency>
<_exportcontents>
org.jboss.xb.annotations;version=${version.jboss.xb},
- org.jboss.xb.binding.resolver;version=${version.jboss.xb},
- org.jboss.xb.binding.sunday.unmarshalling;version=${version.jboss.xb},
+ org.jboss.xb.binding*;version=${version.jboss.xb},
org.jboss.xb.util;version=${version.jboss.xb},
</_exportcontents>
</instructions>
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/pom.xml 2009-11-30 08:01:38 UTC (rev 97155)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/pom.xml 2009-11-30 08:17:04 UTC (rev 97156)
@@ -189,33 +189,48 @@
org.jboss.osgi.microcontainer.internal
</Private-Package>
<Import-Package>
- <!-- system -->
- javax.management,
- javax.naming*,
- javax.xml.bind;version=2.1,
- org.w3c.dom,
- org.xml.sax,
+ javassist*;version="[3.9,4.0)",
- <!-- osgi -->
- org.osgi.framework,
- org.osgi.service.log,
- org.osgi.util.tracker,
+ javax.management,
+ javax.management.openmbean,
+ javax.naming,
+ javax.xml.bind*,
+ javax.xml.parsers,
+ javax.xml.transform*,
+ javax.xml.validation,
- <!-- import -->
+ org.jboss.beans*;version="[2.0,2.1)",
+ org.jboss.classadapter.spi;version="[2.0,2.1)",
+ org.jboss.config*;version="[2.0,2.1)",
+ org.jboss.joinpoint*;version="[2.0,2.1)",
+ org.jboss.reflect*;version="[2.0,2.1)",
+
org.jboss.logging,
- org.jboss.osgi.deployment.deployer;version=1.0,
- org.jboss.osgi.spi;version=1.0,
- org.jboss.osgi.spi.management;version=1.0,
- org.jboss.osgi.spi.util;version=1.0,
- org.jboss.virtual;version="[2.1,2.2)",
- <!-- optional -->
+ org.jboss.osgi.deployment.deployer;version="[1.0,1.1)",
+ org.jboss.osgi.jbossxb;version="[2.0,2.1)",
+ org.jboss.osgi.jmx;version="[1.0,1.1)",
+ org.jboss.osgi.spi*;version="[1.0,1.1)",
- <!-- exclude -->
- !org.jboss.test.*,
- !junit*,
+ org.jboss.util*,
+
+ org.jboss.virtual*,
+ org.jboss.xb.annotations;version="[2.0,2.1)",
+ org.jboss.xb.binding*;version="[2.0,2.1)",
+ org.jboss.xb.util;version="[2.0,2.1)",
+
+ org.osgi.framework,
+ org.osgi.service.packageadmin,
+ org.osgi.service.startlevel,
+ org.osgi.util.tracker,
+
+ org.slf4j,
+ org.w3c.dom,
+ org.xml.sax,
+
+ !junit*,
+ !org.jboss.test*,
</Import-Package>
- <DynamicImport-Package>*</DynamicImport-Package>
<Embed-Transitive>true</Embed-Transitive>
<Embed-Dependency>
jboss-classloader;inline=false,
14 years, 7 months
JBoss-OSGI SVN: r97142 - projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle.
by jboss-osgi-commits@lists.jboss.org
Author: alesj
Date: 2009-11-29 07:46:20 -0500 (Sun, 29 Nov 2009)
New Revision: 97142
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java
Log:
Add TODO.
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-29 12:32:51 UTC (rev 97141)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-29 12:46:20 UTC (rev 97142)
@@ -1165,7 +1165,7 @@
*/
Collection<OSGiServiceState> getServices(AbstractBundleState bundle, String clazz, Filter filter, boolean checkAssignable)
{
- Set<org.jboss.dependency.spi.ControllerContext> contexts;
+ Set<ControllerContext> contexts;
KernelController controller = kernel.getController();
// Don't check assignabilty for the system bundle
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java 2009-11-29 12:32:51 UTC (rev 97141)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java 2009-11-29 12:46:20 UTC (rev 97142)
@@ -571,7 +571,7 @@
other = (OSGiServiceState)reference;
else if (reference instanceof OSGiServiceReferenceWrapper)
other = ((OSGiServiceReferenceWrapper)reference).getServiceState();
- else
+ else // TODO - handle generic service ref wrapper via MDR?
throw new IllegalArgumentException(reference + " is not a service reference");
long thisServiceId = getServiceId();
14 years, 7 months
JBoss-OSGI SVN: r97141 - projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle.
by jboss-osgi-commits@lists.jboss.org
Author: alesj
Date: 2009-11-29 07:32:51 -0500 (Sun, 29 Nov 2009)
New Revision: 97141
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java
Log:
Simple refactoring.
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-29 04:58:48 UTC (rev 97140)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-29 12:32:51 UTC (rev 97141)
@@ -1196,7 +1196,7 @@
// review: optimise this, e.g. index by class
// Use a sorted set to order services according to spec
Set<OSGiServiceState> result = new TreeSet<OSGiServiceState>(ServiceComparator.INSTANCE);
- for (org.jboss.dependency.spi.ControllerContext context : contexts)
+ for (ControllerContext context : contexts)
{
// TODO - fix filtering
if (context instanceof OSGiServiceState)
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java 2009-11-29 04:58:48 UTC (rev 97140)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java 2009-11-29 12:32:51 UTC (rev 97141)
@@ -574,21 +574,18 @@
else
throw new IllegalArgumentException(reference + " is not a service reference");
- long thisServiceId = this.getServiceId();
+ long thisServiceId = getServiceId();
long otherServiceId = other.getServiceId();
if (thisServiceId == otherServiceId)
return 0;
- int thisRanking = this.getServiceRanking();
+ int thisRanking = getServiceRanking();
int otherRanking = other.getServiceRanking();
int ranking = thisRanking - otherRanking;
if (ranking != 0)
return ranking;
- if (thisServiceId > otherServiceId)
- return -1;
- else
- return +1;
+ return (thisServiceId > otherServiceId) ? -1 : 1;
}
@Override
14 years, 7 months
JBoss-OSGI SVN: r97135 - in projects/jboss-osgi/trunk/reactor/framework/src: test/java/org/jboss/test/osgi/service and 1 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: alesj
Date: 2009-11-28 17:10:52 -0500 (Sat, 28 Nov 2009)
New Revision: 97135
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java
projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java
Log:
Simplify tracking a bit.
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java 2009-11-28 22:04:37 UTC (rev 97134)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/AbstractBundleState.java 2009-11-28 22:10:52 UTC (rev 97135)
@@ -342,14 +342,16 @@
* Increment the use count of a context for this bundle
*
* @param context the context
+ * @return target
*/
- void addContextInUse(ControllerContext context)
+ Object addContextInUse(ControllerContext context)
{
if (context instanceof ContextTracking)
{
ContextTracking ct = (ContextTracking)context;
- ct.getTarget(this);
+ return ct.getTarget(this);
}
+ return context.getTarget();
}
/**
@@ -370,12 +372,12 @@
public ServiceReference[] getServicesInUse()
{
- Set<org.jboss.dependency.spi.ControllerContext> contexts = getUsedContexts(null);
+ Set<ControllerContext> contexts = getUsedContexts(null);
if (contexts == null || contexts.isEmpty())
return null;
List<ServiceReference> references = new ArrayList<ServiceReference>();
- for (org.jboss.dependency.spi.ControllerContext context : contexts)
+ for (ControllerContext context : contexts)
{
if (getUsedByCount(context, this) > 0)
{
@@ -406,11 +408,6 @@
return getBundleManager().getService(this, reference);
}
- Object getService(OSGiServiceState serviceState)
- {
- return getBundleManager().getService(this, serviceState);
- }
-
public ServiceReference getServiceReference(String clazz)
{
checkValidBundleContext();
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-28 22:04:37 UTC (rev 97134)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-28 22:10:52 UTC (rev 97135)
@@ -1387,50 +1387,16 @@
*/
Object getService(AbstractBundleState bundleState, ServiceReference reference)
{
- if (reference instanceof OSGiServiceReferenceWrapper)
- {
- OSGiServiceReferenceWrapper serviceReference = (OSGiServiceReferenceWrapper)reference;
- OSGiServiceState serviceState = serviceReference.getServiceState();
- return getService(bundleState, serviceState);
- }
- else
- {
- ControllerContextHandle handle = (ControllerContextHandle)reference;
- ControllerContext context = handle.getContext();
- Object target = context.getTarget();
- return getResult(bundleState, context, target);
- }
- }
+ ControllerContextHandle handle = (ControllerContextHandle)reference;
+ ControllerContext context = handle.getContext();
+ Controller controller = context.getController();
+ if (controller == null || controller.getStates().isBeforeState(context.getState(), ControllerState.INSTALLED))
+ return null; // we're probably not installed anymore
- /**
- * Get a service
- *
- * @param bundleState the bundle that requests the service
- * @param serviceState the service state
- * @return the service
- */
- Object getService(AbstractBundleState bundleState, OSGiServiceState serviceState)
- {
- Object result = serviceState.getService(bundleState);
- return getResult(bundleState, serviceState, result);
+ return bundleState.addContextInUse(context);
}
/**
- * Get result.
- *
- * @param bundleState the bundle state
- * @param context the context
- * @param result the result
- * @return result
- */
- private Object getResult(AbstractBundleState bundleState, ControllerContext context, Object result)
- {
- if (result != null)
- bundleState.addContextInUse(context);
- return result;
- }
-
- /**
* Unget a service
*
* @param bundleState the bundle state
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java 2009-11-28 22:04:37 UTC (rev 97134)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiServiceState.java 2009-11-28 22:10:52 UTC (rev 97135)
@@ -243,6 +243,16 @@
return getService(bundleState);
}
+ protected Object getTargetForTracker(ContextTracker tracker)
+ {
+ if (tracker instanceof AbstractBundleState)
+ {
+ AbstractBundleState abs = (AbstractBundleState)tracker;
+ return getService(abs);
+ }
+ return getTarget();
+ }
+
public Object invoke(String name, Object[] parameters, String[] signature) throws Throwable
{
return getBeanInfo().invoke(getTarget(), name, signature, parameters);
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java 2009-11-28 22:04:37 UTC (rev 97134)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/ServiceRegistrationUnitTestCase.java 2009-11-28 22:10:52 UTC (rev 97135)
@@ -287,7 +287,7 @@
assertEquals(new ServiceReference[] { reference }, inUse);
assertNull(factory.ungetBundle);
- assertNull(factory.ungetRegisation);
+ assertNull(factory.ungetRegistration);
assertNull(factory.ungetService);
bundleContext.addServiceListener(this);
@@ -306,7 +306,7 @@
inUse = bundle2.getServicesInUse();
assertNull(inUse);
- assertEquals(registration, factory.ungetRegisation);
+ assertEquals(registration, factory.ungetRegistration);
assertEquals(bundleContext, factory.ungetService);
}
finally
Modified: projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java 2009-11-28 22:04:37 UTC (rev 97134)
+++ projects/jboss-osgi/trunk/reactor/framework/src/test/java/org/jboss/test/osgi/service/support/SimpleServiceFactory.java 2009-11-28 22:10:52 UTC (rev 97135)
@@ -39,10 +39,10 @@
public int getCount;
public Bundle ungetBundle;
- public ServiceRegistration ungetRegisation;
+ public ServiceRegistration ungetRegistration;
public Object ungetService;
public int ungetCount;
-
+
public SimpleServiceFactory(Object service)
{
this.service = service;
@@ -58,7 +58,7 @@
public void ungetService(Bundle bundle, ServiceRegistration registration, Object service)
{
ungetBundle = bundle;
- ungetRegisation = registration;
+ ungetRegistration = registration;
ungetService = service;
ungetCount++;
}
14 years, 7 months
JBoss-OSGI SVN: r97131 - projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle.
by jboss-osgi-commits@lists.jboss.org
Author: alesj
Date: 2009-11-28 15:27:48 -0500 (Sat, 28 Nov 2009)
New Revision: 97131
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
Log:
Use service registry.
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-28 20:26:20 UTC (rev 97130)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-28 20:27:48 UTC (rev 97131)
@@ -98,6 +98,7 @@
import org.osgi.framework.ServiceEvent;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.Version;
+import org.osgi.framework.ServiceRegistration;
import org.osgi.service.packageadmin.PackageAdmin;
/**
@@ -1370,9 +1371,9 @@
*/
void unregisterContext(ControllerContext context)
{
- if (context instanceof OSGiServiceState)
+ if (context instanceof ServiceRegistration)
{
- OSGiServiceState service = (OSGiServiceState)context;
+ ServiceRegistration service = (ServiceRegistration)context;
service.unregister();
}
}
14 years, 7 months
JBoss-OSGI SVN: r97130 - projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle.
by jboss-osgi-commits@lists.jboss.org
Author: alesj
Date: 2009-11-28 15:26:20 -0500 (Sat, 28 Nov 2009)
New Revision: 97130
Modified:
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java
Log:
Remove custom service unregistration.
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-28 16:55:14 UTC (rev 97129)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2009-11-28 20:26:20 UTC (rev 97130)
@@ -1364,6 +1364,20 @@
}
/**
+ * Unregister context.
+ *
+ * @param context the context
+ */
+ void unregisterContext(ControllerContext context)
+ {
+ if (context instanceof OSGiServiceState)
+ {
+ OSGiServiceState service = (OSGiServiceState)context;
+ service.unregister();
+ }
+ }
+
+ /**
* Get a service
*
* @param bundleState the bundle that requests the service
@@ -1439,7 +1453,7 @@
* @param context the context
* @return true when the context is still in use by the bundle
*/
- boolean ungetContext(AbstractBundleState bundleState, org.jboss.dependency.spi.ControllerContext context)
+ boolean ungetContext(AbstractBundleState bundleState, ControllerContext context)
{
return bundleState.removeContextInUse(context);
}
Modified: projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java 2009-11-28 16:55:14 UTC (rev 97129)
+++ projects/jboss-osgi/trunk/reactor/framework/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleState.java 2009-11-28 20:26:20 UTC (rev 97130)
@@ -27,6 +27,7 @@
import java.util.Enumeration;
import java.util.concurrent.atomic.AtomicLong;
+import org.jboss.dependency.spi.ControllerContext;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
import org.jboss.osgi.framework.metadata.OSGiMetaData;
@@ -343,24 +344,23 @@
}
}
- // TODO - I guess we need to unget them all, but only OSGi will have a real "unget" notion
- for (OSGiServiceState service : getUsedContexts(OSGiServiceState.class))
+ for (ControllerContext context : getUsedContexts(null))
{
- int count = getUsedByCount(service, this);
+ int count = getUsedByCount(context, this);
while (count > 0)
{
try
{
- getBundleManager().ungetService(this, service);
+ getBundleManager().ungetContext(this, context);
}
catch (Throwable t)
{
- log.debug("Error ungetting service: " + service, t);
+ log.debug("Error ungetting service: " + context, t);
}
count--;
}
- service.unregister();
+ getBundleManager().unregisterContext(context);
}
if (getState() != STOPPING)
14 years, 7 months
JBoss-OSGI SVN: r97124 - in projects/jboss-osgi/projects/bundles/microcontainer/trunk: src/main/java/org/jboss/osgi/microcontainer and 5 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-28 06:33:12 -0500 (Sat, 28 Nov 2009)
New Revision: 97124
Added:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/RefreshMicrocontainerServiceTestCase.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SomeBeanMBean.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/resources/simple/
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/resources/simple/simple-bundle.bnd
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/resources/simple/simple-jboss-beans.xml
Modified:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/scripts/antrun-test-jars.xml
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/AbstractMicrocontainerDeployerService.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/AbstractMicrocontainerService.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceActivator.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/BasicMicrocontainerTestCase.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SimpleActivator.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SomeBean.java
projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SomeService.java
Log:
[JBOSG-212] Add a test to the mc bundle module
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/scripts/antrun-test-jars.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/scripts/antrun-test-jars.xml 2009-11-28 11:32:05 UTC (rev 97123)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/scripts/antrun-test-jars.xml 2009-11-28 11:33:12 UTC (rev 97124)
@@ -46,7 +46,7 @@
<!-- Please add alphabetically -->
<!-- simple-unmarshaller -->
- <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/simple-unmarshaller.jar" files="${tests.resources.dir}/simple/simple-unmarshaller.bnd" />
+ <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/simple-bundle.jar" files="${tests.resources.dir}/simple/simple-bundle.bnd" />
<!-- Please add alphabetically -->
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/AbstractMicrocontainerDeployerService.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/AbstractMicrocontainerDeployerService.java 2009-11-28 11:32:05 UTC (rev 97123)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/AbstractMicrocontainerDeployerService.java 2009-11-28 11:33:12 UTC (rev 97124)
@@ -39,6 +39,8 @@
import org.jboss.virtual.VirtualFile;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -57,10 +59,10 @@
{
// Provide logging
private Logger log = LoggerFactory.getLogger(AbstractMicrocontainerDeployerService.class);
-
+
private VFSDeploymentFactory deploymentFactory = VFSDeploymentFactory.getInstance();
private ServiceTracker registryTracker;
-
+
public abstract MainDeployer getMainDeployer();
public abstract BundleContext getBundleContext();
@@ -80,8 +82,17 @@
try
{
VFSDeployment vfsdep = dep.getAttachment(VFSDeployment.class);
- getMainDeployer().removeDeployment(vfsdep.getName());
- getMainDeployer().process();
+ if (vfsdep != null)
+ {
+ getMainDeployer().removeDeployment(vfsdep.getName());
+ registry.unregisterDeployment(dep);
+ getMainDeployer().process();
+ }
+ else
+ {
+ DeployerService service = getSystemDeployerService();
+ service.undeploy(new Deployment[] { dep });
+ }
}
catch (Exception ex)
{
@@ -90,6 +101,17 @@
}
}
+ private DeployerService getSystemDeployerService() throws InvalidSyntaxException
+ {
+ BundleContext context = getBundleContext();
+ ServiceReference[] srefs = context.getServiceReferences(DeployerService.class.getName(), "(provider=system)");
+ if (srefs == null)
+ throw new IllegalStateException("Cannot obtain system DeployerService");
+
+ DeployerService service = (DeployerService)context.getService(srefs[0]);
+ return service;
+ }
+
public void deploy(Deployment[] depArr) throws BundleException
{
ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
@@ -99,7 +121,7 @@
List<VFSDeployment> depList = new ArrayList<VFSDeployment>();
DeploymentRegistryService registry = getDeploymentRegistry();
-
+
for (Deployment dep : depArr)
{
VirtualFile root = dep.getRoot();
@@ -107,11 +129,11 @@
dep.addAttachment(VFSDeployment.class, vfsdep);
registry.registerDeployment(dep);
depList.add(vfsdep);
-
+
MutableAttachments att = (MutableAttachments)vfsdep.getPredeterminedManagedObjects();
att.addAttachment(OSGiConstants.PROPERTY_START_LEVEL, new Integer(dep.getStartLevel()));
att.addAttachment(OSGiConstants.PROPERTY_AUTO_START, new Boolean(dep.isAutoStart()));
-
+
getMainDeployer().addDeployment(vfsdep);
}
@@ -138,26 +160,33 @@
public void undeploy(Deployment[] depArr) throws BundleException
{
- try
+ DeploymentRegistryService registry = getDeploymentRegistry();
+ for (Deployment dep : depArr)
{
- DeploymentRegistryService registry = getDeploymentRegistry();
-
- for (Deployment dep : depArr)
+ try
{
- registry.unregisterDeployment(dep);
VFSDeployment vfsdep = dep.getAttachment(VFSDeployment.class);
- getMainDeployer().removeDeployment(vfsdep.getName());
+ if (vfsdep != null)
+ {
+ getMainDeployer().removeDeployment(vfsdep.getName());
+ registry.unregisterDeployment(dep);
+ getMainDeployer().process();
+ }
+ else
+ {
+ DeployerService service = getSystemDeployerService();
+ service.undeploy(new Deployment[] { dep });
+ }
}
- getMainDeployer().process();
+ catch (RuntimeException rte)
+ {
+ throw rte;
+ }
+ catch (Exception ex)
+ {
+ log.warn("Cannot undeploy bundles", ex);
+ }
}
- catch (RuntimeException rte)
- {
- throw rte;
- }
- catch (Exception ex)
- {
- log.warn("Cannot undeploy bundles", ex);
- }
}
private DeploymentRegistryService getDeploymentRegistry()
@@ -167,9 +196,11 @@
registryTracker = new ServiceTracker(getBundleContext(), DeploymentRegistryService.class.getName(), null);
registryTracker.open();
}
+
DeploymentRegistryService service = (DeploymentRegistryService)registryTracker.getService();
if (service == null)
throw new IllegalStateException("Cannot obtain DeploymentRegistryService");
+
return service;
}
}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/AbstractMicrocontainerService.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/AbstractMicrocontainerService.java 2009-11-28 11:32:05 UTC (rev 97123)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/AbstractMicrocontainerService.java 2009-11-28 11:33:12 UTC (rev 97124)
@@ -102,10 +102,22 @@
}
catch (Throwable ex)
{
- throw new IllegalStateException("Cannot register bean: " + beanName, ex);
+ throw new IllegalStateException("Cannot install bean: " + beanName, ex);
}
}
+ protected void uninstallBean(KernelController controller, String beanName)
+ {
+ try
+ {
+ controller.uninstall(beanName);
+ }
+ catch (Throwable ex)
+ {
+ log.warn("Cannot uninstall bean: " + beanName, ex);
+ }
+ }
+
protected void registerMicrocontainerServiceMBean(MBeanServer mbeanServer)
{
try
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceActivator.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceActivator.java 2009-11-28 11:32:05 UTC (rev 97123)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceActivator.java 2009-11-28 11:33:12 UTC (rev 97124)
@@ -23,16 +23,9 @@
//$Id$
-import java.util.Properties;
-
-import org.jboss.deployers.client.spi.main.MainDeployer;
-import org.jboss.osgi.deployment.deployer.DeployerService;
import org.jboss.osgi.spi.service.MicrocontainerService;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.osgi.util.tracker.ServiceTracker;
/**
* A BundleActivator that registers the {@link MicrocontainerService}
@@ -50,14 +43,12 @@
String systemBundleName = context.getBundle(0).getSymbolicName();
if ("org.jboss.osgi.framework".equals(systemBundleName))
return;
-
- // Get the classloader that is used to initialize the MC service
- ClassLoader classLoader = getClass().getClassLoader();
-
+
ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
try
{
- Thread.currentThread().setContextClassLoader(classLoader);
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+
mcService = new MicrocontainerServiceImpl(context);
mcService.start();
}
@@ -65,10 +56,6 @@
{
Thread.currentThread().setContextClassLoader(ctxLoader);
}
-
- // Track the MicrocontainerService and register the DeployerService
- MicrocontainerServiceTracker tracker = new MicrocontainerServiceTracker(context, classLoader);
- tracker.open();
}
public void stop(BundleContext context)
@@ -76,41 +63,4 @@
if (mcService != null)
mcService.stop();
}
-
- /**
- * Register the DeployerService that uses the MC deployers
- */
- class MicrocontainerServiceTracker extends ServiceTracker
- {
- private ClassLoader classLoader;
-
- public MicrocontainerServiceTracker(BundleContext context, ClassLoader classLoader)
- {
- super(context, MicrocontainerService.class.getName(), null);
- this.classLoader = classLoader;
- }
-
- @Override
- public Object addingService(ServiceReference reference)
- {
- MicrocontainerService mcService = (MicrocontainerService)super.addingService(reference);
- ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
- try
- {
- Thread.currentThread().setContextClassLoader(classLoader);
-
- Properties props = new Properties();
- props.setProperty("provider", "microcontainer");
- props.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
- MainDeployer mainDeployer = (MainDeployer)mcService.getRegisteredBean("MainDeployer");
- MicrocontainerDeployerServiceImpl deployerService = new MicrocontainerDeployerServiceImpl(context, mainDeployer);
- context.registerService(DeployerService.class.getName(), deployerService, props);
- }
- finally
- {
- Thread.currentThread().setContextClassLoader(ctxLoader);
- }
- return mcService;
- }
- }
}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java 2009-11-28 11:32:05 UTC (rev 97123)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/main/java/org/jboss/osgi/microcontainer/internal/MicrocontainerServiceImpl.java 2009-11-28 11:33:12 UTC (rev 97124)
@@ -28,17 +28,21 @@
import java.net.URL;
import java.util.Arrays;
import java.util.List;
+import java.util.Properties;
import javax.management.MBeanServer;
+import org.jboss.deployers.client.spi.main.MainDeployer;
import org.jboss.kernel.Kernel;
import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.osgi.deployment.deployer.DeployerService;
import org.jboss.osgi.jbossxb.UnmarshallerService;
import org.jboss.osgi.microcontainer.AbstractMicrocontainerService;
import org.jboss.osgi.spi.management.MicrocontainerServiceMBean;
import org.jboss.osgi.spi.service.MicrocontainerService;
import org.jboss.virtual.VFS;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
@@ -100,12 +104,12 @@
{
UnmarshallerService xmlService;
MBeanServer mbeanServer;
-
+
@Override
public Object addingService(ServiceReference sref)
{
Object service = super.addingService(sref);
-
+
List<String> classList = Arrays.asList((String[])sref.getProperty(OBJECTCLASS));
if (classList.contains(MBeanServer.class.getName()))
mbeanServer = (MBeanServer)service;
@@ -125,10 +129,13 @@
// Register the MicrocontainerService
context.registerService(MicrocontainerService.class.getName(), mcServiceImpl, null);
+ // Register the Microcontainer DeployerService
+ registerMicrocontainerDeployerService();
+
// Register the MicrocontainerServiceMBean
registerMicrocontainerServiceMBean(mbeanServer);
}
-
+
return service;
}
};
@@ -137,11 +144,44 @@
void stop()
{
+ Kernel kernel = getKernel();
+ KernelController controller = kernel.getController();
+
ServiceReference sref = context.getServiceReference(MBeanServer.class.getName());
if (sref != null)
{
MBeanServer mbeanServer = (MBeanServer)context.getService(sref);
unregisterMicrocontainerServiceMBean(mbeanServer);
+ uninstallBean(controller, BEAN_MBEAN_SERVER);
}
+
+ // Undeploy the deployer beans
+ URL deployersURL = context.getBundle().getResource("META-INF/base-deployers-beans.xml");
+ deployer.undeploy(deployersURL);
+
+ // Uninstall preregister some beans
+ uninstallBean(controller, BEAN_SYSTEM_BUNDLE_CONTEXT);
+ uninstallBean(controller, BEAN_KERNEL);
+ uninstallBean(controller, BEAN_KERNEL_CONTROLLER);
}
+
+ private void registerMicrocontainerDeployerService()
+ {
+ ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+
+ Properties props = new Properties();
+ props.setProperty("provider", "microcontainer");
+ props.put(Constants.SERVICE_RANKING, Integer.MAX_VALUE);
+ MainDeployer mainDeployer = (MainDeployer)getRegisteredBean("MainDeployer");
+ MicrocontainerDeployerServiceImpl deployerService = new MicrocontainerDeployerServiceImpl(context, mainDeployer);
+ context.registerService(DeployerService.class.getName(), deployerService, props);
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(ctxLoader);
+ }
+ }
}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/BasicMicrocontainerTestCase.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/BasicMicrocontainerTestCase.java 2009-11-28 11:32:05 UTC (rev 97123)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/BasicMicrocontainerTestCase.java 2009-11-28 11:33:12 UTC (rev 97124)
@@ -23,18 +23,15 @@
//$Id: BasicXMLBindingTestCase.java 97031 2009-11-26 14:54:08Z thomas.diesler(a)jboss.com $
-import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
-import org.jboss.osgi.husky.HuskyCapability;
import org.jboss.osgi.microcontainer.MicrocontainerCapability;
-import org.jboss.osgi.spi.service.MicrocontainerService;
+import org.jboss.osgi.spi.management.MBeanProxy;
+import org.jboss.osgi.testing.OSGiBundle;
import org.jboss.osgi.testing.OSGiRuntime;
-import org.jboss.osgi.testing.OSGiServiceReference;
import org.jboss.osgi.testing.OSGiTest;
-import org.junit.After;
-import org.junit.Before;
+import org.jboss.test.osgi.microcontainer.simple.SomeBeanMBean;
import org.junit.Test;
-import org.osgi.framework.BundleException;
/**
* Test MicrocontainerService
@@ -44,29 +41,27 @@
*/
public class BasicMicrocontainerTestCase extends OSGiTest
{
- private OSGiRuntime runtime;
-
- @Before
- public void setUp() throws Exception
- {
- runtime = getDefaultRuntime();
- runtime.addCapability(new HuskyCapability());
- runtime.addCapability(new MicrocontainerCapability());
-
- //OSGiBundle bundle = runtime.installBundle("simple-unmarshaller.jar");
- //bundle.start();
- }
-
- @After
- public void tearDown() throws BundleException
- {
- runtime.shutdown();
- }
-
@Test
public void testMicrocontainerService() throws Exception
{
- OSGiServiceReference sref = runtime.getServiceReference(MicrocontainerService.class.getName());
- assertNotNull("MicrocontainerService available", sref);
+ OSGiRuntime runtime = getDefaultRuntime();
+ try
+ {
+ runtime.addCapability(new MicrocontainerCapability());
+
+ OSGiBundle bundle = runtime.installBundle("simple-bundle.jar");
+ bundle.start();
+
+ // The bean should have registered itself to the MBeanServer
+ SomeBeanMBean someBean = MBeanProxy.get(SomeBeanMBean.class, SomeBeanMBean.MBEAN_NAME, runtime.getMBeanServer());
+ assertEquals("hello", someBean.echo("hello"));
+
+ // The service should be able to access the bean via the MicrocontainerService
+ assertEquals("hello", someBean.callSomeService("hello"));
+ }
+ finally
+ {
+ runtime.shutdown();
+ }
}
}
\ No newline at end of file
Added: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/RefreshMicrocontainerServiceTestCase.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/RefreshMicrocontainerServiceTestCase.java (rev 0)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/RefreshMicrocontainerServiceTestCase.java 2009-11-28 11:33:12 UTC (rev 97124)
@@ -0,0 +1,83 @@
+/*
+ * 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.test.osgi.microcontainer;
+
+//$Id: BasicXMLBindingTestCase.java 97031 2009-11-26 14:54:08Z thomas.diesler(a)jboss.com $
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.jboss.osgi.microcontainer.MicrocontainerCapability;
+import org.jboss.osgi.spi.management.MBeanProxy;
+import org.jboss.osgi.spi.service.MicrocontainerService;
+import org.jboss.osgi.testing.OSGiBundle;
+import org.jboss.osgi.testing.OSGiPackageAdmin;
+import org.jboss.osgi.testing.OSGiRuntime;
+import org.jboss.osgi.testing.OSGiServiceReference;
+import org.jboss.osgi.testing.OSGiTest;
+import org.jboss.test.osgi.microcontainer.simple.SomeBeanMBean;
+import org.junit.Ignore;
+import org.junit.Test;
+
+/**
+ * Test MicrocontainerService
+ *
+ * @author thomas.diesler(a)jboss.com
+ * @since 26-Nov-2009
+ */
+@Ignore
+public class RefreshMicrocontainerServiceTestCase extends OSGiTest
+{
+ @Test
+ public void testMicrocontainerService() throws Exception
+ {
+ OSGiRuntime runtime = getDefaultRuntime();
+ try
+ {
+ runtime.addCapability(new MicrocontainerCapability());
+
+ OSGiBundle bundle = runtime.installBundle("simple-bundle.jar");
+ bundle.start();
+
+ // The service should be able to access the bean via the MicrocontainerService
+ SomeBeanMBean someBean = MBeanProxy.get(SomeBeanMBean.class, SomeBeanMBean.MBEAN_NAME, runtime.getMBeanServer());
+ assertEquals("hello", someBean.callSomeService("hello"));
+
+ // Uninstall the user bundle
+ bundle.uninstall();
+
+ // Refresh all packages. This should stop/start the MC bundle
+ OSGiPackageAdmin packageAdmin = runtime.getPackageAdmin();
+ packageAdmin.refreshPackages(null);
+
+ // Wait some time for the refresh to finish
+ Thread.sleep(1000);
+
+ OSGiServiceReference sref = runtime.getServiceReference(MicrocontainerService.class.getName());
+ assertNotNull("MicrocontainerService available", sref);
+ }
+ finally
+ {
+ runtime.shutdown();
+ }
+ }
+}
\ No newline at end of file
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SimpleActivator.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SimpleActivator.java 2009-11-28 11:32:05 UTC (rev 97123)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SimpleActivator.java 2009-11-28 11:33:12 UTC (rev 97124)
@@ -23,8 +23,10 @@
//$Id: SomeServiceActivator.java 89664 2009-06-02 12:55:10Z thomas.diesler(a)jboss.com $
+import org.jboss.osgi.spi.service.MicrocontainerService;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
/**
* A Service Activator
@@ -36,6 +38,13 @@
{
public void start(BundleContext context)
{
+ ServiceReference sref = context.getServiceReference(MicrocontainerService.class.getName());
+ MicrocontainerService service = (MicrocontainerService)context.getService(sref);
+
+ SomeBean bean = (SomeBean)service.getRegisteredBean("SomeBean");
+ if (bean == null)
+ throw new IllegalStateException("No MC bean");
+
context.registerService(SomeService.class.getName(), new SomeService(context), null);
}
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SomeBean.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SomeBean.java 2009-11-28 11:32:05 UTC (rev 97123)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SomeBean.java 2009-11-28 11:33:12 UTC (rev 97124)
@@ -21,8 +21,47 @@
*/
package org.jboss.test.osgi.microcontainer.simple;
+import javax.management.MBeanServer;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
//$Id: SomeBean.java 93025 2009-08-31 13:10:16Z thomas.diesler(a)jboss.com $
-public class SomeBean
+public class SomeBean implements SomeBeanMBean
{
+ private BundleContext bundleContext;
+ private MBeanServer mbeanServer;
+
+ public void setMbeanServer(MBeanServer server)
+ {
+ this.mbeanServer = server;
+ }
+
+ public void setBundleContext(BundleContext systemContext)
+ {
+ this.bundleContext = systemContext;
+ }
+
+ public String echo(String msg)
+ {
+ return msg;
+ }
+
+ public String callSomeService(String msg)
+ {
+ ServiceReference sref = bundleContext.getServiceReference(SomeService.class.getName());
+ SomeService service = (SomeService)bundleContext.getService(sref);
+ return service.callSomeBean(msg);
+ }
+
+ public void create() throws Exception
+ {
+ mbeanServer.registerMBean(this, MBEAN_NAME);
+ }
+
+ public void destroy() throws Exception
+ {
+ mbeanServer.unregisterMBean(MBEAN_NAME);
+ }
}
Added: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SomeBeanMBean.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SomeBeanMBean.java (rev 0)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SomeBeanMBean.java 2009-11-28 11:33:12 UTC (rev 97124)
@@ -0,0 +1,37 @@
+/*
+ * 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.test.osgi.microcontainer.simple;
+
+import javax.management.ObjectName;
+
+import org.jboss.osgi.spi.management.ObjectNameFactory;
+
+//$Id: SomeBeanMBean.java 93025 2009-08-31 13:10:16Z thomas.diesler(a)jboss.com $
+
+public interface SomeBeanMBean
+{
+ ObjectName MBEAN_NAME = ObjectNameFactory.create("jboss.osgi:bean=SomeBean");
+
+ String callSomeService(String msg);
+
+ String echo(String msg);
+}
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SomeService.java
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SomeService.java 2009-11-28 11:32:05 UTC (rev 97123)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/java/org/jboss/test/osgi/microcontainer/simple/SomeService.java 2009-11-28 11:33:12 UTC (rev 97124)
@@ -21,34 +21,34 @@
*/
package org.jboss.test.osgi.microcontainer.simple;
-//$Id: SomeService.java 93025 2009-08-31 13:10:16Z thomas.diesler(a)jboss.com $
-
import org.jboss.osgi.spi.service.MicrocontainerService;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-/**
- * A service that accesses the MicrocontainerService
- *
- * @author thomas.diesler(a)jboss.com
- * @since 24-Apr-2009
- */
+//$Id: SomeService.java 93025 2009-08-31 13:10:16Z thomas.diesler(a)jboss.com $
+
public class SomeService
{
- // Provide logging
- private static Logger log = LoggerFactory.getLogger(SomeService.class);
-
+ private BundleContext context;
+
public SomeService(BundleContext context)
{
+ this.context = context;
+ }
+
+ public String callSomeBean(String msg)
+ {
+ MicrocontainerService mcService = getMicrocontainerService();
+ SomeBean bean = (SomeBean)mcService.getRegisteredBean("SomeBean");
+ return bean.echo(msg);
+ }
+
+ private MicrocontainerService getMicrocontainerService()
+ {
ServiceReference sref = context.getServiceReference(MicrocontainerService.class.getName());
- MicrocontainerService service = (MicrocontainerService)context.getService(sref);
+ if (sref == null)
+ throw new IllegalStateException("No MicrocontainerService");
- SomeBean bean = (SomeBean)service.getRegisteredBean("SomeBean");
- if (bean == null)
- throw new IllegalStateException("No MC bean");
-
- log.info("MC bean available");
+ return (MicrocontainerService)context.getService(sref);
}
}
Added: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/resources/simple/simple-bundle.bnd
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/resources/simple/simple-bundle.bnd (rev 0)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/resources/simple/simple-bundle.bnd 2009-11-28 11:33:12 UTC (rev 97124)
@@ -0,0 +1,8 @@
+# bnd build -classpath target/test-classes -output target/test-libs/simple-bundleA.jar src/test/resources/simple/simple-bundleA.bnd
+
+Bundle-SymbolicName: simple-bundleA
+Bundle-Activator: org.jboss.test.osgi.microcontainer.simple.SimpleActivator
+Export-Package: org.jboss.test.osgi.microcontainer.simple
+Import-Package: org.slf4j, javax.management, org.jboss.osgi.spi.management, org.jboss.osgi.spi.service, org.osgi.framework
+Include-Resource: META-INF/simple-jboss-beans.xml=simple-jboss-beans.xml
+-removeheaders: Include-Resource
Added: projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/resources/simple/simple-jboss-beans.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/resources/simple/simple-jboss-beans.xml (rev 0)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/src/test/resources/simple/simple-jboss-beans.xml 2009-11-28 11:33:12 UTC (rev 97124)
@@ -0,0 +1,9 @@
+<deployment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:jboss:bean-deployer:2.0 bean-deployer_2_0.xsd" xmlns="urn:jboss:bean-deployer:2.0">
+
+ <bean name="SomeBean" class="org.jboss.test.osgi.microcontainer.simple.SomeBean">
+ <property name="bundleContext"><inject bean="jboss.osgi:service=BundleContext"/></property>
+ <property name="mbeanServer"><inject bean="jboss.osgi:service=MBeanServer"/></property>
+ </bean>
+
+</deployment>
+
14 years, 7 months
JBoss-OSGI SVN: r97123 - in projects/jboss-osgi/trunk/testsuite: example/src/test/java/org/jboss/test/osgi/example/microcontainer/bundleA and 2 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-11-28 06:32:05 -0500 (Sat, 28 Nov 2009)
New Revision: 97123
Modified:
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/microcontainer/MicrocontainerTestCase.java
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/microcontainer/bundleA/SomeService.java
projects/jboss-osgi/trunk/testsuite/functional/pom.xml
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi212/OSGI212TestCase.java
Log:
[JBOSG-212] Add a test to the mc bundle module
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/microcontainer/MicrocontainerTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/microcontainer/MicrocontainerTestCase.java 2009-11-28 09:47:23 UTC (rev 97122)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/microcontainer/MicrocontainerTestCase.java 2009-11-28 11:32:05 UTC (rev 97123)
@@ -45,6 +45,7 @@
public class MicrocontainerTestCase
{
static OSGiRuntime runtime;
+ static OSGiBundle bundleA;
@BeforeClass
public static void setUpClass() throws Exception
@@ -52,7 +53,7 @@
runtime = new OSGiTestHelper().getDefaultRuntime();
runtime.addCapability(new MicrocontainerCapability());
- OSGiBundle bundleA = runtime.installBundle("example-mcservice-bundleA.jar");
+ bundleA = runtime.installBundle("example-mcservice-bundleA.jar");
bundleA.start();
}
@@ -61,6 +62,7 @@
{
runtime.shutdown();
runtime = null;
+ bundleA = null;
}
@Test
@@ -71,7 +73,7 @@
}
@Test
- public void testServiceService() throws Exception
+ public void testServiceAccess() throws Exception
{
SomeBeanMBean someBean = MBeanProxy.get(SomeBeanMBean.class, MBEAN_NAME, runtime.getMBeanServer());
assertEquals("hello", someBean.callSomeService("hello"));
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/microcontainer/bundleA/SomeService.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/microcontainer/bundleA/SomeService.java 2009-11-28 09:47:23 UTC (rev 97122)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/microcontainer/bundleA/SomeService.java 2009-11-28 11:32:05 UTC (rev 97123)
@@ -52,10 +52,9 @@
private MicrocontainerService getMicrocontainerService()
{
ServiceReference sref = context.getServiceReference(MicrocontainerService.class.getName());
- MicrocontainerService service = (MicrocontainerService)context.getService(sref);
- if (service == null)
+ if (sref == null)
throw new IllegalStateException("No MicrocontainerService");
- return service;
+ return (MicrocontainerService)context.getService(sref);
}
}
Modified: projects/jboss-osgi/trunk/testsuite/functional/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/pom.xml 2009-11-28 09:47:23 UTC (rev 97122)
+++ projects/jboss-osgi/trunk/testsuite/functional/pom.xml 2009-11-28 11:32:05 UTC (rev 97123)
@@ -198,8 +198,6 @@
<configuration>
<excludes>
<exclude>${target.container.excludes}</exclude>
- <!-- [JBOSGI-212] Cannot refresh Microcontainer service -->
- <exclude>org/jboss/test/osgi/jbosgi212/**</exclude>
</excludes>
</configuration>
</plugin>
Modified: projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi212/OSGI212TestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi212/OSGI212TestCase.java 2009-11-28 09:47:23 UTC (rev 97122)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi212/OSGI212TestCase.java 2009-11-28 11:32:05 UTC (rev 97123)
@@ -46,9 +46,9 @@
public class OSGI212TestCase extends OSGiTest
{
@Test
- public void testLogging() throws Exception
+ public void testServiceRestart() throws Exception
{
- OSGiRuntime runtime = getEmbeddedRuntime();
+ OSGiRuntime runtime = getDefaultRuntime();
try
{
runtime.addCapability(new MicrocontainerCapability());
@@ -61,7 +61,8 @@
assertEquals("Bundle ACTIVE", Bundle.ACTIVE, bundle.getState());
// Update the MC bundle
- // bundle.update();
+ bundle.stop();
+ bundle.start();
}
OSGiServiceReference sref = runtime.getServiceReference(MicrocontainerService.class.getName());
14 years, 7 months