You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by am...@apache.org on 2013/06/02 22:31:10 UTC
svn commit: r1488782 - 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/
Author: amichai
Date: Sun Jun 2 20:31:10 2013
New Revision: 1488782
URL: http://svn.apache.org/r1488782
Log:
DOSGI-171 Fix missing ungetService in EndpointListenerNotifier and unitified duplicate code
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
cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/ExportServiceTest.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=1488782&r1=1488781&r2=1488782&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 Sun Jun 2 20:31:10 2013
@@ -58,14 +58,17 @@ public class EndpointListenerNotifier {
@Override
public Object addingService(ServiceReference epListenerRef) {
LOG.debug("new EndpointListener detected");
- notifyListenerOfAdding(epListenerRef, endpointRepository.getAllEndpoints());
- return super.addingService(epListenerRef);
+ // the super.addingService call must come before notifyListener, since we need
+ // to keep at least one service reference alive when ungetService is called
+ Object service = super.addingService(epListenerRef);
+ notifyListener(true, epListenerRef, endpointRepository.getAllEndpoints());
+ return service;
}
@Override
public void modifiedService(ServiceReference epListenerRef, Object service) {
LOG.debug("EndpointListener modified");
- notifyListenerOfAdding(epListenerRef, endpointRepository.getAllEndpoints());
+ notifyListener(true, epListenerRef, endpointRepository.getAllEndpoints());
super.modifiedService(epListenerRef, service);
}
@@ -80,53 +83,48 @@ public class EndpointListenerNotifier {
public void stop() {
stEndpointListeners.close();
}
-
- void notifyListenersOfAdding(Collection<EndpointDescription> endpoints) {
- ServiceReference[] listeners = stEndpointListeners.getServiceReferences();
- if (listeners != null) {
- for (ServiceReference eplistener : listeners) {
- notifyListenerOfAdding(eplistener, endpoints);
- }
- }
- }
-
- void notifyListenersOfRemoval(Collection<EndpointDescription> endpoints) {
+
+ /**
+ * Notifies all endpoint listeners about endpoints being added or removed.
+ *
+ * @param added specifies whether endpoints were added (true) or removed (false)
+ * @param endpoints the endpoints the listeners should be notified about
+ */
+ void notifyListeners(boolean added, Collection<EndpointDescription> endpoints) {
ServiceReference[] listeners = stEndpointListeners.getServiceReferences();
if (listeners != null) {
- for (ServiceReference epListenerReference : listeners) {
- notifyListenerOfRemoval(epListenerReference, endpoints);
+ for (ServiceReference eplReference : listeners) {
+ notifyListener(added, eplReference, endpoints);
}
}
}
-
+
/**
- * Notifies the listener if he is interested in the provided registrations.
- *
- * @param epListenerReference the ServiceReference for an EndpointListener
- * @param endpoints the registrations the listener should be informed about
+ * Notifies an endpoint listener about endpoints being added or removed.
+ *
+ * @param added specifies whether endpoints were added (true) or removed (false)
+ * @param eplReference the ServiceReference of an EndpointListener to notify
+ * @param endpoints the endpoints the listener should be notified about
*/
- private void notifyListenerOfAdding(ServiceReference epListenerReference,
- Collection<EndpointDescription> endpoints) {
- EndpointListener epl = (EndpointListener)bctx.getService(epListenerReference);
- List<Filter> filters = getFiltersFromEndpointListenerScope(epListenerReference, bctx);
-
- LOG.debug("notifyListenerOfAdding");
- for (EndpointDescription endpoint : endpoints) {
- List<Filter> matchingFilters = getMatchingFilters(filters, endpoint);
- for (Filter filter : matchingFilters) {
- epl.endpointAdded(endpoint, filter.toString());
+ void notifyListener(boolean added, ServiceReference eplReference,
+ Collection<EndpointDescription> endpoints) {
+ List<Filter> filters = getFiltersFromEndpointListenerScope(eplReference, bctx);
+ EndpointListener epl = (EndpointListener)bctx.getService(eplReference);
+ try {
+ LOG.debug("notifyListener (added={})", added);
+ for (EndpointDescription endpoint : endpoints) {
+ List<Filter> matchingFilters = getMatchingFilters(filters, endpoint);
+ for (Filter filter : matchingFilters) {
+ if (added) {
+ epl.endpointAdded(endpoint, filter.toString());
+ } else {
+ epl.endpointRemoved(endpoint, filter.toString());
+ }
+ }
}
- }
- }
-
- void notifyListenerOfRemoval(ServiceReference epListenerReference,
- Collection<EndpointDescription> endpoints) {
- EndpointListener epl = (EndpointListener)bctx.getService(epListenerReference);
- List<Filter> filters = getFiltersFromEndpointListenerScope(epListenerReference, bctx);
- for (EndpointDescription endpoint : endpoints) {
- List<Filter> matchingFilters = getMatchingFilters(filters, endpoint);
- for (Filter filter : matchingFilters) {
- epl.endpointRemoved(endpoint, filter.toString());
+ } finally {
+ if (epl != null) {
+ bctx.ungetService(eplReference);
}
}
}
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=1488782&r1=1488781&r2=1488782&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 Sun Jun 2 20:31:10 2013
@@ -88,7 +88,7 @@ public class TopologyManagerExport {
public void removed(RemoteServiceAdmin rsa) {
List<EndpointDescription> endpoints = endpointRepo.removeRemoteServiceAdmin(rsa);
- epListenerNotifier.notifyListenersOfRemoval(endpoints);
+ epListenerNotifier.notifyListeners(false, endpoints);
}
});
serviceListener = new ServiceListener() {
@@ -102,7 +102,7 @@ public class TopologyManagerExport {
} else if (event.getType() == ServiceEvent.UNREGISTERING) {
LOG.debug("Received UNREGISTERING ServiceEvent: {}", event);
List<EndpointDescription> endpoints = endpointRepo.removeService(sref);
- epListenerNotifier.notifyListenersOfRemoval(endpoints);
+ epListenerNotifier.notifyListeners(false, endpoints);
}
}
};
@@ -172,7 +172,7 @@ public class TopologyManagerExport {
endpoints.add(getExportedEndpoint(exportReg));
}
LOG.info("TopologyManager: export successful Endpoints: {}", endpoints);
- epListenerNotifier.notifyListenersOfAdding(endpoints);
+ epListenerNotifier.notifyListeners(true, endpoints);
}
endpointRepo.addEndpoints(sref, remoteServiceAdmin, endpoints);
}
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=1488782&r1=1488781&r2=1488782&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 Sun Jun 2 20:31:10 2013
@@ -93,7 +93,7 @@ public class EndpointListenerNotifierTes
endpoints.add(epd);
endpoints.add(epd2);
- tm.notifyListenerOfRemoval(sref, endpoints);
+ tm.notifyListener(false, sref, endpoints);
c.verify();
EasyMock.verify(epl);
Modified: cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/ExportServiceTest.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/ExportServiceTest.java?rev=1488782&r1=1488781&r2=1488782&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/ExportServiceTest.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-topology-manager/src/test/java/org/apache/cxf/dosgi/topologymanager/exporter/ExportServiceTest.java Sun Jun 2 20:31:10 2013
@@ -75,7 +75,7 @@ public class ExportServiceTest {
simulateUserServicePublished(bctx, sref);
EasyMock.expect(rsa.exportService(EasyMock.same(sref), (Map<String, Object>)EasyMock.anyObject()))
.andReturn(Collections.singletonList(exportRegistration)).once();
- mockEpListenerNotifier.notifyListenersOfAdding(EasyMock.eq(Collections.singletonList(endpoint)));
+ mockEpListenerNotifier.notifyListeners(EasyMock.eq(true), EasyMock.eq(Collections.singletonList(endpoint)));
EasyMock.expectLastCall().once();
c.replay();