[jboss-cvs] JBossAS SVN: r92533 - in projects/jboss-osgi/trunk: reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Aug 18 12:13:50 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-08-18 12:13:49 -0400 (Tue, 18 Aug 2009)
New Revision: 92533

Modified:
   projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/ServiceEventManager.java
   projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/ServiceRegistry.java
   projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleContextImpl.java
   projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceEventManagerImpl.java
   projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceReferenceImpl.java
   projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceRegistryImpl.java
   projects/jboss-osgi/trunk/testsuite/pom.xml
Log:
Basic service registry

Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/ServiceEventManager.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/ServiceEventManager.java	2009-08-18 15:22:46 UTC (rev 92532)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/ServiceEventManager.java	2009-08-18 16:13:49 UTC (rev 92533)
@@ -37,4 +37,6 @@
    void fireServiceEvent(ServiceEvent event);
 
    void addServiceListener(ServiceListener listener);
+
+   void addServiceListener(ServiceListener listener, String filter);
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/ServiceRegistry.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/ServiceRegistry.java	2009-08-18 15:22:46 UTC (rev 92532)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/api/ServiceRegistry.java	2009-08-18 16:13:49 UTC (rev 92533)
@@ -44,4 +44,6 @@
    ServiceReference getServiceReference(String clazz);
 
    ServiceReference[] getServiceReferences(String clazz, String filter);
+
+   Object getService(ServiceReference sref);
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleContextImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleContextImpl.java	2009-08-18 15:22:46 UTC (rev 92532)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/BundleContextImpl.java	2009-08-18 16:13:49 UTC (rev 92533)
@@ -92,7 +92,8 @@
 
    public void addServiceListener(ServiceListener listener, String filter) throws InvalidSyntaxException
    {
-      throw new NotImplementedException();
+      ServiceEventManager eventManager = getFramework().getServiceEventManager();
+      eventManager.addServiceListener(listener, filter);
    }
 
    public Filter createFilter(String filter) throws InvalidSyntaxException
@@ -136,7 +137,8 @@
 
    public Object getService(ServiceReference reference)
    {
-      throw new NotImplementedException();
+      ServiceRegistry serviceRegistry = getFramework().getServiceRegistry();
+      return serviceRegistry.getService(reference);
    }
 
    public ServiceReference getServiceReference(String clazz)

Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceEventManagerImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceEventManagerImpl.java	2009-08-18 15:22:46 UTC (rev 92532)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceEventManagerImpl.java	2009-08-18 16:13:49 UTC (rev 92533)
@@ -56,11 +56,16 @@
       for (ServiceListener listener : listeners)
          listener.serviceChanged(event);
       
-      // [TODO] ServiceEvent object delivery to ServiceListener  objects is filtered
+      // [TODO] ServiceEvent object delivery to ServiceListener objects is filtered
    }
 
    public void addServiceListener(ServiceListener listener)
    {
       listeners.add(listener);
    }
+
+   public void addServiceListener(ServiceListener listener, String filter)
+   {
+      listeners.add(listener);
+   }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceReferenceImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceReferenceImpl.java	2009-08-18 15:22:46 UTC (rev 92532)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceReferenceImpl.java	2009-08-18 16:13:49 UTC (rev 92533)
@@ -45,14 +45,32 @@
    final Logger log = Logger.getLogger(ServiceReferenceImpl.class);
 
    private Bundle bundle;
+   private Object service;
    private Dictionary<String, String> properties;
+   private boolean unregistered;
    
-   public ServiceReferenceImpl(Bundle bundle, Dictionary<String, String> properties)
+   public ServiceReferenceImpl(Bundle bundle, Object service, Dictionary<String, String> properties)
    {
       this.bundle = bundle;
+      this.service = service;
       this.properties = properties;
    }
 
