Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2007-03-12 20:29:57 +0000
committerslewis2007-03-12 20:29:57 +0000
commitf6d35c307670cfc634f128a584f16ff9a466803b (patch)
treeacad3f7aa65191fe8e54fb308e2cd908207af97a /server-side/bundles
parent99ecfba286b566a6321228e5269afa79b790ad3a (diff)
downloadorg.eclipse.ecf-f6d35c307670cfc634f128a584f16ff9a466803b.tar.gz
org.eclipse.ecf-f6d35c307670cfc634f128a584f16ff9a466803b.tar.xz
org.eclipse.ecf-f6d35c307670cfc634f128a584f16ff9a466803b.zip
Added org.eclipse.ecf.server.generic.configuration extension point. This extension point allows ECF generic server instances to be configurated via an extension.
Diffstat (limited to 'server-side/bundles')
-rw-r--r--server-side/bundles/org.eclipse.ecf.server.generic/META-INF/MANIFEST.MF2
-rw-r--r--server-side/bundles/org.eclipse.ecf.server.generic/build.properties3
-rw-r--r--server-side/bundles/org.eclipse.ecf.server.generic/plugin.xml17
-rw-r--r--server-side/bundles/org.eclipse.ecf.server.generic/schema/configuration.exsd158
-rw-r--r--server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/internal/server/generic/Activator.java27
-rw-r--r--server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/server/generic/ServerManager.java184
-rw-r--r--server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/server/generic/ServerStarter.java112
7 files changed, 383 insertions, 120 deletions
diff --git a/server-side/bundles/org.eclipse.ecf.server.generic/META-INF/MANIFEST.MF b/server-side/bundles/org.eclipse.ecf.server.generic/META-INF/MANIFEST.MF
index d8be8c19d..bdefe5d1a 100644
--- a/server-side/bundles/org.eclipse.ecf.server.generic/META-INF/MANIFEST.MF
+++ b/server-side/bundles/org.eclipse.ecf.server.generic/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %plugin.name
-Bundle-SymbolicName: org.eclipse.ecf.server.generic
+Bundle-SymbolicName: org.eclipse.ecf.server.generic;singleton:=true
Bundle-Version: 1.0.0.v20070215
Bundle-Activator: org.eclipse.ecf.internal.server.generic.Activator
Bundle-Vendor: %plugin.provider
diff --git a/server-side/bundles/org.eclipse.ecf.server.generic/build.properties b/server-side/bundles/org.eclipse.ecf.server.generic/build.properties
index 34d2e4d2d..e9863e281 100644
--- a/server-side/bundles/org.eclipse.ecf.server.generic/build.properties
+++ b/server-side/bundles/org.eclipse.ecf.server.generic/build.properties
@@ -1,4 +1,5 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
- .
+ .,\
+ plugin.xml
diff --git a/server-side/bundles/org.eclipse.ecf.server.generic/plugin.xml b/server-side/bundles/org.eclipse.ecf.server.generic/plugin.xml
new file mode 100644
index 000000000..20b7749e4
--- /dev/null
+++ b/server-side/bundles/org.eclipse.ecf.server.generic/plugin.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension-point id="configuration" name="ECF Generic Server Configuration" schema="schema/configuration.exsd"/>
+ <extension
+ point="org.eclipse.ecf.server.generic.configuration">
+ <connector
+ hostname="localhost"
+ keepAlive="30000"
+ port="3282">
+ <group
+ name="server">
+ </group>
+ </connector>
+ </extension>
+
+</plugin>
diff --git a/server-side/bundles/org.eclipse.ecf.server.generic/schema/configuration.exsd b/server-side/bundles/org.eclipse.ecf.server.generic/schema/configuration.exsd
new file mode 100644
index 000000000..093af4e27
--- /dev/null
+++ b/server-side/bundles/org.eclipse.ecf.server.generic/schema/configuration.exsd
@@ -0,0 +1,158 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.ecf.server.generic">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.ecf.server.generic" id="configuration" name="ECF Generic Server Configuration"/>
+ </appInfo>
+ <documentation>
+ This extension point allows ECF generic server instances to be configured via extension point definition.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="connector" minOccurs="1" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute translatable="true"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="connector">
+ <annotation>
+ <documentation>
+ A connector defines the port and other information for an ECF generic server to receive connection requests from clients.
+ </documentation>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="group" minOccurs="1" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="hostname" type="string">
+ <annotation>
+ <documentation>
+ Defines the hostname expected in the server ID...e.g. &quot;localhost&quot;. If not specified, default is &quot;localhost&quot;.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="port" type="string">
+ <annotation>
+ <documentation>
+ The port (e.g. 3282) for the connector to listen on. If not specified, is set to 3282.
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="keepAlive" type="string">
+ <annotation>
+ <documentation>
+ The timeout associated with the ECF generic server failure detector (in ms). If not specified, defaults to 30000 (30 seconds).
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="group">
+ <annotation>
+ <documentation>
+ A specific named group for the parent connector. e.g. &apos;server&apos; in ecftcp://localhost:3282/server
+ </documentation>
+ </annotation>
+ <complexType>
+ <attribute name="name" type="string" use="required">
+ <annotation>
+ <documentation>
+ The name for the group in the ID: e.g. &apos;server&apos; in ecftcp://localhost:3282/server
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ 1.0.0
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ The following is an example use of the org.eclipse.ecf.server.generic.configration extension point:
+
+&lt;pre&gt;
+ &lt;extension
+ point=&quot;org.eclipse.ecf.server.generic.configuration&quot;&gt;
+ &lt;connector
+ hostname=&quot;localhost&quot;
+ keepAlive=&quot;30000&quot;
+ port=&quot;3282&quot;&gt;
+ &lt;group
+ name=&quot;server&quot;&gt;
+ &lt;/group&gt;
+ &lt;/connector&gt;
+ &lt;/extension&gt;
+&lt;/pre&gt;
+
+Produces a server with groupID: ecftcp://localhost:3333/groupName
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ No public programmatic API
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+ Copyright (c) 2004 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
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/internal/server/generic/Activator.java b/server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/internal/server/generic/Activator.java
index 88b60ef41..258395785 100644
--- a/server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/internal/server/generic/Activator.java
+++ b/server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/internal/server/generic/Activator.java
@@ -1,10 +1,12 @@
package org.eclipse.ecf.internal.server.generic;
+import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
-import org.eclipse.ecf.server.generic.ServerStarter;
+import org.eclipse.ecf.server.generic.ServerManager;
import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
/**
* The activator class controls the plug-in life cycle
@@ -17,14 +19,20 @@ public class Activator extends Plugin {
// The shared instance
private static Activator plugin;
- private ServerStarter servers;
+ private ServerManager serverManager;
+ private ServiceTracker extensionRegistryTracker = null;
+
/**
* The constructor
*/
public Activator() {
}
+ public IExtensionRegistry getExtensionRegistry() {
+ return (IExtensionRegistry) extensionRegistryTracker.getService();
+ }
+
/*
* (non-Javadoc)
* @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
@@ -32,7 +40,10 @@ public class Activator extends Plugin {
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
- servers = new ServerStarter(context.getBundle().getEntry(Messages.Activator_SERVER_XML).openStream());
+ this.extensionRegistryTracker = new ServiceTracker(context,
+ IExtensionRegistry.class.getName(), null);
+ this.extensionRegistryTracker.open();
+ serverManager = new ServerManager();
}
/*
@@ -41,9 +52,13 @@ public class Activator extends Plugin {
*/
public void stop(BundleContext context) throws Exception {
plugin = null;
- if (servers != null) {
- servers.destroyServers();
- servers = null;
+ if (serverManager != null) {
+ serverManager.closeServers();
+ serverManager = null;
+ }
+ if (extensionRegistryTracker != null) {
+ extensionRegistryTracker.close();
+ extensionRegistryTracker = null;
}
super.stop(context);
}
diff --git a/server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/server/generic/ServerManager.java b/server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/server/generic/ServerManager.java
new file mode 100644
index 000000000..21e44cda4
--- /dev/null
+++ b/server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/server/generic/ServerManager.java
@@ -0,0 +1,184 @@
+/****************************************************************************
+ * Copyright (c) 2004 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.server.generic;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IExtensionRegistry;
+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.sharedobject.ISharedObjectContainer;
+import org.eclipse.ecf.internal.server.generic.Activator;
+import org.eclipse.ecf.internal.server.generic.Messages;
+import org.eclipse.ecf.provider.app.Connector;
+import org.eclipse.ecf.provider.app.NamedGroup;
+import org.eclipse.ecf.provider.app.ServerConfigParser;
+import org.eclipse.ecf.provider.generic.SOContainerConfig;
+import org.eclipse.ecf.provider.generic.TCPServerSOContainer;
+import org.eclipse.ecf.provider.generic.TCPServerSOContainerGroup;
+import org.eclipse.osgi.util.NLS;
+
+public class ServerManager {
+
+ static TCPServerSOContainerGroup serverGroups[] = null;
+
+ static Map servers = new HashMap();
+
+ public static final String EXTENSION_POINT_NAME = "configuration";
+
+ public static final String EXTENSION_POINT = Activator.PLUGIN_ID + "."
+ + EXTENSION_POINT_NAME;
+
+ public static final String CONFIGURATION_ELEMENT = "configuration";
+ public static final String CONNECTOR_ELEMENT = "connector";
+ public static final String GROUP_ELEMENT = "group";
+
+ public static final String HOSTNAME_ATTR = "hostname";
+ public static final String PORT_ATTR = "port";
+ public static final String KEEPALIVE_ATTR = "keepAlive";
+ public static final String NAME_ATTR = "name";
+
+ public ServerManager() {
+ IExtensionRegistry reg = Activator.getDefault().getExtensionRegistry();
+ try {
+ if (reg != null) {
+ createServersFromExtensionRegistry(reg);
+ } else {
+ createServersFromConfigurationFile(Activator.getDefault()
+ .getBundle().getEntry(Messages.Activator_SERVER_XML)
+ .openStream());
+ }
+ } catch (Exception e) {
+ Activator.log(Messages.ServerStarter_EXCEPTION_CREATING_SERVER, e);
+ }
+ }
+
+ public synchronized ISharedObjectContainer getServer(ID id) {
+ if (id == null)
+ return null;
+ return (ISharedObjectContainer) servers.get(id);
+ }
+
+ private void createServersFromExtensionRegistry(IExtensionRegistry registry)
+ throws Exception {
+ IExtensionPoint extensionPoint = registry
+ .getExtensionPoint(EXTENSION_POINT);
+ if (extensionPoint == null)
+ return;
+ IConfigurationElement[] elements = extensionPoint
+ .getConfigurationElements();
+ List connectors = new ArrayList();
+ for (int i = 0; i < elements.length; i++) {
+ IConfigurationElement element = elements[i];
+ String portString = element.getAttribute(PORT_ATTR);
+ int port = TCPServerSOContainer.DEFAULT_PORT;
+ if (portString != null)
+ port = Integer.parseInt(portString);
+ int keepAlive = TCPServerSOContainer.DEFAULT_KEEPALIVE;
+ String keepAliveString = element.getAttribute(KEEPALIVE_ATTR);
+ if (keepAliveString != null)
+ keepAlive = Integer.parseInt(keepAliveString);
+ Connector connector = new Connector(null, element
+ .getAttribute(HOSTNAME_ATTR), port, keepAlive);
+ IConfigurationElement[] groupElements = element
+ .getChildren(GROUP_ELEMENT);
+ for (int j = 0; j < groupElements.length; j++) {
+ String groupName = groupElements[i].getAttribute(NAME_ATTR);
+ if (groupName != null)
+ connector.addGroup(new NamedGroup(groupName));
+ }
+ connectors.add(connector);
+ }
+ createServersFromConnectorList(connectors);
+ }
+
+ protected boolean isActive() {
+ return (servers.size() > 0);
+ }
+
+ public synchronized void closeServers() {
+ for (Iterator i = servers.keySet().iterator(); i.hasNext();) {
+ ID serverID = (ID) i.next();
+ TCPServerSOContainer server = (TCPServerSOContainer) servers
+ .get(serverID);
+ if (server != null) {
+ try {
+ server.dispose();
+ } catch (Exception e) {
+ Activator.log(
+ Messages.ServerStarter_EXCEPTION_DISPOSING_SERVER,
+ e); //$NON-NLS-1$
+ }
+ }
+ }
+ servers.clear();
+ if (serverGroups != null) {
+ for (int i = 0; i < serverGroups.length; i++) {
+ serverGroups[i].takeOffTheAir();
+ }
+ serverGroups = null;
+ }
+ }
+
+ private synchronized void createServersFromConnectorList(List connectors)
+ throws IDCreateException, IOException {
+ serverGroups = new TCPServerSOContainerGroup[connectors.size()];
+ int j = 0;
+ for (Iterator i = connectors.iterator(); i.hasNext();) {
+ Connector connect = (Connector) i.next();
+ serverGroups[j] = createServerGroup(connect);
+ List groups = connect.getGroups();
+ for (Iterator g = groups.iterator(); g.hasNext();) {
+ NamedGroup group = (NamedGroup) g.next();
+ TCPServerSOContainer cont = createServerContainer(group
+ .getIDForGroup(), serverGroups[j], group.getName(),
+ connect.getTimeout());
+ servers.put(cont.getID(), cont);
+ Activator.log(NLS.bind(Messages.ServerStarter_STARTING_SERVER,
+ cont.getID().getName())); //$NON-NLS-1$
+ }
+ serverGroups[j].putOnTheAir();
+ j++;
+ }
+ }
+
+ private void createServersFromConfigurationFile(InputStream ins)
+ throws Exception {
+ ServerConfigParser scp = new ServerConfigParser();
+ List connectors = scp.load(ins);
+ if (connectors != null)
+ createServersFromConnectorList(connectors);
+ }
+
+ private TCPServerSOContainerGroup createServerGroup(Connector connector) {
+ TCPServerSOContainerGroup group = new TCPServerSOContainerGroup(
+ connector.getHostname(), connector.getPort());
+ return group;
+ }
+
+ private TCPServerSOContainer createServerContainer(String id,
+ TCPServerSOContainerGroup group, String path, int keepAlive)
+ throws IDCreateException {
+ ID newServerID = IDFactory.getDefault().createStringID(id);
+ return new TCPServerSOContainer(new SOContainerConfig(newServerID),
+ group, path, keepAlive);
+ }
+}
diff --git a/server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/server/generic/ServerStarter.java b/server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/server/generic/ServerStarter.java
deleted file mode 100644
index d5fd74eab..000000000
--- a/server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/server/generic/ServerStarter.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/****************************************************************************
- * Copyright (c) 2004 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.server.generic;
-
-import java.io.InputStream;
-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.IDCreateException;
-import org.eclipse.ecf.core.identity.IDFactory;
-import org.eclipse.ecf.internal.server.generic.Activator;
-import org.eclipse.ecf.internal.server.generic.Messages;
-import org.eclipse.ecf.provider.app.Connector;
-import org.eclipse.ecf.provider.app.NamedGroup;
-import org.eclipse.ecf.provider.app.ServerConfigParser;
-import org.eclipse.ecf.provider.generic.SOContainerConfig;
-import org.eclipse.ecf.provider.generic.TCPServerSOContainer;
-import org.eclipse.ecf.provider.generic.TCPServerSOContainerGroup;
-import org.eclipse.osgi.util.NLS;
-
-public class ServerStarter {
-
- static TCPServerSOContainerGroup serverGroups[] = null;
-
- static List servers = new ArrayList();
-
- public ServerStarter(InputStream ins) {
- try {
- createServers(ins);
- } catch (Exception e) {
- Activator.log(Messages.ServerStarter_EXCEPTION_CREATING_SERVER,e); //$NON-NLS-1$
- }
- }
-
- protected boolean isActive() {
- return (servers.size() > 0);
- }
-
- public synchronized void destroyServers() {
- for (Iterator i = servers.iterator(); i.hasNext();) {
- TCPServerSOContainer server = (TCPServerSOContainer) i.next();
- if (server != null) {
- try {
- server.dispose();
- } catch (Exception e) {
- Activator.log(Messages.ServerStarter_EXCEPTION_DISPOSING_SERVER,e); //$NON-NLS-1$
- }
- }
- }
- servers.clear();
- if (serverGroups != null) {
- for (int i = 0; i < serverGroups.length; i++) {
- serverGroups[i].takeOffTheAir();
- }
- serverGroups = null;
- }
- }
-
- protected synchronized void createServers(InputStream ins) throws Exception {
- ServerConfigParser scp = new ServerConfigParser();
- List connectors = scp.load(ins);
- 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] = createServerGroup(connect.getHostname(),
- connect.getPort());
- List groups = connect.getGroups();
- for (Iterator g = groups.iterator(); g.hasNext();) {
- NamedGroup group = (NamedGroup) g.next();
- TCPServerSOContainer cont = createServerContainer(group
- .getIDForGroup(), serverGroups[j], group.getName(),
- connect.getTimeout());
- servers.add(cont);
- log(NLS.bind(Messages.ServerStarter_STARTING_SERVER,cont.getID().getName())); //$NON-NLS-1$
- }
- serverGroups[j].putOnTheAir();
- j++;
- }
- }
- }
-
- protected void log(String output) {
- Activator.log(output);
- }
-
- protected TCPServerSOContainerGroup createServerGroup(String name, int port) {
- TCPServerSOContainerGroup group = new TCPServerSOContainerGroup(name,
- port);
- return group;
- }
-
- protected TCPServerSOContainer createServerContainer(String id,
- TCPServerSOContainerGroup group, String path, int keepAlive)
- throws IDCreateException {
- ID newServerID = IDFactory.getDefault().createStringID(id);
- return new TCPServerSOContainer(new SOContainerConfig(newServerID),
- group, path, keepAlive);
- }
-}

Back to the top