[jboss-cvs] JBossAS SVN: r99944 - in projects/jboss-osgi/trunk: testsuite and 9 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jan 26 10:27:43 EST 2010


Author: thomas.diesler at jboss.com
Date: 2010-01-26 10:27:43 -0500 (Tue, 26 Jan 2010)
New Revision: 99944

Added:
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/ServiceLoaderTestCase.java
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/client/
   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/service/
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/service/AccountService.java
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/service/internal/
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/service/internal/AccountServiceImpl.java
   projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/services/org.jboss.test.osgi.example.serviceloader.service.AccountService
   projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/
   projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-api.bnd
   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-impl.bnd
Modified:
   projects/jboss-osgi/trunk/pom.xml
   projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml
   projects/jboss-osgi/trunk/testsuite/example/scripts/assembly-bundles.xml
   projects/jboss-osgi/trunk/testsuite/pom.xml
Log:
Add serviceloader example

Modified: projects/jboss-osgi/trunk/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/pom.xml	2010-01-26 15:26:29 UTC (rev 99943)
+++ projects/jboss-osgi/trunk/pom.xml	2010-01-26 15:27:43 UTC (rev 99944)
@@ -69,6 +69,7 @@
     <version.jboss.osgi.runtime.equinox>3.5.1</version.jboss.osgi.runtime.equinox>
     <version.jboss.osgi.runtime.felix>2.0.2</version.jboss.osgi.runtime.felix>
     <version.jboss.osgi.runtime.jbossas>1.0.2</version.jboss.osgi.runtime.jbossas>
+    <version.jboss.osgi.serviceloader>1.0.0-SNAPSHOT</version.jboss.osgi.serviceloader>
     <version.jboss.osgi.spi>1.0.4-SNAPSHOT</version.jboss.osgi.spi>
     <version.jboss.osgi.webapp>0.7.2</version.jboss.osgi.webapp>
     <version.jboss.osgi.webconsole>1.0.2</version.jboss.osgi.webconsole>
@@ -169,6 +170,11 @@
       </dependency>
       <dependency>
         <groupId>org.jboss.osgi.bundles</groupId>
+        <artifactId>jboss-osgi-serviceloader</artifactId>
+        <version>${version.jboss.osgi.serviceloader}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.jboss.osgi.bundles</groupId>
         <artifactId>jboss-osgi-webapp</artifactId>
         <version>${version.jboss.osgi.webapp}</version>
       </dependency>

Modified: projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml	2010-01-26 15:26:29 UTC (rev 99943)
+++ projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml	2010-01-26 15:27:43 UTC (rev 99944)
@@ -67,6 +67,11 @@
     <!-- mcservice -->
     <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example-mcservice-bundleA.jar" files="${tests.resources.dir}/mcservice/example-mcservice-bundleA.bnd" />
   	
+    <!-- serviceloader -->
+    <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example-serviceloader-api.jar" files="${tests.resources.dir}/serviceloader/example-serviceloader-api.bnd" />
+    <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example-serviceloader-client.jar" files="${tests.resources.dir}/serviceloader/example-serviceloader-client.bnd" />
+    <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example-serviceloader-impl.jar" files="${tests.resources.dir}/serviceloader/example-serviceloader-impl.bnd" />
+    
     <!-- simple -->
     <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example-simple.jar" files="${tests.resources.dir}/simple/example-simple.bnd" />
     <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example-simple-husky.jar" files="${tests.resources.dir}/simple/example-simple-husky.bnd" />

Modified: projects/jboss-osgi/trunk/testsuite/example/scripts/assembly-bundles.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/scripts/assembly-bundles.xml	2010-01-26 15:26:29 UTC (rev 99943)
+++ projects/jboss-osgi/trunk/testsuite/example/scripts/assembly-bundles.xml	2010-01-26 15:27:43 UTC (rev 99944)
@@ -25,6 +25,7 @@
         <include>*:jboss-osgi-jndi:jar</include>
         <include>*:jboss-osgi-jta:jar</include>
         <include>*:jboss-osgi-reflect:jar</include>