+   public boolean isUnregistered()
+   {
+      return unregistered;
+   }
+
+   public void setUnregistered(boolean unregistered)
+   {
+      this.unregistered = unregistered;
+   }
+
+   public Object getService()
+   {
+      return service;
+   }
+   
    public int compareTo(Object reference)
    {
       throw new NotImplementedException();

Modified: projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceRegistryImpl.java
===================================================================
--- projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceRegistryImpl.java	2009-08-18 15:22:46 UTC (rev 92532)
+++ projects/jboss-osgi/trunk/reactor/runtime/jbossmc/src/main/java/org/jboss/osgi/jbossmc/framework/ServiceRegistryImpl.java	2009-08-18 16:13:49 UTC (rev 92533)
@@ -23,8 +23,10 @@
 
 //$Id: SystemBundleContext.java 91789 2009-07-29 20:49:03Z thomas.diesler at jboss.com $
 
+import java.util.ArrayList;
 import java.util.Dictionary;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.jboss.logging.Logger;
@@ -48,7 +50,7 @@
    // Provide logging
    final Logger log = Logger.getLogger(ServiceRegistryImpl.class);
    
-   private Map<String, ServiceReference> registry = new HashMap<String, ServiceReference>();
+   private Map<String, List<ServiceReference>> registry = new HashMap<String, List<ServiceReference>>();
    private FrameworkImpl framework;
 
    public ServiceRegistryImpl(FrameworkImpl framework)
@@ -68,18 +70,58 @@
 
    public ServiceReference getServiceReference(String clazz)
    {
+      ServiceReference sref = null;
+      
       // [TODO] If multiple such services exist, the service with the highest ranking (as specified in its Constants.SERVICE_RANKING property) is returned.
 
       // [TODO] If there is a tie in ranking, the service with the lowest service ID (as specified in its Constants.SERVICE_ID property); that is, the service that was registered first is returned. 
       
-      return registry.get(clazz);
+      List<ServiceReference> srefs = registry.get(clazz);
+      if (srefs != null && srefs.size() > 0)
+         sref = srefs.iterator().next();
+      
+      return sref;
    }
    
    public ServiceReference[] getServiceReferences(String clazz, String filter)
    {
-      throw new NotImplementedException();
+      ServiceReference[] srefArr = null;
+      
+      // [TODO] The result is an array of ServiceReference objects for all services that meet all of the following conditions:
+      //   * If the specified class name, clazz, is not null, the service must have been registered with the specified class name. The complete list of class names with which a service was registered is available from the service's objectClass property.
+      //   * If the specified filter is not null, the filter expression must match the service.
+      //   * If the Java Runtime Environment supports permissions, the caller must have ServicePermission with the GET action for at least one of the class names under which the service was registered.
+      //   * For each class name with which the service was registered, calling ServiceReference.isAssignableTo(Bundle, String) with the context bundle and the class name on the service's ServiceReference object must return true
+      
+      List<ServiceReference> srefs = registry.get(clazz);
+      if (srefs != null)
+      {
+         srefArr = new ServiceReference[srefs.size()];
+         srefs.toArray(srefArr);
+      }
+      return srefArr;   
    }
 
+   public Object getService(ServiceReference sref)
+   {
+      ServiceReferenceImpl srefImpl = (ServiceReferenceImpl)sref;
+      
+      // If the service has been unregistered, null is returned.
+      if (srefImpl.isUnregistered())
+         return null;
+      
+      // [TODO] The context bundle's use count for this service is incremented by one.
+      
+      // [TODO] The service was registered with an object implementing the ServiceFactory interface
+      Object service = srefImpl.getService();
+      if (service instanceof ServiceFactory)
+         throw new NotImplementedException("Get service from a ServiceFactory");
+      
+      // The service object for the service is returned.
+      
+      return service;
+   }
+   
    private ServiceRegistration registerServiceInternal(Bundle bundle, String clazz, Object service, Dictionary properties)
    {
       // If service is not a ServiceFactory, an IllegalArgumentException is thrown if service 
@@ -98,20 +140,26 @@
          }
       }
       
-      ServiceReferenceImpl serviceRef = new ServiceReferenceImpl(bundle, properties);
+      ServiceReferenceImpl sref = new ServiceReferenceImpl(bundle, service, properties);
       
       // 2. The Framework adds the following service properties to the service properties from the specified Dictionary (which may be null):
       //    A property named Constants.SERVICE_ID identifying the registration number of the service
       //    A property named Constants.OBJECTCLASS containing all the specified classes.
       
       // 3. The service is added to the Framework service registry and may now be used by other bundles.
