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/18 15:14:11 UTC
svn commit: r1494131 - in /cxf/dosgi/trunk:
discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/
dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/
dsw/cxf-topology-manager/src/main/java/org/apache/cxf/do...
Author: amichai
Date: Tue Jun 18 13:14:10 2013
New Revision: 1494131
URL: http://svn.apache.org/r1494131
Log:
Little refactorings, fixes and improved docs and logs
Modified:
cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitor.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ClientServiceFactory.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportRegistrationImpl.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java
cxf/dosgi/trunk/dsw/cxf-topology-manager/src/main/java/org/apache/cxf/dosgi/topologymanager/exporter/TopologyManagerExport.java
Modified: cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitor.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitor.java?rev=1494131&r1=1494130&r2=1494131&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitor.java (original)
+++ cxf/dosgi/trunk/discovery/distributed/cxf-discovery/src/main/java/org/apache/cxf/dosgi/discovery/zookeeper/InterfaceMonitor.java Tue Jun 18 13:14:10 2013
@@ -211,7 +211,7 @@ public class InterfaceMonitor implements
private EndpointDescription getEndpointDescriptionFromNode(String node) {
try {
Stat s = zookeeper.exists(node, false);
- if (s.getDataLength() <= 0) {
+ if (s == null || s.getDataLength() <= 0) {
return null;
}
byte[] data = zookeeper.getData(node, false, null);
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ClientServiceFactory.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ClientServiceFactory.java?rev=1494131&r1=1494130&r2=1494131&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ClientServiceFactory.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ClientServiceFactory.java Tue Jun 18 13:14:10 2013
@@ -20,6 +20,8 @@ package org.apache.cxf.dosgi.dsw.service
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.util.Arrays;
+import java.util.List;
import org.apache.cxf.dosgi.dsw.handlers.ConfigurationTypeHandler;
import org.apache.cxf.dosgi.dsw.qos.IntentUnsatisfiedException;
@@ -39,7 +41,6 @@ public class ClientServiceFactory implem
private Class<?> iClass;
private EndpointDescription sd;
private ConfigurationTypeHandler handler;
-
private ImportRegistrationImpl importRegistration;
private boolean closeable;
@@ -55,63 +56,51 @@ public class ClientServiceFactory implem
}
public Object getService(final Bundle requestingBundle, final ServiceRegistration sreg) {
- String interfaceName = sd.getInterfaces() != null && !sd.getInterfaces().isEmpty() ? (String)sd
- .getInterfaces().toArray()[0] : null;
-
+ List<String> interfaces = sd.getInterfaces();
+ String interfaceName = interfaces == null || interfaces.isEmpty() ? null : interfaces.get(0);
LOG.debug("getService() from serviceFactory for {}", interfaceName);
-
try {
Object proxy = AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
- return handler.createProxy(sreg.getReference(), dswContext, requestingBundle
- .getBundleContext(), iClass, sd);
+ return handler.createProxy(sreg.getReference(), dswContext,
+ requestingBundle.getBundleContext(), iClass, sd);
}
});
synchronized (this) {
- ++serviceCounter;
+ serviceCounter++;
}
return proxy;
} catch (IntentUnsatisfiedException iue) {
- LOG.info("Did not create proxy for " + interfaceName + " because intent " + iue.getIntent()
- + " could not be satisfied");
- } catch (Exception ex) {
- LOG.warn("Problem creating a remote proxy for " + interfaceName + " from CXF FindHook: ", ex);
+ LOG.info("Did not create proxy for {} because intent {} could not be satisfied",
+ interfaceName, iue.getIntent());
+ } catch (Exception e) {
+ LOG.warn("Problem creating a remote proxy for {}", interfaceName, e);
}
-
return null;
}
public void ungetService(Bundle requestingBundle, ServiceRegistration sreg, Object serviceObject) {
- StringBuilder sb = new StringBuilder(64);
- sb.append("Releasing a client object");
- String[] objectClass = (String[])sreg.getReference().getProperty(org.osgi.framework.Constants.OBJECTCLASS);
- if (objectClass != null) {
- sb.append(", interfaces: ");
- for (String s : objectClass) {
- sb.append(' ').append(s);
- }
- }
- LOG.info(sb.toString());
+ String[] interfaces = (String[])sreg.getReference().getProperty(org.osgi.framework.Constants.OBJECTCLASS);
+ LOG.info("Releasing a client object, interfaces: {}", Arrays.toString(interfaces));
synchronized (this) {
- --serviceCounter;
+ serviceCounter--;
LOG.debug("Services still provided by this ServiceFactory: {}", serviceCounter);
closeIfUnused();
}
}
- // called only in synchronized block
- private void closeIfUnused() {
- if (serviceCounter <= 0 && closeable) {
- importRegistration.closeAll();
- }
- }
-
public void setCloseable(boolean closeable) {
synchronized (this) {
this.closeable = closeable;
closeIfUnused();
}
}
+
+ private synchronized void closeIfUnused() {
+ if (serviceCounter <= 0 && closeable) {
+ importRegistration.closeAll();
+ }
+ }
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportRegistrationImpl.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportRegistrationImpl.java?rev=1494131&r1=1494130&r2=1494131&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportRegistrationImpl.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ImportRegistrationImpl.java Tue Jun 18 13:14:10 2013
@@ -74,12 +74,19 @@ public class ImportRegistrationImpl impl
children = new ArrayList<ImportRegistrationImpl>(1);
}
+ private void ensureParent() {
+ if (parent != this) {
+ throw new IllegalStateException("this method may only be called on the parent");
+ }
+ }
+
/**
* Called on parent when a child is added.
*
* @param iri the child
*/
private synchronized void instanceAdded(ImportRegistrationImpl iri) {
+ ensureParent();
children.add(iri);
}
@@ -89,6 +96,7 @@ public class ImportRegistrationImpl impl
* @param iri the child
*/
private void instanceClosed(ImportRegistrationImpl iri) {
+ ensureParent();
synchronized (this) {
children.remove(iri);
if (!children.isEmpty() || detached || !closed) {
@@ -181,15 +189,27 @@ public class ImportRegistrationImpl impl
return exception != null || closed;
}
- public void setImportedServiceRegistration(ServiceRegistration proxyRegistration) {
- if (parent != this) {
- throw new IllegalStateException("this method may only be called on the parent");
- }
-
- importedService = proxyRegistration;
+ /**
+ * Sets the {@link ServiceRegistration} representing the locally
+ * registered {@link ClientServiceFactory} service which provides
+ * proxies to the remote imported service. It is set only on the parent.
+ *
+ * @param sreg the ServiceRegistration
+ */
+ public void setImportedServiceRegistration(ServiceRegistration sreg) {
+ ensureParent();
+ importedService = sreg;
}
+ /**
+ * Sets the {@link ClientServiceFactory} which is the implementation
+ * of the locally registered service which provides proxies to the
+ * remote imported service. It is set only on the parent.
+ *
+ * @param csf the ClientServiceFactory
+ */
public void setClientServiceFactory(ClientServiceFactory csf) {
+ ensureParent();
clientServiceFactory = csf;
}
Modified: cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java
URL: http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java?rev=1494131&r1=1494130&r2=1494131&view=diff
==============================================================================
--- cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java (original)
+++ cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java Tue Jun 18 13:14:10 2013
@@ -164,14 +164,14 @@ public class RemoteServiceAdminCore impl
if (interfaceClass != null) {
ExportResult exportResult = handler.createServer(serviceReference, bctx, bundle.getBundleContext(),
serviceProperties, interfaceClass, service);
- LOG.info("created server for interface " + iface);
EndpointDescription epd = new EndpointDescription(exportResult.getEndpointProps());
ExportRegistrationImpl exportRegistration = new ExportRegistrationImpl(serviceReference, epd, this);
if (exportResult.getException() == null) {
+ LOG.info("created server for interface " + iface);
exportRegistration.setServer(exportResult.getServer());
exportRegistration.startServiceTracker(bctx);
} else {
- LOG.error(exportResult.getException().getMessage(), exportResult.getException());
+ LOG.error("failed to create server for interface " + iface, exportResult.getException());
exportRegistration.setException(exportResult.getException());
}
exportRegs.add(exportRegistration);
@@ -340,9 +340,8 @@ public class RemoteServiceAdminCore impl
imRegs.add(imReg);
eventProducer.publishNotification(imReg);
return imReg;
- } else {
- return null;
}
+ return null;
}
}
@@ -371,7 +370,6 @@ public class RemoteServiceAdminCore impl
serviceProps.put(RemoteConstants.SERVICE_IMPORTED, true);
serviceProps.remove(RemoteConstants.SERVICE_EXPORTED_INTERFACES);
- // synchronized (discoveredServices) {
ClientServiceFactory csf = new ClientServiceFactory(actualContext, iClass, ed, handler, imReg);
imReg.setClientServiceFactory(csf);
ServiceRegistration proxyReg = actualContext.registerService(interfaceName, csf, serviceProps);
@@ -414,7 +412,7 @@ public class RemoteServiceAdminCore impl
}
}
- // remove all import registrations associated with the given bundle
+ // remove all import registrations
protected void removeImportRegistrations() {
Collection<ImportRegistrationImpl> copy = new ArrayList<ImportRegistrationImpl>();
synchronized (importedServices) {
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=1494131&r1=1494130&r2=1494131&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 Tue Jun 18 13:14:10 2013
@@ -76,8 +76,10 @@ public class TopologyManagerExport {
epListenerNotifier = notif == null ? new EndpointListenerNotifier(ctx, endpointRepo) : notif;
execService = new ThreadPoolExecutor(5, 10, 50, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
bctx = ctx;
- this.remoteServiceAdminTracker = rsaTracker;
- this.remoteServiceAdminTracker.addListener(new SimpleServiceTrackerListener<RemoteServiceAdmin>() {
+ remoteServiceAdminTracker = rsaTracker;
+
+ // track RemoteServiceAdmins through which we can export services
+ remoteServiceAdminTracker.addListener(new SimpleServiceTrackerListener<RemoteServiceAdmin>() {
public void added(RemoteServiceAdmin rsa) {
LOG.debug("RemoteServiceAdmin added: {}, total {}",
@@ -94,6 +96,9 @@ public class TopologyManagerExport {
epListenerNotifier.notifyListeners(false, endpoints);
}
});
+
+ // track all service registrations so we can export any services that are configured to be exported
+ // ServiceListener events may be delivered out of order, concurrently, re-entrant, etc. (see spec or docs)
serviceListener = new ServiceListener() {
public void serviceChanged(ServiceEvent event) {
@@ -134,7 +139,11 @@ public class TopologyManagerExport {
protected void triggerExport(final ServiceReference sref) {
execService.execute(new Runnable() {
public void run() {
- doExportService(sref);
+ try {
+ doExportService(sref);
+ } catch (Throwable t) {
+ LOG.error("export failed", t);
+ }
}
});
}
@@ -167,6 +176,7 @@ public class TopologyManagerExport {
LOG.debug("exporting...");
Collection<ExportRegistration> exportRegs = remoteServiceAdmin.exportService(sref, null);
List<EndpointDescription> endpoints = new ArrayList<EndpointDescription>();
+ // note: endpoints list may contain ExportRegistrations with an exception, not only successful ones
if (exportRegs.isEmpty()) {
// TODO export failed -> What should be done here?
LOG.error("export failed");