Author: cschneider
Date: Mon Nov 5 15:38:23 2012
New Revision: 1405841
URL: http://svn.apache.org/viewvc?rev=1405841&view=rev
Log:
DOSGI-139 Reverting parts of last commit as I removed the copying of
ExportRegistrations that is required by the spec
Modified:
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/RemoteServiceAdminCore.java
Modified:
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java?rev=1405841&r1=1405840&r2=1405841&view=diff
==============================================================================
---
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java
(original)
+++
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportReferenceImpl.java
Mon Nov 5 15:38:23 2012
@@ -23,14 +23,19 @@ import org.osgi.service.remoteserviceadm
import org.osgi.service.remoteserviceadmin.ExportReference;
public class ExportReferenceImpl implements ExportReference {
- private final ServiceReference serviceReference;
- private final EndpointDescription endpointDescription;
+ private ServiceReference serviceReference;
+ private EndpointDescription endpointDescription;
public ExportReferenceImpl(ServiceReference serviceReference,
EndpointDescription endpointDescription) {
this.serviceReference = serviceReference;
this.endpointDescription = endpointDescription;
}
+ public ExportReferenceImpl(ExportReference exportReference) {
+ this.serviceReference = exportReference.getExportedService();
+ this.endpointDescription = exportReference.getExportedEndpoint();
+ }
+
public EndpointDescription getExportedEndpoint() {
return endpointDescription;
}
@@ -70,5 +75,8 @@ public class ExportReferenceImpl impleme
return true;
}
-
+ synchronized void close() {
+ this.endpointDescription = null;
+ this.serviceReference = null;
+ }
}
Modified:
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java?rev=1405841&r1=1405840&r2=1405841&view=diff
==============================================================================
---
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java
(original)
+++
cxf/dosgi/trunk/dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/service/ExportRegistrationImpl.java
Mon Nov 5 15:38:23 2012
@@ -43,53 +43,92 @@ public class ExportRegistrationImpl impl
private Server server;
private boolean closed = false;
-
private Throwable exception = null;
private ExportRegistrationImpl parent = null;
+ private volatile int instanceCount = 1;
private RemoteServiceAdminCore rsaCore;
- private ExportReference exportReference;
+ private ExportReferenceImpl exportReference;
private ServiceTracker serviceTracker;
- public ExportRegistrationImpl(ExportReference exportReference,
RemoteServiceAdminCore remoteServiceAdminCore) {
- this.exportReference = exportReference;
+ // provide a clone of the provided exp.Reg that is linked to this instance
+ public ExportRegistrationImpl(ExportRegistrationImpl exportRegistration) {
+
+ parent = exportRegistration;
+ exportReference = new ExportReferenceImpl(parent.getExportReference());
+ exception = parent.getException();
+ rsaCore = parent.getRsaCore();
+ parent.instanceAdded();
+ }
+
+ private void instanceAdded() {
+ ++instanceCount;
+ }
+
+ public ExportRegistrationImpl(ServiceReference sref, EndpointDescription
endpoint, RemoteServiceAdminCore remoteServiceAdminCore) {
+ exportReference = new ExportReferenceImpl(sref, endpoint);
parent = this;
rsaCore = remoteServiceAdminCore;
}
public synchronized void close() {
- if (closed) {
+ if (closed)
return;
- }
closed = true;
rsaCore.removeExportRegistration(this);
+ parent.instanceClosed();
if (server != null) {
server.stop();
server = null;
}
- exportReference = null;
- exception = null;
+ exportReference.close();
+ }
+
+ private void instanceClosed() {
+ --instanceCount;
+ if (instanceCount <= 0) {
+ // really close the ExReg
+ // TODO close it and remove from management structure .... !
+
+ LOG.fine("really closing ExportRegistartion now! ");
+
+ synchronized (this) {
+ if (server != null) {
+ // FIXME: is this done like this ?
+ server.stop();
+ server = null;
+ }
+ }
+ }
}
public Throwable getException() {
- return exception;
+ if (!closed)
+ return exception;
+ else
+ return null;
}
@Override
public String toString() {
- String r = "Endpoint Desctiption for ServiceReference " +
getExportReference().getExportedService();
+ if (exportReference == null) {
+ return "Exportregistration closed";
+ }
+ EndpointDescription endpointDescription =
getExportReference().getExportedEndpoint();
+ ServiceReference serviceReference =
getExportReference().getExportedService();
+ String r = "Endpoint Desctiption for ServiceReference " +
serviceReference;
r += "\n";
r += "*** EndpointDescription: **** \n";
- if (getExportReference().getExportedService() == null) {
+ if (endpointDescription == null) {
r += "---> NULL <---- \n";
} else {
- Set<Map.Entry<String,Object>> props =
getExportReference().getExportedEndpoint().getProperties().entrySet();
+ Set<Map.Entry<String,Object>> props =
endpointDescription.getProperties().entrySet();
for (Map.Entry<String,Object> entry : props) {
Object value = entry.getValue();
r += entry.getKey() + " => " +
@@ -103,16 +142,16 @@ public class ExportRegistrationImpl impl
this.server = server;
}
+ public Server getServer() {
+ return server;
+ }
+
public void setException(Throwable ex) {
exception = ex;
}
public ExportReference getExportReference() {
- return exportReference;
- }
-
- protected EndpointDescription getEndpointDescriptionAlways() {
- return getExportReference().getExportedEndpoint();
+ return exportReference;
}
/**
@@ -164,4 +203,7 @@ public class ExportRegistrationImpl impl
this.rsaCore = rsaCore;
}
+ public RemoteServiceAdminCore getRsaCore() {
+ return rsaCore;
+ }
}
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=1405841&r1=1405840&r2=1405841&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
Mon Nov 5 15:38:23 2012
@@ -30,7 +30,6 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
-import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.cxf.common.logging.LogUtils;
@@ -111,7 +110,7 @@ public class RemoteServiceAdminCore impl
// create one copy for each distinct endpoint
description
if (!copiedEndpoints.contains(epd)) {
copiedEndpoints.add(epd);
- copy.add(exportRegistration);
+ copy.add(new
ExportRegistrationImpl(exportRegistrationImpl));
}
}
}
@@ -215,7 +214,16 @@ public class RemoteServiceAdminCore impl
return Collections.emptyList();
}
- LinkedHashMap<String, ExportRegistrationImpl> exportRegs = new
LinkedHashMap<String, ExportRegistrationImpl>();
+ LinkedHashMap<String, ExportRegistrationImpl> exportRegs = new
LinkedHashMap<String, ExportRegistrationImpl>(
+
1);
+
+ for (String iface : interfaces) {
+ LOG.info("creating initial ExportDescription for interface " +
iface
+ + " with configuration types " + configurationTypes);
+
+ // create initial ExportRegistartion
+
+ }
// FIXME: move out of synchronized ... -> blocks until publication
is finished
for (String iface : interfaces) {
@@ -238,25 +246,22 @@ public class RemoteServiceAdminCore impl
Class<?> interfaceClass =
ClassUtils.getInterfaceClass(serviceObject, interfaceName);
if (interfaceClass != null) {
- ExportRegistrationImpl exportRegistration = null;
try {
- ExportResult exportResult =
handler.createServer(serviceReference, bctx,
- callingContext, serviceProperties,
interfaceClass, serviceObject);
- EndpointDescription epd = new
EndpointDescription(exportResult.getEndpointProps());
- ExportReference exportRef = new
ExportReferenceImpl(serviceReference, epd);
- exportRegistration = new
ExportRegistrationImpl(exportRef , this);
- exportRegistration.setServer(exportResult.getServer());
+ ExportResult exportResult =
handler.createServer(serviceReference, bctx, callingContext, serviceProperties,
+ interfaceClass, serviceObject);
LOG.info("created server for interface " + iface);
+
+ EndpointDescription epd = new
EndpointDescription(exportResult.getEndpointProps());
+ ExportRegistrationImpl exportRegistration = new
ExportRegistrationImpl(serviceReference, epd, this);
exportRegistration.startServiceTracker(bctx);
+ exportRegs.put(iface, exportRegistration);
} catch (Exception e) {
- EndpointDescription epd = new
EndpointDescription(null);
- ExportReference exportRef = new
ExportReferenceImpl(serviceReference, epd);
- exportRegistration = new
ExportRegistrationImpl(exportRef , this);
+ LOG.warning("server creation for interface " + iface +
" failed!");
+ EndpointDescription epd = new EndpointDescription(new
HashMap<String, Object>());
+ ExportRegistrationImpl exportRegistration = new
ExportRegistrationImpl(serviceReference, epd, this);
exportRegistration.setException(e);
- LOG.log(Level.WARNING, "Server creation for interface
" + iface + " failed!", e);
- // Fire event happens at the end
+ exportRegs.put(iface, exportRegistration);
}
- exportRegs.put(iface, exportRegistration);
}
}
@@ -301,16 +306,13 @@ public class RemoteServiceAdminCore impl
public Collection<ExportReference> getExportedServices() {
synchronized (exportedServices) {
- List<ExportReference> eRefs = new ArrayList<ExportReference>();
+ List<ExportReference> ers = new ArrayList<ExportReference>();
for (Collection<ExportRegistration> exportRegistrations :
exportedServices.values()) {
for (ExportRegistration er : exportRegistrations) {
- ExportReference eRef = er.getExportReference();
- if (eRef != null) {
- eRefs.add(eRef);
- }
+ ers.add(new ExportReferenceImpl(er.getExportReference()));
}
}
- return Collections.unmodifiableCollection(eRefs);
+ return Collections.unmodifiableCollection(ers);
}
}
@@ -375,8 +377,7 @@ public class RemoteServiceAdminCore impl
}
if (usableConfigurationTypes.size() == 0) {
- LOG
- .severe("the supplied endpoint has no compatible
configuration type. Supported types are: "
+ LOG.severe("the supplied endpoint has no compatible
configuration type. Supported types are: "
+ supportedConfigurationTypes
+ " Types needed by the endpoint: "
+ remoteConfigurationTypes);
@@ -470,21 +471,20 @@ public class RemoteServiceAdminCore impl
* Removes the provided Export Registration from the internal management
structures -> intended to be used
* when the export Registration is closed
*/
- protected void removeExportRegistration(ExportRegistration eri) {
+ protected void removeExportRegistration(ExportRegistrationImpl eri) {
synchronized (exportedServices) {
- Collection<ExportRegistration> exRegs =
exportedServices.get(eri.getExportReference().getExportedService());
+ ServiceReference sref =
eri.getExportReference().getExportedService();
+ Collection<ExportRegistration> exRegs = exportedServices.get(sref);
if (exRegs != null && exRegs.contains(eri)) {
+ eventProducer.notifyRemoval(eri);
exRegs.remove(eri);
} else {
LOG.severe("An exportRegistartion was intended to be removed
form internal management structure but couldn't be found in it !! ");
}
if (exRegs == null || exRegs.size() == 0) {
-
exportedServices.remove(eri.getExportReference().getExportedService());
+ exportedServices.remove(sref);
}
-
- eventProducer.notifyRemoval(eri);
}
-
}
// Remove all export registrations associated with the given bundle