Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2008-03-05 07:15:31 +0000
committerslewis2008-03-05 07:15:31 +0000
commitfb8b9c772025ebac5ae445436504ba6bcc145fc3 (patch)
treef0549002519afe44174eaa0c68fa0a93e31a223a /server-side/examples/bundles
parenta5a1e1652b4d4f56321bee52938f9ee6afb0bb2d (diff)
downloadorg.eclipse.ecf-fb8b9c772025ebac5ae445436504ba6bcc145fc3.tar.gz
org.eclipse.ecf-fb8b9c772025ebac5ae445436504ba6bcc145fc3.tar.xz
org.eclipse.ecf-fb8b9c772025ebac5ae445436504ba6bcc145fc3.zip
Simplified handling/finding of container instance in client example remote environment info service access handler. Also added utility methods in AbstractRemoteServiceHandler
Diffstat (limited to 'server-side/examples/bundles')
-rw-r--r--server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.client/src/org/eclipse/ecf/internal/examples/remoteservices/client/Activator.java15
-rw-r--r--server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.client/src/org/eclipse/ecf/internal/examples/remoteservices/client/RemoteEnvironmentInfoServiceAccessHandler.java88
2 files changed, 41 insertions, 62 deletions
diff --git a/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.client/src/org/eclipse/ecf/internal/examples/remoteservices/client/Activator.java b/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.client/src/org/eclipse/ecf/internal/examples/remoteservices/client/Activator.java
index 173665e52..3bcfd7de1 100644
--- a/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.client/src/org/eclipse/ecf/internal/examples/remoteservices/client/Activator.java
+++ b/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.client/src/org/eclipse/ecf/internal/examples/remoteservices/client/Activator.java
@@ -11,7 +11,6 @@
package org.eclipse.ecf.internal.examples.remoteservices.client;
-import org.eclipse.ecf.core.IContainer;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@@ -26,8 +25,6 @@ public class Activator extends AbstractUIPlugin {
// The shared instance
private static Activator plugin;
- private IContainer serviceHostContainer;
-
private BundleContext context;
/**
@@ -53,10 +50,6 @@ public class Activator extends AbstractUIPlugin {
public void stop(BundleContext context) throws Exception {
plugin = null;
super.stop(context);
- if (serviceHostContainer != null) {
- serviceHostContainer.disconnect();
- serviceHostContainer = null;
- }
this.context = null;
}
@@ -64,14 +57,6 @@ public class Activator extends AbstractUIPlugin {
return context;
}
- public IContainer getContainer() {
- return serviceHostContainer;
- }
-
- public void setContainer(IContainer container) {
- this.serviceHostContainer = container;
- }
-
/**
* Returns the shared instance
*
diff --git a/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.client/src/org/eclipse/ecf/internal/examples/remoteservices/client/RemoteEnvironmentInfoServiceAccessHandler.java b/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.client/src/org/eclipse/ecf/internal/examples/remoteservices/client/RemoteEnvironmentInfoServiceAccessHandler.java
index 5a60a099d..d08afab53 100644
--- a/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.client/src/org/eclipse/ecf/internal/examples/remoteservices/client/RemoteEnvironmentInfoServiceAccessHandler.java
+++ b/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.client/src/org/eclipse/ecf/internal/examples/remoteservices/client/RemoteEnvironmentInfoServiceAccessHandler.java
@@ -12,6 +12,8 @@
package org.eclipse.ecf.internal.examples.remoteservices.client;
import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Map;
import javax.naming.ServiceUnavailableException;
@@ -21,6 +23,7 @@ import org.eclipse.ecf.core.IContainer;
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.util.ECFException;
import org.eclipse.ecf.core.util.IAsyncResult;
+import org.eclipse.ecf.discovery.identity.IServiceID;
import org.eclipse.ecf.discovery.ui.views.AbstractRemoteServiceAccessHandler;
import org.eclipse.ecf.examples.remoteservices.common.IRemoteEnvironmentInfo;
import org.eclipse.ecf.remoteservice.IRemoteCall;
@@ -42,71 +45,62 @@ import org.osgi.util.tracker.ServiceTracker;
public class RemoteEnvironmentInfoServiceAccessHandler extends AbstractRemoteServiceAccessHandler {
+ static Map remoteEnvironmentContainers = new HashMap();
+
public RemoteEnvironmentInfoServiceAccessHandler() {
}
- /* (non-Javadoc)
- * @see org.eclipse.ecf.discovery.ui.views.AbstractRemoteServiceAccessHandler#getContributionsForMatchingService()
- */
- protected IContributionItem[] getContributionsForMatchingService() {
- // If singleton not already set, create a new container (of type specified in serviceInfo
- // and set the singleton to it. If we can't create it for whatever reason, we have no
- // contribution
- if (Activator.getDefault().getContainer() == null) {
- try {
- final IContainer c = createContainer();
- final IRemoteServiceContainerAdapter adapter = (IRemoteServiceContainerAdapter) c.getAdapter(IRemoteServiceContainerAdapter.class);
+ private IContainer findContainerForService(IServiceID serviceID) throws ContainerCreateException {
+ IContainer result = null;
+ synchronized (remoteEnvironmentContainers) {
+ result = (IContainer) remoteEnvironmentContainers.get(serviceID);
+ if (result == null) {
+ result = createContainer();
+ final IRemoteServiceContainerAdapter adapter = (IRemoteServiceContainerAdapter) result.getAdapter(IRemoteServiceContainerAdapter.class);
if (adapter == null)
- return EMPTY_CONTRIBUTION;
- Activator.getDefault().setContainer(c);
- } catch (final ContainerCreateException e) {
- return EMPTY_CONTRIBUTION;
+ throw new ContainerCreateException("Container does not implement remote service container adapter.");
+ remoteEnvironmentContainers.put(serviceID, result);
}
}
- // The container is now not null
- final IContainer container = Activator.getDefault().getContainer();
- // not connected already...so setup contribution that allows connect
- final String ns = getConnectNamespace();
- final String id = getConnectID();
- // If there is no connect namespace or connect id specified, then we have no contribution
- if (container == null || ns == null || id == null)
- return EMPTY_CONTRIBUTION;
- // Create a new connect id from namespace and id
- ID connectTargetID = null;
- try {
- connectTargetID = createID(ns, id);
- } catch (final Exception e) {
- return EMPTY_CONTRIBUTION;
- }
- final ID connectedID = container.getConnectedID();
- // If the container is not already connected
- if (connectedID != null) {
- // If we're already connected, and connected to the *wrong* remote, then disconnect
- if (!connectedID.equals(connectTargetID)) {
- container.disconnect();
- // Otherwise we're already connected to the correct container, and we get the normal contributions
- } else
- return getConnectedContributions(container);
- }
- // Otherwise we need to connect so we create a contribution to allow the user to connect
- // Now we get the contribution to make connection to correct connectTargetID
- final ID cTargetID = connectTargetID;
+ return result;
+ }
+
+ private IContributionItem[] getConnectContribution(final IContainer container, final ID targetID) {
final IAction action = new Action() {
public void run() {
try {
- // Then we connect
- connectContainer(container, cTargetID, null);
- showInformation("Connected", NLS.bind("Connected to {0}", cTargetID.getName()));
+ // connect to target ID
+ connectContainer(container, targetID, null);
} catch (final ContainerConnectException e) {
showException(e);
}
}
};
- action.setText(NLS.bind("Connect to {0}", connectTargetID.getName()));
+ action.setText(NLS.bind("Connect to {0}", targetID.getName()));
return new IContributionItem[] {new ActionContributionItem(action)};
}
/* (non-Javadoc)
+ * @see org.eclipse.ecf.discovery.ui.views.AbstractRemoteServiceAccessHandler#getContributionsForMatchingService()
+ */
+ protected IContributionItem[] getContributionsForMatchingService() {
+ IContainer container = null;
+ try {
+ container = findContainerForService(getServiceInfo().getServiceID());
+ if (container == null)
+ return EMPTY_CONTRIBUTION;
+ if (container.getConnectedID() == null) {
+ // The container is not connected so we create/return action for connecting
+ return getConnectContribution(container, createConnectID());
+ } else {
+ return getConnectedContributions(container);
+ }
+ } catch (final ECFException e) {
+ return EMPTY_CONTRIBUTION;
+ }
+ }
+
+ /* (non-Javadoc)
* @see org.eclipse.ecf.discovery.ui.views.AbstractRemoteServiceAccessHandler#getContributionItemsForService(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter)
*/
protected IContributionItem[] getContributionItemsForService(final IRemoteServiceContainerAdapter adapter) {

Back to the top