[jboss-cvs] JBossAS SVN: r99996 - in projects/jboss-osgi: projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Jan 27 08:47:51 EST 2010
Author: thomas.diesler at jboss.com
Date: 2010-01-27 08:47:50 -0500 (Wed, 27 Jan 2010)
New Revision: 99996
Modified:
projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java
projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/client/ServiceLoaderClientActivator.java
projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-client.bnd
Log:
Improve serviceloader example
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2010-01-27 12:35:09 UTC (rev 99995)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/main/java/org/jboss/osgi/framework/bundle/OSGiBundleManager.java 2010-01-27 13:47:50 UTC (rev 99996)
@@ -115,8 +115,8 @@
private static String OSGi_FRAMEWORK_PROCESSOR;
/** The framework vendor */
private static String OSGi_FRAMEWORK_VENDOR = "jboss.org";
- /** The framework version */
- private static String OSGi_FRAMEWORK_VERSION = "r4v42";
+ /** The framework version. This is the version of the org.osgi.framework package in r4v42 */
+ private static String OSGi_FRAMEWORK_VERSION = "1.5";
/** The bundles by id */
private List<AbstractBundleState> allBundles = new CopyOnWriteArrayList<AbstractBundleState>();
/** The kernel */
Modified: projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java
===================================================================
--- projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java 2010-01-27 12:35:09 UTC (rev 99995)
+++ projects/jboss-osgi/projects/runtime/framework/trunk/src/test/java/org/jboss/test/osgi/bundle/BundleContextUnitTestCase.java 2010-01-27 13:47:50 UTC (rev 99996)
@@ -184,7 +184,7 @@
bundle.start();
BundleContext bundleContext = bundle.getBundleContext();
assertNotNull(bundleContext);
- assertEquals("r4v42", bundleContext.getProperty(Constants.FRAMEWORK_VERSION));
+ assertEquals("1.5", bundleContext.getProperty(Constants.FRAMEWORK_VERSION));
assertEquals("jboss.org", bundleContext.getProperty(Constants.FRAMEWORK_VENDOR));
assertEquals(Locale.getDefault().getISO3Language(), bundleContext.getProperty(Constants.FRAMEWORK_LANGUAGE));
assertSystemProperty(bundleContext, "os.name", Constants.FRAMEWORK_OS_NAME);
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/client/ServiceLoaderClientActivator.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/client/ServiceLoaderClientActivator.java 2010-01-27 12:35:09 UTC (rev 99995)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/client/ServiceLoaderClientActivator.java 2010-01-27 13:47:50 UTC (rev 99996)
@@ -27,8 +27,12 @@
import org.jboss.test.osgi.example.serviceloader.service.AccountService;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
+import org.osgi.util.tracker.ServiceTracker;
/**
* A Service Activator
@@ -38,17 +42,30 @@
*/
public class ServiceLoaderClientActivator implements BundleActivator
{
+ private AccountService service;
+
+ // Note, the example-serviceloader-impl does NOT register the service itself.
+ // Instead, jboss-osgi-serviceloader generically registeres all services in META-INF/services
public void start(BundleContext context)
{
// Use the traditional ServiceLoader API to get the service
- AccountService service = ServiceLoader.loadService(AccountService.class);
+ service = ServiceLoader.loadService(AccountService.class);
if (service != null)
throw new IllegalStateException("Traditional ServiceLoader API, expected to fail");
-
- // Get the registered service.
- // Note, the example-serviceloader-impl does NOT register the service itself.
- // Instead, jboss-osgi-serviceloader generically registeres all services in META-INF/services
-
+
+ checkStaticServiceAccess(context);
+
+ checkDynamicServiceAccess(context);
+ }
+
+ public void stop(BundleContext context)
+ {
+ if (service == null)
+ throw new IllegalStateException("ServiceTracker could not obtain the service");
+ }
+
+ private void checkStaticServiceAccess(BundleContext context)
+ {
ServiceReference[] srefs = null;
try
{
@@ -61,11 +78,31 @@
}
if (srefs == null || srefs.length != 1)
throw new IllegalStateException("Cannot obtain service");
-
- service = (AccountService)context.getService(srefs[0]);
}
- public void stop(BundleContext context)
+ private void checkDynamicServiceAccess(BundleContext context)
{
+ Filter filter = null;
+ try
+ {
+ String filterstr = "(&(" + Constants.OBJECTCLASS + "=" + AccountService.class.getName() + ")(version=1.0.0))";
+ filter = FrameworkUtil.createFilter(filterstr);
+ }
+ catch (InvalidSyntaxException ex)
+ {
+ throw new IllegalStateException(ex);
+ }
+
+ // Track the service
+ ServiceTracker tracker = new ServiceTracker(context, filter, null)
+ {
+ public Object addingService(ServiceReference reference)
+ {
+ service = (AccountService)super.addingService(reference);
+ return service;
+ }
+ };
+ tracker.open();
}
+
}
\ No newline at end of file
Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-client.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-client.bnd 2010-01-27 12:35:09 UTC (rev 99995)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-client.bnd 2010-01-27 13:47:50 UTC (rev 99996)
@@ -2,6 +2,6 @@
Bundle-SymbolicName: example-serviceloader-client
Bundle-Activator: org.jboss.test.osgi.example.serviceloader.client.ServiceLoaderClientActivator
-Import-Package: org.osgi.framework, org.jboss.osgi.spi.util, org.jboss.test.osgi.example.serviceloader.service
+Import-Package: org.osgi.framework, org.osgi.util.tracker, org.jboss.osgi.spi.util, org.jboss.test.osgi.example.serviceloader.service
Private-Package: org.jboss.test.osgi.example.serviceloader.client
More information about the jboss-cvs-commits
mailing list