Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorafinkbein2009-01-14 23:38:25 +0000
committerafinkbein2009-01-14 23:38:25 +0000
commite493f6ca0e250186a260df28e33dfb3da6c7faa9 (patch)
tree2feb067ccc42662821c9afdce6958e3579f5509e
parent54cda96ed77872438942afc9b60c19b25d240ba9 (diff)
downloadorg.eclipse.osee-e493f6ca0e250186a260df28e33dfb3da6c7faa9.tar.gz
org.eclipse.osee-e493f6ca0e250186a260df28e33dfb3da6c7faa9.tar.xz
org.eclipse.osee-e493f6ca0e250186a260df28e33dfb3da6c7faa9.zip
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/.classpath7
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/.project28
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/META-INF/MANIFEST.MF18
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/build.properties5
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/plugin.xml11
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/Activator.java122
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/ConnectorContribution.java16
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/IJiniConnectorLink.java8
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/IJiniConnectorRegistrar.java24
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniClientSideConnector.java56
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniConnector.java238
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniConnectorRegistrar.java276
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniServiceSideConnector.java177
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/TestEntry.java39
-rw-r--r--MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/util/LeaseRenewTask.java49
15 files changed, 1074 insertions, 0 deletions
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/.classpath b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/.classpath
new file mode 100644
index 00000000000..02159672985
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/.project b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/.project
new file mode 100644
index 00000000000..f58c70bae35
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.osee.ote.connection.jini</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/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/META-INF/MANIFEST.MF b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/META-INF/MANIFEST.MF
new file mode 100644
index 00000000000..e35a97117ea
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/META-INF/MANIFEST.MF
@@ -0,0 +1,18 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: JINI Connector provider
+Bundle-SymbolicName: org.eclipse.osee.ote.connection.jini;singleton:=true
+Bundle-Version: 0.4.0.qualifier
+Bundle-Activator: org.eclipse.osee.ote.connection.jini.Activator
+Bundle-Vendor: Boeing
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.osee.framework.jini,
+ net.jini,
+ org.eclipse.osee.framework.plugin.core,
+ org.eclipse.osee.framework.logging;bundle-version="0.4.0"
+Bundle-ActivationPolicy: lazy
+Import-Package: org.eclipse.osee.connection.service,
+ org.eclipse.osee.framework.jdk.core.util,
+ org.eclipse.osee.framework.jdk.core.util.network
+Export-Package: org.eclipse.osee.ote.connection.jini
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/build.properties b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/build.properties
new file mode 100644
index 00000000000..6f20375d6c7
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/plugin.xml b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/plugin.xml
new file mode 100644
index 00000000000..1eeb99023b5
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/plugin.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.2"?>
+<plugin>
+ <extension
+ point="org.eclipse.osee.connection.service.ext">
+ <ConnectorContribution
+ className="org.eclipse.osee.ote.connection.jini.ConnectorContribution">
+ </ConnectorContribution>
+ </extension>
+
+</plugin>
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/Activator.java b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/Activator.java
new file mode 100644
index 00000000000..47e85eccd6f
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/Activator.java
@@ -0,0 +1,122 @@
+package org.eclipse.osee.ote.connection.jini;
+
+import java.util.logging.Level;
+
+import org.eclipse.core.runtime.Plugin;
+import org.eclipse.osee.connection.service.IConnectionService;
+import org.eclipse.osee.framework.jini.JiniClassServer;
+import org.eclipse.osee.framework.jini.discovery.RelaxedSecurity;
+import org.eclipse.osee.framework.logging.OseeLog;
+import org.eclipse.osee.framework.plugin.core.util.ExportClassLoader;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.packageadmin.PackageAdmin;
+import org.osgi.util.tracker.ServiceTracker;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends Plugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.osee.ote.connection.jini";
+
+ // The shared instance
+ private static Activator plugin;
+
+ private ServiceTracker connectionServiceTracker;
+ private ServiceTracker packageAdminTracker;
+ private JiniConnectorRegistrar registrar;
+
+ private ExportClassLoader exportClassLoader;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ System.setSecurityManager(new RelaxedSecurity());
+ super.start(context);
+ plugin = this;
+
+
+
+ }
+
+ void startJini() throws Exception {
+ try {
+ JiniClassServer.getInstance();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ BundleContext context = getBundle().getBundleContext();
+ connectionServiceTracker = new ServiceTracker(context,
+ IConnectionService.class.getName(), null);
+ connectionServiceTracker.open();
+
+ packageAdminTracker = new ServiceTracker(context, PackageAdmin.class
+ .getName(), null);
+ packageAdminTracker.open();
+
+ PackageAdmin pa = (PackageAdmin) packageAdminTracker.getService();
+
+ exportClassLoader = new ExportClassLoader(pa);
+ IConnectionService service = (IConnectionService) connectionServiceTracker
+ .getService();
+
+ registrar = new JiniConnectorRegistrar(exportClassLoader, service);
+
+ // register the service
+ context.registerService(IJiniConnectorRegistrar.class.getName(),
+ registrar, null);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ registrar.shutdown();
+ super.stop(context);
+ connectionServiceTracker.close();
+ packageAdminTracker.close();
+ exportClassLoader = null;
+ registrar = null;
+ plugin = null;
+ try {
+ JiniClassServer.stopServer();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ ClassLoader getExportClassLoader() {
+ return exportClassLoader;
+ }
+
+ public static void log(Level level, String message, Throwable t) {
+ OseeLog.log(Activator.class, level, message, t);
+ }
+
+ public static void log(Level level, String message) {
+ log(level, message, null);
+ }
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/ConnectorContribution.java b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/ConnectorContribution.java
new file mode 100644
index 00000000000..91d015a178e
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/ConnectorContribution.java
@@ -0,0 +1,16 @@
+package org.eclipse.osee.ote.connection.jini;
+
+import org.eclipse.osee.connection.service.IConnectorContributor;
+
+public class ConnectorContribution implements IConnectorContributor {
+
+ public ConnectorContribution() {
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ public void init() throws Exception {
+ Activator.getDefault().startJini();
+ }
+
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/IJiniConnectorLink.java b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/IJiniConnectorLink.java
new file mode 100644
index 00000000000..2e3f1413c8a
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/IJiniConnectorLink.java
@@ -0,0 +1,8 @@
+package org.eclipse.osee.ote.connection.jini;
+
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+public interface IJiniConnectorLink extends Remote {
+ boolean ping() throws RemoteException;
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/IJiniConnectorRegistrar.java b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/IJiniConnectorRegistrar.java
new file mode 100644
index 00000000000..42b53440d93
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/IJiniConnectorRegistrar.java
@@ -0,0 +1,24 @@
+/*
+ * Created on May 16, 2008
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+package org.eclipse.osee.ote.connection.jini;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+
+import net.jini.core.discovery.LookupLocator;
+
+/**
+ * @author b1529404
+ */
+public interface IJiniConnectorRegistrar {
+ void addLocators(String... hosts) throws MalformedURLException, ClassNotFoundException, IOException;
+
+ LookupLocator[] getLocators();
+
+ void addGroup(String... groups) throws IOException;
+
+ String[] getGroups();
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniClientSideConnector.java b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniClientSideConnector.java
new file mode 100644
index 00000000000..459d6cf30c6
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniClientSideConnector.java
@@ -0,0 +1,56 @@
+package org.eclipse.osee.ote.connection.jini;
+
+import java.io.File;
+import java.net.URI;
+import java.rmi.RemoteException;
+
+import net.jini.core.lookup.ServiceItem;
+
+/**
+ * @author b1529404
+ */
+public class JiniClientSideConnector extends JiniConnector {
+ public static final String TYPE = "jini.client-end";
+ private final ServiceItem serviceItem;
+ private final IJiniConnectorLink link;
+ JiniClientSideConnector(ServiceItem serviceItem) {
+ super();
+ this.serviceItem = serviceItem;
+ buildPropertiesFromEntries(serviceItem.attributeSets, getProperties());
+ link = (IJiniConnectorLink) getProperties().getProperty(LINK_PROPERTY);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.connection.service.IServiceConnector#getService()
+ */
+ @Override
+ public Object getService() {
+ return serviceItem.service;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.connection.service.IServiceConnector#getType()
+ */
+ @Override
+ public String getConnectorType() {
+ return TYPE;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.osee.connection.service.IServiceConnector#upload(java.io.File)
+ */
+ @Override
+ public URI upload(File file) throws Exception {
+ return null;
+ }
+
+ @Override
+ public boolean ping() {
+ try {
+ return link.ping();
+ } catch (RemoteException e) {
+ return false;
+ }
+ }
+
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniConnector.java b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniConnector.java
new file mode 100644
index 00000000000..29a458de6fe
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniConnector.java
@@ -0,0 +1,238 @@
+/*
+ * Created on Jun 11, 2008
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+package org.eclipse.osee.ote.connection.jini;
+
+import java.io.Serializable;
+import java.net.UnknownHostException;
+import java.rmi.Remote;
+import java.rmi.server.ExportException;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+
+import net.jini.core.entry.Entry;
+import net.jini.export.Exporter;
+import net.jini.jeri.BasicILFactory;
+import net.jini.jeri.BasicJeriExporter;
+import net.jini.jeri.tcp.TcpServerEndpoint;
+
+import org.eclipse.osee.connection.service.IServiceConnector;
+import org.eclipse.osee.connection.service.IServicePropertyChangeListener;
+import org.eclipse.osee.framework.jdk.core.util.EnhancedProperties;
+import org.eclipse.osee.framework.jdk.core.util.Network;
+import org.eclipse.osee.framework.jini.service.core.PropertyEntry;
+
+/**
+ * @author b1529404
+ */
+public abstract class JiniConnector implements IServiceConnector {
+ protected final static String LINK_PROPERTY = "JINI_CONNECTOR_LINK";
+ private final HashMap<Object, ExportInfo> exports = new HashMap<Object, ExportInfo>();
+ private final EnhancedProperties properties;
+ private final HashSet<IServicePropertyChangeListener> propertyChangeListeners = new HashSet<IServicePropertyChangeListener>();
+
+
+ private static final class ExportInfo {
+ private final Exporter exporter;
+ private final Object exportedObject;
+
+ private ExportInfo(Exporter exporter, Object exportedObject) {
+ this.exportedObject = exportedObject;
+ this.exporter = exporter;
+ }
+ }
+
+ protected JiniConnector() {
+ this(new EnhancedProperties());
+ }
+
+ protected JiniConnector(EnhancedProperties properties) {
+ this.properties = properties;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.osee.connection.service.IServiceConnector#export(java.lang
+ * .Object)
+ */
+ @Override
+ public Object export(Object callback) throws ExportException {
+ try {
+ Exporter exporter = createExporter();
+ Object exportedObject = exporter.export((Remote) callback);
+ exports.put(callback, new ExportInfo(exporter, exportedObject));
+ return exportedObject;
+ } catch (UnknownHostException e) {
+ throw new ExportException("failed to export", e);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.osee.connection.service.IServiceConnector#unexport(java.lang
+ * .Object)
+ */
+ @Override
+ public void unexport(Object callback) throws Exception {
+ ExportInfo info = exports.remove(callback);
+ if (info != null) {
+ info.exporter.unexport(false);
+ }
+ }
+
+ @Override
+ public Object findExport(Object callback) {
+ ExportInfo info = exports.get(callback);
+ if (info != null) {
+ return info.exportedObject;
+ }
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.osee.connection.service.IServiceConnector#stop()
+ */
+ @Override
+ public void stop() throws Exception {
+ for (ExportInfo info : exports.values()) {
+ info.exporter.unexport(false);
+ }
+ exports.clear();
+ }
+
+ private Exporter createExporter() throws UnknownHostException {
+ return new BasicJeriExporter(TcpServerEndpoint.getInstance(Network
+ .getValidIP().getHostAddress(), 0), new BasicILFactory(null,
+ null, Activator.getDefault().getExportClassLoader()), false,
+ false);
+ }
+
+ protected static void buildPropertiesFromEntries(Entry[] entries,
+ EnhancedProperties properties) {
+ for (Entry entry : entries) {
+ if (entry instanceof PropertyEntry) {
+ ((PropertyEntry) entry).fillProps(properties.asMap());
+ // } else if (entry instanceof ServiceInfo) {
+ // ServiceInfo si = (ServiceInfo) entry;
+ // properties.setProperty("name", si.name);
+ // properties.setProperty("model", si.model == null ? "N.A."
+ // : si.model);
+ // } else if (entry instanceof Comment) {
+ // properties.setProperty("comment", ((Comment) entry).comment);
+ // } else if (entry instanceof GroupEntry) {
+ // properties.setProperty("groups", ((GroupEntry) entry)
+ // .getFormmatedString());
+ // } else if (entry instanceof StaticStationInfo) {
+ // StaticStationInfo ssi = (StaticStationInfo) entry;
+ // properties.setProperty("type", ssi.type);
+ // properties.setProperty("station", ssi.station);
+ // properties.setProperty("mode", ssi.mode);
+ // properties.setProperty("date", ssi.dateStarted);
+ // properties.setProperty("version", ssi.version);
+ // } else if (entry instanceof Name) {
+ // properties.setProperty("name", ((Name) entry).name);
+ // } else if (entry instanceof VersionEntry) {
+ // properties.setProperty("version",
+ // ((VersionEntry) entry).version);
+ // } else if (entry instanceof TestEntry) {
+ // System.out.println("test entry data = "
+ // + ((TestEntry) entry).getData());
+ }
+ }
+ }
+
+ protected Entry[] createEntries() {
+ LinkedList<Entry> entries = new LinkedList<Entry>();
+ // GroupEntry group = new GroupEntry();
+ // group.group =
+ // OseeProperties.getInstance().getOseeJiniServiceGroups();
+ // entries.add(group);
+ // // entries.add(new StaticStationInfo((String) properties
+ // // .getProperty("station"), "", (String) properties
+ // // .getProperty("type"), "", "", new Date()));
+ // entries.add(new ServiceInfo((String) properties.getProperty("name"),
+ // "", "", "", "", ""));
+ // // entries.add(new TestEntry("this is test data"));
+ PropertyEntry entry = new PropertyEntry(properties.asMap());
+ assert entry.getProperty("date", null) != null;
+ entries.add(entry);
+ return entries.toArray(new Entry[entries.size()]);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.osee.connection.service.IServiceConnector#getProperty(java
+ * .lang.String, java.lang.String)
+ */
+ @Override
+ public Serializable getProperty(String property, Serializable defaultValue) {
+ return properties.getProperty(property, defaultValue);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.osee.connection.service.IServiceConnector#
+ * addPropertyChangeListener
+ * (org.eclipse.osee.connection.service.IServicePropertyChangeListener)
+ */
+ @Override
+ public void addPropertyChangeListener(
+ IServicePropertyChangeListener listener) {
+ propertyChangeListeners.add(listener);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @seeorg.eclipse.osee.connection.service.IServiceConnector#
+ * removePropertyChangeListener
+ * (org.eclipse.osee.connection.service.IServicePropertyChangeListener)
+ */
+ @Override
+ public void removePropertyChangeListener(
+ IServicePropertyChangeListener listener) {
+ propertyChangeListeners.remove(listener);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.osee.connection.service.IServiceConnector#setProperty(java
+ * .lang.String, java.lang.String)
+ */
+ @Override
+ public void setProperty(String key, Serializable value) {
+ properties.setProperty(key, value);
+ for (IServicePropertyChangeListener listener : propertyChangeListeners) {
+ listener.propertyChanged(this, key, value);
+ }
+ }
+
+ protected EnhancedProperties getProperties() {
+ return properties;
+ }
+
+ public void entriesChanged(Entry[] entries) {
+ EnhancedProperties newProps = new EnhancedProperties();
+ buildPropertiesFromEntries(entries, newProps);
+ for (String key : properties.differences(newProps)) {
+ for (IServicePropertyChangeListener listener : propertyChangeListeners) {
+ listener
+ .propertyChanged(this, key, properties.getProperty(key));
+ }
+ }
+ }
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniConnectorRegistrar.java b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniConnectorRegistrar.java
new file mode 100644
index 00000000000..0784ce0be27
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniConnectorRegistrar.java
@@ -0,0 +1,276 @@
+
+package org.eclipse.osee.ote.connection.jini;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.logging.Level;
+
+import net.jini.config.Configuration;
+import net.jini.config.ConfigurationException;
+import net.jini.core.discovery.LookupLocator;
+import net.jini.core.lookup.ServiceID;
+import net.jini.core.lookup.ServiceItem;
+import net.jini.core.lookup.ServiceRegistrar;
+import net.jini.core.lookup.ServiceRegistration;
+import net.jini.core.lookup.ServiceTemplate;
+import net.jini.discovery.DiscoveryEvent;
+import net.jini.discovery.DiscoveryListener;
+import net.jini.discovery.LookupDiscoveryManager;
+import net.jini.lookup.LookupCache;
+import net.jini.lookup.ServiceDiscoveryEvent;
+import net.jini.lookup.ServiceDiscoveryListener;
+import net.jini.lookup.ServiceDiscoveryManager;
+
+import org.eclipse.osee.connection.service.IConnectionService;
+import org.eclipse.osee.connection.service.IConnectorListener;
+import org.eclipse.osee.connection.service.IServiceConnector;
+import org.eclipse.osee.framework.jini.discovery.OseeJiniConfiguration;
+import org.eclipse.osee.framework.plugin.core.config.JiniLookupGroupConfig;
+
+/**
+ * @author b1529404
+ */
+public class JiniConnectorRegistrar implements IJiniConnectorRegistrar, IConnectorListener,
+ ServiceDiscoveryListener, DiscoveryListener {
+
+ private final HashMap<JiniServiceSideConnector, HashSet<ServiceRegistrar>> serverSideConnectors = new HashMap<JiniServiceSideConnector, HashSet<ServiceRegistrar>>();
+ private final HashSet<ServiceRegistrar> serviceRegistrars = new HashSet<ServiceRegistrar>();
+ private final IConnectionService connectionService;
+ private final HashMap<ServiceID, JiniClientSideConnector> clientSideConnectors = new HashMap<ServiceID, JiniClientSideConnector>();
+
+ private LookupDiscoveryManager lookupDiscoveryManager;
+ private ServiceDiscoveryManager serviceDiscoveryManager;
+ private LookupCache lookupCache;
+ private boolean isShutdown = false;
+
+ public JiniConnectorRegistrar(ClassLoader loader, IConnectionService connectionService)
+ throws Exception, ConfigurationException {
+ this.connectionService = connectionService;
+ connectionService.addListener(this);
+ String[] groups = JiniLookupGroupConfig.getOseeJiniServiceGroups();
+ if (groups == null) {
+ groups = new String[] {};
+ }
+ Configuration config = new OseeJiniConfiguration();
+ ClassLoader previousLoader = Thread.currentThread().getContextClassLoader();
+ try {
+ Thread.currentThread().setContextClassLoader(loader);
+ lookupDiscoveryManager = new LookupDiscoveryManager(groups, null, this, config);
+ serviceDiscoveryManager = new ServiceDiscoveryManager(lookupDiscoveryManager, null, config);
+
+ lookupCache = serviceDiscoveryManager.createLookupCache(new ServiceTemplate(null,new Class[] {},null),
+ null,
+ this);
+ }
+ finally {
+ Thread.currentThread().setContextClassLoader(previousLoader);
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @seeorg.eclipse.osee.connection.service.IConnectorListener# onConnectionServiceStopped()
+ */
+ @Override
+ public void onConnectionServiceStopped() {
+ shutdown();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.osee.connection.service.IConnectorListener#onConnectorAdded
+ * (org.eclipse.osee.connection.service.IServiceConnector)
+ */
+ @Override
+ public synchronized void onConnectorsAdded(
+ Collection<IServiceConnector> connectors) {
+ for (IServiceConnector connector : connectors) {
+ if (connector.getConnectorType().equals(JiniServiceSideConnector.TYPE)) {
+ System.out.println("found jini server side connector");
+ JiniServiceSideConnector jiniConnector = (JiniServiceSideConnector) connector;
+ HashSet<ServiceRegistrar> list = new HashSet<ServiceRegistrar>(serviceRegistrars);
+ serverSideConnectors.put(jiniConnector, list);
+ for (ServiceRegistrar registrar : list) {
+ try {
+ final ServiceRegistration registration = registrar.register(
+ jiniConnector.getServiceItem(),
+ Long.MAX_VALUE);
+ jiniConnector.addRegistration(registration);
+ }
+ catch (RemoteException ex) {
+ Activator.log(Level.WARNING, "Error registering service", ex);
+ }
+ }
+
+ }
+ }
+ }
+
+ public synchronized void shutdown() {
+ if (!isShutdown) {
+ System.out.println("shuting down JiniRegistrar");
+ isShutdown = true;
+ lookupDiscoveryManager.terminate();
+ serviceDiscoveryManager.terminate();
+ serviceRegistrars.clear();
+ for (JiniServiceSideConnector connector : serverSideConnectors.keySet()) {
+ try {
+ connector.removeAllRegistrations();
+ }
+ catch (Exception ex) {
+ Activator.log(Level.WARNING, "Error removing registrations on shutdown", ex);
+ }
+ }
+ if (!connectionService.isStopped()) {
+ for (JiniServiceSideConnector connector : serverSideConnectors.keySet()) {
+ try {
+ connectionService.removeConnector(connector);
+ }
+ catch (Exception ex) {
+ Activator.log(Level.WARNING, "Error removing connectors on shutdown", ex);
+ }
+ }
+ for (JiniClientSideConnector connector : new ArrayList<JiniClientSideConnector>(
+ clientSideConnectors.values())) {
+ try {
+ connectionService.removeConnector(connector);
+ }
+ catch (Exception ex) {
+ Activator.log(Level.WARNING, "Error removing connectors on shutdown", ex);
+ }
+ }
+ }
+ serverSideConnectors.clear();
+ clientSideConnectors.clear();
+ }
+ }
+
+ @Override
+ public void addGroup(String... groups) throws IOException {
+ lookupDiscoveryManager.addGroups(groups);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.osee.connection.service.IConnectorListener#onConnectorRemoved
+ * (org.eclipse.osee.connection.service.IServiceConnector)
+ */
+ @Override
+ public synchronized void onConnectorRemoved(IServiceConnector connector) {
+ if (connector.getConnectorType().equals(JiniServiceSideConnector.TYPE)) {
+ JiniServiceSideConnector jiniConnector = (JiniServiceSideConnector) connector;
+ serverSideConnectors.remove(jiniConnector);
+ }
+ else if (connector.getConnectorType().equals(JiniClientSideConnector.TYPE)) {
+ Iterator<Entry<ServiceID, JiniClientSideConnector>> iter = clientSideConnectors.entrySet().iterator();
+ while (iter.hasNext()) {
+ final Entry<ServiceID, JiniClientSideConnector> entry = iter.next();
+ if (entry.getValue().equals(connector)) {
+ iter.remove();
+ }
+ }
+ }
+ }
+
+ @Override
+ public synchronized void discovered(DiscoveryEvent event) {
+ try {
+ for (ServiceRegistrar registrar : event.getRegistrars()) {
+ System.out.println("Lookup Discovered: Service ID= " + registrar.getServiceID());
+ try {
+ for (String group : registrar.getGroups()) {
+ Activator.log(Level.INFO, "found JINI registrar group: " + group);
+ }
+ }
+ catch (RemoteException ex) {
+ ex.printStackTrace();
+ }
+ serviceRegistrars.add(registrar);
+ for (Map.Entry<JiniServiceSideConnector, HashSet<ServiceRegistrar>> entry : serverSideConnectors.entrySet()) {
+ final ServiceRegistration registration = registrar.register(
+ entry.getKey().getServiceItem(),
+ Long.MAX_VALUE);
+ entry.getKey().addRegistration(registration);
+ entry.getValue().addAll(serviceRegistrars);
+ }
+ }
+ }
+ catch (Exception ex) {
+ Activator.log(Level.SEVERE, "Error processing service discovery", ex);
+ }
+ }
+
+ @Override
+ public synchronized void discarded(DiscoveryEvent event) {
+ this.serviceRegistrars.removeAll(Arrays.asList(event.getRegistrars()));
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see net.jini.lookup.ServiceDiscoveryListener#serviceAdded(net.jini.lookup
+ * .ServiceDiscoveryEvent)
+ */
+ public synchronized void serviceAdded(ServiceDiscoveryEvent event) {
+ ServiceItem serviceItem = event.getPostEventServiceItem();
+ JiniClientSideConnector connector = new JiniClientSideConnector(serviceItem);
+ clientSideConnectors.put(serviceItem.serviceID, connector);
+ connectionService.addConnector(connector);
+ }
+
+ @Override
+ public synchronized void serviceRemoved(ServiceDiscoveryEvent event) {
+ JiniClientSideConnector connector = clientSideConnectors.remove(event.getPreEventServiceItem().serviceID);
+
+ if (connector != null) {
+ try {
+ connectionService.removeConnector(connector);
+ }
+ catch (Exception e) {
+ Activator.log(Level.SEVERE, "error processing removed service event", e);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see net.jini.lookup.ServiceDiscoveryListener#serviceChanged(net.jini.lookup
+ * .ServiceDiscoveryEvent)
+ */
+ public synchronized void serviceChanged(ServiceDiscoveryEvent event) {
+ ServiceItem item = event.getPostEventServiceItem();
+ JiniClientSideConnector connector = clientSideConnectors.get(item.serviceID);
+ if (connector != null) {
+ connector.entriesChanged(item.attributeSets);
+ }
+ }
+
+ @Override
+ public String[] getGroups() {
+ return lookupDiscoveryManager.getGroups();
+ }
+
+ @Override
+ public void addLocators(String... hosts) throws MalformedURLException, ClassNotFoundException, IOException {
+ LookupLocator[] locators = new LookupLocator[hosts.length];
+ int i = 0;
+ for (String host : hosts) {
+ locators[i++] = new LookupLocator(host);
+ }
+ lookupDiscoveryManager.addLocators(locators);
+ }
+
+ @Override
+ public LookupLocator[] getLocators() {
+ return lookupDiscoveryManager.getLocators();
+ }
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniServiceSideConnector.java b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniServiceSideConnector.java
new file mode 100644
index 00000000000..aa093d17184
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniServiceSideConnector.java
@@ -0,0 +1,177 @@
+package org.eclipse.osee.ote.connection.jini;
+
+import java.io.File;
+import java.io.Serializable;
+import java.net.URI;
+import java.net.UnknownHostException;
+import java.rmi.Remote;
+import java.rmi.server.ExportException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Timer;
+import java.util.logging.Level;
+
+import net.jini.core.entry.Entry;
+import net.jini.core.lookup.ServiceID;
+import net.jini.core.lookup.ServiceItem;
+import net.jini.core.lookup.ServiceRegistration;
+import net.jini.id.Uuid;
+import net.jini.id.UuidFactory;
+import net.jini.jeri.BasicILFactory;
+import net.jini.jeri.BasicJeriExporter;
+import net.jini.jeri.tcp.TcpServerEndpoint;
+
+import org.eclipse.osee.framework.jdk.core.util.EnhancedProperties;
+import org.eclipse.osee.framework.jdk.core.util.Network;
+import org.eclipse.osee.ote.connection.jini.util.LeaseRenewTask;
+
+/**
+ * @author b1529404
+ */
+public class JiniServiceSideConnector extends JiniConnector implements
+ IJiniConnectorLink {
+ public static final String TYPE = "jini.service-end";
+ private final HashMap<ServiceRegistration, LeaseRenewTask> registrations = new HashMap<ServiceRegistration, LeaseRenewTask>();
+ private final Remote service;
+ private final Remote serviceProxy;
+ private final BasicJeriExporter serviceExporter;
+ private final ServiceID serviceId;
+ private final Timer timer = new Timer();
+ private final ServiceItem serviceItem;
+ private final BasicJeriExporter linkExporter;
+ private final IJiniConnectorLink exportedThis;
+
+ public JiniServiceSideConnector(Remote service, EnhancedProperties props)
+ throws UnknownHostException, ExportException {
+ super(props);
+ this.service = service;
+ serviceId = generateServiceId();
+ serviceExporter = new BasicJeriExporter(TcpServerEndpoint.getInstance(
+ Network.getValidIP().getHostAddress(), 0), new BasicILFactory(
+ null, null, Activator.getDefault().getExportClassLoader()),
+ false, false);
+ linkExporter = new BasicJeriExporter(TcpServerEndpoint.getInstance(
+ Network.getValidIP().getHostAddress(), 0), new BasicILFactory(
+ null, null, Activator.getDefault().getExportClassLoader()),
+ false, false);
+ serviceProxy = (Remote) serviceExporter.export(service);
+ exportedThis = (IJiniConnectorLink) linkExporter.export(this);
+ props.setProperty(LINK_PROPERTY, (Serializable) exportedThis);
+ serviceItem = new ServiceItem(serviceId, serviceProxy, createEntries());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.osee.connection.service.IServiceConnector#getService()
+ */
+ @Override
+ public Remote getService() {
+ return service;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.osee.connection.service.IServiceConnector#stop()
+ */
+ @Override
+ public synchronized void stop() throws Exception {
+ super.stop();
+ removeAllRegistrations();
+ serviceExporter.unexport(true);
+ linkExporter.unexport(true);
+ }
+
+ /**
+ * this method will cancel all current registrations of this connector
+ */
+ synchronized void removeAllRegistrations() {
+ for (ServiceRegistration registration : registrations.keySet()) {
+ try {
+ removeRegistration(registration);
+ } catch (Exception e) {
+ Activator.log(Level.SEVERE, "exception removing registration",
+ e);
+ }
+ }
+ }
+
+ private ServiceID generateServiceId() {
+ Uuid uuid = UuidFactory.generate();
+ Long lsb = new Long(uuid.getLeastSignificantBits());
+ Long msb = new Long(uuid.getMostSignificantBits());
+ return new ServiceID(msb.longValue(), lsb.longValue());
+ }
+
+ synchronized void addRegistration(ServiceRegistration registration) {
+ registrations
+ .put(registration, new LeaseRenewTask(timer, registration));
+ }
+
+ synchronized void removeRegistration(ServiceRegistration registration) {
+ System.out.println("removing registration");
+ LeaseRenewTask task = registrations.remove(registration);
+ if (task != null) {
+ task.cancel();
+ }
+ }
+
+ ServiceItem getServiceItem() {
+ return serviceItem;
+ }
+
+ private synchronized void setAttributes(Entry[] entry) {
+ Iterator<ServiceRegistration> iter = registrations.keySet().iterator();
+ while (iter.hasNext()) {
+ ServiceRegistration registration = iter.next();
+ try {
+ registration.setAttributes(entry);
+ } catch (Exception ex) {
+ Activator.log(Level.SEVERE, "exception setting attributes", ex);
+ registrations.remove(registration);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.osee.connection.service.IServiceConnector#getType()
+ */
+ @Override
+ public String getConnectorType() {
+ return TYPE;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.osee.ote.connection.jini.JiniConnector#setProperty(java.lang
+ * .String, java.lang.String)
+ */
+ @Override
+ public void setProperty(String key, Serializable value) {
+ super.setProperty(key, value);
+ setAttributes(createEntries());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.osee.connection.service.IServiceConnector#upload(java.io.
+ * File)
+ */
+ @Override
+ public URI upload(File file) throws Exception {
+ return null;
+ }
+
+ @Override
+ public boolean ping() {
+ return true;
+ }
+
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/TestEntry.java b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/TestEntry.java
new file mode 100644
index 00000000000..19126e0f09c
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/TestEntry.java
@@ -0,0 +1,39 @@
+/*
+ * Created on Jul 3, 2008
+ *
+ * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
+ */
+package org.eclipse.osee.ote.connection.jini;
+
+import net.jini.entry.AbstractEntry;
+
+/**
+ * @author b1529404
+ */
+public class TestEntry extends AbstractEntry {
+ /**
+ *
+ */
+ private static final long serialVersionUID = -2239353039479522642L;
+ public final String data;
+
+ public TestEntry() {
+ data = "<none>";
+ }
+
+ /**
+ * @param data
+ */
+ public TestEntry(String data) {
+ super();
+ this.data = data;
+ }
+
+ /**
+ * @return the data
+ */
+ public String getData() {
+ return data;
+ }
+
+}
diff --git a/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/util/LeaseRenewTask.java b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/util/LeaseRenewTask.java
new file mode 100644
index 00000000000..dd417717d9b
--- /dev/null
+++ b/MS_0.6.0_20090114/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/util/LeaseRenewTask.java
@@ -0,0 +1,49 @@
+package org.eclipse.osee.ote.connection.jini.util;
+
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.logging.Level;
+
+import net.jini.core.lookup.ServiceRegistration;
+
+import org.eclipse.osee.ote.connection.jini.Activator;
+
+public class LeaseRenewTask extends TimerTask {
+ /**
+ * The amount of time before a lease expires to first attempt renewal. This amount of time should be sufficiently
+ * large to account for delays in communication (i.e. network delays), and allow for at least a few retries in the
+ * event the service is not reachable. This time is specified in milliseconds.
+ */
+ private static final long RENEWAL_TIME = 2 * 60 * 1000; // 2 minutes
+
+ private final ServiceRegistration registration;
+
+ public LeaseRenewTask(Timer timer, ServiceRegistration registration) {
+ this.registration = registration;
+ timer.scheduleAtFixedRate(this, 0, RENEWAL_TIME);
+ }
+
+ public void run() {
+ try {
+ // Renew for the maximum amount of time allowed
+ registration.getLease().renew(RENEWAL_TIME + 10000);
+ } catch (Exception ex) {
+ Activator.log(Level.SEVERE, "error renewing lease", ex);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see java.util.TimerTask#cancel()
+ */
+ @Override
+ public boolean cancel() {
+ boolean result = super.cancel();
+ try {
+ registration.getLease().cancel();
+ } catch (Exception ex) {
+ throw new RuntimeException("failed to cancel lease", ex);
+ }
+ return result;
+ }
+
+} \ No newline at end of file

Back to the top