+        <include>*:jboss-osgi-serviceloader:jar</include>
         <include>*:jboss-osgi-webapp:jar</include>
         <include>*:jboss-osgi-xml-binding:jar</include>
         <include>*:org.apache.aries.blueprint:jar</include>

Added: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/ServiceLoaderTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/ServiceLoaderTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/ServiceLoaderTestCase.java	2010-01-26 15:27:43 UTC (rev 99944)
@@ -0,0 +1,102 @@
+/*
+ * 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.example.serviceloader;
+
+//$Id$
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import org.jboss.osgi.serviceloader.ServiceLoaderCapability;
+import org.jboss.osgi.spi.util.ServiceLoader;
+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.jboss.test.osgi.example.serviceloader.service.AccountService;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+
+/**
+ * A test that deployes a bundle and verifies its state
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 26-Jan-2010
+ */
+public class ServiceLoaderTestCase extends OSGiTest
+{
+   @Test
+   public void testTraditionalServiceLoaderAPI() throws Exception
+   {
+      // Use the traditional ServiceLoader API to get the service
+      AccountService service = ServiceLoader.loadService(AccountService.class);
+      assertNotNull("AccountService loaded", service);
+      
+      assertEquals(0, service.getBalance());
+      assertEquals(100, service.credit(100));
+      assertEquals(80, service.withdraw(20));
+      
+      try
+      {
+         service.withdraw(100);
+         fail("Insuffient funds expected");
+      }
+      catch (RuntimeException e)
+      {
+         assertEquals(80, service.getBalance());
+      }
+   }
+
+   @Test
+   public void testOSGiServiceAPI() throws Exception
+   {
+      // Get the default runtime
+      OSGiRuntime runtime = getDefaultRuntime();
+      runtime.addCapability(new ServiceLoaderCapability());
+      
+      try
+      {
+         // Install the API bundle
+         runtime.installBundle("example-serviceloader-api.jar");
+         
+         // Install/Start the client bundle
+         OSGiBundle implBundle = runtime.installBundle("example-serviceloader-impl.jar");
+         implBundle.start();
+         
+         // Install/Start the client bundle
+         OSGiBundle clientBundle = runtime.installBundle("example-serviceloader-client.jar");
+         clientBundle.start();
+         
+         OSGiServiceReference sref = runtime.getServiceReference(AccountService.class.getName());
+         assertNotNull("AccountService available", sref);
+         
+         assertBundleState(Bundle.ACTIVE, implBundle.getState());
+         assertBundleState(Bundle.ACTIVE, clientBundle.getState());
+      }
+      finally
+      {
+         // Shutdown the runtime 
+         runtime.shutdown();
+      }
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/ServiceLoaderTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: 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	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/client/ServiceLoaderClientActivator.java	2010-01-26 15:27:43 UTC (rev 99944)
@@ -0,0 +1,57 @@
+/*
+ * 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.example.serviceloader.client;
+
+//$Id$
+
+import org.jboss.osgi.spi.util.ServiceLoader;
+import org.jboss.test.osgi.example.serviceloader.service.AccountService;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * A Service Activator
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 26-Jan-2010
+ */
+public class ServiceLoaderClientActivator implements BundleActivator
+{
+   public void start(BundleContext context)
+   {
+      // Use the traditional ServiceLoader API to get the service
+      AccountService 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  
+      ServiceReference sref = context.getServiceReference(AccountService.class.getName());
+      service = (AccountService)context.getService(sref);
+   }
+
+   public void stop(BundleContext context)
+   {
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/client/ServiceLoaderClientActivator.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/service/AccountService.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/service/AccountService.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/service/AccountService.java	2010-01-26 15:27:43 UTC (rev 99944)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.osgi.example.serviceloader.service;
+
+//$Id$
+
+/**
+ * A simple bank account service 
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 26-Jan-2010
+ */
+public interface AccountService
+{
+   /** Get the current balance */
+   long getBalance();
+
+   /** Credit the given amount and return the current balance */
+   long credit(long amount);
+
+   /** Withdraw the given amount and return the current balance */
+   long withdraw(long amount);
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/service/AccountService.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/service/internal/AccountServiceImpl.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/service/internal/AccountServiceImpl.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/service/internal/AccountServiceImpl.java	2010-01-26 15:27:43 UTC (rev 99944)
@@ -0,0 +1,57 @@
+/*
+ * 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.example.serviceloader.service.internal;
+
+import org.jboss.test.osgi.example.serviceloader.service.AccountService;
+
+//$Id$
+
+/**
+ * A simple bank account service 
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 26-Jan-2010
+ */
+public class AccountServiceImpl implements AccountService
+{
+   private long balance;
+
+   public long credit(long amount)
+   {
+      balance += amount;
+      return balance;
+   }
+
+   public long getBalance()
+   {
+      return balance;
+   }
+
+   public long withdraw(long amount)
+   {
+      if (balance - amount < 0)
+         throw new IllegalArgumentException("Insufficient funds: " + balance);
+      
+      balance -= amount;
+      return balance;
+   }
+}
\ No newline at end of file


Property changes on: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/serviceloader/service/internal/AccountServiceImpl.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/services/org.jboss.test.osgi.example.serviceloader.service.AccountService
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/services/org.jboss.test.osgi.example.serviceloader.service.AccountService	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/META-INF/services/org.jboss.test.osgi.example.serviceloader.service.AccountService	2010-01-26 15:27:43 UTC (rev 99944)
@@ -0,0 +1 @@
+org.jboss.test.osgi.example.serviceloader.service.internal.AccountServiceImpl
\ No newline at end of file

Added: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-api.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-api.bnd	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-api.bnd	2010-01-26 15:27:43 UTC (rev 99944)
@@ -0,0 +1,6 @@
+# bnd build -classpath target/test-classes -output target/test-libs/example-serviceloader-api.jar src/test/resources/example/serviceloader/example-serviceloader-api.bnd
+
+Bundle-SymbolicName: example-serviceloader-api
+
+Export-Package: org.jboss.test.osgi.example.serviceloader.service
+

Added: 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	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-client.bnd	2010-01-26 15:27:43 UTC (rev 99944)
@@ -0,0 +1,7 @@
+# bnd build -classpath target/test-classes -output target/test-libs/example-serviceloader-client.jar src/test/resources/example/serviceloader/example-serviceloader-client.bnd
+
+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
+Private-Package: org.jboss.test.osgi.example.serviceloader.client
+

Added: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-impl.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-impl.bnd	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/serviceloader/example-serviceloader-impl.bnd	2010-01-26 15:27:43 UTC (rev 99944)
@@ -0,0 +1,10 @@
+# bnd build -classpath target/test-classes -output target/test-libs/example-serviceloader-impl.jar src/test/resources/example/serviceloader/example-serviceloader-impl.bnd
+
+Bundle-SymbolicName: example-serviceloader-impl
+
+Import-Package: org.jboss.test.osgi.example.serviceloader.service
+Private-Package: org.jboss.test.osgi.example.serviceloader.service.internal
+Include-Resource: META-INF/services/org.jboss.test.osgi.example.serviceloader.service.AccountService=../META-INF/services/org.jboss.test.osgi.example.serviceloader.service.AccountService
+
+-removeheaders: Include-Resource
+

Modified: projects/jboss-osgi/trunk/testsuite/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/pom.xml	2010-01-26 15:26:29 UTC (rev 99943)
+++ projects/jboss-osgi/trunk/testsuite/pom.xml	2010-01-26 15:27:43 UTC (rev 99944)
@@ -159,16 +159,21 @@
     </dependency>
     <dependency>
       <groupId>org.jboss.osgi.bundles</groupId>
-      <artifactId>jboss-osgi-webapp</artifactId>
+      <artifactId>jboss-osgi-reflect</artifactId>
       <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>org.jboss.osgi.bundles</groupId>
-      <artifactId>jboss-osgi-reflect</artifactId>
+      <artifactId>jboss-osgi-serviceloader</artifactId>
       <scope>provided</scope>
     </dependency>
     <dependency>
       <groupId>org.jboss.osgi.bundles</groupId>
+      <artifactId>jboss-osgi-webapp</artifactId>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.osgi.bundles</groupId>
       <artifactId>jboss-osgi-xml-binding</artifactId>
       <scope>provided</scope>
     </dependency>




More information about the jboss-cvs-commits mailing list