Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2007-03-13 02:26:18 -0400
committerslewis2007-03-13 02:26:18 -0400
commitc2eb5438d8ddb679b081d93977c3e4c61280f022 (patch)
tree2c3094c4a7dbc89a17612d94cf16dbb1352b965f /server-side
parentf0ab1319063683f267aa34334f956c8fbfa670ab (diff)
downloadorg.eclipse.ecf-c2eb5438d8ddb679b081d93977c3e4c61280f022.tar.gz
org.eclipse.ecf-c2eb5438d8ddb679b081d93977c3e4c61280f022.tar.xz
org.eclipse.ecf-c2eb5438d8ddb679b081d93977c3e4c61280f022.zip
Added support for discovery registration to org.eclipse.ecf.server.generic ServerManager
Diffstat (limited to 'server-side')
-rw-r--r--server-side/bundles/org.eclipse.ecf.server.generic/META-INF/MANIFEST.MF5
-rw-r--r--server-side/bundles/org.eclipse.ecf.server.generic/plugin.xml1
-rw-r--r--server-side/bundles/org.eclipse.ecf.server.generic/schema/configuration.exsd7
-rw-r--r--server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/internal/server/generic/Activator.java13
-rw-r--r--server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/internal/server/generic/Messages.java2
-rw-r--r--server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/internal/server/generic/messages.properties2
-rw-r--r--server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/server/generic/ServerManager.java63
7 files changed, 82 insertions, 11 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 bdefe5d1a..3a751022e 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
@@ -8,5 +8,8 @@ Bundle-Vendor: %plugin.provider
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ecf,
org.eclipse.ecf.sharedobject,
- org.eclipse.ecf.provider
+ org.eclipse.ecf.provider,
+ org.eclipse.ecf.discovery
Eclipse-LazyStart: true
+Export-Package: org.eclipse.ecf.internal.server.generic;x-internal:=true,
+ org.eclipse.ecf.server.generic
diff --git a/server-side/bundles/org.eclipse.ecf.server.generic/plugin.xml b/server-side/bundles/org.eclipse.ecf.server.generic/plugin.xml
index a39ac7645..996522c44 100644
--- a/server-side/bundles/org.eclipse.ecf.server.generic/plugin.xml
+++ b/server-side/bundles/org.eclipse.ecf.server.generic/plugin.xml
@@ -5,6 +5,7 @@
<extension
point="org.eclipse.ecf.server.generic.configuration">
<connector
+ discovery="true"
hostname="localhost"
keepAlive="30000"
port="3283">
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
index 093af4e27..8fcc6984f 100644
--- a/server-side/bundles/org.eclipse.ecf.server.generic/schema/configuration.exsd
+++ b/server-side/bundles/org.eclipse.ecf.server.generic/schema/configuration.exsd
@@ -73,6 +73,13 @@
</documentation>
</annotation>
</attribute>
+ <attribute name="discovery" type="boolean">
+ <annotation>
+ <documentation>
+ The discovery flag determines if the given service is published for discovery via the IDiscoveryService
+ </documentation>
+ </annotation>
+ </attribute>
</complexType>
</element>
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 258395785..587874009 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
@@ -4,6 +4,7 @@ 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.discovery.service.IDiscoveryService;
import org.eclipse.ecf.server.generic.ServerManager;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
@@ -23,6 +24,8 @@ public class Activator extends Plugin {
private ServiceTracker extensionRegistryTracker = null;
+ private ServiceTracker discoveryTracker = null;
+
/**
* The constructor
*/
@@ -33,6 +36,10 @@ public class Activator extends Plugin {
return (IExtensionRegistry) extensionRegistryTracker.getService();
}
+ public IDiscoveryService getDiscovery() {
+ return (IDiscoveryService) discoveryTracker.getService();
+ }
+
/*
* (non-Javadoc)
* @see org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
@@ -43,6 +50,8 @@ public class Activator extends Plugin {
this.extensionRegistryTracker = new ServiceTracker(context,
IExtensionRegistry.class.getName(), null);
this.extensionRegistryTracker.open();
+ this.discoveryTracker = new ServiceTracker(context, IDiscoveryService.class.getName(), null);
+ this.discoveryTracker.open();
serverManager = new ServerManager();
}
@@ -60,6 +69,10 @@ public class Activator extends Plugin {
extensionRegistryTracker.close();
extensionRegistryTracker = null;
}
+ if (discoveryTracker != null) {
+ discoveryTracker.close();
+ discoveryTracker = null;
+ }
super.stop(context);
}
diff --git a/server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/internal/server/generic/Messages.java b/server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/internal/server/generic/Messages.java
index 77af889fd..6dab1f005 100644
--- a/server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/internal/server/generic/Messages.java
+++ b/server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/internal/server/generic/Messages.java
@@ -19,6 +19,8 @@ import org.eclipse.osgi.util.NLS;
public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.ecf.internal.server.generic.messages"; //$NON-NLS-1$
public static String Activator_SERVER_XML;
+ public static String ServerManager_EXCEPTION_DISCOVERY_REGISTRATION;
+ public static String ServerManager_SERVICE_TYPE;
public static String ServerStarter_EXCEPTION_CREATING_SERVER;
public static String ServerStarter_EXCEPTION_DISPOSING_SERVER;
diff --git a/server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/internal/server/generic/messages.properties b/server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/internal/server/generic/messages.properties
index 97ea8acd1..a2e3ccfde 100644
--- a/server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/internal/server/generic/messages.properties
+++ b/server-side/bundles/org.eclipse.ecf.server.generic/src/org/eclipse/ecf/internal/server/generic/messages.properties
@@ -2,3 +2,5 @@ Activator_SERVER_XML=server.xml
ServerStarter_EXCEPTION_CREATING_SERVER=Exception creating servers
ServerStarter_EXCEPTION_DISPOSING_SERVER=Exception disposing server
ServerStarter_STARTING_SERVER=Starting Server with id={0}
+ServerManager_SERVICE_TYPE=_ecftcp._tcp.local.
+ServerManager_EXCEPTION_DISCOVERY_REGISTRATION=Discovery registration exception
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
index 21e44cda4..c78328ff9 100644
--- 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
@@ -13,11 +13,14 @@ package org.eclipse.ecf.server.generic;
import java.io.IOException;
import java.io.InputStream;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
@@ -26,6 +29,10 @@ 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.discovery.ServiceInfo;
+import org.eclipse.ecf.discovery.ServiceProperties;
+import org.eclipse.ecf.discovery.identity.ServiceID;
+import org.eclipse.ecf.discovery.service.IDiscoveryService;
import org.eclipse.ecf.internal.server.generic.Activator;
import org.eclipse.ecf.internal.server.generic.Messages;
import org.eclipse.ecf.provider.app.Connector;
@@ -38,24 +45,34 @@ import org.eclipse.osgi.util.NLS;
public class ServerManager {
+ private static final String GROUP_PROPERTY_NAME = "group"; //$NON-NLS-1$
+
+ private static final String PWREQUIRED_PROPERTY_NAME = "pwrequired"; //$NON-NLS-1$
+
+ private static final String PROTOCOL_PROPERTY_NAME = "protocol"; //$NON-NLS-1$
+
+ private static final String SERVICE_TYPE = Messages.ServerManager_SERVICE_TYPE;
+
static TCPServerSOContainerGroup serverGroups[] = null;
static Map servers = new HashMap();
- public static final String EXTENSION_POINT_NAME = "configuration";
+ public static final String EXTENSION_POINT_NAME = "configuration"; //$NON-NLS-1$
- public static final String EXTENSION_POINT = Activator.PLUGIN_ID + "."
+ public static final String EXTENSION_POINT = Activator.PLUGIN_ID + "." //$NON-NLS-1$
+ 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 CONFIGURATION_ELEMENT = "configuration"; //$NON-NLS-1$
+ public static final String CONNECTOR_ELEMENT = "connector"; //$NON-NLS-1$
+ public static final String GROUP_ELEMENT = GROUP_PROPERTY_NAME;
- 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 static final String HOSTNAME_ATTR = "hostname"; //$NON-NLS-1$
+ public static final String PORT_ATTR = "port"; //$NON-NLS-1$
+ public static final String KEEPALIVE_ATTR = "keepAlive"; //$NON-NLS-1$
+ public static final String NAME_ATTR = "name"; //$NON-NLS-1$
+ public static final String DISCOVERY_ATTR = "discovery"; //$NON-NLS-1$
+
public ServerManager() {
IExtensionRegistry reg = Activator.getDefault().getExtensionRegistry();
try {
@@ -96,8 +113,11 @@ public class ServerManager {
String keepAliveString = element.getAttribute(KEEPALIVE_ATTR);
if (keepAliveString != null)
keepAlive = Integer.parseInt(keepAliveString);
+ boolean discovery = false;
+ String discoveryString = element.getAttribute(DISCOVERY_ATTR);
+ if (discoveryString != null) discovery = Boolean.parseBoolean(discoveryString);
Connector connector = new Connector(null, element
- .getAttribute(HOSTNAME_ATTR), port, keepAlive);
+ .getAttribute(HOSTNAME_ATTR), port, keepAlive, discovery);
IConfigurationElement[] groupElements = element
.getChildren(GROUP_ELEMENT);
for (int j = 0; j < groupElements.length; j++) {
@@ -151,6 +171,7 @@ public class ServerManager {
TCPServerSOContainer cont = createServerContainer(group
.getIDForGroup(), serverGroups[j], group.getName(),
connect.getTimeout());
+ if (connect.shouldRegisterForDiscovery()) registerServerForDiscovery(group, false);
servers.put(cont.getID(), cont);
Activator.log(NLS.bind(Messages.ServerStarter_STARTING_SERVER,
cont.getID().getName())); //$NON-NLS-1$
@@ -181,4 +202,26 @@ public class ServerManager {
return new TCPServerSOContainer(new SOContainerConfig(newServerID),
group, path, keepAlive);
}
+
+ private void registerServerForDiscovery(NamedGroup group, boolean pwrequired) {
+ IDiscoveryService discovery = Activator.getDefault().getDiscovery();
+ if (discovery != null) {
+ discovery.registerServiceType(SERVICE_TYPE);
+ String rawGroupName = group.getRawName();
+ ServiceID serviceID = new ServiceID(SERVICE_TYPE,rawGroupName);
+ Connector connector = group.getConnector();
+ Properties props = new Properties();
+ props.put(PROTOCOL_PROPERTY_NAME,TCPServerSOContainer.DEFAULT_PROTOCOL);
+ props.put(PWREQUIRED_PROPERTY_NAME, new Boolean(pwrequired).toString());
+ props.put(GROUP_PROPERTY_NAME,rawGroupName);
+ try {
+ InetAddress host = InetAddress.getByName(connector.getHostname());
+ ServiceInfo svcInfo = new ServiceInfo(host, serviceID, connector.getPort(),
+ 0, 0, new ServiceProperties(props));
+ discovery.registerService(svcInfo);
+ } catch (Exception e) {
+ Activator.log(Messages.ServerManager_EXCEPTION_DISCOVERY_REGISTRATION,e);
+ }
+ }
+ }
}

Back to the top