Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2008-02-07 01:46:09 +0000
committerslewis2008-02-07 01:46:09 +0000
commitccf3a833b18b409dc6017086fa608a725733356b (patch)
treed55b4998af1ef750e5ae07083f74fdee11f2bb5b /server-side
parentc36e37c55163c2500ffea93f7d67fac6b7fba265 (diff)
downloadorg.eclipse.ecf-ccf3a833b18b409dc6017086fa608a725733356b.tar.gz
org.eclipse.ecf-ccf3a833b18b409dc6017086fa608a725733356b.tar.xz
org.eclipse.ecf-ccf3a833b18b409dc6017086fa608a725733356b.zip
Additions to example remote service client and server
Diffstat (limited to 'server-side')
-rw-r--r--server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.client/META-INF/MANIFEST.MF4
-rw-r--r--server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.client/src/org/eclipse/ecf/internal/examples/remoteservices/client/Activator.java42
-rw-r--r--server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.client/src/org/eclipse/ecf/internal/examples/remoteservices/client/RemoteEnvironmentInfoServiceAccessHandler.java102
3 files changed, 70 insertions, 78 deletions
diff --git a/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.client/META-INF/MANIFEST.MF b/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.client/META-INF/MANIFEST.MF
index b21b9c491..a27282ad6 100644
--- a/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.client/META-INF/MANIFEST.MF
+++ b/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.client/META-INF/MANIFEST.MF
@@ -9,9 +9,11 @@ Bundle-Localization: plugin
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.ecf;bundle-version="1.3.0",
+ org.eclipse.ecf.discovery;bundle-version="2.0.0",
org.eclipse.ecf.discovery.ui;bundle-version="2.0.0",
org.eclipse.ecf.remoteservice;bundle-version="1.2.0",
- org.eclipse.ecf.examples.remoteservices.common;bundle-version="1.0.0"
+ org.eclipse.ecf.examples.remoteservices.common;bundle-version="1.0.0",
+ org.eclipse.ecf.ui;bundle-version="1.3.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.4
Eclipse-LazyStart: true
Export-Package: org.eclipse.ecf.internal.examples.remoteservices.client;x-internal:=true
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 bae3be2b1..70c81f0dc 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
@@ -2,13 +2,7 @@ package org.eclipse.ecf.internal.examples.remoteservices.client;
import org.eclipse.ecf.core.ContainerFactory;
import org.eclipse.ecf.core.IContainer;
-import org.eclipse.ecf.core.IContainerListener;
-import org.eclipse.ecf.core.events.IContainerEvent;
-import org.eclipse.ecf.core.identity.ID;
-import org.eclipse.ecf.core.identity.IDFactory;
import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter;
-import org.eclipse.ecf.remoteservice.IRemoteServiceListener;
-import org.eclipse.ecf.remoteservice.events.IRemoteServiceEvent;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
@@ -17,43 +11,16 @@ import org.osgi.framework.BundleContext;
*/
public class Activator extends AbstractUIPlugin {
+ private static final String ECF_GENERIC_CLIENT = "ecf.generic.client";
+
// The plug-in ID
public static final String PLUGIN_ID = "org.eclipse.ecf.examples.remoteservices.client";
- private static final String DEFAULT_CONNECT_TARGET = "ecftcp://ecf.eclipse.org:3282/server";
-
// The shared instance
private static Activator plugin;
private IContainer serviceHostContainer;
- private IRemoteServiceContainerAdapter getRemoteServiceContainerAdapter(IContainer container) {
- return (IRemoteServiceContainerAdapter) container.getAdapter(IRemoteServiceContainerAdapter.class);
- }
-
- private void createAndConnectServiceHostContainer() {
- try {
- serviceHostContainer = ContainerFactory.getDefault().createContainer("ecf.generic.client");
- final ID targetID = IDFactory.getDefault().createID(serviceHostContainer.getConnectNamespace(), DEFAULT_CONNECT_TARGET);
- serviceHostContainer.addListener(new IContainerListener() {
- public void handleEvent(IContainerEvent event) {
- // TODO Auto-generated method stub
- System.out.println("serviceHostContainerEvent(" + event + ")");
- }
- });
- final IRemoteServiceContainerAdapter containerAdapter = getRemoteServiceContainerAdapter(serviceHostContainer);
- containerAdapter.addRemoteServiceListener(new IRemoteServiceListener() {
-
- public void handleServiceEvent(IRemoteServiceEvent event) {
- System.out.println("remoteServiceEvent(" + event + ")");
- }
- });
- serviceHostContainer.connect(targetID, null);
- } catch (final Exception e) {
- e.printStackTrace();
- }
- }
-
/**
* The constructor
*/
@@ -67,7 +34,8 @@ public class Activator extends AbstractUIPlugin {
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
- createAndConnectServiceHostContainer();
+ serviceHostContainer = ContainerFactory.getDefault().createContainer(ECF_GENERIC_CLIENT);
+ serviceHostContainer.getAdapter(IRemoteServiceContainerAdapter.class);
}
/*
@@ -83,7 +51,7 @@ public class Activator extends AbstractUIPlugin {
}
}
- public IContainer getConnectedContainer() {
+ public IContainer getContainer() {
return serviceHostContainer;
}
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 559559adb..e7ec51a3b 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
@@ -1,11 +1,11 @@
package org.eclipse.ecf.internal.examples.remoteservices.client;
import java.io.NotSerializableException;
-import java.util.ArrayList;
import java.util.Arrays;
-import java.util.List;
+import org.eclipse.ecf.core.ContainerConnectException;
import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.discovery.ui.handlers.AbstractRemoteServiceAccessHandler;
import org.eclipse.ecf.examples.remoteservices.common.IRemoteEnvironmentInfo;
import org.eclipse.ecf.remoteservice.IRemoteCall;
@@ -30,24 +30,57 @@ public class RemoteEnvironmentInfoServiceAccessHandler extends AbstractRemoteSer
public RemoteEnvironmentInfoServiceAccessHandler() {
}
- protected List getRemoteServiceContainerAdapters() {
- final List results = new ArrayList();
- final IContainer container = Activator.getDefault().getConnectedContainer();
- if (container == null)
- return results;
- // If it's not connected already, then return empty list
- if (container.getConnectedID() == null)
- return results;
- final IRemoteServiceContainerAdapter adapter = (IRemoteServiceContainerAdapter) container.getAdapter(IRemoteServiceContainerAdapter.class);
- // If namespaces match and there's an adapter then add it to list
- if (container.getConnectNamespace().getName().equals(getConnectNamespace()) && adapter != null)
- results.add(adapter);
- return results;
+ protected IContributionItem[] getContributionsForMatchingService() {
+ final IContainer container = Activator.getDefault().getContainer();
+ // not connected already...so setup contribution that allows connect
+ final String ns = getConnectNamespace();
+ final String id = getConnectID();
+ if (container == null || ns == null || id == null)
+ return EMPTY_CONTRIBUTION;
+ ID connectTargetID = null;
+ try {
+ connectTargetID = createID(ns, id);
+ } catch (final Exception e) {
+ return EMPTY_CONTRIBUTION;
+ }
+ final ID connectedID = container.getConnectedID();
+ 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 right container
+ } else
+ return super.getContributionsForMatchingService();
+ }
+ // Now we get the contribution to make connection to correct connectTargetID
+ final ID cTargetID = connectTargetID;
+ final IAction action = new Action() {
+ public void run() {
+ try {
+ // Then we connect
+ connectContainer(container, cTargetID, null);
+ } catch (ContainerConnectException e) {
+ showException(e);
+ }
+ }
+ };
+ action.setText(NLS.bind("Connect to {0}", connectTargetID.getName()));
+ return new IContributionItem[] {new ActionContributionItem(action)};
}
- protected IRemoteCall createGetPropertyRemoteCall() throws ClassNotFoundException, NotSerializableException {
+ protected IContributionItem[] getContributionItemsForService(final IRemoteServiceContainerAdapter adapter) {
+ final String className = getRemoteServiceClass();
+ if (className == null)
+ return NOT_AVAILABLE_CONTRIBUTION;
+ else if (className.equals(IRemoteEnvironmentInfo.class.getName()))
+ return getContributionItemsForRemoteEnvironmentService(adapter);
+ else
+ return NOT_AVAILABLE_CONTRIBUTION;
+ }
+
+ private IRemoteCall createGetPropertyRemoteCall() throws ClassNotFoundException, NotSerializableException {
IRemoteEnvironmentInfo.class.getDeclaredMethods();
- final InputDialog input = new InputDialog(null, "Get property", "Enter key", "user.name", null);
+ final InputDialog input = new InputDialog(null, "Get property", "Enter property key", "user.name", null);
input.setBlockOnOpen(true);
final Object[] params = new Object[1];
if (input.open() == Window.OK) {
@@ -71,16 +104,17 @@ public class RemoteEnvironmentInfoServiceAccessHandler extends AbstractRemoteSer
return null;
}
- protected void showResult(final Object result) {
+ private void showResult(final String serviceInterface, final IRemoteCall remoteCall, final Object result) {
final Object display = (result != null && result.getClass().isArray()) ? Arrays.asList((Object[]) result) : result;
+ final Object[] bindings = new Object[] {serviceInterface, remoteCall.getMethod(), Arrays.asList(remoteCall.getParameters()), display};
Display.getDefault().asyncExec(new Runnable() {
public void run() {
- MessageDialog.openInformation(null, "Received Response", NLS.bind("{0}", display));
+ MessageDialog.openInformation(null, "Received Response", NLS.bind("Service: {0}\n\nMethod: {1}\nParameters: {2}\n\nResult: {3}", bindings));
}
});
}
- protected void showException(final Throwable t) {
+ private void showException(final Throwable t) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
MessageDialog.openInformation(null, "Received Exception", NLS.bind("Exception: {0}", t.getLocalizedMessage()));
@@ -88,16 +122,6 @@ public class RemoteEnvironmentInfoServiceAccessHandler extends AbstractRemoteSer
});
}
- protected IContributionItem[] getContributionItemsForService(final IRemoteServiceContainerAdapter adapter) {
- final String className = getRemoteServiceClass();
- if (className == null)
- return NOT_AVAILABLE_CONTRIBUTION;
- else if (className.equals(IRemoteEnvironmentInfo.class.getName()))
- return getContributionItemsForRemoteEnvironmentService(adapter);
- else
- return NOT_AVAILABLE_CONTRIBUTION;
- }
-
private IContributionItem createContributionItem(final IRemoteService remoteService, final int invokeMode) {
final IAction action = new Action() {
public void run() {
@@ -107,7 +131,7 @@ public class RemoteEnvironmentInfoServiceAccessHandler extends AbstractRemoteSer
switch (invokeMode) {
// callSynch
case 0 :
- showResult(remoteService.callSynch(remoteCall));
+ showResult(IRemoteEnvironmentInfo.class.getName(), remoteCall, remoteService.callSynch(remoteCall));
break;
// callAsynch (listener)
case 1 :
@@ -118,19 +142,19 @@ public class RemoteEnvironmentInfoServiceAccessHandler extends AbstractRemoteSer
if (complete.hadException()) {
showException(complete.getException());
} else
- showResult(complete.getResponse());
+ showResult(IRemoteEnvironmentInfo.class.getName(), remoteCall, complete.getResponse());
}
}
});
break;
// callAsynch (future)
case 2 :
- showResult(remoteService.callAsynch(remoteCall).get());
+ showResult(IRemoteEnvironmentInfo.class.getName(), remoteCall, remoteService.callAsynch(remoteCall).get());
break;
// proxy
case 3 :
IRemoteEnvironmentInfo proxy = (IRemoteEnvironmentInfo) remoteService.getProxy();
- showResult(proxy.getProperty((String) remoteCall.getParameters()[0]));
+ showResult(IRemoteEnvironmentInfo.class.getName(), remoteCall, proxy.getProperty((String) remoteCall.getParameters()[0]));
break;
}
}
@@ -142,16 +166,16 @@ public class RemoteEnvironmentInfoServiceAccessHandler extends AbstractRemoteSer
};
switch (invokeMode) {
case 0 :
- action.setText("getProperty (synch)");
+ action.setText("getProperty (s)");
break;
case 1 :
- action.setText("getProperty (async)");
+ action.setText("getProperty (a)");
break;
case 2 :
- action.setText("getProperty (future)");
+ action.setText("getProperty (f)");
break;
case 3 :
- action.setText("getProperty (proxy)");
+ action.setText("getProperty (p)");
break;
}
return new ActionContributionItem(action);
@@ -169,8 +193,6 @@ public class RemoteEnvironmentInfoServiceAccessHandler extends AbstractRemoteSer
final IRemoteService remoteService = adapter.getRemoteService(references[0]);
return new IContributionItem[] {createContributionItem(remoteService, 0), createContributionItem(remoteService, 1), createContributionItem(remoteService, 2), createContributionItem(remoteService, 3)};
} catch (final Exception e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
return NOT_AVAILABLE_CONTRIBUTION;
}

Back to the top