Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2008-02-11 06:56:22 +0000
committerslewis2008-02-11 06:56:22 +0000
commit46a4b0cec0a9fbf1c81bd4161c437f4f9c10b6f1 (patch)
tree5bebc07fb51498e1d9e4d0c443e071f1ba63d772 /server-side
parent85f13e35d40cd728ed3f98efb424a436b2b8bc72 (diff)
downloadorg.eclipse.ecf-46a4b0cec0a9fbf1c81bd4161c437f4f9c10b6f1.tar.gz
org.eclipse.ecf-46a4b0cec0a9fbf1c81bd4161c437f4f9c10b6f1.tar.xz
org.eclipse.ecf-46a4b0cec0a9fbf1c81bd4161c437f4f9c10b6f1.zip
Created IApplication for example updatesite server and example remoteservices server.
Diffstat (limited to 'server-side')
-rw-r--r--server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.server/build.properties7
-rw-r--r--server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.server/launch/Remote EnvironmentInfo Server.launch22
-rw-r--r--server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.server/plugin.xml6
-rw-r--r--server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.server/src/org/eclipse/ecf/internal/examples/remoteservices/server/Activator.java108
-rw-r--r--server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.server/src/org/eclipse/ecf/internal/examples/remoteservices/server/DiscoverableServer.java162
5 files changed, 206 insertions, 99 deletions
diff --git a/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.server/build.properties b/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.server/build.properties
index 68a8af793..ef2047191 100644
--- a/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.server/build.properties
+++ b/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.server/build.properties
@@ -4,7 +4,10 @@ bin.includes = META-INF/,\
.,\
about.html,\
plugin.properties,\
- plugin.xml
+ plugin.xml,\
+ launch/
src.includes = META-INF/,\
about.html,\
- plugin.properties
+ plugin.properties,\
+ launch/,\
+ plugin.xml
diff --git a/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.server/launch/Remote EnvironmentInfo Server.launch b/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.server/launch/Remote EnvironmentInfo Server.launch
new file mode 100644
index 000000000..abfb12ed0
--- /dev/null
+++ b/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.server/launch/Remote EnvironmentInfo Server.launch
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<launchConfiguration type="org.eclipse.pde.ui.EquinoxLauncher">
+<booleanAttribute key="append.args" value="true"/>
+<booleanAttribute key="automaticAdd" value="false"/>
+<booleanAttribute key="automaticValidate" value="false"/>
+<stringAttribute key="bootstrap" value=""/>
+<stringAttribute key="checked" value="[NONE]"/>
+<booleanAttribute key="clearConfig" value="false"/>
+<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/Remote EnvironmentInfo Server"/>
+<booleanAttribute key="default_auto_start" value="false"/>
+<intAttribute key="default_start_level" value="4"/>
+<booleanAttribute key="includeOptional" value="true"/>
+<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.5.0_13"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-console -consolelog -application org.eclipse.ecf.examples.remoteservices.server.remoteServicesServer ecftcp://ecf.eclipse.org:3283/server"/>
+<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
+<stringAttribute key="pde.version" value="3.3"/>
+<booleanAttribute key="show_selected_only" value="false"/>
+<stringAttribute key="target_bundles" value="javax.servlet@default:default,org.apache.commons.logging@default:default,org.apache.commons.logging@default:default,org.eclipse.core.contenttype@default:default,org.eclipse.core.jobs@default:default,org.eclipse.core.runtime@default:default,org.eclipse.core.runtime.compatibility.auth@default:default,org.eclipse.core.runtime.compatibility.registry@default:default,org.eclipse.equinox.app@default:true,org.eclipse.equinox.common@default:default,org.eclipse.equinox.preferences@default:default,org.eclipse.equinox.registry@default:default,org.eclipse.osgi@:,org.eclipse.osgi.services@default:default,org.eclipse.osgi.util@default:default"/>
+<booleanAttribute key="tracing" value="false"/>
+<booleanAttribute key="useDefaultConfigArea" value="true"/>
+<stringAttribute key="workspace_bundles" value="org.eclipse.ecf@default:default,org.eclipse.ecf.discovery@default:default,org.eclipse.ecf.examples.remoteservices.common@default:default,org.eclipse.ecf.examples.remoteservices.server@default:default,org.eclipse.ecf.identity@default:default,org.eclipse.ecf.provider@default:default,org.eclipse.ecf.provider.jmdns@default:true,org.eclipse.ecf.provider.remoteservice@default:default,org.eclipse.ecf.remoteservice@default:default,org.eclipse.ecf.sharedobject@default:default"/>
+</launchConfiguration>
diff --git a/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.server/plugin.xml b/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.server/plugin.xml
index 33ca93ceb..732dc1684 100644
--- a/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.server/plugin.xml
+++ b/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.server/plugin.xml
@@ -2,4 +2,10 @@
<?eclipse version="3.2"?>
<plugin>
+ <extension id="remoteServicesServer" point="org.eclipse.core.runtime.applications">
+ <application cardinality="1" thread="main" visible="true">
+ <run class="org.eclipse.ecf.internal.examples.remoteservices.server.DiscoverableServer"/>
+ </application>
+ </extension>
+
</plugin>
diff --git a/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.server/src/org/eclipse/ecf/internal/examples/remoteservices/server/Activator.java b/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.server/src/org/eclipse/ecf/internal/examples/remoteservices/server/Activator.java
index 6ea12063e..78d3e73b2 100644
--- a/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.server/src/org/eclipse/ecf/internal/examples/remoteservices/server/Activator.java
+++ b/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.server/src/org/eclipse/ecf/internal/examples/remoteservices/server/Activator.java
@@ -11,23 +11,7 @@
package org.eclipse.ecf.internal.examples.remoteservices.server;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.ecf.core.ContainerFactory;
-import org.eclipse.ecf.core.IContainer;
-import org.eclipse.ecf.core.identity.ID;
-import org.eclipse.ecf.core.identity.IDFactory;
-import org.eclipse.ecf.discovery.IDiscoveryContainerAdapter;
-import org.eclipse.ecf.discovery.IServiceInfo;
-import org.eclipse.ecf.discovery.ServiceInfo;
-import org.eclipse.ecf.discovery.ServiceProperties;
-import org.eclipse.ecf.discovery.identity.IServiceID;
-import org.eclipse.ecf.discovery.identity.ServiceIDFactory;
import org.eclipse.ecf.discovery.service.IDiscoveryService;
-import org.eclipse.ecf.examples.remoteservices.common.IRemoteEnvironmentInfo;
-import org.eclipse.ecf.remoteservice.Constants;
-import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter;
-import org.eclipse.ecf.remoteservice.util.DiscoveryProperties;
-import org.eclipse.ecf.remoteservice.util.RemoteServiceProperties;
import org.eclipse.osgi.service.environment.EnvironmentInfo;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -38,30 +22,15 @@ import org.osgi.util.tracker.ServiceTracker;
*/
public class Activator implements BundleActivator {
- private static final String ECF_GENERIC_CLIENT = "ecf.generic.client";
-
- private static final String ECF_DISCOVERY_JMDNS = "ecf.discovery.jmdns";
-
- // The plug-in ID
- public static final String PLUGIN_ID = "org.eclipse.ecf.examples.remoteservices.server";
-
- private static final String REMOTE_SERVICE_TYPE = "_" + Constants.DISCOVERY_SERVICE_TYPE + "._tcp.local.";
-
- private static final String DEFAULT_CONNECT_TARGET = "ecftcp://ecf.eclipse.org:3283/server";
-
// The shared instance
private static Activator plugin;
private BundleContext context;
- private IContainer serviceHostContainer;
-
- private IServiceInfo serviceInfo;
-
- private IDiscoveryContainerAdapter discovery;
-
private ServiceTracker environmentInfoTracker;
+ private ServiceTracker discoveryTracker;
+
/**
* The constructor
*/
@@ -76,43 +45,12 @@ public class Activator implements BundleActivator {
return (EnvironmentInfo) environmentInfoTracker.getService();
}
- private void registerRemoteService(String className, Object service) {
- try {
- final IRemoteServiceContainerAdapter containerAdapter = (IRemoteServiceContainerAdapter) serviceHostContainer.getAdapter(IRemoteServiceContainerAdapter.class);
- Assert.isNotNull(containerAdapter);
- // register remote service
- containerAdapter.registerRemoteService(new String[] {className}, service, new RemoteServiceProperties(ECF_GENERIC_CLIENT, serviceHostContainer));
- System.out.println("Remote service registered for class " + className);
-
- // then register for discovery
- final String serviceName = System.getProperty("user.name") + System.currentTimeMillis();
- final IServiceID serviceID = ServiceIDFactory.getDefault().createServiceID(discovery.getServicesNamespace(), REMOTE_SERVICE_TYPE, serviceName);
- serviceInfo = new ServiceInfo(Constants.DISCOVERY_SERVICE_TYPE, null, 80, serviceID, new ServiceProperties(new DiscoveryProperties(className, ECF_GENERIC_CLIENT, serviceHostContainer)));
- // register discovery here
- discovery.registerService(serviceInfo);
- System.out.println("Service registered for discovery with IServiceID: " + serviceID);
- } catch (final Exception e) {
- e.printStackTrace();
- }
- }
-
- private void setupDiscovery() {
- try {
- if (discovery == null) {
- final ServiceTracker serviceTracker = new ServiceTracker(context, IDiscoveryService.class.getName(), null);
- serviceTracker.open();
- // XXX this should not be done in Activator...but we're going do do it anyway
- discovery = (IDiscoveryContainerAdapter) serviceTracker.waitForService(5000);
- serviceTracker.close();
- if (discovery == null) {
- final IContainer discoveryContainer = ContainerFactory.getDefault().createContainer(ECF_DISCOVERY_JMDNS);
- discoveryContainer.connect(null, null);
- discovery = (IDiscoveryContainerAdapter) discoveryContainer.getAdapter(IDiscoveryContainerAdapter.class);
- }
- }
- } catch (final Exception e) {
- e.printStackTrace();
+ public IDiscoveryService getDiscoveryService(int waittime) throws InterruptedException {
+ if (discoveryTracker == null) {
+ discoveryTracker = new ServiceTracker(context, org.eclipse.ecf.discovery.service.IDiscoveryService.class.getName(), null);
+ discoveryTracker.open();
}
+ return (IDiscoveryService) discoveryTracker.waitForService(waittime);
}
/*
@@ -122,19 +60,6 @@ public class Activator implements BundleActivator {
public void start(BundleContext context) throws Exception {
plugin = this;
this.context = context;
- setupDiscovery();
- createAndConnectServiceHostContainer();
- registerRemoteService(IRemoteEnvironmentInfo.class.getName(), new RemoteEnvironmentInfoImpl());
- }
-
- private void createAndConnectServiceHostContainer() {
- try {
- serviceHostContainer = ContainerFactory.getDefault().createContainer(ECF_GENERIC_CLIENT);
- final ID targetID = IDFactory.getDefault().createID(serviceHostContainer.getConnectNamespace(), DEFAULT_CONNECT_TARGET);
- serviceHostContainer.connect(targetID, null);
- } catch (final Exception e) {
- e.printStackTrace();
- }
}
/*
@@ -143,25 +68,14 @@ public class Activator implements BundleActivator {
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
- if (serviceInfo != null) {
- if (discovery != null) {
- discovery.unregisterService(serviceInfo);
- serviceInfo = null;
- final IContainer container = (IContainer) discovery.getAdapter(IContainer.class);
- if (container != null) {
- container.disconnect();
- }
- discovery = null;
- }
- }
- if (serviceHostContainer != null) {
- serviceHostContainer.disconnect();
- serviceHostContainer = null;
- }
if (environmentInfoTracker != null) {
environmentInfoTracker.close();
environmentInfoTracker = null;
}
+ if (discoveryTracker != null) {
+ discoveryTracker.close();
+ discoveryTracker = null;
+ }
this.context = null;
}
diff --git a/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.server/src/org/eclipse/ecf/internal/examples/remoteservices/server/DiscoverableServer.java b/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.server/src/org/eclipse/ecf/internal/examples/remoteservices/server/DiscoverableServer.java
new file mode 100644
index 000000000..fc64e59b1
--- /dev/null
+++ b/server-side/examples/bundles/org.eclipse.ecf.examples.remoteservices.server/src/org/eclipse/ecf/internal/examples/remoteservices/server/DiscoverableServer.java
@@ -0,0 +1,162 @@
+/****************************************************************************
+ * Copyright (c) 2008 Composent, Inc. and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Composent, Inc. - initial API and implementation
+ *****************************************************************************/
+
+package org.eclipse.ecf.internal.examples.remoteservices.server;
+
+import java.security.InvalidParameterException;
+import java.util.Map;
+
+import org.eclipse.ecf.core.ContainerFactory;
+import org.eclipse.ecf.core.IContainer;
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDFactory;
+import org.eclipse.ecf.core.security.ConnectContextFactory;
+import org.eclipse.ecf.core.security.IConnectContext;
+import org.eclipse.ecf.core.util.ECFException;
+import org.eclipse.ecf.discovery.IDiscoveryContainerAdapter;
+import org.eclipse.ecf.discovery.IServiceInfo;
+import org.eclipse.ecf.discovery.ServiceInfo;
+import org.eclipse.ecf.discovery.ServiceProperties;
+import org.eclipse.ecf.discovery.identity.IServiceID;
+import org.eclipse.ecf.discovery.identity.ServiceIDFactory;
+import org.eclipse.ecf.examples.remoteservices.common.IRemoteEnvironmentInfo;
+import org.eclipse.ecf.remoteservice.Constants;
+import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter;
+import org.eclipse.ecf.remoteservice.util.DiscoveryProperties;
+import org.eclipse.ecf.remoteservice.util.RemoteServiceProperties;
+import org.eclipse.equinox.app.IApplication;
+import org.eclipse.equinox.app.IApplicationContext;
+
+/**
+ *
+ */
+public class DiscoverableServer implements IApplication {
+
+ private static final String ECF_GENERIC_CLIENT = "ecf.generic.client";
+
+ private IContainer serviceHostContainer;
+
+ private IServiceInfo serviceInfo;
+
+ private IDiscoveryContainerAdapter discovery;
+
+ private String containerType;
+ private String connectTarget;
+ private String connectPassword;
+ private String serviceType;
+
+ private boolean done = false;
+
+ private String getCompleteServiceType() {
+ return "_" + serviceType + "._tcp.local."; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
+ */
+ public Object start(IApplicationContext ctxt) throws Exception {
+ final Map args = ctxt.getArguments();
+ initializeFromArguments((String[]) args.get("application.args")); //$NON-NLS-1$
+
+ serviceHostContainer = ContainerFactory.getDefault().createContainer(containerType);
+ final ID targetID = IDFactory.getDefault().createID(serviceHostContainer.getConnectNamespace(), connectTarget);
+ final IConnectContext connectContext = (connectPassword == null) ? null : ConnectContextFactory.createPasswordConnectContext(connectPassword);
+ serviceHostContainer.connect(targetID, connectContext);
+
+ discovery = Activator.getDefault().getDiscoveryService(3000);
+
+ final IRemoteServiceContainerAdapter containerAdapter = (IRemoteServiceContainerAdapter) serviceHostContainer.getAdapter(IRemoteServiceContainerAdapter.class);
+ // register remote service
+ final String className = IRemoteEnvironmentInfo.class.getName();
+ containerAdapter.registerRemoteService(new String[] {className}, new RemoteEnvironmentInfoImpl(), new RemoteServiceProperties(containerType, serviceHostContainer));
+ System.out.println("Registered remote service " + className);
+
+ // then register for discovery
+ final String serviceName = System.getProperty("user.name") + System.currentTimeMillis();
+ final IServiceID serviceID = ServiceIDFactory.getDefault().createServiceID(discovery.getServicesNamespace(), getCompleteServiceType(), serviceName);
+ serviceInfo = new ServiceInfo(serviceType, null, 80, serviceID, new ServiceProperties(new DiscoveryProperties(className, containerType, serviceHostContainer)));
+ // register discovery here
+ discovery.registerService(serviceInfo);
+ System.out.println("discovery publish\n\tserviceName=" + serviceID.getServiceName() + "\n\tserviceTypeID=" + serviceID.getServiceTypeID()); //$NON-NLS-1$ //$NON-NLS-2$
+
+ // wait until done
+ synchronized (this) {
+ while (!done) {
+ wait();
+ }
+ }
+ return new Integer(0);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.equinox.app.IApplication#stop()
+ */
+ public void stop() {
+ if (serviceInfo != null) {
+ if (discovery != null) {
+ try {
+ discovery.unregisterService(serviceInfo);
+ } catch (final ECFException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ serviceInfo = null;
+ final IContainer container = (IContainer) discovery.getAdapter(IContainer.class);
+ if (container != null) {
+ container.disconnect();
+ }
+ discovery = null;
+ }
+ }
+ if (serviceHostContainer != null) {
+ serviceHostContainer.disconnect();
+ serviceHostContainer = null;
+ }
+ synchronized (this) {
+ done = true;
+ notifyAll();
+ }
+
+ }
+
+ private void initializeFromArguments(String[] args) throws Exception {
+ if (args == null)
+ return;
+ for (int i = 0; i < args.length; i++) {
+ if (!args[i].startsWith("-")) { //$NON-NLS-1$
+ connectTarget = args[i++];
+ } else {
+ if (args[i - 1].equalsIgnoreCase("-containerType")) //$NON-NLS-1$
+ containerType = args[++i];
+ else if (args[i - 1].equalsIgnoreCase("-connectPassword")) //$NON-NLS-1$
+ connectPassword = args[++i];
+ else if (args[i - 1].equalsIgnoreCase("-serviceType")) //$NON-NLS-1$
+ serviceType = args[++i];
+ }
+ }
+ if (connectTarget == null) {
+ usage();
+ throw new InvalidParameterException("connectTarget cannot be null");
+ }
+ if (containerType == null)
+ containerType = ECF_GENERIC_CLIENT;
+ if (serviceType == null)
+ serviceType = Constants.DISCOVERY_SERVICE_TYPE;
+ }
+
+ /**
+ *
+ */
+ private void usage() {
+ System.out.println("usage: eclipse -console -application org.eclipse.ecf.examples.remoteservices.server.remoteServicesServer <connectTarget>");
+ }
+
+}

Back to the top