Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2007-07-05 23:50:36 +0000
committerslewis2007-07-05 23:50:36 +0000
commita7d651691540a9d68b28efb61ee98c3bcf3b6989 (patch)
tree3030c42a3b095b6f7bd4eefeab480c13b5d86714 /framework/bundles/org.eclipse.ecf.provider
parent816a269f28dc7017bbbd7f78db5d8160342a9097 (diff)
downloadorg.eclipse.ecf-a7d651691540a9d68b28efb61ee98c3bcf3b6989.tar.gz
org.eclipse.ecf-a7d651691540a9d68b28efb61ee98c3bcf3b6989.tar.xz
org.eclipse.ecf-a7d651691540a9d68b28efb61ee98c3bcf3b6989.zip
Added GenericServer application
Diffstat (limited to 'framework/bundles/org.eclipse.ecf.provider')
-rw-r--r--framework/bundles/org.eclipse.ecf.provider/META-INF/MANIFEST.MF3
-rw-r--r--framework/bundles/org.eclipse.ecf.provider/launchconfigs/ECF Client Application.launch12
-rw-r--r--framework/bundles/org.eclipse.ecf.provider/plugin.xml10
-rw-r--r--framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/app/GenericServer.java231
4 files changed, 249 insertions, 7 deletions
diff --git a/framework/bundles/org.eclipse.ecf.provider/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf.provider/META-INF/MANIFEST.MF
index 0f67af7bb..4db377fe0 100644
--- a/framework/bundles/org.eclipse.ecf.provider/META-INF/MANIFEST.MF
+++ b/framework/bundles/org.eclipse.ecf.provider/META-INF/MANIFEST.MF
@@ -18,7 +18,8 @@ Eclipse-BuddyPolicy: global
Bundle-ManifestVersion: 2
Require-Bundle: org.eclipse.equinox.common,
org.eclipse.ecf,
- org.eclipse.ecf.sharedobject
+ org.eclipse.ecf.sharedobject,
+ org.eclipse.equinox.app
Import-Package: org.eclipse.osgi.util;version="1.0.0",
org.osgi.framework;version="1.3.0",
org.osgi.service.log;version="1.3.0",
diff --git a/framework/bundles/org.eclipse.ecf.provider/launchconfigs/ECF Client Application.launch b/framework/bundles/org.eclipse.ecf.provider/launchconfigs/ECF Client Application.launch
index 82284cbc8..11dfa4ada 100644
--- a/framework/bundles/org.eclipse.ecf.provider/launchconfigs/ECF Client Application.launch
+++ b/framework/bundles/org.eclipse.ecf.provider/launchconfigs/ECF Client Application.launch
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
-<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.ecf.provider.app.ClientApplication"/>
+<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
+<listEntry value="/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/app/ClientApplication.java"/>
+</listAttribute>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
-<listEntry value="4"/>
+<listEntry value="1"/>
</listAttribute>
+<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
+<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.eclipse.ecf.provider.app.ClientApplication"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="org.eclipse.ecf.provider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Dorg.eclipse.ecf.core.internal.Trace=true -Dorg.eclipse.ecf.provider.Trace=true"/>
-<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
-<listEntry value="/org.eclipse.ecf.provider"/>
-</listAttribute>
-<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
</launchConfiguration>
diff --git a/framework/bundles/org.eclipse.ecf.provider/plugin.xml b/framework/bundles/org.eclipse.ecf.provider/plugin.xml
index 9663f57d6..79dd3cdf4 100644
--- a/framework/bundles/org.eclipse.ecf.provider/plugin.xml
+++ b/framework/bundles/org.eclipse.ecf.provider/plugin.xml
@@ -19,4 +19,14 @@
name="ecf.generic.client">
</containerFactory>
</extension>
+ <extension
+ id="GenericServer"
+ point="org.eclipse.core.runtime.applications">
+ <application
+ cardinality="*"
+ thread="main">
+ <run
+ class="org.eclipse.ecf.provider.app.GenericServer"/>
+ </application>
+ </extension>
</plugin>
diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/app/GenericServer.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/app/GenericServer.java
new file mode 100644
index 000000000..10a2381aa
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/app/GenericServer.java
@@ -0,0 +1,231 @@
+package org.eclipse.ecf.provider.app;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.security.PermissionCollection;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.ecf.core.identity.ID;
+import org.eclipse.ecf.core.identity.IDCreateException;
+import org.eclipse.ecf.core.identity.IDFactory;
+import org.eclipse.ecf.core.security.IConnectHandlerPolicy;
+import org.eclipse.ecf.core.sharedobject.ISharedObjectContainerGroupManager;
+import org.eclipse.ecf.provider.generic.SOContainerConfig;
+import org.eclipse.ecf.provider.generic.TCPServerSOContainer;
+import org.eclipse.ecf.provider.generic.TCPServerSOContainerGroup;
+import org.eclipse.equinox.app.IApplication;
+import org.eclipse.equinox.app.IApplicationContext;
+
+/**
+ * This class controls all aspects of the application's execution
+ */
+public class GenericServer implements IApplication {
+
+ private static Map serverGroups = new HashMap();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
+ */
+ public Object start(IApplicationContext context) throws Exception {
+ try {
+ String[] args = mungeArguments((String[]) context.getArguments()
+ .get("application.args")); //$NON-NLS-1$
+ if (args.length == 1
+ && (args[0].equals("-help") || args[0].equals("-h"))) { //$NON-NLS-1$ //$NON-NLS-2$
+ usage();
+ return IApplication.EXIT_OK;
+ } else if (args.length == 2
+ && (args[0].equals("-config") || args[0].equals("-c"))) { //$NON-NLS-1$ //$NON-NLS-2$
+ // Setup from configuration file (expected after -c <file>
+ FileInputStream fis = null;
+ try {
+ fis = new FileInputStream(args[1]);
+ setupServerFromConfig(new ServerConfigParser().load(fis));
+ } finally {
+ if (fis != null)
+ fis.close();
+ }
+ } else {
+ String hostname = TCPServerSOContainer.DEFAULT_HOST;
+ int port = TCPServerSOContainer.DEFAULT_PORT;
+ String name = TCPServerSOContainer.DEFAULT_NAME;
+ int keepAlive = TCPServerSOContainer.DEFAULT_KEEPALIVE;
+ switch (args.length) {
+ case 4:
+ keepAlive = Integer.parseInt(args[3]);
+ case 3:
+ name = args[2];
+ case 2:
+ hostname = args[1];
+ case 1:
+ port = Integer.parseInt(args[0]);
+ }
+ setupServerFromParameters(hostname, port, name, keepAlive);
+ }
+ synchronized (this) {
+ this.wait();
+ }
+ return IApplication.EXIT_OK;
+ } catch (Exception e) {
+ stop();
+ throw e;
+ }
+ }
+
+ private void usage() {
+ System.out
+ .println("Usage: eclipse.exe -application " //$NON-NLS-1$
+ + this.getClass().getName()
+ + "[port [hostname [groupname [keepAlive]]]] | [-config|-c <configfile.xml>]"); //$NON-NLS-1$
+ System.out
+ .println(" Examples: eclipse -application org.eclipse.ecf.provider.GenericServer"); //$NON-NLS-1$
+ System.out
+ .println(" eclipse -application org.eclipse.ecf.provider.GenericServer " + 7777); //$NON-NLS-1$
+ System.out
+ .println(" eclipse -application org.eclipse.ecf.provider.GenericServer " + 7777 //$NON-NLS-1$
+ + " foobarhost group 35000"); //$NON-NLS-1$
+ System.out
+ .println(" eclipse -application org.eclipse.ecf.provider.GenericServer -c myconfig.xml"); //$NON-NLS-1$
+
+ }
+
+ /**
+ * @param hostname
+ * @param port
+ * @param name
+ * @param keepAlive
+ */
+ private void setupServerFromParameters(String hostname, int port,
+ String name, int keepAlive) throws IOException, IDCreateException {
+ String hostnamePort = hostname + ":" + port; //$NON-NLS-1$
+ synchronized (serverGroups) {
+ TCPServerSOContainerGroup serverGroup = (TCPServerSOContainerGroup) serverGroups
+ .get(hostnamePort);
+ if (serverGroup == null) {
+ System.out
+ .println("Putting server " + hostnamePort + " on the air..."); //$NON-NLS-1$ //$NON-NLS-2$
+ serverGroup = new TCPServerSOContainerGroup(hostname, port);
+ String url = TCPServerSOContainer.DEFAULT_PROTOCOL + "://" //$NON-NLS-1$
+ + hostnamePort + name;
+ TCPServerSOContainer container = createServerContainer(url,
+ serverGroup, name, keepAlive);
+ // Setup join policy
+ ((ISharedObjectContainerGroupManager) container)
+ .setConnectPolicy(new JoinListener());
+ serverGroup.putOnTheAir();
+ serverGroups.put(hostnamePort, serverGroup);
+ System.out
+ .println("GenericServer " + hostnamePort + " on the air."); //$NON-NLS-1$ //$NON-NLS-2$
+ } else {
+ System.out.println("GenericServer " + hostnamePort //$NON-NLS-1$
+ + " already on the air. No changes made."); //$NON-NLS-1$
+ }
+ }
+
+ }
+
+ /**
+ * @param load
+ */
+ private void setupServerFromConfig(List connectors) throws IOException,
+ IDCreateException {
+ for (Iterator i = connectors.iterator(); i.hasNext();) {
+ Connector connector = (Connector) i.next();
+ String hostname = connector.getHostname();
+ int port = connector.getPort();
+ String hostnamePort = hostname + ":" + port; //$NON-NLS-1$
+ TCPServerSOContainerGroup serverGroup = null;
+ synchronized (serverGroups) {
+ serverGroup = (TCPServerSOContainerGroup) serverGroups
+ .get(hostnamePort);
+ if (serverGroup == null) {
+ System.out
+ .println("Putting server " + hostnamePort + " on the air..."); //$NON-NLS-1$ //$NON-NLS-2$
+ serverGroup = new TCPServerSOContainerGroup(hostname, port);
+ List groups = connector.getGroups();
+ for (Iterator g = groups.iterator(); g.hasNext();) {
+ NamedGroup group = (NamedGroup) g.next();
+ TCPServerSOContainer container = createServerContainer(
+ group.getIDForGroup(), serverGroup, group
+ .getName(), connector.getTimeout());
+ // Setup join policy
+ ((ISharedObjectContainerGroupManager) container)
+ .setConnectPolicy(new JoinListener());
+ }
+ serverGroup.putOnTheAir();
+ serverGroups.put(hostnamePort, serverGroup);
+ System.out.println("GenericServer " + hostnamePort //$NON-NLS-1$
+ + " on the air."); //$NON-NLS-1$
+ } else {
+ System.out.println("GenericServer " + hostnamePort //$NON-NLS-1$
+ + " already on the air. No changes made."); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.equinox.app.IApplication#stop()
+ */
+ public void stop() {
+ synchronized (serverGroups) {
+ for (Iterator i = serverGroups.keySet().iterator(); i.hasNext();) {
+ TCPServerSOContainerGroup serverGroup = (TCPServerSOContainerGroup) serverGroups
+ .get(i.next());
+ serverGroup.takeOffTheAir();
+ Iterator iter = serverGroup.elements();
+ for (; iter.hasNext();) {
+ TCPServerSOContainer container = (TCPServerSOContainer) iter
+ .next();
+ container.dispose();
+ }
+ }
+ }
+ synchronized (this) {
+ this.notify();
+ }
+ }
+
+ private String[] mungeArguments(String originalArgs[]) {
+ if (originalArgs == null)
+ return new String[0];
+ List l = new ArrayList();
+ for (int i = 0; i < originalArgs.length; i++)
+ if (!originalArgs[i].equals("-pdelaunch")) //$NON-NLS-1$
+ l.add(originalArgs[i]);
+ return (String[]) l.toArray(new String[] {});
+ }
+
+ private static TCPServerSOContainer createServerContainer(String id,
+ TCPServerSOContainerGroup group, String path, int keepAlive)
+ throws IDCreateException {
+ System.out
+ .println(" Creating container with id=" + id + " keepAlive=" + keepAlive); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ ID newServerID = IDFactory.getDefault().createStringID(id);
+ SOContainerConfig config = new SOContainerConfig(newServerID);
+ return new TCPServerSOContainer(config, group, path, keepAlive);
+ }
+
+ static class JoinListener implements IConnectHandlerPolicy {
+ public PermissionCollection checkConnect(Object addr, ID fromID,
+ ID targetID, String targetGroup, Object joinData)
+ throws Exception {
+ System.out
+ .println("CLIENT CONNECT: fromAddress=" + addr + ";fromID=" + fromID + ";targetGroup=" + targetGroup); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ return null;
+ }
+
+ public void refresh() {
+ }
+
+ }
+
+}

Back to the top