-      registry.put(clazz, serviceRef);
+      List<ServiceReference> list = registry.get(clazz);
+      if (list == null)
+      {
+         list = new ArrayList<ServiceReference>();
+         registry.put(clazz, list);
+      }
+      list.add(sref);
       
       // 4. A service event of type ServiceEvent.REGISTERED is fired.
       ServiceEventManager eventManager = framework.getServiceEventManager();
-      eventManager.fireServiceEvent(new ServiceEvent(ServiceEvent.REGISTERED, serviceRef));
+      eventManager.fireServiceEvent(new ServiceEvent(ServiceEvent.REGISTERED, sref));
       
       // 5. A ServiceRegistration object for this registration is returned.
-      return new ServiceRegistrationImpl(serviceRef);
+      return new ServiceRegistrationImpl(sref);
    }
 }
\ No newline at end of file

Modified: projects/jboss-osgi/trunk/testsuite/pom.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/pom.xml	2009-08-18 15:22:46 UTC (rev 92532)
+++ projects/jboss-osgi/trunk/testsuite/pom.xml	2009-08-18 16:13:49 UTC (rev 92533)
@@ -68,24 +68,64 @@
       <artifactId>org.apache.felix.configadmin</artifactId>
       <version>${version.apache.felix.configadmin}</version>
       <scope>provided</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>org.apache.felix</groupId>
+          <artifactId>org.osgi.core</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.apache.felix</groupId>
+          <artifactId>org.osgi.compendium</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.apache.felix</groupId>
       <artifactId>org.apache.felix.http.jetty</artifactId>
       <version>${version.apache.felix.http.jetty}</version>
       <scope>provided</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>org.apache.felix</groupId>
+          <artifactId>org.osgi.core</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.apache.felix</groupId>
+          <artifactId>org.osgi.compendium</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.apache.felix</groupId>
       <artifactId>org.apache.felix.log</artifactId>
       <version>${version.apache.felix.log}</version>
       <scope>provided</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>org.apache.felix</groupId>
+          <artifactId>org.osgi.core</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.apache.felix</groupId>
+          <artifactId>org.osgi.compendium</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.apache.felix</groupId>
       <artifactId>org.apache.felix.metatype</artifactId>
       <version>${version.apache.felix.metatype}</version>
       <scope>provided</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>org.apache.felix</groupId>
+          <artifactId>org.osgi.core</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.apache.felix</groupId>
+          <artifactId>org.osgi.compendium</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.jboss.osgi.bundles</groupId>
@@ -105,7 +145,7 @@
       <version>${version.jboss.osgi.common}</version>
       <scope>provided</scope>
     </dependency>
-    
+
     <!-- Test Dependencies -->
     <dependency>
       <groupId>junit</groupId>
@@ -150,18 +190,6 @@
           <version>${version.jboss.osgi.runtime.felix}</version>
           <scope>provided</scope>
         </dependency>
-        <dependency>
-          <groupId>org.apache.felix</groupId>
-          <artifactId>org.osgi.core</artifactId>
-          <version>${version.apache.felix.core}</version>
-          <scope>provided</scope>
-        </dependency>
-        <dependency>
-          <groupId>org.apache.felix</groupId>
-          <artifactId>org.osgi.compendium</artifactId>
-          <version>${version.apache.felix.core}</version>
-          <scope>provided</scope>
-        </dependency>
       </dependencies>
     </profile>
 
@@ -184,18 +212,6 @@
           <version>${version.jboss.osgi.runtime.felix}</version>
           <scope>provided</scope>
         </dependency>
-        <dependency>
-          <groupId>org.apache.felix</groupId>
-          <artifactId>org.osgi.core</artifactId>
-          <version>${version.apache.felix.core}</version>
-          <scope>provided</scope>
-        </dependency>
-        <dependency>
-          <groupId>org.apache.felix</groupId>
-          <artifactId>org.osgi.compendium</artifactId>
-          <version>${version.apache.felix.core}</version>
-          <scope>provided</scope>
-        </dependency>
       </dependencies>
     </profile>
 




More information about the jboss-cvs-commits mailing list