Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2005-05-06 02:28:48 -0400
committerslewis2005-05-06 02:28:48 -0400
commite5c237a7f4e179b82810fe66b73ec92c6e4fd108 (patch)
treeb02c9819f0886cd9e39e05c5b09e008196aa1cd3
parent28600909db1d8a643d42dfbd3321b3722e68ad0f (diff)
downloadorg.eclipse.ecf-e5c237a7f4e179b82810fe66b73ec92c6e4fd108.tar.gz
org.eclipse.ecf-e5c237a7f4e179b82810fe66b73ec92c6e4fd108.tar.xz
org.eclipse.ecf-e5c237a7f4e179b82810fe66b73ec92c6e4fd108.zip
Added code for parsing xml config file. See -c param to ServerApplication class in org.eclipse.ecf.provider project
-rw-r--r--framework/bundles/org.eclipse.ecf.provider/build.properties6
-rw-r--r--framework/bundles/org.eclipse.ecf.provider/conf/server.xml5
-rw-r--r--framework/bundles/org.eclipse.ecf.provider/launchconfigs/ServerApplication.launch1
-rw-r--r--framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/app/Connector.java63
-rw-r--r--framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/app/NamedGroup.java26
-rw-r--r--framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/app/ServerApplication.java107
-rw-r--r--framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/app/ServerConfigParser.java72
-rw-r--r--server-side/features/org.eclipse.ecf.server-feature/bin/startserver.bat2
-rw-r--r--server-side/features/org.eclipse.ecf.server-feature/bin/startserver.cmd2
-rw-r--r--server-side/features/org.eclipse.ecf.server-feature/bin/startserver.sh2
-rw-r--r--server-side/features/org.eclipse.ecf.server-feature/build.properties3
-rw-r--r--server-side/features/org.eclipse.ecf.server-feature/conf/server.xml5
12 files changed, 205 insertions, 89 deletions
diff --git a/framework/bundles/org.eclipse.ecf.provider/build.properties b/framework/bundles/org.eclipse.ecf.provider/build.properties
index 21ccba963..fdd135bf2 100644
--- a/framework/bundles/org.eclipse.ecf.provider/build.properties
+++ b/framework/bundles/org.eclipse.ecf.provider/build.properties
@@ -2,8 +2,10 @@ source.provider.jar = src/
output.provider.jar = bin/
bin.includes = plugin.xml,\
provider.jar,\
- META-INF/
+ META-INF/,\
+ conf/
src.includes = src/,\
plugin.xml,\
provider.jar,\
- META-INF/
+ META-INF/,\
+ conf/
diff --git a/framework/bundles/org.eclipse.ecf.provider/conf/server.xml b/framework/bundles/org.eclipse.ecf.provider/conf/server.xml
new file mode 100644
index 000000000..61399a028
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.provider/conf/server.xml
@@ -0,0 +1,5 @@
+<server>
+ <connector protocol="ecftcp" hostname="localhost" port="3282" timeout="10000">
+ <group name="server"/>
+ </connector>
+</server> \ No newline at end of file
diff --git a/framework/bundles/org.eclipse.ecf.provider/launchconfigs/ServerApplication.launch b/framework/bundles/org.eclipse.ecf.provider/launchconfigs/ServerApplication.launch
index 42cc1b5d2..9fdcc5a9e 100644
--- a/framework/bundles/org.eclipse.ecf.provider/launchconfigs/ServerApplication.launch
+++ b/framework/bundles/org.eclipse.ecf.provider/launchconfigs/ServerApplication.launch
@@ -1,6 +1,7 @@
<?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.ServerApplication"/>
+<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-c conf/server.xml"/>
<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"/>
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/app/Connector.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/app/Connector.java
new file mode 100644
index 000000000..81d802f05
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/app/Connector.java
@@ -0,0 +1,63 @@
+/**
+ *
+ */
+package org.eclipse.ecf.provider.app;
+
+import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.ecf.provider.generic.TCPServerSOContainer;
+
+
+public class Connector {
+ public static final int DEFAULT_PORT = TCPServerSOContainer.DEFAULT_PORT;
+ public static final int DEFAULT_TIMEOUT = TCPServerSOContainer.DEFAULT_KEEPALIVE;
+ public static final String DEFAULT_HOSTNAME = TCPServerSOContainer.DEFAULT_HOST;
+ public static final String DEFAULT_SERVERNAME = TCPServerSOContainer.DEFAULT_NAME;
+ public static final String DEFAULT_PROTOCOL = TCPServerSOContainer.DEFAULT_PROTOCOL;
+
+ private final ServerConfigParser parser;
+ int port = DEFAULT_PORT;
+ int timeout = DEFAULT_TIMEOUT;
+ String protocol = DEFAULT_PROTOCOL;
+ String hostname = DEFAULT_HOSTNAME;
+ List groups = new ArrayList();
+
+ public Connector(ServerConfigParser parser, String protocol, String host, int port, int timeout) {
+ this.parser = parser;
+ if (protocol != null && !protocol.equals("")) this.protocol = protocol;
+ if (host != null && !host.equals("")) this.hostname = host;
+ else {
+ try {
+ InetAddress addr = InetAddress.getLocalHost();
+ this.hostname = addr.getCanonicalHostName();
+ } catch (Exception e) {
+ this.hostname = "localhost";
+ }
+ }
+ this.port = port;
+ this.timeout = timeout;
+ }
+ public void addGroup(NamedGroup grp) {
+ groups.add(grp);
+ }
+ public String getProtocol() {
+ return protocol;
+ }
+ public String getHostname() {
+ return hostname;
+ }
+ public int getPort() {
+ return port;
+ }
+ public int getTimeout() {
+ return timeout;
+ }
+ public List getGroups() {
+ return groups;
+ }
+ public String getID() {
+ return getProtocol()+"://"+getHostname()+":"+getPort();
+ }
+} \ No newline at end of file
diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/app/NamedGroup.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/app/NamedGroup.java
new file mode 100644
index 000000000..84beb1952
--- /dev/null
+++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/app/NamedGroup.java
@@ -0,0 +1,26 @@
+/**
+ *
+ */
+package org.eclipse.ecf.provider.app;
+
+public class NamedGroup {
+ Connector parent;
+ String name;
+
+ public NamedGroup(String name) {
+ this.name = name;
+ }
+ protected void setParent(Connector c) {
+ this.parent = c;
+ }
+ public String getName() {
+ return cleanGroupName(name);
+ }
+ public String getIDForGroup() {
+ return parent.getID()+getName();
+ }
+ protected String cleanGroupName(String name) {
+ String res = ((name.startsWith("/"))?name:"/"+name);
+ return res;
+ }
+} \ No newline at end of file
diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/app/ServerApplication.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/app/ServerApplication.java
index 00de1ea57..6681a2780 100644
--- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/app/ServerApplication.java
+++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/app/ServerApplication.java
@@ -1,7 +1,13 @@
package org.eclipse.ecf.provider.app;
+import java.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
import org.eclipse.ecf.core.identity.ID;
import org.eclipse.ecf.core.identity.IDFactory;
+import org.eclipse.ecf.core.identity.IDInstantiationException;
import org.eclipse.ecf.provider.generic.SOContainerConfig;
import org.eclipse.ecf.provider.generic.TCPServerSOContainer;
import org.eclipse.ecf.provider.generic.TCPServerSOContainerGroup;
@@ -9,8 +15,9 @@ import org.eclipse.ecf.provider.generic.TCPServerSOContainerGroup;
/**
* An ECF server container implementation that runs as an application.
* <p>
- * Usage: java org.eclipse.ecf.provider.app.ServerApplication &lt;serverid&gt
+ * Usage: java org.eclipse.ecf.provider.app.ServerApplication [-c &lt;configfile&gt | &lt;serverid&gt]
* <p>
+ * If -p &lt;configfile&gt is used, the server configuration is loaded and used to setup servers.
* If &lt;serverid&gt; is omitted or "-" is specified,
* ecftcp://localhost:3282/server" is used. The &lt;serverid&gt; must correspond to URI syntax as
* defined by <a href="http://www.ietf.org/rfc/rfc2396.txt"><i>RFC&nbsp;2396: Uniform
@@ -20,42 +27,80 @@ import org.eclipse.ecf.provider.generic.TCPServerSOContainerGroup;
*/
public class ServerApplication {
public static final int DEFAULT_KEEPALIVE = TCPServerSOContainer.DEFAULT_KEEPALIVE;
- static TCPServerSOContainerGroup serverGroup = null;
- static TCPServerSOContainer server = null;
+ static TCPServerSOContainerGroup serverGroups[] = null;
+ static List servers = new ArrayList();
public static void main(String args[]) throws Exception {
// Get server identity
String serverName = null;
+ List connectors = null;
if (args.length > 0) {
- if (!args[0].equals("-"))
+ if (args[0].equals("-c")) {
+ ServerConfigParser parser = new ServerConfigParser();
+ connectors = parser.load(new FileInputStream(args[1]));
+ } else if (!args[0].equals("-"))
serverName = args[0];
}
- if (serverName == null) {
- serverName = TCPServerSOContainer.getDefaultServerURL();
- }
- java.net.URI anURL = new java.net.URI(serverName);
- int port = anURL.getPort();
- if (port == -1) {
- port = TCPServerSOContainer.DEFAULT_PORT;
- }
- String name = anURL.getPath();
- if (name == null) {
- name = TCPServerSOContainer.DEFAULT_NAME;
- }
- // Setup server group
- serverGroup = new TCPServerSOContainerGroup(anURL.getPort());
- // Create identity for server
- ID id = IDFactory.makeStringID(serverName);
- // Create server config object with identity and default timeout
- SOContainerConfig config = new SOContainerConfig(id);
- // Make server instance
- System.out.print("Creating ECF server container...");
- server = new TCPServerSOContainer(config, serverGroup, name,
- TCPServerSOContainer.DEFAULT_KEEPALIVE);
- serverGroup.putOnTheAir();
- System.out.println("success!");
- System.out
- .println("Waiting for client connections at '" + id.getName() + "'...");
- System.out.println("<ctrl>-c to stop server");
+ if (connectors != null) {
+ serverGroups = new TCPServerSOContainerGroup[connectors.size()];
+ int j=0;
+ for(Iterator i=connectors.iterator(); i.hasNext(); ) {
+ Connector connect = (Connector) i.next();
+ serverGroups[j] = makeServerGroup(connect.getHostname(),connect.getPort());
+ List groups = connect.getGroups();
+
+ for(Iterator g=groups.iterator(); g.hasNext(); ) {
+ NamedGroup group = (NamedGroup) g.next();
+ TCPServerSOContainer cont = makeServerContainer(group.getIDForGroup(),serverGroups[j],group.getName(),connect.getTimeout());
+ servers.add(cont);
+ }
+ System.out.println("Putting server "+connect.getHostname()+" on the air");
+ serverGroups[j].putOnTheAir();
+ j++;
+ System.out.println("<ctrl>-c to stop server");
+ }
+ } else {
+ if (serverName == null) {
+ serverName = TCPServerSOContainer.getDefaultServerURL();
+ }
+ java.net.URI anURL = new java.net.URI(serverName);
+ int port = anURL.getPort();
+ if (port == -1) {
+ port = TCPServerSOContainer.DEFAULT_PORT;
+ }
+ String name = anURL.getPath();
+ if (name == null) {
+ name = TCPServerSOContainer.DEFAULT_NAME;
+ }
+ serverGroups = new TCPServerSOContainerGroup[1];
+ // Setup server group
+ serverGroups[0] = new TCPServerSOContainerGroup(anURL.getPort());
+ // Create identity for server
+ ID id = IDFactory.makeStringID(serverName);
+ // Create server config object with identity and default timeout
+ SOContainerConfig config = new SOContainerConfig(id);
+ // Make server instance
+ System.out.print("Creating ECF server container...");
+ TCPServerSOContainer server = new TCPServerSOContainer(config, serverGroups[0], name,
+ TCPServerSOContainer.DEFAULT_KEEPALIVE);
+ serverGroups[0].putOnTheAir();
+ servers.add(server);
+ System.out.println("success!");
+ System.out
+ .println("Waiting for client connections at '" + id.getName() + "'...");
+ System.out.println("<ctrl>-c to stop server");
+ }
}
+
+ protected static TCPServerSOContainerGroup makeServerGroup(String name, int port) {
+ System.out.println("Creating server named "+name+" to listen on port "+port);
+ TCPServerSOContainerGroup group = new TCPServerSOContainerGroup(name,port);
+ return group;
+ }
+ protected static TCPServerSOContainer makeServerContainer(String id, TCPServerSOContainerGroup group, String path, int keepAlive) throws IDInstantiationException {
+ System.out.println(" Creating container with identity "+id+", path "+path+" keepAlive="+keepAlive);
+ ID newServerID = IDFactory.makeStringID(id);
+ SOContainerConfig config = new SOContainerConfig(newServerID);
+ return new TCPServerSOContainer(config,group,path,keepAlive);
+ }
} \ No newline at end of file
diff --git a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/app/ServerConfigParser.java b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/app/ServerConfigParser.java
index a4757c950..c2aa10939 100644
--- a/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/app/ServerConfigParser.java
+++ b/framework/bundles/org.eclipse.ecf.provider/src/org/eclipse/ecf/provider/app/ServerConfigParser.java
@@ -1,5 +1,6 @@
package org.eclipse.ecf.provider.app;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
@@ -19,60 +20,17 @@ import org.xml.sax.SAXException;
public class ServerConfigParser {
- public static final int DEFAULT_PORT = 3282;
- public static final long DEFAULT_TIMEOUT = 10000L;
-
public static final String SERVER_ELEMENT = "server";
public static final String CONNECTOR_ELEMENT = "connector";
public static final String GROUP_ELEMENT = "group";
+ public static final String PROTOCOL_ATTR = "protocol";
+ public static final String HOSTNAME_ATTR = "hostname";
public static final String PORT_ATTR = "port";
public static final String TIMEOUT_ATTR = "timeout";
public static final String NAME_ATTR = "name";
- protected int defaultPort = DEFAULT_PORT;
- protected long defaultTimeout = DEFAULT_TIMEOUT;
-
- class Connector {
- int port = defaultPort;
- long timeout = defaultTimeout;
- List groups = new ArrayList();
-
- public Connector() {
-
- }
- public Connector(int port, long timeout) {
- this.port = port;
- this.timeout = timeout;
- }
- public void addGroup(NamedGroup grp) {
- groups.add(grp);
- }
- public int getPort() {
- return port;
- }
- public long getTimeout() {
- return timeout;
- }
- public List getGroups() {
- return groups;
- }
- }
- class NamedGroup {
- Connector parent;
- String name;
-
- public NamedGroup(String name) {
- this.name = name;
- }
- protected void setParent(Connector c) {
- this.parent = c;
- }
- public String getGroup() {
- return name;
- }
- }
- protected void findElementsNamed(Node top, String name, List aList) {
+ protected void findElementsNamed(Node top, String name, List aList) {
int type = top.getNodeType();
switch (type) {
case Node.DOCUMENT_TYPE_NODE:
@@ -100,7 +58,7 @@ public class ServerConfigParser {
for(Iterator i=connectorNodes.iterator(); i.hasNext(); ) {
Node n = (Node) i.next();
String ports = getAttributeValue(n,PORT_ATTR);
- int port = defaultPort;
+ int port = Connector.DEFAULT_PORT;
if (ports != null) {
try {
Integer porti = new Integer(ports);
@@ -110,16 +68,18 @@ public class ServerConfigParser {
}
}
String timeouts = getAttributeValue(n,TIMEOUT_ATTR);
- long timeout = defaultTimeout;
+ int timeout = Connector.DEFAULT_TIMEOUT;
if (timeouts != null) {
try {
- Long timeouti = new Long(timeouts);
- timeout = timeouti.longValue();
+ Integer timeouti = new Integer(timeouts);
+ timeout = timeouti.intValue();
} catch (NumberFormatException e) {
// ignore
}
}
- Connector c = new Connector(port,timeout);
+ String prot = getAttributeValue(n,PROTOCOL_ATTR);
+ String host = getAttributeValue(n,HOSTNAME_ATTR);
+ Connector c = new Connector(this, prot,host,port,timeout);
processConnector(n,c);
res.add(c);
}
@@ -130,10 +90,11 @@ public class ServerConfigParser {
findElementsNamed(n,GROUP_ELEMENT,groupList);
for(Iterator i=groupList.iterator(); i.hasNext(); ) {
Node node = (Node) i.next();
- String name = getAttributeValue(n,NAME_ATTR);
+ String name = getAttributeValue(node,NAME_ATTR);
if (name != null && !name.equals("")) {
NamedGroup g = new NamedGroup(name);
c.addGroup(g);
+ g.setParent(c);
}
}
}
@@ -156,4 +117,11 @@ public class ServerConfigParser {
Document doc = db.parse(ins);
return loadConnectors(doc);
}
+
+ public static void main(String [] args) throws Exception {
+ InputStream ins = new FileInputStream(args[0]);
+ ServerConfigParser configParser = new ServerConfigParser();
+ List res = configParser.load(ins);
+ System.out.println("result is "+res);
+ }
}
diff --git a/server-side/features/org.eclipse.ecf.server-feature/bin/startserver.bat b/server-side/features/org.eclipse.ecf.server-feature/bin/startserver.bat
index bb13f17a4..fe013e17f 100644
--- a/server-side/features/org.eclipse.ecf.server-feature/bin/startserver.bat
+++ b/server-side/features/org.eclipse.ecf.server-feature/bin/startserver.bat
@@ -20,7 +20,7 @@ set TRACE=-Dorg.eclipse.ecf.Trace=true -Dorg.eclipse.ecf.provider.Trace=true
set OPTIONS=
set MAINCLASS=org.eclipse.ecf.provider.app.ServerApplication
-set ARGS=%*
+set ARGS=-c ..\conf\server.xml %*
rem Start server
echo "Starting server with options: %OPTIONS% and args: %ARGS%"
diff --git a/server-side/features/org.eclipse.ecf.server-feature/bin/startserver.cmd b/server-side/features/org.eclipse.ecf.server-feature/bin/startserver.cmd
index bb13f17a4..fe013e17f 100644
--- a/server-side/features/org.eclipse.ecf.server-feature/bin/startserver.cmd
+++ b/server-side/features/org.eclipse.ecf.server-feature/bin/startserver.cmd
@@ -20,7 +20,7 @@ set TRACE=-Dorg.eclipse.ecf.Trace=true -Dorg.eclipse.ecf.provider.Trace=true
set OPTIONS=
set MAINCLASS=org.eclipse.ecf.provider.app.ServerApplication
-set ARGS=%*
+set ARGS=-c ..\conf\server.xml %*
rem Start server
echo "Starting server with options: %OPTIONS% and args: %ARGS%"
diff --git a/server-side/features/org.eclipse.ecf.server-feature/bin/startserver.sh b/server-side/features/org.eclipse.ecf.server-feature/bin/startserver.sh
index 8e68dc565..1ea7d81f0 100644
--- a/server-side/features/org.eclipse.ecf.server-feature/bin/startserver.sh
+++ b/server-side/features/org.eclipse.ecf.server-feature/bin/startserver.sh
@@ -20,7 +20,7 @@ TRACE="-Dorg.eclipse.ecf.Trace=true -Dorg.eclipse.ecf.provider.Trace=true"
OPTIONS=
MAINCLASS=org.eclipse.ecf.provider.app.ServerApplication
-ARGS=$*
+ARGS=-c ../conf/server.xml $*
# Start server
echo "Starting server with options: ${OPTIONS} and args: ${ARGS}"
diff --git a/server-side/features/org.eclipse.ecf.server-feature/build.properties b/server-side/features/org.eclipse.ecf.server-feature/build.properties
index 842227899..a531c6cf7 100644
--- a/server-side/features/org.eclipse.ecf.server-feature/build.properties
+++ b/server-side/features/org.eclipse.ecf.server-feature/build.properties
@@ -1,3 +1,4 @@
bin.includes = bin/,\
lib/,\
- feature.xml
+ feature.xml,\
+ conf/
diff --git a/server-side/features/org.eclipse.ecf.server-feature/conf/server.xml b/server-side/features/org.eclipse.ecf.server-feature/conf/server.xml
new file mode 100644
index 000000000..61399a028
--- /dev/null
+++ b/server-side/features/org.eclipse.ecf.server-feature/conf/server.xml
@@ -0,0 +1,5 @@
+<server>
+ <connector protocol="ecftcp" hostname="localhost" port="3282" timeout="10000">
+ <group name="server"/>
+ </connector>
+</server> \ No newline at end of file

Back to the top