JBoss-OSGI SVN: r93022 - in projects/jboss-osgi/trunk/testsuite/example: src/test/resources/META-INF and 1 other directory.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-08-31 05:21:28 -0400 (Mon, 31 Aug 2009)
New Revision: 93022
Modified:
projects/jboss-osgi/trunk/testsuite/example/pom.xml
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
Log:
[JBOSGI-145] JAXB classes are loaded from the system classpath
Enable JAXB example test
Modified: projects/jboss-osgi/trunk/testsuite/example/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/pom.xml 2009-08-31 08:46:50 UTC (rev 93021)
+++ projects/jboss-osgi/trunk/testsuite/example/pom.xml 2009-08-31 09:21:28 UTC (rev 93022)
@@ -226,7 +226,6 @@
<exclude>org/jboss/test/osgi/example/blueprint/**</exclude>
<exclude>org/jboss/test/osgi/example/http/**</exclude>
<exclude>org/jboss/test/osgi/example/microcontainer/**</exclude>
- <exclude>org/jboss/test/osgi/example/xml/jaxb/**</exclude>
</excludes>
</configuration>
</plugin>
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2009-08-31 08:46:50 UTC (rev 93021)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/jboss-osgi-bootstrap.xml 2009-08-31 09:21:28 UTC (rev 93022)
@@ -15,6 +15,9 @@
<entry><key>org.osgi.framework.storage</key><value>${log4j.output.dir}/osgi-store</value></entry>
<entry><key>org.osgi.framework.storage.clean</key><value>onFirstInit</value></entry>
<entry><key>org.osgi.framework.system.packages.extra</key><value>
+ <!-- [JBOSGI-145] JAXB classes are loaded from the system classpath -->
+ com.sun.xml.internal.bind.v2,
+
org.jboss.logging;version=2.0,
org.jboss.osgi.spi.capability;version=1.0,
org.jboss.osgi.spi.framework;version=1.0,
16 years, 3 months
JBoss-OSGI SVN: r93021 - projects/jboss-osgi/trunk.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-08-31 04:46:50 -0400 (Mon, 31 Aug 2009)
New Revision: 93021
Modified:
projects/jboss-osgi/trunk/pom.xml
Log:
Use jbossxb snapshot
Modified: projects/jboss-osgi/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/pom.xml 2009-08-31 08:44:31 UTC (rev 93020)
+++ projects/jboss-osgi/trunk/pom.xml 2009-08-31 08:46:50 UTC (rev 93021)
@@ -59,7 +59,7 @@
<version.jboss.osgi.runtime.jbossmc>1.0.2-SNAPSHOT</version.jboss.osgi.runtime.jbossmc>
<version.jboss.osgi.spi>1.0.1-SNAPSHOT</version.jboss.osgi.spi>
<version.jboss.osgi.webconsole>1.0.0</version.jboss.osgi.webconsole>
- <version.jboss.osgi.xml.binding>2.0.1</version.jboss.osgi.xml.binding>
+ <version.jboss.osgi.xml.binding>2.0.1-SNAPSHOT</version.jboss.osgi.xml.binding>
<version.osgi>r4v42-20090728</version.osgi>
</properties>
16 years, 3 months
JBoss-OSGI SVN: r93020 - projects/jboss-osgi/projects/bundles/microcontainer/trunk.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-08-31 04:44:31 -0400 (Mon, 31 Aug 2009)
New Revision: 93020
Modified:
projects/jboss-osgi/projects/bundles/microcontainer/trunk/pom.xml
Log:
Use jbossxb snapshot
Modified: projects/jboss-osgi/projects/bundles/microcontainer/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/microcontainer/trunk/pom.xml 2009-08-31 08:42:05 UTC (rev 93019)
+++ projects/jboss-osgi/projects/bundles/microcontainer/trunk/pom.xml 2009-08-31 08:44:31 UTC (rev 93020)
@@ -27,17 +27,17 @@
<parent>
<groupId>org.jboss.osgi</groupId>
<artifactId>jboss-osgi-parent</artifactId>
- <version>1.0.1</version>
+ <version>1.0.2-SNAPSHOT</version>
</parent>
<!-- Properties -->
<properties>
<version.jboss.deployers>2.0.5.SP1</version.jboss.deployers>
<version.jboss.microcontainer>2.0.9-SNAPSHOT</version.jboss.microcontainer>
- <version.jboss.osgi.jmx>1.0.0</version.jboss.osgi.jmx>
+ <version.jboss.osgi.jmx>1.0.1-SNAPSHOT</version.jboss.osgi.jmx>
<version.jboss.osgi.runtime.deployers>1.0.1-SNAPSHOT</version.jboss.osgi.runtime.deployers>
- <version.jboss.osgi.xml.binding>2.0.1</version.jboss.osgi.xml.binding>
- <version.osgi>r4v41</version.osgi>
+ <version.jboss.osgi.xml.binding>2.0.1-SNAPSHOT</version.jboss.osgi.xml.binding>
+ <version.osgi>r4v42-20090728</version.osgi>
</properties>
<!-- Dependencies -->
16 years, 3 months
JBoss-OSGI SVN: r93019 - in projects/jboss-osgi/projects/bundles/xml-binding/trunk: src/main/java/org/jboss/osgi/jbossxb/internal and 1 other directory.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-08-31 04:42:05 -0400 (Mon, 31 Aug 2009)
New Revision: 93019
Modified:
projects/jboss-osgi/projects/bundles/xml-binding/trunk/pom.xml
projects/jboss-osgi/projects/bundles/xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/XMLBindingActivator.java
Log:
Use jboss provided SAXParserFactory
Modified: projects/jboss-osgi/projects/bundles/xml-binding/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/projects/bundles/xml-binding/trunk/pom.xml 2009-08-31 08:10:55 UTC (rev 93018)
+++ projects/jboss-osgi/projects/bundles/xml-binding/trunk/pom.xml 2009-08-31 08:42:05 UTC (rev 93019)
@@ -21,22 +21,22 @@
<artifactId>jboss-osgi-xml-binding</artifactId>
<packaging>bundle</packaging>
- <version>2.0.1</version>
+ <version>2.0.1-SNAPSHOT</version>
<!-- Parent -->
<parent>
<groupId>org.jboss.osgi</groupId>
<artifactId>jboss-osgi-parent</artifactId>
- <version>1.0.1</version>
+ <version>1.0.2-SNAPSHOT</version>
</parent>
<!-- Properties -->
<properties>
<version.jboss.xb>2.0.1.GA</version.jboss.xb>
<version.javassist>3.9.0.GA</version.javassist>
- <version.jboss.osgi.jaxb>2.1.10.SP1</version.jboss.osgi.jaxb>
+ <version.jboss.osgi.jaxb>2.1.10-SNAPSHOT</version.jboss.osgi.jaxb>
<version.jboss.reflect>2.0.0.GA</version.jboss.reflect>
- <version.osgi>r4v41</version.osgi>
+ <version.osgi>r4v42-20090728</version.osgi>
</properties>
<dependencies>
Modified: projects/jboss-osgi/projects/bundles/xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/XMLBindingActivator.java
===================================================================
--- projects/jboss-osgi/projects/bundles/xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/XMLBindingActivator.java 2009-08-31 08:10:55 UTC (rev 93018)
+++ projects/jboss-osgi/projects/bundles/xml-binding/trunk/src/main/java/org/jboss/osgi/jbossxb/internal/XMLBindingActivator.java 2009-08-31 08:42:05 UTC (rev 93019)
@@ -27,6 +27,7 @@
import org.jboss.osgi.common.log.LogServiceTracker;
import org.jboss.osgi.jbossxb.XMLBindingService;
+import org.jboss.osgi.xml.XMLParserCapability;
import org.jboss.xb.binding.JBossXBException;
import org.jboss.xb.binding.parser.sax.SaxJBossXBParser;
import org.osgi.framework.BundleActivator;
@@ -49,20 +50,25 @@
{
log = new LogServiceTracker(context);
+
ServiceTracker saxTracker = new ServiceTracker(context, SAXParserFactory.class.getName(), null)
{
@Override
public Object addingService(ServiceReference reference)
{
+ String provider = (String)reference.getProperty(XMLParserCapability.PARSER_PROVIDER);
+ boolean hasJBossSAXParser = XMLParserCapability.PROVIDER_JBOSS_OSGI.equals(provider);
+ boolean hasXMLBindingService = context.getServiceReference(XMLBindingService.class.getName()) != null;
+
SAXParserFactory saxFactory = (SAXParserFactory)super.addingService(reference);
- if (context.getServiceReference(XMLBindingService.class.getName()) == null)
+ if (hasXMLBindingService == false && hasJBossSAXParser == true)
{
log.log(LogService.LOG_DEBUG, "JBossXB SAXParserFactory: " + saxFactory);
ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
try
{
- Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+ Thread.currentThread().setContextClassLoader(saxFactory.getClass().getClassLoader());
try
{
// SaxJBossXBParser initializes the SAXParserFactory in a static block
16 years, 3 months
JBoss-OSGI SVN: r93018 - in projects/jboss-osgi/trunk: testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi142 and 1 other directory.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-08-31 04:10:55 -0400 (Mon, 31 Aug 2009)
New Revision: 93018
Modified:
projects/jboss-osgi/trunk/distribution/installer/runtime/server/conf/jboss-osgi-felix-all.properties
projects/jboss-osgi/trunk/distribution/installer/runtime/server/conf/jboss-osgi-felix-default.properties
projects/jboss-osgi/trunk/distribution/installer/runtime/server/conf/jboss-osgi-felix-minimal.properties
projects/jboss-osgi/trunk/distribution/installer/runtime/server/conf/jboss-osgi-felix-web.properties
projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi142/OSGI142TestCase.java
Log:
Add spi.framework to runtime system packages
Modified: projects/jboss-osgi/trunk/distribution/installer/runtime/server/conf/jboss-osgi-felix-all.properties
===================================================================
--- projects/jboss-osgi/trunk/distribution/installer/runtime/server/conf/jboss-osgi-felix-all.properties 2009-08-31 06:20:42 UTC (rev 93017)
+++ projects/jboss-osgi/trunk/distribution/installer/runtime/server/conf/jboss-osgi-felix-all.properties 2009-08-31 08:10:55 UTC (rev 93018)
@@ -36,6 +36,7 @@
org.jboss.net.protocol, \
org.jboss.osgi.spi;version=1.0, \
org.jboss.osgi.spi.capability;version=1.0, \
+ org.jboss.osgi.spi.framework;version=1.0, \
org.jboss.osgi.spi.logging;version=1.0, \
org.jboss.osgi.spi.management;version=1.0, \
org.jboss.osgi.spi.service;version=1.0, \
Modified: projects/jboss-osgi/trunk/distribution/installer/runtime/server/conf/jboss-osgi-felix-default.properties
===================================================================
--- projects/jboss-osgi/trunk/distribution/installer/runtime/server/conf/jboss-osgi-felix-default.properties 2009-08-31 06:20:42 UTC (rev 93017)
+++ projects/jboss-osgi/trunk/distribution/installer/runtime/server/conf/jboss-osgi-felix-default.properties 2009-08-31 08:10:55 UTC (rev 93018)
@@ -25,6 +25,7 @@
org.jboss.net.protocol, \
org.jboss.osgi.spi;version=1.0, \
org.jboss.osgi.spi.capability;version=1.0, \
+ org.jboss.osgi.spi.framework;version=1.0, \
org.jboss.osgi.spi.logging;version=1.0, \
org.jboss.osgi.spi.management;version=1.0, \
org.jboss.osgi.spi.service;version=1.0, \
Modified: projects/jboss-osgi/trunk/distribution/installer/runtime/server/conf/jboss-osgi-felix-minimal.properties
===================================================================
--- projects/jboss-osgi/trunk/distribution/installer/runtime/server/conf/jboss-osgi-felix-minimal.properties 2009-08-31 06:20:42 UTC (rev 93017)
+++ projects/jboss-osgi/trunk/distribution/installer/runtime/server/conf/jboss-osgi-felix-minimal.properties 2009-08-31 08:10:55 UTC (rev 93018)
@@ -10,7 +10,11 @@
org.osgi.framework.system.packages.extra=\
org.jboss.logging, \
org.jboss.osgi.spi;version=1.0, \
+ org.jboss.osgi.spi.capability;version=1.0, \
+ org.jboss.osgi.spi.framework;version=1.0, \
+ org.jboss.osgi.spi.logging;version=1.0, \
org.jboss.osgi.spi.management;version=1.0, \
org.jboss.osgi.spi.service;version=1.0, \
+ org.jboss.osgi.spi.testing;version=1.0, \
org.jboss.osgi.spi.util;version=1.0
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/distribution/installer/runtime/server/conf/jboss-osgi-felix-web.properties
===================================================================
--- projects/jboss-osgi/trunk/distribution/installer/runtime/server/conf/jboss-osgi-felix-web.properties 2009-08-31 06:20:42 UTC (rev 93017)
+++ projects/jboss-osgi/trunk/distribution/installer/runtime/server/conf/jboss-osgi-felix-web.properties 2009-08-31 08:10:55 UTC (rev 93018)
@@ -31,6 +31,7 @@
org.jboss.net.protocol, \
org.jboss.osgi.spi;version=1.0, \
org.jboss.osgi.spi.capability;version=1.0, \
+ org.jboss.osgi.spi.framework;version=1.0, \
org.jboss.osgi.spi.logging;version=1.0, \
org.jboss.osgi.spi.management;version=1.0, \
org.jboss.osgi.spi.service;version=1.0, \
Modified: projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi142/OSGI142TestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi142/OSGI142TestCase.java 2009-08-31 06:20:42 UTC (rev 93017)
+++ projects/jboss-osgi/trunk/testsuite/functional/src/test/java/org/jboss/test/osgi/jbosgi142/OSGI142TestCase.java 2009-08-31 08:10:55 UTC (rev 93018)
@@ -103,7 +103,7 @@
}
else
{
- fail("ClassNotFoundException expected for: " + message);
+ fail("ClassNotFoundException expected for: " + message + "\nLoaded from " + wasClass.getClassLoader());
}
}
catch (ClassNotFoundException ex)
16 years, 3 months
JBoss-OSGI SVN: r93012 - in projects/jboss-osgi/projects/runtime/microcontainer/trunk/src: main/java/org/jboss/osgi/plugins/util and 2 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-08-30 14:44:30 -0400 (Sun, 30 Aug 2009)
New Revision: 93012
Added:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/ServiceFactoryUnitTestCase.java
Removed:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/simple/
Modified:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/util/CaseInsensitiveDictionary.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/GetUnGetServiceUnitTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/RegisterServiceUnitTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/ServiceRegistrationUnitTestCase.java
Log:
[JBOSGI-144] Framework does not handle ServiceFactory provided services properly
* Framework caches service provided by the ServiceFactory
* ServiceFactory.getService/ungetService are called with the bundle which requests the service (not the one that created it)
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java 2009-08-30 18:32:52 UTC (rev 93011)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java 2009-08-30 18:44:30 UTC (rev 93012)
@@ -691,6 +691,11 @@
Collection<OSGiServiceState> services = getServices(bundleState, clazz, null, checkAssignable);
if (services == null || services.isEmpty())
return null;
+
+ // [TODO] service ranking and service id
+ // 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.
OSGiServiceState service = services.iterator().next();
return service.getReferenceInternal();
@@ -773,7 +778,7 @@
/**
* Get a service
*
- * @param bundleState the bundle state
+ * @param bundleState the bundle that requests the service
* @param reference the service reference
* @return the service
*/
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java 2009-08-30 18:32:52 UTC (rev 93011)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java 2009-08-30 18:44:30 UTC (rev 93012)
@@ -27,7 +27,9 @@
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
import org.jboss.logging.Logger;
@@ -54,37 +56,37 @@
{
/** The log */
private static final Logger log = Logger.getLogger(OSGiServiceState.class);
-
+
/** Used to generate a unique id */
private static final AtomicLong serviceIDGenerator = new AtomicLong();
- /** The bundle state */
+ /** The bundle that registered the service */
private AbstractBundleState bundleState;
/** The service reference */
private OSGiServiceReferenceWrapper serviceReference;
-
+
/** The service registration */
private OSGiServiceRegistrationWrapper serviceRegistration;
/** The service id */
private long serviceId = serviceIDGenerator.incrementAndGet();
-
+
/** The service interfaces */
private String[] clazzes;
-
- /** The service */
- private Object service;
-
- /** The service factory */
- private ServiceFactory serviceFactory;
-
+
+ /** The service or service factory */
+ private Object serviceOrFactory;
+
+ /** The service factory provided service cache */
+ private Map<AbstractBundleState, Object> serviceCache;
+
/** The properties */
private CaseInsensitiveDictionary properties;
/** The using bundles */
- private Set<AbstractBundleState> usingBundles = new ConcurrentSet<AbstractBundleState>();
-
+ private Set<AbstractBundleState> usingBundles = new ConcurrentSet<AbstractBundleState>();
+
/**
* Create a new OSGiServiceState.
*
@@ -101,6 +103,7 @@
throw new IllegalArgumentException("Null bundle state");
if (clazzes == null || clazzes.length == 0)
throw new IllegalArgumentException("Null or empty clazzes");
+
for (String clazz : clazzes)
{
if (clazz == null)
@@ -111,20 +114,17 @@
this.bundleState = bundleState;
this.clazzes = clazzes;
- if (service instanceof ServiceFactory)
- {
- this.serviceFactory = (ServiceFactory) service;
- }
- else
- {
- this.service = service;
+ this.serviceOrFactory = service;
+
+ if (service instanceof ServiceFactory == false)
checkObjClass(service);
- }
+
if (properties != null)
this.properties = new CaseInsensitiveDictionary(properties);
+
serviceRegistration = new OSGiServiceRegistrationWrapper(this);
}
-
+
/**
* Get the serviceId.
*
@@ -169,25 +169,32 @@
// [TODO] fix race condition with unregistration
if (isUnregistered())
return null;
-
+
checkPermission("get", false);
- if (service != null)
- return service;
-
- if (serviceFactory != null)
+ Object service = serviceOrFactory;
+ if (serviceOrFactory instanceof ServiceFactory)
{
- try
+ if (serviceCache == null)
+ serviceCache = new ConcurrentHashMap<AbstractBundleState, Object>();
+
+ service = serviceCache.get(bundleState);
+ if (service == null)
{
- service = checkObjClass(serviceFactory.getService(bundleState.getBundle(), getRegistration()));
+ ServiceFactory serviceFactory = (ServiceFactory)serviceOrFactory;
+ try
+ {
+ service = checkObjClass(serviceFactory.getService(bundleState.getBundle(), getRegistration()));
+ serviceCache.put(bundleState, service);
+ }
+ catch (Throwable t)
+ {
+ log.error("Error from getService for " + this, t);
+ FrameworkEventsPlugin plugin = bundleState.getBundleManager().getPlugin(FrameworkEventsPlugin.class);
+ plugin.fireFrameworkEvent(bundleState, FrameworkEvent.ERROR, new BundleException("Error using service factory:" + serviceFactory, t));
+ return null;
+ }
}
- catch (Throwable t)
- {
- log.error("Error from getService for " + this, t);
- FrameworkEventsPlugin plugin = bundleState.getBundleManager().getPlugin(FrameworkEventsPlugin.class);
- plugin.fireFrameworkEvent(bundleState, FrameworkEvent.ERROR, new BundleException("Error using service factory:" + serviceFactory, t));
- return null;
- }
}
return service;
}
@@ -201,13 +208,13 @@
{
return serviceRegistration;
}
-
+
public ServiceReference getReference()
{
checkUnregistered();
return getReferenceInternal();
}
-
+
public ServiceReference getReferenceInternal()
{
if (serviceReference == null)
@@ -256,19 +263,19 @@
}
result.add(Constants.SERVICE_ID);
result.add(Constants.OBJECTCLASS);
- return result.toArray(new String[result.size()]);
+ return result.toArray(new String[result.size()]);
}
@SuppressWarnings("unchecked")
public void setProperties(Dictionary properties)
{
checkUnregistered();
-
+
if (properties == null)
this.properties = null;
else
this.properties = new CaseInsensitiveDictionary(properties);
-
+
FrameworkEventsPlugin plugin = bundleState.getBundleManager().getPlugin(FrameworkEventsPlugin.class);
plugin.fireServiceEvent(bundleState, ServiceEvent.MODIFIED, this);
}
@@ -292,7 +299,7 @@
{
usingBundles.remove(bundleState);
}
-
+
public Bundle[] getUsingBundles()
{
if (usingBundles.isEmpty())
@@ -312,8 +319,8 @@
throw new IllegalArgumentException("Null class name");
if (bundle instanceof OSGiBundleWrapper == false)
throw new IllegalArgumentException("Unknown bundle: " + bundle);
-
- OSGiBundleWrapper wrapper = (OSGiBundleWrapper) bundle;
+
+ OSGiBundleWrapper wrapper = (OSGiBundleWrapper)bundle;
AbstractBundleState other = wrapper.getBundleState();
return isAssignableTo(other, className);
}
@@ -339,11 +346,11 @@
Class<?> otherSource = (Class<?>)other.getSource(className);
if (otherSource == null)
return false;
-
- Class<?> source = (Class<?>)bundleState.getSource(className);
+
+ Class<?> source = (Class<?>)bundleState.getSource(className);
if (source == null)
return false;
-
+
boolean equals = otherSource.equals(source);
if (equals == false && otherSource.getName().equals(source.getName()))
{
@@ -381,7 +388,7 @@
/**
* Match the class
- *
+ *
* @param other the other bundle state
* @param className the class name
* @return true when the class name matches
@@ -402,10 +409,10 @@
public void unregister()
{
checkUnregistered();
-
+
try
{
- getBundleState().unregisterService(this);
+ bundleState.unregisterService(this);
}
finally
{
@@ -420,12 +427,12 @@
{
if (reference == null)
throw new IllegalArgumentException("Null reference");
-
+
OSGiServiceState other;
if (reference instanceof OSGiServiceState)
- other = (OSGiServiceState) reference;
+ other = (OSGiServiceState)reference;
else if (reference instanceof OSGiServiceReferenceWrapper)
- other = ((OSGiServiceReferenceWrapper) reference).getServiceState();
+ other = ((OSGiServiceReferenceWrapper)reference).getServiceState();
else
throw new IllegalArgumentException(reference + " is not a service reference");
@@ -433,13 +440,13 @@
long otherServiceId = other.getServiceId();
if (thisServiceId == otherServiceId)
return 0;
-
+
int thisRanking = this.getServiceRanking();
int otherRanking = other.getServiceRanking();
int ranking = thisRanking - otherRanking;
if (ranking != 0)
return ranking;
-
+
if (thisServiceId > otherServiceId)
return -1;
else
@@ -451,15 +458,15 @@
{
if (obj == null)
return false;
-
+
OSGiServiceState other;
if (obj instanceof OSGiServiceState)
- other = (OSGiServiceState) obj;
+ other = (OSGiServiceState)obj;
else if (obj instanceof OSGiServiceReferenceWrapper)
- other = ((OSGiServiceReferenceWrapper) obj).getServiceState();
+ other = ((OSGiServiceReferenceWrapper)obj).getServiceState();
else
return false;
- return this == other;
+ return this == other;
}
@Override
@@ -487,10 +494,7 @@
builder.append("id=").append(getServiceId());
builder.append(" bundle=").append(getBundleState().getCanonicalName());
builder.append(" classes=").append(Arrays.asList(getClasses()));
- if (service != null)
- builder.append(" service=").append(service);
- if (serviceFactory != null)
- builder.append(" factory=").append(serviceFactory);
+ builder.append(serviceOrFactory instanceof ServiceFactory ? " factory=" : " service=").append(serviceOrFactory);
if (properties != null)
builder.append(" properties=").append(properties);
if (usingBundles.isEmpty() == false)
@@ -516,28 +520,30 @@
if (usingBundles.isEmpty() == false)
{
for (AbstractBundleState using : usingBundles)
- using.ungetService(this);
+ {
+ if (using.ungetService(this) == false)
+ {
+ if (serviceOrFactory instanceof ServiceFactory)
+ {
+ ServiceFactory serviceFactory = (ServiceFactory)serviceOrFactory;
+ try
+ {
+ Object service = serviceCache.remove(using);
+ serviceFactory.ungetService(using.getBundle(), getRegistration(), service);
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error from ungetService for " + this, t);
+ FrameworkEventsPlugin plugin = bundleState.getBundleManager().getPlugin(FrameworkEventsPlugin.class);
+ plugin.fireFrameworkEvent(bundleState, FrameworkEvent.WARNING, new BundleException("Error using service factory:" + serviceFactory, t));
+ }
+ }
+ }
+ }
}
getBundleState().removeRegisteredService(this);
-
- if (serviceFactory != null && service != null)
- {
- try
- {
- serviceFactory.ungetService(getBundle(), getRegistration(), service);
- }
- catch (Throwable t)
- {
- log.warn("Error from ungetService for " + this, t);
- FrameworkEventsPlugin plugin = bundleState.getBundleManager().getPlugin(FrameworkEventsPlugin.class);
- plugin.fireFrameworkEvent(bundleState, FrameworkEvent.WARNING, new BundleException("Error using service factory:" + serviceFactory, t));
- }
- finally
- {
- service = null;
- }
- }
+ serviceOrFactory = null;
}
/**
@@ -550,7 +556,7 @@
{
if (object == null)
throw new IllegalArgumentException("Null object");
-
+
for (String className : getClasses())
{
try
@@ -558,16 +564,16 @@
Class<?> clazz = getBundleState().loadClass(className);
// [TODO] show classloader information all interfaces for debugging purposes
if (clazz.isInstance(object) == false)
- throw new IllegalArgumentException(object.getClass().getName() + " does not implement " + className);
+ throw new IllegalArgumentException(object.getClass().getName() + " does not implement " + className);
}
catch (ClassNotFoundException e)
{
- throw new IllegalArgumentException(object.getClass().getName() + " cannot load class: " + className, e);
+ throw new IllegalArgumentException(object.getClass().getName() + " cannot load class: " + className, e);
}
}
return object;
}
-
+
/**
* Check whether the caller has permission
*
@@ -579,7 +585,7 @@
SecurityManager sm = System.getSecurityManager();
if (sm == null)
return;
-
+
String[] clazzes = getClasses();
SecurityException se = null;
for (String clazz : clazzes)
@@ -601,10 +607,10 @@
if (se != null)
throw se;
}
-
+
/**
* Check whether the caller has permission
- *
+ *
* @param accessControlContext access control context
* @param action the action to check
* @param all whether all permissions are required
@@ -613,7 +619,7 @@
{
if (System.getSecurityManager() == null)
return;
-
+
String[] clazzes = getClasses();
SecurityException se = null;
for (String clazz : clazzes)
@@ -672,10 +678,10 @@
}
return false;
}
-
+
/**
* Check if the service is unregistered
- *
+ *
* @throws IllegalStateException if unregistered
*/
private void checkUnregistered()
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/util/CaseInsensitiveDictionary.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/util/CaseInsensitiveDictionary.java 2009-08-30 18:32:52 UTC (rev 93011)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/plugins/util/CaseInsensitiveDictionary.java 2009-08-30 18:44:30 UTC (rev 93012)
@@ -53,6 +53,7 @@
{
if (delegate == null)
throw new IllegalArgumentException("Null delegaqte");
+
this.delegate = new Hashtable<String, Object>(delegate.size());
this.originalKeys = Collections.synchronizedSet(new HashSet<String>());
Enumeration<String> e = delegate.keys();
@@ -61,6 +62,7 @@
String key = e.nextElement();
if (get(key) != null)
throw new IllegalArgumentException("Properties contain duplicates with varying case for key=" + key + " : " + delegate);
+
this.delegate.put(key.toLowerCase(), delegate.get(key));
originalKeys.add(key);
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/GetUnGetServiceUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/GetUnGetServiceUnitTestCase.java 2009-08-30 18:32:52 UTC (rev 93011)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/GetUnGetServiceUnitTestCase.java 2009-08-30 18:44:30 UTC (rev 93012)
@@ -25,7 +25,6 @@
import org.jboss.test.osgi.OSGiTestCase;
import org.jboss.test.osgi.service.support.BrokenServiceFactory;
-import org.jboss.test.osgi.service.support.SimpleServiceFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkEvent;
@@ -152,103 +151,6 @@
}
}
- public void testGetServiceFactory() throws Exception
- {
- String OBJCLASS = BundleContext.class.getName();
-
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
- try
- {
- bundle.start();
- BundleContext bundleContext = bundle.getBundleContext();
- assertNotNull(bundleContext);
-
- ServiceRegistration registration = bundleContext.registerService(OBJCLASS, new SimpleServiceFactory(bundleContext), null);
- ServiceReference reference = registration.getReference();
-
- Object actual = bundleContext.getService(reference);
- assertEquals(bundleContext, actual);
-
- actual = bundleContext.getService(reference);
- assertEquals(bundleContext, actual);
-
- registration.unregister();
- actual = bundleContext.getService(reference);
- assertNull("" + actual, actual);
- }
- finally
- {
- uninstall(bundle);
- }
- }
-
- public void testGetServiceFactoryAfterStop() throws Exception
- {
- String OBJCLASS = BundleContext.class.getName();
-
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
- try
- {
- bundle.start();
- BundleContext bundleContext = bundle.getBundleContext();
- assertNotNull(bundleContext);
-
- ServiceRegistration registration = bundleContext.registerService(OBJCLASS, new SimpleServiceFactory(bundleContext), null);
- ServiceReference reference = registration.getReference();
-
- Object actual = bundleContext.getService(reference);
- assertEquals(bundleContext, actual);
-
- bundle.stop();
- try
- {
- bundleContext.getService(reference);
- fail("Should not be here!");
- }
- catch (Throwable t)
- {
- checkThrowable(IllegalStateException.class, t);
- }
- }
- finally
- {
- uninstall(bundle);
- }
- }
-
- public void testGetWrongInterfacesForServiceFactory() throws Exception
- {
- String[] OBJCLASSES = {String.class.getName(), BundleContext.class.getName()};
-
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
- try
- {
- bundle.start();
- BundleContext bundleContext = bundle.getBundleContext();
- assertNotNull(bundleContext);
-
- bundleContext.addFrameworkListener(this);
-
- ServiceRegistration registration = bundleContext.registerService(String.class.getName(), new SimpleServiceFactory(bundleContext), null);
- ServiceReference reference = registration.getReference();
- Object actual = bundleContext.getService(reference);
- assertNull("" + actual, actual);
-
- assertFrameworkEvent(FrameworkEvent.ERROR, bundle, IllegalArgumentException.class);
-
- registration = bundleContext.registerService(OBJCLASSES, new SimpleServiceFactory(bundleContext), null);
- reference = registration.getReference();
- actual = bundleContext.getService(reference);
- assertNull("" + actual, actual);
-
- assertFrameworkEvent(FrameworkEvent.ERROR, bundle, IllegalArgumentException.class);
- }
- finally
- {
- uninstall(bundle);
- }
- }
-
public void testErrorInGetService() throws Exception
{
Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/RegisterServiceUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/RegisterServiceUnitTestCase.java 2009-08-30 18:32:52 UTC (rev 93011)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/RegisterServiceUnitTestCase.java 2009-08-30 18:44:30 UTC (rev 93012)
@@ -26,9 +26,7 @@
import junit.framework.Test;
-import org.jboss.osgi.plugins.facade.bundle.OSGiBundleWrapper;
import org.jboss.test.osgi.OSGiTestCase;
-import org.jboss.test.osgi.service.support.SimpleServiceFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@@ -246,67 +244,4 @@
uninstall(bundle);
}
}
-
- public void testRegisterServiceFactory() throws Exception
- {
- Bundle bundleA = addBundle("/bundles/simple/", "simple-bundle1");
- try
- {
- bundleA.start();
- BundleContext contextA = bundleA.getBundleContext();
- assertNotNull(contextA);
-
- SimpleServiceFactory serviceFactory = new SimpleServiceFactory(contextA);
- ServiceRegistration sregA = contextA.registerService(OBJCLASS, serviceFactory, null);
-
- ServiceReference srefA = sregA.getReference();
- Object actual = contextA.getService(srefA);
- assertEquals(contextA, actual);
- assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
- assertEquals(bundleA.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
- assertEquals(1, serviceFactory.getCount);
-
- srefA = contextA.getServiceReference(OBJCLASS);
- actual = contextA.getService(srefA);
- assertEquals(contextA, actual);
- assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
- assertEquals(bundleA.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
- assertEquals(1, serviceFactory.getCount);
-
- sregA = contextA.registerService(OBJCLASSES, serviceFactory, null);
- srefA = sregA.getReference();
- actual = contextA.getService(srefA);
- assertEquals(contextA, actual);
- assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
- assertEquals(bundleA.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
-
- System.out.println("[JBOSGI-144] Framework does not handle ServiceFactory provided services properly");
- //assertEquals(1, serviceFactory.getCount);
-
- Bundle bundleB = addBundle("/bundles/simple/", "simple-bundle2");
- try
- {
- bundleB.start();
- BundleContext contextB = bundleB.getBundleContext();
- assertNotNull(contextB);
-
- ServiceReference srefB = contextB.getServiceReference(OBJCLASS);
- actual = contextB.getService(srefB);
- assertEquals(contextA, actual);
- assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
-
- System.out.println("[JBOSGI-144] Framework does not handle ServiceFactory provided services properly");
- //assertEquals(bundleB.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
- //assertEquals(2, serviceFactory.getCount);
- }
- finally
- {
- uninstall(bundleB);
- }
- }
- finally
- {
- uninstall(bundleA);
- }
- }
}
Copied: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/ServiceFactoryUnitTestCase.java (from rev 93011, projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/ServiceFactoryUnitTestCase.java)
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/ServiceFactoryUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/ServiceFactoryUnitTestCase.java 2009-08-30 18:44:30 UTC (rev 93012)
@@ -0,0 +1,198 @@
+/*
+* 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.test.osgi.service.test;
+
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleWrapper;
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.service.support.SimpleServiceFactory;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * GetUnGetServiceUnitTestCase.
+ *
+ * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
+ * @author Thomas.Diesler(a)jboss.com
+ * @version $Revision$
+ */
+public class ServiceFactoryUnitTestCase extends OSGiTestCase
+{
+ static String OBJCLASS = BundleContext.class.getName();
+ static String[] OBJCLASSES = new String[] { OBJCLASS };
+
+ public ServiceFactoryUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testRegisterServiceFactory() throws Exception
+ {
+ Bundle bundleA = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundleA.start();
+ BundleContext contextA = bundleA.getBundleContext();
+ assertNotNull(contextA);
+
+ SimpleServiceFactory serviceFactory = new SimpleServiceFactory(contextA);
+ ServiceRegistration sregA = contextA.registerService(OBJCLASS, serviceFactory, null);
+
+ ServiceReference srefA = sregA.getReference();
+ Object actual = contextA.getService(srefA);
+ assertEquals(contextA, actual);
+ assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
+ assertEquals(bundleA.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
+ assertEquals(1, serviceFactory.getCount);
+
+ srefA = contextA.getServiceReference(OBJCLASS);
+ actual = contextA.getService(srefA);
+ assertEquals(contextA, actual);
+ assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
+ assertEquals(bundleA.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
+ assertEquals(1, serviceFactory.getCount);
+
+ Bundle bundleB = addBundle("/bundles/simple/", "simple-bundle2");
+ try
+ {
+ bundleB.start();
+ BundleContext contextB = bundleB.getBundleContext();
+ assertNotNull(contextB);
+
+ ServiceReference srefB = contextB.getServiceReference(OBJCLASS);
+ actual = contextB.getService(srefB);
+ assertEquals(contextA, actual);
+ assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
+
+ assertEquals(bundleB.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
+ assertEquals(2, serviceFactory.getCount);
+ }
+ finally
+ {
+ uninstall(bundleB);
+ }
+ }
+ finally
+ {
+ uninstall(bundleA);
+ }
+ }
+
+ public void testGetServiceFactory() throws Exception
+ {
+ String OBJCLASS = BundleContext.class.getName();
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(OBJCLASS, new SimpleServiceFactory(bundleContext), null);
+ ServiceReference reference = registration.getReference();
+
+ Object actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+
+ actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+
+ registration.unregister();
+ actual = bundleContext.getService(reference);
+ assertNull("" + actual, actual);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testGetServiceFactoryAfterStop() throws Exception
+ {
+ String OBJCLASS = BundleContext.class.getName();
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(OBJCLASS, new SimpleServiceFactory(bundleContext), null);
+ ServiceReference reference = registration.getReference();
+
+ Object actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+
+ bundle.stop();
+ try
+ {
+ bundleContext.getService(reference);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testGetWrongInterfacesForServiceFactory() throws Exception
+ {
+ String[] OBJCLASSES = {String.class.getName(), BundleContext.class.getName()};
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ bundleContext.addFrameworkListener(this);
+
+ ServiceRegistration registration = bundleContext.registerService(String.class.getName(), new SimpleServiceFactory(bundleContext), null);
+ ServiceReference reference = registration.getReference();
+ Object actual = bundleContext.getService(reference);
+ assertNull("" + actual, actual);
+
+ assertFrameworkEvent(FrameworkEvent.ERROR, bundle, IllegalArgumentException.class);
+
+ registration = bundleContext.registerService(OBJCLASSES, new SimpleServiceFactory(bundleContext), null);
+ reference = registration.getReference();
+ actual = bundleContext.getService(reference);
+ assertNull("" + actual, actual);
+
+ assertFrameworkEvent(FrameworkEvent.ERROR, bundle, IllegalArgumentException.class);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/ServiceRegistrationUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/ServiceRegistrationUnitTestCase.java 2009-08-30 18:32:52 UTC (rev 93011)
+++ projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/test/java/org/jboss/test/osgi/service/test/ServiceRegistrationUnitTestCase.java 2009-08-30 18:44:30 UTC (rev 93012)
@@ -306,7 +306,7 @@
inUse = bundle2.getServicesInUse();
assertNull(inUse);
- assertEquals(bundle, factory.ungetBundle);
+ assertEquals(bundle2, factory.ungetBundle);
assertEquals(registration, factory.ungetRegisation);
assertEquals(bundleContext, factory.ungetService);
}
16 years, 3 months
JBoss-OSGI SVN: r93011 - in projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src: main/java/org/jboss/osgi/plugins/util and 2 other directories.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-08-30 14:32:52 -0400 (Sun, 30 Aug 2009)
New Revision: 93011
Removed:
projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/simple/
Modified:
projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java
projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/util/CaseInsensitiveDictionary.java
projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/GetUnGetServiceUnitTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/ServiceFactoryUnitTestCase.java
Log:
Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java 2009-08-30 16:29:22 UTC (rev 93010)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java 2009-08-30 18:32:52 UTC (rev 93011)
@@ -115,6 +115,7 @@
this.bundleState = bundleState;
this.clazzes = clazzes;
this.serviceOrFactory = service;
+
if (service instanceof ServiceFactory == false)
checkObjClass(service);
Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/util/CaseInsensitiveDictionary.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/util/CaseInsensitiveDictionary.java 2009-08-30 16:29:22 UTC (rev 93010)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/util/CaseInsensitiveDictionary.java 2009-08-30 18:32:52 UTC (rev 93011)
@@ -53,6 +53,7 @@
{
if (delegate == null)
throw new IllegalArgumentException("Null delegaqte");
+
this.delegate = new Hashtable<String, Object>(delegate.size());
this.originalKeys = Collections.synchronizedSet(new HashSet<String>());
Enumeration<String> e = delegate.keys();
@@ -61,6 +62,7 @@
String key = e.nextElement();
if (get(key) != null)
throw new IllegalArgumentException("Properties contain duplicates with varying case for key=" + key + " : " + delegate);
+
this.delegate.put(key.toLowerCase(), delegate.get(key));
originalKeys.add(key);
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/GetUnGetServiceUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/GetUnGetServiceUnitTestCase.java 2009-08-30 16:29:22 UTC (rev 93010)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/GetUnGetServiceUnitTestCase.java 2009-08-30 18:32:52 UTC (rev 93011)
@@ -25,7 +25,6 @@
import org.jboss.test.osgi.OSGiTestCase;
import org.jboss.test.osgi.service.support.BrokenServiceFactory;
-import org.jboss.test.osgi.service.support.SimpleServiceFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkEvent;
Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/ServiceFactoryUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/ServiceFactoryUnitTestCase.java 2009-08-30 16:29:22 UTC (rev 93010)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/ServiceFactoryUnitTestCase.java 2009-08-30 18:32:52 UTC (rev 93011)
@@ -73,16 +73,6 @@
assertEquals(bundleA.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
assertEquals(1, serviceFactory.getCount);
- sregA = contextA.registerService(OBJCLASSES, serviceFactory, null);
- srefA = sregA.getReference();
- actual = contextA.getService(srefA);
- assertEquals(contextA, actual);
- assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
- assertEquals(bundleA.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
-
- System.out.println("[JBOSGI-144] Framework does not handle ServiceFactory provided services properly");
- //assertEquals(1, serviceFactory.getCount);
-
Bundle bundleB = addBundle("/bundles/simple/", "simple-bundle2");
try
{
@@ -95,9 +85,8 @@
assertEquals(contextA, actual);
assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
- System.out.println("[JBOSGI-144] Framework does not handle ServiceFactory provided services properly");
- //assertEquals(bundleB.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
- //assertEquals(2, serviceFactory.getCount);
+ assertEquals(bundleB.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
+ assertEquals(2, serviceFactory.getCount);
}
finally
{
16 years, 3 months
JBoss-OSGI SVN: r92997 - projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-08-30 03:56:29 -0400 (Sun, 30 Aug 2009)
New Revision: 92997
Added:
projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/ServiceFactoryUnitTestCase.java
Log:
[JBOSGI-144]
Added: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/ServiceFactoryUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/ServiceFactoryUnitTestCase.java (rev 0)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/ServiceFactoryUnitTestCase.java 2009-08-30 07:56:29 UTC (rev 92997)
@@ -0,0 +1,209 @@
+/*
+* 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.test.osgi.service.test;
+
+import org.jboss.osgi.plugins.facade.bundle.OSGiBundleWrapper;
+import org.jboss.test.osgi.OSGiTestCase;
+import org.jboss.test.osgi.service.support.SimpleServiceFactory;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkEvent;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
+
+/**
+ * GetUnGetServiceUnitTestCase.
+ *
+ * @author <a href="adrian(a)jboss.com">Adrian Brock</a>
+ * @author Thomas.Diesler(a)jboss.com
+ * @version $Revision$
+ */
+public class ServiceFactoryUnitTestCase extends OSGiTestCase
+{
+ static String OBJCLASS = BundleContext.class.getName();
+ static String[] OBJCLASSES = new String[] { OBJCLASS };
+
+ public ServiceFactoryUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testRegisterServiceFactory() throws Exception
+ {
+ Bundle bundleA = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundleA.start();
+ BundleContext contextA = bundleA.getBundleContext();
+ assertNotNull(contextA);
+
+ SimpleServiceFactory serviceFactory = new SimpleServiceFactory(contextA);
+ ServiceRegistration sregA = contextA.registerService(OBJCLASS, serviceFactory, null);
+
+ ServiceReference srefA = sregA.getReference();
+ Object actual = contextA.getService(srefA);
+ assertEquals(contextA, actual);
+ assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
+ assertEquals(bundleA.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
+ assertEquals(1, serviceFactory.getCount);
+
+ srefA = contextA.getServiceReference(OBJCLASS);
+ actual = contextA.getService(srefA);
+ assertEquals(contextA, actual);
+ assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
+ assertEquals(bundleA.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
+ assertEquals(1, serviceFactory.getCount);
+
+ sregA = contextA.registerService(OBJCLASSES, serviceFactory, null);
+ srefA = sregA.getReference();
+ actual = contextA.getService(srefA);
+ assertEquals(contextA, actual);
+ assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
+ assertEquals(bundleA.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
+
+ System.out.println("[JBOSGI-144] Framework does not handle ServiceFactory provided services properly");
+ //assertEquals(1, serviceFactory.getCount);
+
+ Bundle bundleB = addBundle("/bundles/simple/", "simple-bundle2");
+ try
+ {
+ bundleB.start();
+ BundleContext contextB = bundleB.getBundleContext();
+ assertNotNull(contextB);
+
+ ServiceReference srefB = contextB.getServiceReference(OBJCLASS);
+ actual = contextB.getService(srefB);
+ assertEquals(contextA, actual);
+ assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
+
+ System.out.println("[JBOSGI-144] Framework does not handle ServiceFactory provided services properly");
+ //assertEquals(bundleB.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
+ //assertEquals(2, serviceFactory.getCount);
+ }
+ finally
+ {
+ uninstall(bundleB);
+ }
+ }
+ finally
+ {
+ uninstall(bundleA);
+ }
+ }
+
+ public void testGetServiceFactory() throws Exception
+ {
+ String OBJCLASS = BundleContext.class.getName();
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(OBJCLASS, new SimpleServiceFactory(bundleContext), null);
+ ServiceReference reference = registration.getReference();
+
+ Object actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+
+ actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+
+ registration.unregister();
+ actual = bundleContext.getService(reference);
+ assertNull("" + actual, actual);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testGetServiceFactoryAfterStop() throws Exception
+ {
+ String OBJCLASS = BundleContext.class.getName();
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ ServiceRegistration registration = bundleContext.registerService(OBJCLASS, new SimpleServiceFactory(bundleContext), null);
+ ServiceReference reference = registration.getReference();
+
+ Object actual = bundleContext.getService(reference);
+ assertEquals(bundleContext, actual);
+
+ bundle.stop();
+ try
+ {
+ bundleContext.getService(reference);
+ fail("Should not be here!");
+ }
+ catch (Throwable t)
+ {
+ checkThrowable(IllegalStateException.class, t);
+ }
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+
+ public void testGetWrongInterfacesForServiceFactory() throws Exception
+ {
+ String[] OBJCLASSES = {String.class.getName(), BundleContext.class.getName()};
+
+ Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
+ try
+ {
+ bundle.start();
+ BundleContext bundleContext = bundle.getBundleContext();
+ assertNotNull(bundleContext);
+
+ bundleContext.addFrameworkListener(this);
+
+ ServiceRegistration registration = bundleContext.registerService(String.class.getName(), new SimpleServiceFactory(bundleContext), null);
+ ServiceReference reference = registration.getReference();
+ Object actual = bundleContext.getService(reference);
+ assertNull("" + actual, actual);
+
+ assertFrameworkEvent(FrameworkEvent.ERROR, bundle, IllegalArgumentException.class);
+
+ registration = bundleContext.registerService(OBJCLASSES, new SimpleServiceFactory(bundleContext), null);
+ reference = registration.getReference();
+ actual = bundleContext.getService(reference);
+ assertNull("" + actual, actual);
+
+ assertFrameworkEvent(FrameworkEvent.ERROR, bundle, IllegalArgumentException.class);
+ }
+ finally
+ {
+ uninstall(bundle);
+ }
+ }
+}
Property changes on: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/ServiceFactoryUnitTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
16 years, 3 months
JBoss-OSGI SVN: r92996 - in projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src: test/java/org/jboss/test/osgi/service/test and 1 other directory.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-08-30 03:55:58 -0400 (Sun, 30 Aug 2009)
New Revision: 92996
Modified:
projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java
projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/GetUnGetServiceUnitTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/RegisterServiceUnitTestCase.java
projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/ServiceRegistrationUnitTestCase.java
Log:
[JBOSGI-144]
Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java 2009-08-30 07:54:31 UTC (rev 92995)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java 2009-08-30 07:55:58 UTC (rev 92996)
@@ -691,6 +691,11 @@
Collection<OSGiServiceState> services = getServices(bundleState, clazz, null, checkAssignable);
if (services == null || services.isEmpty())
return null;
+
+ // [TODO] service ranking and service id
+ // 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.
OSGiServiceState service = services.iterator().next();
return service.getReferenceInternal();
@@ -773,7 +778,7 @@
/**
* Get a service
*
- * @param bundleState the bundle state
+ * @param bundleState the bundle that requests the service
* @param reference the service reference
* @return the service
*/
Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java 2009-08-30 07:54:31 UTC (rev 92995)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiServiceState.java 2009-08-30 07:55:58 UTC (rev 92996)
@@ -27,7 +27,9 @@
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;
import org.jboss.logging.Logger;
@@ -54,37 +56,37 @@
{
/** The log */
private static final Logger log = Logger.getLogger(OSGiServiceState.class);
-
+
/** Used to generate a unique id */
private static final AtomicLong serviceIDGenerator = new AtomicLong();
- /** The bundle state */
+ /** The bundle that registered the service */
private AbstractBundleState bundleState;
/** The service reference */
private OSGiServiceReferenceWrapper serviceReference;
-
+
/** The service registration */
private OSGiServiceRegistrationWrapper serviceRegistration;
/** The service id */
private long serviceId = serviceIDGenerator.incrementAndGet();
-
+
/** The service interfaces */
private String[] clazzes;
-
- /** The service */
- private Object service;
-
- /** The service factory */
- private ServiceFactory serviceFactory;
-
+
+ /** The service or service factory */
+ private Object serviceOrFactory;
+
+ /** The service factory provided service cache */
+ private Map<AbstractBundleState, Object> serviceCache;
+
/** The properties */
private CaseInsensitiveDictionary properties;
/** The using bundles */
- private Set<AbstractBundleState> usingBundles = new ConcurrentSet<AbstractBundleState>();
-
+ private Set<AbstractBundleState> usingBundles = new ConcurrentSet<AbstractBundleState>();
+
/**
* Create a new OSGiServiceState.
*
@@ -101,6 +103,7 @@
throw new IllegalArgumentException("Null bundle state");
if (clazzes == null || clazzes.length == 0)
throw new IllegalArgumentException("Null or empty clazzes");
+
for (String clazz : clazzes)
{
if (clazz == null)
@@ -111,20 +114,16 @@
this.bundleState = bundleState;
this.clazzes = clazzes;
- if (service instanceof ServiceFactory)
- {
- this.serviceFactory = (ServiceFactory) service;
- }
- else
- {
- this.service = service;
+ this.serviceOrFactory = service;
+ if (service instanceof ServiceFactory == false)
checkObjClass(service);
- }
+
if (properties != null)
this.properties = new CaseInsensitiveDictionary(properties);
+
serviceRegistration = new OSGiServiceRegistrationWrapper(this);
}
-
+
/**
* Get the serviceId.
*
@@ -169,25 +168,32 @@
// [TODO] fix race condition with unregistration
if (isUnregistered())
return null;
-
+
checkPermission("get", false);
- if (service != null)
- return service;
-
- if (serviceFactory != null)
+ Object service = serviceOrFactory;
+ if (serviceOrFactory instanceof ServiceFactory)
{
- try
+ if (serviceCache == null)
+ serviceCache = new ConcurrentHashMap<AbstractBundleState, Object>();
+
+ service = serviceCache.get(bundleState);
+ if (service == null)
{
- service = checkObjClass(serviceFactory.getService(bundleState.getBundle(), getRegistration()));
+ ServiceFactory serviceFactory = (ServiceFactory)serviceOrFactory;
+ try
+ {
+ service = checkObjClass(serviceFactory.getService(bundleState.getBundle(), getRegistration()));
+ serviceCache.put(bundleState, service);
+ }
+ catch (Throwable t)
+ {
+ log.error("Error from getService for " + this, t);
+ FrameworkEventsPlugin plugin = bundleState.getBundleManager().getPlugin(FrameworkEventsPlugin.class);
+ plugin.fireFrameworkEvent(bundleState, FrameworkEvent.ERROR, new BundleException("Error using service factory:" + serviceFactory, t));
+ return null;
+ }
}
- catch (Throwable t)
- {
- log.error("Error from getService for " + this, t);
- FrameworkEventsPlugin plugin = bundleState.getBundleManager().getPlugin(FrameworkEventsPlugin.class);
- plugin.fireFrameworkEvent(bundleState, FrameworkEvent.ERROR, new BundleException("Error using service factory:" + serviceFactory, t));
- return null;
- }
}
return service;
}
@@ -201,13 +207,13 @@
{
return serviceRegistration;
}
-
+
public ServiceReference getReference()
{
checkUnregistered();
return getReferenceInternal();
}
-
+
public ServiceReference getReferenceInternal()
{
if (serviceReference == null)
@@ -256,19 +262,19 @@
}
result.add(Constants.SERVICE_ID);
result.add(Constants.OBJECTCLASS);
- return result.toArray(new String[result.size()]);
+ return result.toArray(new String[result.size()]);
}
@SuppressWarnings("unchecked")
public void setProperties(Dictionary properties)
{
checkUnregistered();
-
+
if (properties == null)
this.properties = null;
else
this.properties = new CaseInsensitiveDictionary(properties);
-
+
FrameworkEventsPlugin plugin = bundleState.getBundleManager().getPlugin(FrameworkEventsPlugin.class);
plugin.fireServiceEvent(bundleState, ServiceEvent.MODIFIED, this);
}
@@ -292,7 +298,7 @@
{
usingBundles.remove(bundleState);
}
-
+
public Bundle[] getUsingBundles()
{
if (usingBundles.isEmpty())
@@ -312,8 +318,8 @@
throw new IllegalArgumentException("Null class name");
if (bundle instanceof OSGiBundleWrapper == false)
throw new IllegalArgumentException("Unknown bundle: " + bundle);
-
- OSGiBundleWrapper wrapper = (OSGiBundleWrapper) bundle;
+
+ OSGiBundleWrapper wrapper = (OSGiBundleWrapper)bundle;
AbstractBundleState other = wrapper.getBundleState();
return isAssignableTo(other, className);
}
@@ -339,11 +345,11 @@
Class<?> otherSource = (Class<?>)other.getSource(className);
if (otherSource == null)
return false;
-
- Class<?> source = (Class<?>)bundleState.getSource(className);
+
+ Class<?> source = (Class<?>)bundleState.getSource(className);
if (source == null)
return false;
-
+
boolean equals = otherSource.equals(source);
if (equals == false && otherSource.getName().equals(source.getName()))
{
@@ -381,7 +387,7 @@
/**
* Match the class
- *
+ *
* @param other the other bundle state
* @param className the class name
* @return true when the class name matches
@@ -402,10 +408,10 @@
public void unregister()
{
checkUnregistered();
-
+
try
{
- getBundleState().unregisterService(this);
+ bundleState.unregisterService(this);
}
finally
{
@@ -420,12 +426,12 @@
{
if (reference == null)
throw new IllegalArgumentException("Null reference");
-
+
OSGiServiceState other;
if (reference instanceof OSGiServiceState)
- other = (OSGiServiceState) reference;
+ other = (OSGiServiceState)reference;
else if (reference instanceof OSGiServiceReferenceWrapper)
- other = ((OSGiServiceReferenceWrapper) reference).getServiceState();
+ other = ((OSGiServiceReferenceWrapper)reference).getServiceState();
else
throw new IllegalArgumentException(reference + " is not a service reference");
@@ -433,13 +439,13 @@
long otherServiceId = other.getServiceId();
if (thisServiceId == otherServiceId)
return 0;
-
+
int thisRanking = this.getServiceRanking();
int otherRanking = other.getServiceRanking();
int ranking = thisRanking - otherRanking;
if (ranking != 0)
return ranking;
-
+
if (thisServiceId > otherServiceId)
return -1;
else
@@ -451,15 +457,15 @@
{
if (obj == null)
return false;
-
+
OSGiServiceState other;
if (obj instanceof OSGiServiceState)
- other = (OSGiServiceState) obj;
+ other = (OSGiServiceState)obj;
else if (obj instanceof OSGiServiceReferenceWrapper)
- other = ((OSGiServiceReferenceWrapper) obj).getServiceState();
+ other = ((OSGiServiceReferenceWrapper)obj).getServiceState();
else
return false;
- return this == other;
+ return this == other;
}
@Override
@@ -487,10 +493,7 @@
builder.append("id=").append(getServiceId());
builder.append(" bundle=").append(getBundleState().getCanonicalName());
builder.append(" classes=").append(Arrays.asList(getClasses()));
- if (service != null)
- builder.append(" service=").append(service);
- if (serviceFactory != null)
- builder.append(" factory=").append(serviceFactory);
+ builder.append(serviceOrFactory instanceof ServiceFactory ? " factory=" : " service=").append(serviceOrFactory);
if (properties != null)
builder.append(" properties=").append(properties);
if (usingBundles.isEmpty() == false)
@@ -516,28 +519,30 @@
if (usingBundles.isEmpty() == false)
{
for (AbstractBundleState using : usingBundles)
- using.ungetService(this);
+ {
+ if (using.ungetService(this) == false)
+ {
+ if (serviceOrFactory instanceof ServiceFactory)
+ {
+ ServiceFactory serviceFactory = (ServiceFactory)serviceOrFactory;
+ try
+ {
+ Object service = serviceCache.remove(using);
+ serviceFactory.ungetService(using.getBundle(), getRegistration(), service);
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error from ungetService for " + this, t);
+ FrameworkEventsPlugin plugin = bundleState.getBundleManager().getPlugin(FrameworkEventsPlugin.class);
+ plugin.fireFrameworkEvent(bundleState, FrameworkEvent.WARNING, new BundleException("Error using service factory:" + serviceFactory, t));
+ }
+ }
+ }
+ }
}
getBundleState().removeRegisteredService(this);
-
- if (serviceFactory != null && service != null)
- {
- try
- {
- serviceFactory.ungetService(getBundle(), getRegistration(), service);
- }
- catch (Throwable t)
- {
- log.warn("Error from ungetService for " + this, t);
- FrameworkEventsPlugin plugin = bundleState.getBundleManager().getPlugin(FrameworkEventsPlugin.class);
- plugin.fireFrameworkEvent(bundleState, FrameworkEvent.WARNING, new BundleException("Error using service factory:" + serviceFactory, t));
- }
- finally
- {
- service = null;
- }
- }
+ serviceOrFactory = null;
}
/**
@@ -550,7 +555,7 @@
{
if (object == null)
throw new IllegalArgumentException("Null object");
-
+
for (String className : getClasses())
{
try
@@ -558,16 +563,16 @@
Class<?> clazz = getBundleState().loadClass(className);
// [TODO] show classloader information all interfaces for debugging purposes
if (clazz.isInstance(object) == false)
- throw new IllegalArgumentException(object.getClass().getName() + " does not implement " + className);
+ throw new IllegalArgumentException(object.getClass().getName() + " does not implement " + className);
}
catch (ClassNotFoundException e)
{
- throw new IllegalArgumentException(object.getClass().getName() + " cannot load class: " + className, e);
+ throw new IllegalArgumentException(object.getClass().getName() + " cannot load class: " + className, e);
}
}
return object;
}
-
+
/**
* Check whether the caller has permission
*
@@ -579,7 +584,7 @@
SecurityManager sm = System.getSecurityManager();
if (sm == null)
return;
-
+
String[] clazzes = getClasses();
SecurityException se = null;
for (String clazz : clazzes)
@@ -601,10 +606,10 @@
if (se != null)
throw se;
}
-
+
/**
* Check whether the caller has permission
- *
+ *
* @param accessControlContext access control context
* @param action the action to check
* @param all whether all permissions are required
@@ -613,7 +618,7 @@
{
if (System.getSecurityManager() == null)
return;
-
+
String[] clazzes = getClasses();
SecurityException se = null;
for (String clazz : clazzes)
@@ -672,10 +677,10 @@
}
return false;
}
-
+
/**
* Check if the service is unregistered
- *
+ *
* @throws IllegalStateException if unregistered
*/
private void checkUnregistered()
Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/GetUnGetServiceUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/GetUnGetServiceUnitTestCase.java 2009-08-30 07:54:31 UTC (rev 92995)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/GetUnGetServiceUnitTestCase.java 2009-08-30 07:55:58 UTC (rev 92996)
@@ -152,103 +152,6 @@
}
}
- public void testGetServiceFactory() throws Exception
- {
- String OBJCLASS = BundleContext.class.getName();
-
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
- try
- {
- bundle.start();
- BundleContext bundleContext = bundle.getBundleContext();
- assertNotNull(bundleContext);
-
- ServiceRegistration registration = bundleContext.registerService(OBJCLASS, new SimpleServiceFactory(bundleContext), null);
- ServiceReference reference = registration.getReference();
-
- Object actual = bundleContext.getService(reference);
- assertEquals(bundleContext, actual);
-
- actual = bundleContext.getService(reference);
- assertEquals(bundleContext, actual);
-
- registration.unregister();
- actual = bundleContext.getService(reference);
- assertNull("" + actual, actual);
- }
- finally
- {
- uninstall(bundle);
- }
- }
-
- public void testGetServiceFactoryAfterStop() throws Exception
- {
- String OBJCLASS = BundleContext.class.getName();
-
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
- try
- {
- bundle.start();
- BundleContext bundleContext = bundle.getBundleContext();
- assertNotNull(bundleContext);
-
- ServiceRegistration registration = bundleContext.registerService(OBJCLASS, new SimpleServiceFactory(bundleContext), null);
- ServiceReference reference = registration.getReference();
-
- Object actual = bundleContext.getService(reference);
- assertEquals(bundleContext, actual);
-
- bundle.stop();
- try
- {
- bundleContext.getService(reference);
- fail("Should not be here!");
- }
- catch (Throwable t)
- {
- checkThrowable(IllegalStateException.class, t);
- }
- }
- finally
- {
- uninstall(bundle);
- }
- }
-
- public void testGetWrongInterfacesForServiceFactory() throws Exception
- {
- String[] OBJCLASSES = {String.class.getName(), BundleContext.class.getName()};
-
- Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
- try
- {
- bundle.start();
- BundleContext bundleContext = bundle.getBundleContext();
- assertNotNull(bundleContext);
-
- bundleContext.addFrameworkListener(this);
-
- ServiceRegistration registration = bundleContext.registerService(String.class.getName(), new SimpleServiceFactory(bundleContext), null);
- ServiceReference reference = registration.getReference();
- Object actual = bundleContext.getService(reference);
- assertNull("" + actual, actual);
-
- assertFrameworkEvent(FrameworkEvent.ERROR, bundle, IllegalArgumentException.class);
-
- registration = bundleContext.registerService(OBJCLASSES, new SimpleServiceFactory(bundleContext), null);
- reference = registration.getReference();
- actual = bundleContext.getService(reference);
- assertNull("" + actual, actual);
-
- assertFrameworkEvent(FrameworkEvent.ERROR, bundle, IllegalArgumentException.class);
- }
- finally
- {
- uninstall(bundle);
- }
- }
-
public void testErrorInGetService() throws Exception
{
Bundle bundle = addBundle("/bundles/simple/", "simple-bundle1");
Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/RegisterServiceUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/RegisterServiceUnitTestCase.java 2009-08-30 07:54:31 UTC (rev 92995)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/RegisterServiceUnitTestCase.java 2009-08-30 07:55:58 UTC (rev 92996)
@@ -26,9 +26,7 @@
import junit.framework.Test;
-import org.jboss.osgi.plugins.facade.bundle.OSGiBundleWrapper;
import org.jboss.test.osgi.OSGiTestCase;
-import org.jboss.test.osgi.service.support.SimpleServiceFactory;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@@ -246,67 +244,4 @@
uninstall(bundle);
}
}
-
- public void testRegisterServiceFactory() throws Exception
- {
- Bundle bundleA = addBundle("/bundles/simple/", "simple-bundle1");
- try
- {
- bundleA.start();
- BundleContext contextA = bundleA.getBundleContext();
- assertNotNull(contextA);
-
- SimpleServiceFactory serviceFactory = new SimpleServiceFactory(contextA);
- ServiceRegistration sregA = contextA.registerService(OBJCLASS, serviceFactory, null);
-
- ServiceReference srefA = sregA.getReference();
- Object actual = contextA.getService(srefA);
- assertEquals(contextA, actual);
- assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
- assertEquals(bundleA.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
- assertEquals(1, serviceFactory.getCount);
-
- srefA = contextA.getServiceReference(OBJCLASS);
- actual = contextA.getService(srefA);
- assertEquals(contextA, actual);
- assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
- assertEquals(bundleA.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
- assertEquals(1, serviceFactory.getCount);
-
- sregA = contextA.registerService(OBJCLASSES, serviceFactory, null);
- srefA = sregA.getReference();
- actual = contextA.getService(srefA);
- assertEquals(contextA, actual);
- assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
- assertEquals(bundleA.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
-
- System.out.println("[JBOSGI-144] Framework does not handle ServiceFactory provided services properly");
- //assertEquals(1, serviceFactory.getCount);
-
- Bundle bundleB = addBundle("/bundles/simple/", "simple-bundle2");
- try
- {
- bundleB.start();
- BundleContext contextB = bundleB.getBundleContext();
- assertNotNull(contextB);
-
- ServiceReference srefB = contextB.getServiceReference(OBJCLASS);
- actual = contextB.getService(srefB);
- assertEquals(contextA, actual);
- assertInstanceOf(serviceFactory.getBundle, OSGiBundleWrapper.class);
-
- System.out.println("[JBOSGI-144] Framework does not handle ServiceFactory provided services properly");
- //assertEquals(bundleB.getSymbolicName(), serviceFactory.getBundle.getSymbolicName());
- //assertEquals(2, serviceFactory.getCount);
- }
- finally
- {
- uninstall(bundleB);
- }
- }
- finally
- {
- uninstall(bundleA);
- }
- }
}
Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/ServiceRegistrationUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/ServiceRegistrationUnitTestCase.java 2009-08-30 07:54:31 UTC (rev 92995)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/test/java/org/jboss/test/osgi/service/test/ServiceRegistrationUnitTestCase.java 2009-08-30 07:55:58 UTC (rev 92996)
@@ -306,7 +306,7 @@
inUse = bundle2.getServicesInUse();
assertNull(inUse);
- assertEquals(bundle, factory.ungetBundle);
+ assertEquals(bundle2, factory.ungetBundle);
assertEquals(registration, factory.ungetRegisation);
assertEquals(bundleContext, factory.ungetService);
}
16 years, 3 months
JBoss-OSGI SVN: r92995 - projects/jboss-osgi/projects/runtime/microcontainer/branches.
by jboss-osgi-commits@lists.jboss.org
Author: thomas.diesler(a)jboss.com
Date: 2009-08-30 03:54:31 -0400 (Sun, 30 Aug 2009)
New Revision: 92995
Added:
projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/
Log:
recreate userbranch
Copied: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler (from rev 92994, projects/jboss-osgi/projects/runtime/microcontainer/trunk)
16 years, 3 months