cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1482773 - in /cxf/dosgi/trunk/dsw/cxf-topology-manager/src: main/java/org/apache/cxf/dosgi/topologymanager/exporter/ test/java/org/apache/cxf/dosgi/topologymanager/exporter/
Date Wed, 15 May 2013 11:42:49 GMT
Author: cschneider
Date: Wed May 15 11:42:48 2013
New Revision: 1482773

URL: http://svn.apache.org/r1482773
Log:
DOSGI-180 Changing TopologyManager to use EndpointDescription instead of ExportRegistration

Added:
    cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointRepository.java
  (with props)
Removed:
    cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/ExportRepository.java
Modified:
    cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java
    cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java
    cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifierTest.java

Modified: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java?rev=1482773&r1=1482772&r2=1482773&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifier.java
Wed May 15 11:42:48 2013
@@ -43,24 +43,24 @@ public class EndpointListenerNotifier {
     private static final Logger LOG = LoggerFactory.getLogger(EndpointListenerNotifier.class);
     private BundleContext bctx;
     private ServiceTracker stEndpointListeners;
-    private ExportRepository exportRepository;
+    private EndpointRepository exportRepository;
 
-    public EndpointListenerNotifier(BundleContext bctx, ExportRepository exportRepository)
{
+    public EndpointListenerNotifier(BundleContext bctx, EndpointRepository exportRepository)
{
         this.bctx = bctx;
         this.exportRepository = exportRepository;
         this.stEndpointListeners = new ServiceTracker(bctx, EndpointListener.class.getName(),
null) {
             @Override
-            public Object addingService(ServiceReference reference) {
+            public Object addingService(ServiceReference epListenerRef) {
                 LOG.debug("new EndpointListener detected");
-                notifyListenerOfAllExistingExports(reference);
-                return super.addingService(reference);
+                notifyListenerOfAllExistingExports(epListenerRef);
+                return super.addingService(epListenerRef);
             }
 
             @Override
-            public void modifiedService(ServiceReference reference, Object service) {
+            public void modifiedService(ServiceReference epListenerRef, Object service) {
                 LOG.debug("EndpointListener modified");
-                notifyListenerOfAllExistingExports(reference);
-                super.modifiedService(reference, service);
+                notifyListenerOfAllExistingExports(epListenerRef);
+                super.modifiedService(epListenerRef, service);
             }
 
         };
@@ -77,27 +77,27 @@ public class EndpointListenerNotifier {
     
     private void notifyListenerOfAllExistingExports(
             ServiceReference reference) {
-        Collection<ExportRegistration> registrations = exportRepository.getAllExportRegistrations();
+        Collection<EndpointDescription> registrations = exportRepository.getAllEndpoints();
         notifyListenerOfAdding(reference, registrations);
     }
     
-    void nofifyEndpointListenersOfAdding(Collection<ExportRegistration> exportRegistrations)
{
+    void nofifyEndpointListenersOfAdding(Collection<EndpointDescription> endpoints)
{
         ServiceReference[] epListeners = getEndpointListeners(bctx);
-        for (ServiceReference sref : epListeners) {
-            notifyListenerOfAdding(sref, exportRegistrations);
+        for (ServiceReference eplistener : epListeners) {
+            notifyListenerOfAdding(eplistener, endpoints);
         }
     }
     
-    void notifyAllListenersOfRemoval(Collection<ExportRegistration> endpoints) {
+    void notifyAllListenersOfRemoval(Collection<EndpointDescription> endpoints) {
         ServiceReference[] refs = getEndpointListeners(bctx);
         for (ServiceReference epListenerReference : refs) {
             notifyListenersOfRemoval(epListenerReference, endpoints);
         }
     }
     
-    void notifyListenersOfRemoval(Collection<ExportRegistration> registrations) {
+    void notifyListenersOfRemoval(Collection<EndpointDescription> endpoints) {
         for (ServiceReference epListenerReference : stEndpointListeners.getServiceReferences())
{
-            notifyListenersOfRemoval(epListenerReference, registrations);
+            notifyListenersOfRemoval(epListenerReference, endpoints);
         }
     }
     
@@ -105,16 +105,15 @@ public class EndpointListenerNotifier {
      * Notifies the listener if he is interested in the provided registrations
      * 
      * @param sref The ServiceReference for an EndpointListener
-     * @param exportRegistrations the registrations, the listener should be informed about
+     * @param endpoints the registrations, the listener should be informed about
      */
     private void notifyListenerOfAdding(ServiceReference epListenerReference,
-                                        Collection<ExportRegistration> exportRegistrations)
{
+                                        Collection<EndpointDescription> endpoints)
{
         EndpointListener epl = (EndpointListener)bctx.getService(epListenerReference);
         List<Filter> filters = getFiltersFromEndpointListenerScope(epListenerReference,
bctx);
 
         LOG.debug("notifyListenerOfAdding");
-        for (ExportRegistration exReg : exportRegistrations) {
-            EndpointDescription endpoint = getExportedEndpoint(exReg);
+        for (EndpointDescription endpoint : endpoints) {
             List<Filter> matchingFilters = getMatchingFilters(filters, endpoint);
             for (Filter filter : matchingFilters) {
                 epl.endpointAdded(endpoint, filter.toString());
@@ -124,11 +123,10 @@ public class EndpointListenerNotifier {
     }
 
     void notifyListenersOfRemoval(ServiceReference epListenerReference,
-                                          Collection<ExportRegistration> exportRegistrations)
{
+                                          Collection<EndpointDescription> endpoints)
{
         EndpointListener epl = (EndpointListener)bctx.getService(epListenerReference);
         List<Filter> filters = getFiltersFromEndpointListenerScope(epListenerReference,
bctx);
-        for (ExportRegistration exReg : exportRegistrations) {
-            EndpointDescription endpoint = getExportedEndpoint(exReg);
+        for (EndpointDescription endpoint : endpoints) {
             List<Filter> matchingFilters = getMatchingFilters(filters, endpoint);
             for (Filter filter : matchingFilters) {
                 epl.endpointRemoved(endpoint, filter.toString());
@@ -205,16 +203,6 @@ public class EndpointListenerNotifier {
     }
    
     /**
-     * Retrieve exported Endpoint while handling null
-     * @param exReg
-     * @return exported Endpoint or null if not present
-     */
-    private EndpointDescription getExportedEndpoint(ExportRegistration exReg) {
-        ExportReference ref = (exReg == null) ? null : exReg.getExportReference();
-        return (ref == null) ? null : ref.getExportedEndpoint(); 
-    }
-   
-    /**
      * Retrieve endpoint properties as Dictionary
      * 
      * @param ep

Added: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointRepository.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointRepository.java?rev=1482773&view=auto
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointRepository.java
(added)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointRepository.java
Wed May 15 11:42:48 2013
@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.dosgi.topologymanager.exporter;
+
+import java.util.Collection;
+
+import org.osgi.service.remoteserviceadmin.EndpointDescription;
+
+public interface EndpointRepository {
+    Collection<EndpointDescription> getAllEndpoints();
+}

Propchange: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointRepository.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java?rev=1482773&r1=1482772&r2=1482773&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java
Wed May 15 11:42:48 2013
@@ -36,6 +36,7 @@ import org.osgi.framework.InvalidSyntaxE
 import org.osgi.framework.ServiceEvent;
 import org.osgi.framework.ServiceListener;
 import org.osgi.framework.ServiceReference;
+import org.osgi.service.remoteserviceadmin.EndpointDescription;
 import org.osgi.service.remoteserviceadmin.ExportReference;
 import org.osgi.service.remoteserviceadmin.ExportRegistration;
 import org.osgi.service.remoteserviceadmin.RemoteConstants;
@@ -48,7 +49,7 @@ import org.slf4j.LoggerFactory;
  * <li>This class keeps a list of currently imported and exported endpoints <li>It
requests the import/export
  * from RemoteAdminServices
  */
-public class TopologyManagerExport implements ExportRepository {
+public class TopologyManagerExport implements EndpointRepository {
 
     private static final Logger LOG = LoggerFactory.getLogger(TopologyManagerExport.class);
 
@@ -76,8 +77,8 @@ public class TopologyManagerExport imple
      * </pre>
      */
     private final Map<ServiceReference, 
-                      Map<RemoteServiceAdmin, Collection<ExportRegistration>>>
exportedServices = 
-        new LinkedHashMap<ServiceReference, Map<RemoteServiceAdmin, Collection<ExportRegistration>>>();
+                      Map<RemoteServiceAdmin, Collection<EndpointDescription>>>
exportedServices = 
+        new LinkedHashMap<ServiceReference, Map<RemoteServiceAdmin, Collection<EndpointDescription>>>();
 
     public TopologyManagerExport(BundleContext ctx, RemoteServiceAdminTracker rsaTracker)
{
         execService = new ThreadPoolExecutor(5, 10, 50, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
@@ -112,6 +113,16 @@ public class TopologyManagerExport imple
     }
     
     /**
+     * Retrieve exported Endpoint while handling null
+     * @param exReg
+     * @return exported Endpoint or null if not present
+     */
+    private EndpointDescription getExportedEndpoint(ExportRegistration exReg) {
+        ExportReference ref = (exReg == null) ? null : exReg.getExportReference();
+        return (ref == null) ? null : ref.getExportedEndpoint(); 
+    }
+    
+    /**
      * checks if a Service is intended to be exported
      */
     private boolean shouldExportService(ServiceReference sref) {
@@ -127,10 +138,10 @@ public class TopologyManagerExport imple
      */
     protected void removeRemoteServiceAdmin(RemoteServiceAdmin rsa) {
         synchronized (exportedServices) {
-            for (Map<RemoteServiceAdmin, Collection<ExportRegistration>> exports
: exportedServices
+            for (Map<RemoteServiceAdmin, Collection<EndpointDescription>> exports
: exportedServices
                 .values()) {
                 if (exports.containsKey(rsa)) {
-                    Collection<ExportRegistration> endpoints = exports.get(rsa);
+                    Collection<EndpointDescription> endpoints = exports.get(rsa);
                     this.epListenerNotifier.notifyAllListenersOfRemoval(endpoints);
                     exports.remove(rsa);
                 }
@@ -143,7 +154,7 @@ public class TopologyManagerExport imple
 
         synchronized (exportedServices) {
             for (ServiceReference serviceRef : exportedServices.keySet()) {
-                Map<RemoteServiceAdmin, Collection<ExportRegistration>> rsaExports
= exportedServices.get(serviceRef);
+                Map<RemoteServiceAdmin, Collection<EndpointDescription>> rsaExports
= exportedServices.get(serviceRef);
                 String bundleName = serviceRef.getBundle().getSymbolicName();
                 if (rsaExports.containsKey(rsa)) {
                     // already handled....
@@ -179,16 +190,11 @@ public class TopologyManagerExport imple
     void removeService(ServiceReference sref) {
         synchronized (exportedServices) {
             if (exportedServices.containsKey(sref)) {
-                Map<RemoteServiceAdmin, Collection<ExportRegistration>> rsas
= exportedServices.get(sref);
-                for (Map.Entry<RemoteServiceAdmin, Collection<ExportRegistration>>
entry : rsas.entrySet()) {
+                Map<RemoteServiceAdmin, Collection<EndpointDescription>> rsas
= exportedServices.get(sref);
+                for (Map.Entry<RemoteServiceAdmin, Collection<EndpointDescription>>
entry : rsas.entrySet()) {
                     if (entry.getValue() != null) {
-                        Collection<ExportRegistration> registrations = entry.getValue();
+                        Collection<EndpointDescription> registrations = entry.getValue();
                         this.epListenerNotifier.notifyListenersOfRemoval(registrations);
-                        for (ExportRegistration exReg : registrations) {
-                            if (exReg != null) {
-                                exReg.close();
-                            }
-                        }
                     }
                 }
 
@@ -203,7 +209,7 @@ public class TopologyManagerExport imple
             LOG.info("TopologyManager: adding service to exportedServices list to export
it --- from bundle:  "
                       + sref.getBundle().getSymbolicName());
             exportedServices.put(sref,
-                                 new LinkedHashMap<RemoteServiceAdmin, Collection<ExportRegistration>>());
+                                 new LinkedHashMap<RemoteServiceAdmin, Collection<EndpointDescription>>());
         }
         triggerExport(sref);
     }
@@ -219,7 +225,7 @@ public class TopologyManagerExport imple
     private void doExportService(final ServiceReference sref) {
         LOG.debug("Exporting service");
 
-        Map<RemoteServiceAdmin, Collection<ExportRegistration>> exports = null;
+        Map<RemoteServiceAdmin, Collection<EndpointDescription>> exports = null;
 
         synchronized (exportedServices) {
             exports = Collections.synchronizedMap(exportedServices.get(sref));
@@ -247,13 +253,17 @@ public class TopologyManagerExport imple
             } else {
                 // TODO: additional parameter Map ?
                 LOG.debug("exporting ...");
-                Collection<ExportRegistration> endpoints = remoteServiceAdmin
+                Collection<ExportRegistration> exportRegs = remoteServiceAdmin
                         .exportService(sref, null);
-                if (endpoints == null) {
+                if (exportRegs == null) {
                     // TODO export failed -> What should be done here?
                     LOG.error("export failed");
                     exports.put(remoteServiceAdmin, null);
                 } else {
+                	List<EndpointDescription> endpoints = new ArrayList<EndpointDescription>();
+                	for (ExportRegistration exportReg : exportRegs) {
+						endpoints.add(getExportedEndpoint(exportReg));
+					}
                     LOG.info("TopologyManager: export sucessful Endpoints: {}", endpoints);
                     // enqueue in local list of endpoints
                     exports.put(remoteServiceAdmin, endpoints);
@@ -264,11 +274,11 @@ public class TopologyManagerExport imple
         }
     }
     
-    public Collection<ExportRegistration> getAllExportRegistrations() {
-        List<ExportRegistration> registrations = new ArrayList<ExportRegistration>();
+    public Collection<EndpointDescription> getAllEndpoints() {
+        List<EndpointDescription> registrations = new ArrayList<EndpointDescription>();
         synchronized (exportedServices) {
-            for (Map<RemoteServiceAdmin, Collection<ExportRegistration>> exports
: exportedServices.values()) {
-                for (Collection<ExportRegistration> regs : exports.values()) {
+            for (Map<RemoteServiceAdmin, Collection<EndpointDescription>> exports
: exportedServices.values()) {
+                for (Collection<EndpointDescription> regs : exports.values()) {
                     if (regs != null) {
                         registrations.addAll(regs);
                     }
@@ -294,9 +304,9 @@ public class TopologyManagerExport imple
         if (sref != null) {
             synchronized (exportedServices) {
 
-                Map<RemoteServiceAdmin, Collection<ExportRegistration>> ex =
exportedServices.get(sref);
+                Map<RemoteServiceAdmin, Collection<EndpointDescription>> ex =
exportedServices.get(sref);
                 if (ex != null) {
-                    for (Map.Entry<RemoteServiceAdmin, Collection<ExportRegistration>>
export : ex.entrySet()) {
+                    for (Map.Entry<RemoteServiceAdmin, Collection<EndpointDescription>>
export : ex.entrySet()) {
                         export.getValue().contains(exportRegistration);
                     }
                 }

Modified: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifierTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifierTest.java?rev=1482773&r1=1482772&r2=1482773&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifierTest.java
(original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/EndpointListenerNotifierTest.java
Wed May 15 11:42:48 2013
@@ -19,6 +19,8 @@
 package org.apache.cxf.dosgi.topologymanager.exporter;
 
 
+import static org.junit.Assert.assertEquals;
+
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -36,10 +38,6 @@ import org.osgi.framework.InvalidSyntaxE
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.remoteserviceadmin.EndpointDescription;
 import org.osgi.service.remoteserviceadmin.EndpointListener;
-import org.osgi.service.remoteserviceadmin.ExportReference;
-import org.osgi.service.remoteserviceadmin.ExportRegistration;
-
-import static org.junit.Assert.assertEquals;
 
 public class EndpointListenerNotifierTest {
 
@@ -50,14 +48,9 @@ public class EndpointListenerNotifierTes
 
         BundleContext bc = c.createMock(BundleContext.class);
         ServiceReference sref = c.createMock(ServiceReference.class);
-        ExportRegistration exReg = c.createMock(ExportRegistration.class);
-        ExportRegistration exReg2 = c.createMock(ExportRegistration.class);
         EndpointListener epl = EasyMock.createMock(EndpointListener.class);
         EndpointDescription epd = c.createMock(EndpointDescription.class);
         EndpointDescription epd2 = c.createMock(EndpointDescription.class);
-        ExportReference exRef = c.createMock(ExportReference.class);
-        ExportReference exRef2 = c.createMock(ExportReference.class);
-        
         
         Map<String, Object> props = new HashMap<String, Object>();
         String[] oc = new String[1];
@@ -80,19 +73,14 @@ public class EndpointListenerNotifierTes
             .andReturn("(objectClass=myClass)").anyTimes();
 
         
-        EasyMock.expect(exReg.getExportReference()).andReturn(exRef).anyTimes();
-        EasyMock.expect(exRef.getExportedEndpoint()).andReturn(epd).anyTimes();
         EasyMock.expect(epd.getProperties()).andReturn(props).anyTimes();
-        
-        EasyMock.expect(exReg2.getExportReference()).andReturn(exRef2).anyTimes();
-        EasyMock.expect(exRef2.getExportedEndpoint()).andReturn(epd2).anyTimes();
         EasyMock.expect(epd2.getProperties()).andReturn(props2).anyTimes();
         
         // must only be called for the first EndpointDestription ! 
         epl.endpointRemoved(EasyMock.eq(epd), EasyMock.eq("(objectClass=myClass)"));
         EasyMock.expectLastCall().once();
         
-        ExportRepository exportRepository = EasyMock.createMock(ExportRepository.class);
+        EndpointRepository exportRepository = EasyMock.createMock(EndpointRepository.class);
         
         c.replay();
         EasyMock.replay(epl);
@@ -101,11 +89,11 @@ public class EndpointListenerNotifierTes
         EndpointListenerNotifier tm = new EndpointListenerNotifier(bc, exportRepository);
 
 
-        List<ExportRegistration> exRegs = new ArrayList<ExportRegistration>();
-        exRegs.add(exReg);
-        exRegs.add(exReg2);
+        List<EndpointDescription> endpoints = new ArrayList<EndpointDescription>();
+        endpoints.add(epd);
+        endpoints.add(epd2);
 
-        tm.notifyListenersOfRemoval(sref, exRegs);
+        tm.notifyListenersOfRemoval(sref, endpoints);
 
         c.verify();
         EasyMock.verify(epl);



Mime
View raw message