diff options
| author | slewis | 2005-05-15 23:38:48 +0000 |
|---|---|---|
| committer | slewis | 2005-05-15 23:38:48 +0000 |
| commit | 7434c8145764fae524f09f79a636a6430050d35e (patch) | |
| tree | e47ea4b685cdc30c0fa076efc3108980b2ba1478 | |
| parent | 3d4c2271765b935df01a1740d8e6f837daf526c1 (diff) | |
| download | org.eclipse.ecf-7434c8145764fae524f09f79a636a6430050d35e.tar.gz org.eclipse.ecf-7434c8145764fae524f09f79a636a6430050d35e.tar.xz org.eclipse.ecf-7434c8145764fae524f09f79a636a6430050d35e.zip | |
Initial checkin of ECF Discovery API
15 files changed, 456 insertions, 0 deletions
diff --git a/framework/bundles/org.eclipse.ecf.discovery/.classpath b/framework/bundles/org.eclipse.ecf.discovery/.classpath new file mode 100644 index 000000000..065ac06e1 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.discovery/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/framework/bundles/org.eclipse.ecf.discovery/.cvsignore b/framework/bundles/org.eclipse.ecf.discovery/.cvsignore new file mode 100644 index 000000000..ba077a403 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.discovery/.cvsignore @@ -0,0 +1 @@ +bin diff --git a/framework/bundles/org.eclipse.ecf.discovery/.options b/framework/bundles/org.eclipse.ecf.discovery/.options new file mode 100644 index 000000000..4ac035f90 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.discovery/.options @@ -0,0 +1,3 @@ +org.eclipse.ecf.discovery/debug = true +org.eclipse.ecf.discovery/debug/filter = * +org.eclipse.ecf.discovery/debug/flag = true
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.discovery/.project b/framework/bundles/org.eclipse.ecf.discovery/.project new file mode 100644 index 000000000..707d4c275 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.discovery/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.ecf.discovery</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/framework/bundles/org.eclipse.ecf.discovery/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf.discovery/META-INF/MANIFEST.MF new file mode 100644 index 000000000..790cf0d05 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.discovery/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: ECF Discovery API +Bundle-SymbolicName: org.eclipse.ecf.discovery +Bundle-Version: 0.2.0 +Bundle-ClassPath: discovery.jar +Bundle-Activator: org.eclipse.ecf.discovery.DiscoveryPlugin +Bundle-Vendor: Eclipse.org +Bundle-Localization: plugin +Require-Bundle: org.eclipse.core.runtime, + org.eclipse.ecf +Eclipse-AutoStart: true +Export-Package: org.eclipse.ecf.discovery, + org.eclipse.ecf.discovery.impl diff --git a/framework/bundles/org.eclipse.ecf.discovery/build.properties b/framework/bundles/org.eclipse.ecf.discovery/build.properties new file mode 100644 index 000000000..b9a983f1b --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.discovery/build.properties @@ -0,0 +1,4 @@ +source.discovery.jar = src/ +output.discovery.jar = bin/ +bin.includes = META-INF/,\ + discovery.jar diff --git a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/DiscoveryPlugin.java b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/DiscoveryPlugin.java new file mode 100644 index 000000000..09b0b093c --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/DiscoveryPlugin.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * 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.discovery; + +import org.eclipse.core.runtime.Plugin; +import org.osgi.framework.BundleContext; +import java.util.*; + +/** + * The main plugin class to be used in the desktop. + */ +public class DiscoveryPlugin extends Plugin { + //The shared instance. + private static DiscoveryPlugin plugin; + //Resource bundle. + private ResourceBundle resourceBundle; + + public static final String PLUGIN_ID = "org.eclipse.ecf.discovery"; + + /** + * The constructor. + */ + public DiscoveryPlugin() { + super(); + plugin = this; + } + + /** + * This method is called upon plug-in activation + */ + public void start(BundleContext context) throws Exception { + super.start(context); + } + + /** + * This method is called when the plug-in is stopped + */ + public void stop(BundleContext context) throws Exception { + super.stop(context); + plugin = null; + resourceBundle = null; + } + + /** + * Returns the shared instance. + */ + public static DiscoveryPlugin getDefault() { + return plugin; + } + + /** + * Returns the string from the plugin's resource bundle, + * or 'key' if not found. + */ + public static String getResourceString(String key) { + ResourceBundle bundle = DiscoveryPlugin.getDefault().getResourceBundle(); + try { + return (bundle != null) ? bundle.getString(key) : key; + } catch (MissingResourceException e) { + return key; + } + } + + /** + * Returns the plugin's resource bundle, + */ + public ResourceBundle getResourceBundle() { + try { + if (resourceBundle == null) + resourceBundle = ResourceBundle.getBundle("org.eclipse.ecf.discovery.DiscoveryPluginResources"); + } catch (MissingResourceException x) { + resourceBundle = null; + } + return resourceBundle; + } + +} diff --git a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IDiscoveryContainer.java b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IDiscoveryContainer.java new file mode 100644 index 000000000..56df50f78 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IDiscoveryContainer.java @@ -0,0 +1,18 @@ +/******************************************************************************* + * 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.discovery; + +public interface IDiscoveryContainer { + public void addServiceListener(IServiceListener listener); + public void removeServiceListener(IServiceListener listener); + public void addServiceTypeListener(IServiceTypeListener listener); + public void removeServiceTypeListener(IServiceTypeListener listener); + public void registerService(IServiceInfo serviceInfo); +} diff --git a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IServiceEvent.java b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IServiceEvent.java new file mode 100644 index 000000000..ced25e108 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IServiceEvent.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * 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.discovery; + +import org.eclipse.ecf.core.events.IContainerEvent; + +public interface IServiceEvent extends IContainerEvent { + + public IServiceInfo getServiceInfo(); +} diff --git a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IServiceInfo.java b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IServiceInfo.java new file mode 100644 index 000000000..e6d4bfadb --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IServiceInfo.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * 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.discovery; + +import java.net.InetAddress; +import java.util.Map; + +import org.eclipse.ecf.core.identity.ServiceID; + +public interface IServiceInfo { + + public InetAddress getAddress(); + public ServiceID getServiceID(); + public int getPort(); + public int getPriority(); + public int getWeight(); + public Map getProperties(); +} diff --git a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IServiceListener.java b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IServiceListener.java new file mode 100644 index 000000000..6e1d48273 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IServiceListener.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * 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.discovery; + +public interface IServiceListener { + + public void serviceAdded(IServiceEvent event); + public void serviceRemoved(IServiceEvent event); + public void serviceResolved(IServiceEvent event); +} diff --git a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IServiceTypeListener.java b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IServiceTypeListener.java new file mode 100644 index 000000000..5d3110b2d --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/IServiceTypeListener.java @@ -0,0 +1,15 @@ +/******************************************************************************* + * 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.discovery; + +public interface IServiceTypeListener { + + public void serviceTypeAdded(IServiceEvent event); +} diff --git a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/Trace.java b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/Trace.java new file mode 100644 index 000000000..0d2f872aa --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/Trace.java @@ -0,0 +1,124 @@ +/**************************************************************************** +* 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.discovery; + +import java.text.SimpleDateFormat; +import java.util.Date; +import org.eclipse.core.runtime.Platform; + +public class Trace { + public static final String tracePrefix = "(trace)"; + + public static boolean ON = false; + protected static boolean isEclipse = false; + protected static String pluginName = ""; + protected static String debugPrefix = "/debug/"; + static { + try { + ON = Platform.inDebugMode(); + String val = System.getProperty(DiscoveryPlugin.PLUGIN_ID+".Trace"); + if (val != null) { + setTrace(true); + isEclipse = false; + // No eclipse Platform available + System.out.println("WARNING: Eclipse platform not available for trace...overridden by system property org.eclipse.ecf.Trace"); + } else { + isEclipse = true; + pluginName = DiscoveryPlugin.PLUGIN_ID; + } + } catch (Exception e) { + try { + String val = System.getProperty(DiscoveryPlugin.PLUGIN_ID+".Trace"); + if (val != null) { + setTrace(true); + isEclipse = false; + // No eclipse Platform available + System.out.println("WARNING: Eclipse platform not available for trace...using system.out for org.eclipse.ecf"); + } else { + System.out.println(Trace.class.getName()+": OFF"); + } + } catch (Exception except) { + } + } + } + public static void setTrace(boolean on) { + ON = on; + } + + public static Trace create(String key) { + if (isEclipse) { + String res = ""; + try { + res = Platform.getDebugOption(pluginName + debugPrefix + key); + } catch (Exception e) { + // ignore...this means that the Platform class not found. + } + if (res != null) { + Boolean on = new Boolean(res); + if (on.booleanValue()) + return new Trace(pluginName + "(" + key + ")"); + else + return null; + } else { + return null; + } + } else + return new Trace(key); + } + + String name; + + public void dumpStack(Throwable e, String msg) { + msg(msg); + e.printStackTrace(System.err); + } + + public void msg(String msg) { + StringBuffer sb = new StringBuffer(name); + sb.append(getTimeString()).append(msg); + System.out.println(sb.toString()); + } + + protected static String getTimeString() { + Date d = new Date(); + SimpleDateFormat df = new SimpleDateFormat("[MM/dd/yy;HH:mm:ss:SSS]"); + return df.format(d); + } + + protected Trace(String str) { + name = tracePrefix+str; + } + public static String convertStringAToString(String [] strings) { + if (strings==null) return ""; + StringBuffer sb = new StringBuffer(); + for(int i=0; i < strings.length; i++) { + if (strings[i]==null) sb.append("(null)"); + else sb.append(strings[i]); + if (i != (strings.length-1)) sb.append(";"); + } + return sb.toString(); + } + public static String convertObjectAToString(Object [] objs) { + if (objs==null) return ""; + StringBuffer sb = new StringBuffer(); + for(int i=0; i < objs.length; i++) { + if (objs[i]==null) sb.append("(null)"); + else sb.append(objs[i].toString()); + if (i != (objs.length-1)) sb.append(";"); + } + return sb.toString(); + } + + public static void setThreadDebugGroup(Object obj) { + // Do nothing + } +}
\ No newline at end of file diff --git a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/impl/ServiceContainerEvent.java b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/impl/ServiceContainerEvent.java new file mode 100644 index 000000000..5e04a0339 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/impl/ServiceContainerEvent.java @@ -0,0 +1,35 @@ +/******************************************************************************* + * 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.discovery.impl; + +import org.eclipse.ecf.core.identity.ID; +import org.eclipse.ecf.discovery.IServiceEvent; +import org.eclipse.ecf.discovery.IServiceInfo; + +public class ServiceContainerEvent implements IServiceEvent { + + private static final long serialVersionUID = 1L; + + protected IServiceInfo info; + protected ID containerID; + + public ServiceContainerEvent(IServiceInfo info, ID containerID) { + this.info = info; + this.containerID = containerID; + } + public IServiceInfo getServiceInfo() { + return info; + } + + public ID getLocalContainerID() { + return containerID; + } + +} diff --git a/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/impl/ServiceInfo.java b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/impl/ServiceInfo.java new file mode 100644 index 000000000..1a28aa1a2 --- /dev/null +++ b/framework/bundles/org.eclipse.ecf.discovery/src/org/eclipse/ecf/discovery/impl/ServiceInfo.java @@ -0,0 +1,64 @@ +/******************************************************************************* + * 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.discovery.impl; + +import java.io.Serializable; +import java.net.InetAddress; +import java.util.Map; + +import org.eclipse.ecf.core.identity.ServiceID; +import org.eclipse.ecf.discovery.IServiceInfo; + +public class ServiceInfo implements IServiceInfo, Serializable { + + private static final long serialVersionUID = 1L; + + InetAddress addr = null; + ServiceID serviceID; + int port; + int priority; + int weight; + Map properties; + + public ServiceInfo(InetAddress address, ServiceID id, int port, int priority, int weight, Map props) { + this.addr = address; + this.serviceID = id; + this.port = port; + this.priority = priority; + this.weight = weight; + this.properties = props; + } + public InetAddress getAddress() { + return addr; + } + + protected void setAddress(InetAddress address) { + this.addr = address; + } + public ServiceID getServiceID() { + return serviceID; + } + + public int getPort() { + return port; + } + + public int getPriority() { + return priority; + } + + public int getWeight() { + return weight; + } + + public Map getProperties() { + return properties; + } +} |
