Improved fix for bug
https://bugs.eclipse.org/bugs/show_bug.cgi?id=489177

Change-Id: I0000000000000000000000000000000000000000
diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java
index f7861d1..7b442db 100644
--- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java
+++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/internal/osgi/services/remoteserviceadmin/Activator.java
@@ -57,6 +57,9 @@
 
 	public static final String PLUGIN_ID = "org.eclipse.ecf.osgi.services.remoteserviceadmin"; //$NON-NLS-1$
 
+	private static final String RSA_PROXY_PREFIX = "ECF RSA PROXY for ED="; //$NON-NLS-1$
+	private static final String RSA_PROXY_BUNDLE_SYMBOLIC_ID = "org.eclipse.ecf.osgi.services.remoteserviceadmin.proxy"; //$NON-NLS-1$
+
 	private static BundleContext context;
 	private static Activator instance;
 
@@ -87,8 +90,6 @@
 	private Object saxParserFactoryTrackerLock = new Object();
 	private ServiceTracker saxParserFactoryTracker;
 
-	private static final String RSA_PROXY_BUNDLE_SYMBOLIC_ID = "org.eclipse.ecf.osgi.services.remoteserviceadmin.proxy"; //$NON-NLS-1$
-
 	private BundleContext proxyServiceFactoryBundleContext;
 
 	private Collection<ExportRegistration> exportedRegistrations;
@@ -178,8 +179,6 @@
 		return (proxyBundle != null)?proxyBundle.getBundleContext():proxyServiceFactoryBundleContext;
 	}
 
-	private static final String RSA_PROXY_PREFIX = "ECF RSA PROXY for "; //$NON-NLS-1$
-
 	static Bundle findExistingProxyBundle(String bundleSymbolicName) {
 		BundleContext bc = getContext();
 		if (bc != null) 
diff --git a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdmin.java b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdmin.java
index 37cf353..2b6d0d7 100644
--- a/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdmin.java
+++ b/osgi/bundles/org.eclipse.ecf.osgi.services.remoteserviceadmin/src/org/eclipse/ecf/osgi/services/remoteserviceadmin/RemoteServiceAdmin.java
@@ -43,9 +43,9 @@
 import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.DebugOptions;
 import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.LogUtility;
 import org.eclipse.ecf.internal.osgi.services.remoteserviceadmin.PropertiesUtil;
-import org.eclipse.ecf.remoteservice.IRSAConsumerContainerAdapter;
 import org.eclipse.ecf.remoteservice.IExtendedRemoteServiceRegistration;
 import org.eclipse.ecf.remoteservice.IOSGiRemoteServiceContainerAdapter;
+import org.eclipse.ecf.remoteservice.IRSAConsumerContainerAdapter;
 import org.eclipse.ecf.remoteservice.IRemoteService;
 import org.eclipse.ecf.remoteservice.IRemoteServiceContainer;
 import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter;
@@ -929,11 +929,10 @@
 
 	class ImportEndpoint {
 
-		private ID importContainerID;
+		private IRemoteServiceContainer rsContainer;
 		private IRemoteService rs;
-		private IRemoteServiceContainerAdapter rsContainerAdapter;
-		private EndpointDescription endpointDescription;
 		private IRemoteServiceListener rsListener;
+		private EndpointDescription endpointDescription;
 		private IRemoteServiceReference rsReference;
 		private ServiceRegistration proxyRegistration;
 		private Set<ImportRegistration> activeImportRegistrations = new HashSet<ImportRegistration>();
@@ -945,25 +944,22 @@
 			return buf.toString();
 		}
 		
-		ImportEndpoint(ID importContainerID, IRemoteServiceContainerAdapter rsContainerAdapter,
+		ImportEndpoint(IRemoteServiceContainer rsContainer,
 				IRemoteServiceReference rsReference,
 				IRemoteService rs,
-				IRemoteServiceListener rsListener,
 				ServiceRegistration proxyRegistration,
 				EndpointDescription endpointDescription) {
-			this.importContainerID = importContainerID;
-			this.rsContainerAdapter = rsContainerAdapter;
-			this.endpointDescription = endpointDescription;
+			this.rsContainer = rsContainer;
 			this.rsReference = rsReference;
+			this.endpointDescription = endpointDescription;
 			this.rs = rs;
-			this.rsListener = rsListener;
 			this.proxyRegistration = proxyRegistration;
+			this.rsListener = new RemoteServiceListener();
 			// Add the remoteservice listener to the container adapter, so that
 			// the rsListener notified asynchronously if our underlying remote
-			// service
-			// reference is unregistered locally due to disconnect or remote
+			// service reference is unregistered locally due to disconnect or remote
 			// ejection
-			this.rsContainerAdapter.addRemoteServiceListener(this.rsListener);
+			this.rsContainer.getContainerAdapter().addRemoteServiceListener(this.rsListener);
 		}
 
 		synchronized EndpointDescription getEndpointDescription() {
@@ -988,24 +984,28 @@
 					.remove(importRegistration);
 			if (removed && activeImportRegistrations.size() == 0) {
 				if (proxyRegistration != null) {
-					proxyRegistration.unregister();
+					try {
+						proxyRegistration.unregister();
+					} catch (Throwable t) {
+						// do nothing
+					}
 					proxyRegistration = null;
 				}
+				IRemoteServiceContainerAdapter rsContainerAdapter = rsContainer.getContainerAdapter();
 				if (rsContainerAdapter != null) {
 					if (rsReference != null) {
 						rsContainerAdapter.ungetRemoteService(rsReference);
 						rsReference = null;
 					}
-					// remove remote service listener
 					if (rsListener != null) {
 						rsContainerAdapter
 								.removeRemoteServiceListener(rsListener);
 						rsListener = null;
 					}
-					rs = null;
-					rsContainerAdapter = null;
 				}
+				rs = null;
 				endpointDescription = null;
+				rsContainer = null;
 			}
 			return removed;
 		}
@@ -1030,7 +1030,7 @@
 			EndpointDescription updatedEndpoint = (endpoint instanceof EndpointDescription) ? ((EndpointDescription) endpoint)
 					: new EndpointDescription(endpoint.getProperties());
 			// Create new proxy properties from updatedEndpoint and rsReference and rs
-			Map newProxyProperties = createProxyProperties(importContainerID, updatedEndpoint,
+			Map newProxyProperties = createProxyProperties(rsContainer.getContainer().getID(), updatedEndpoint,
 					rsReference, rs);
 			// set the endpoint description with the proxy properties
 			updatedEndpoint.setPropertiesOverrides(newProxyProperties);
@@ -1855,9 +1855,7 @@
 					}
 				});
 
-		return new ImportEndpoint(rsContainerID, containerAdapter, selectedRsReference, rs,
-				new RemoteServiceListener(), proxyRegistration,
-				endpointDescription);
+		return new ImportEndpoint(rsContainer, selectedRsReference, rs, proxyRegistration, endpointDescription);
 	}
 
 	private BundleContext getProxyServiceFactoryContext(