ARIES-1940 Handle failure that can happen during service export (#30)
Changed implementation and use of ExportRegistration to align with specification
Changed use of ExportRegistration to deal with cases the ExportRegistration relates to a failed exported services
diff --git a/rsa/src/main/java/org/apache/aries/rsa/core/ExportRegistrationImpl.java b/rsa/src/main/java/org/apache/aries/rsa/core/ExportRegistrationImpl.java
index a02ff3a..715efd2 100644
--- a/rsa/src/main/java/org/apache/aries/rsa/core/ExportRegistrationImpl.java
+++ b/rsa/src/main/java/org/apache/aries/rsa/core/ExportRegistrationImpl.java
@@ -99,12 +99,15 @@
}
public ExportReference getExportReference() {
- /* TODO check if we need to throw exception here
- if (exportReference == null) {
- throw new IllegalStateException(getException());
+ if (closed) {
+ return null;
+ } else {
+ if (exportReference == null) {
+ throw new IllegalStateException(getException());
+ } else {
+ return exportReference;
+ }
}
- */
- return closed ? null : exportReference;
}
public Throwable getException() {
diff --git a/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java b/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java
index d48283c..207c98a 100644
--- a/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java
+++ b/rsa/src/main/java/org/apache/aries/rsa/core/RemoteServiceAdminCore.java
@@ -379,7 +379,7 @@
List<ExportReference> ers = new ArrayList<>();
for (Collection<ExportRegistration> exportRegistrations : exportedServices.values()) {
for (ExportRegistration er : exportRegistrations) {
- if (er.getExportReference() != null) {
+ if (er.getException() == null && er.getExportReference() != null) {
ers.add(new ExportReferenceImpl(er.getExportReference()));
}
}
@@ -502,7 +502,9 @@
synchronized (exportedServices) {
for (Collection<ExportRegistration> value : exportedServices.values()) {
for (ExportRegistration er : value) {
- if (er.getExportReference().getExportedService().equals(sref)) {
+ if (er.getException() != null &&
+ er.getExportReference() != null &&
+ er.getExportReference().getExportedService().equals(sref)) {
regs.add(er);
}
}
@@ -530,7 +532,9 @@
for (Iterator<ExportRegistration> it2 = value.iterator(); it2.hasNext();) {
ExportRegistration er = it2.next();
if (er.equals(eri)) {
- eventProducer.notifyRemoval(eri.getExportReference());
+ if (eri.getException() == null && eri.getExportReference() != null) {
+ eventProducer.notifyRemoval(eri.getExportReference());
+ }
it2.remove();
if (value.isEmpty()) {
it.remove();
@@ -569,7 +573,7 @@
for (Collection<ExportRegistration> regs : exportedServices.values()) {
if (!regs.isEmpty()) {
ExportRegistration exportRegistration = regs.iterator().next();
- if (exportRegistration.getException() == null) {
+ if (exportRegistration.getException() == null && exportRegistration.getExportReference() != null) {
Bundle regBundle = exportRegistration.getExportReference().getExportedService().getBundle();
if (exportingBundle.equals(regBundle)) {
bundleRegs.addAll(regs);