diff options
238 files changed, 5898 insertions, 4302 deletions
diff --git a/features/org.eclipse.osee.client.ote.feature/feature.xml b/features/org.eclipse.osee.client.ote.feature/feature.xml index 658b001c8d0..d89f930bed6 100644 --- a/features/org.eclipse.osee.client.ote.feature/feature.xml +++ b/features/org.eclipse.osee.client.ote.feature/feature.xml @@ -231,4 +231,18 @@ version="0.0.0" unpack="false"/> + <plugin + id="org.eclipse.osee.ote.io" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + + <plugin + id="org.eclipse.osee.ote.properties" + download-size="0" + install-size="0" + version="0.0.0" + unpack="false"/> + </feature> diff --git a/plugins/org.eclipse.osee.framework.jini/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.framework.jini/META-INF/MANIFEST.MF index de4429deaf0..54ffb7eac88 100644 --- a/plugins/org.eclipse.osee.framework.jini/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.framework.jini/META-INF/MANIFEST.MF @@ -5,18 +5,7 @@ Bundle-SymbolicName: org.eclipse.osee.framework.jini;singleton:=true Bundle-Version: 0.21.0.qualifier Bundle-Activator: org.eclipse.osee.framework.jini.JiniPlugin Bundle-Vendor: Eclipse Open System Engineering Environment -Export-Package: org.eclipse.osee.framework.jini, - org.eclipse.osee.framework.jini.discovery, - org.eclipse.osee.framework.jini.lease, - org.eclipse.osee.framework.jini.service.core, - org.eclipse.osee.framework.jini.service.directory.service, - org.eclipse.osee.framework.jini.service.gssfl, - org.eclipse.osee.framework.jini.service.interfaces, - org.eclipse.osee.framework.jini.service.report, - org.eclipse.osee.framework.jini.service.scheduler, - org.eclipse.osee.framework.jini.service.test.interfaces, - org.eclipse.osee.framework.jini.util, - org.eclipse.osee.framework.jini.utility +Export-Package: org.eclipse.osee.framework.jini Require-Bundle: org.eclipse.osee.framework.jdk.core, org.eclipse.core.runtime, net.jini, diff --git a/plugins/org.eclipse.osee.framework.jini/plugin.xml b/plugins/org.eclipse.osee.framework.jini/plugin.xml index 56fac984397..fe42530de73 100644 --- a/plugins/org.eclipse.osee.framework.jini/plugin.xml +++ b/plugins/org.eclipse.osee.framework.jini/plugin.xml @@ -1,18 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.0"?> <plugin> - <extension-point id="JiniInterface" name="JiniInterface" schema="schema/JiniInterface.exsd"/> - <extension - point="org.eclipse.osee.framework.jini.JiniInterface"> - <RegisterBundle/> - </extension> - <extension - id="JiniLookup" - name="JiniLookup" - point="org.eclipse.core.runtime.applications"> - <application> - <run class="org.eclipse.osee.framework.jini.JiniLookupPlatformRunnable"/> - </application> - </extension> </plugin> diff --git a/plugins/org.eclipse.osee.framework.jini/schema/JiniInterface.exsd b/plugins/org.eclipse.osee.framework.jini/schema/JiniInterface.exsd deleted file mode 100644 index 36c0c9ef9d6..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/schema/JiniInterface.exsd +++ /dev/null @@ -1,111 +0,0 @@ -<?xml version='1.0' encoding='UTF-8'?> -<!-- Schema file written by PDE --> -<schema targetNamespace="org.eclipse.osee.framework.jini"> -<annotation> - <appInfo> - <meta.schema plugin="org.eclipse.osee.framework.jini" id="JiniInterface" name="JiniInterface"/> - </appInfo> - <documentation> - [Enter description of this extension point.] - </documentation> - </annotation> - - <element name="extension"> - <complexType> - <choice> - <element ref="Interface" minOccurs="1" maxOccurs="unbounded"/> - <element ref="RegisterBundle"/> - </choice> - <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="Interface"> - <complexType> - <attribute name="classname" type="string" use="required"> - <annotation> - <documentation> - - </documentation> - <appInfo> - <meta.attribute kind="java" basedOn="java.rmi.Remote"/> - </appInfo> - </annotation> - </attribute> - </complexType> - </element> - - <element name="RegisterBundle"> - <complexType> - </complexType> - </element> - - <annotation> - <appInfo> - <meta.section type="since"/> - </appInfo> - <documentation> - [Enter the first release in which this extension point appears.] - </documentation> - </annotation> - - <annotation> - <appInfo> - <meta.section type="examples"/> - </appInfo> - <documentation> - [Enter extension point usage example here.] - </documentation> - </annotation> - - <annotation> - <appInfo> - <meta.section type="apiInfo"/> - </appInfo> - <documentation> - [Enter API information here.] - </documentation> - </annotation> - - <annotation> - <appInfo> - <meta.section type="implementation"/> - </appInfo> - <documentation> - [Enter information about supplied implementation of this extension point.] - </documentation> - </annotation> - - <annotation> - <appInfo> - <meta.section type="copyright"/> - </appInfo> - <documentation> - - </documentation> - </annotation> - -</schema> diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/ExperimentalLookup.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/ExperimentalLookup.java deleted file mode 100644 index bc38539dd4a..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/ExperimentalLookup.java +++ /dev/null @@ -1,202 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.MalformedURLException; -import java.rmi.RemoteException; -import java.util.Collection; -import java.util.logging.Level; -import net.jini.config.ConfigurationException; -import net.jini.core.discovery.LookupLocator; -import net.jini.core.entry.Entry; -import net.jini.core.lookup.ServiceItem; -import net.jini.core.lookup.ServiceRegistrar; -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 net.jini.lookup.entry.Comment; -import net.jini.lookup.entry.Name; -import net.jini.lookup.entry.ServiceInfo; -import org.eclipse.osee.framework.jini.discovery.OseeJiniConfiguration; -import org.eclipse.osee.framework.jini.discovery.RelaxedSecurity; -import org.eclipse.osee.framework.jini.service.core.VersionEntry; -import org.eclipse.osee.framework.logging.OseeLog; - -public class ExperimentalLookup implements ServiceDiscoveryListener, DiscoveryListener { - - private LookupDiscoveryManager lookupDiscoveryManager; - private ServiceDiscoveryManager serviceDiscoveryManager; - private LookupCache lookupCache; - - // ************************************************************************* - // Startup - // ************************************************************************* - - private ExperimentalLookup() { - System.setSecurityManager(new RelaxedSecurity()); - registerWithJINI(); - } - - private void registerWithJINI() { - try { - lookupDiscoveryManager = new LookupDiscoveryManager(new String[] {}, null, this, new OseeJiniConfiguration()); - serviceDiscoveryManager = - new ServiceDiscoveryManager(lookupDiscoveryManager, null, new OseeJiniConfiguration()); - - lookupCache = - serviceDiscoveryManager.createLookupCache(new ServiceTemplate(null, new Class[] {}, null), null, this); - - } catch (RemoteException anRE) { - System.err.println("Failed to setup cache - exiting"); - anRE.printStackTrace(System.err); - System.exit(-1); - } catch (IOException anIOE) { - System.err.println("Failed to setup managers - exiting"); - anIOE.printStackTrace(System.err); - System.exit(-1); - } catch (ConfigurationException ex) { - OseeLog.log(JiniPlugin.class, Level.SEVERE, ex); - } catch (Throwable t) { - OseeLog.log(JiniPlugin.class, Level.SEVERE, "failed to setup managers", t); - } - } - - public void addGroup(String... groups) throws IOException { - lookupDiscoveryManager.addGroups(groups); - } - - public String[] getGroups() { - return lookupDiscoveryManager.getGroups(); - } - - @Override - public synchronized void serviceAdded(ServiceDiscoveryEvent event) { - try { - ServiceItem item = event.getPostEventServiceItem(); - System.out.println("found service:\n\tid = " + item.serviceID); - for (Entry entry : item.attributeSets) { - if (entry instanceof ServiceInfo) { - ServiceInfo serviceInfo = (ServiceInfo) entry; - System.out.println("\tname=" + serviceInfo.name); - System.out.println("\tmanufacturer=" + serviceInfo.manufacturer); - } - if (entry instanceof Name) { - Name name = (Name) entry; - System.out.println("\tname entry =" + name.name); - } - if (entry instanceof Comment) { - Comment comment = (Comment) entry; - System.out.println("\tcomment =" + comment.comment); - } - if (entry instanceof VersionEntry) { - VersionEntry version = (VersionEntry) entry; - System.out.println("\tversion entry =" + version.version); - } - } - } catch (RuntimeException ex) { - OseeLog.log(JiniPlugin.class, Level.SEVERE, "exception while adding service", ex); - } - } - - @Override - public void serviceRemoved(ServiceDiscoveryEvent event) { - ServiceItem item = event.getPreEventServiceItem(); - System.out.println("service removed:\n\tid = " + item.serviceID); - for (Entry entry : item.attributeSets) { - if (entry instanceof ServiceInfo) { - ServiceInfo serviceInfo = (ServiceInfo) entry; - System.out.println("\tname=" + serviceInfo.name); - System.out.println("\tmanufacturer=" + serviceInfo.manufacturer); - } - if (entry instanceof Name) { - Name name = (Name) entry; - System.out.println("\tname entry =" + name.name); - } - if (entry instanceof Comment) { - Comment comment = (Comment) entry; - System.out.println("\tcomment =" + comment.comment); - } - if (entry instanceof VersionEntry) { - VersionEntry version = (VersionEntry) entry; - System.out.println("\tversion entry =" + version.version); - } - } - } - - @Override - public void serviceChanged(ServiceDiscoveryEvent event) { - - } - - @Override - public synchronized void discovered(DiscoveryEvent event) { - for (ServiceRegistrar registrar : event.getRegistrars()) { - System.out.println("Lookup Discovered: Service ID= " + registrar.getServiceID()); - try { - for (String group : registrar.getGroups()) { - System.out.println("\tgroup " + group); - } - } catch (RemoteException ex) { - OseeLog.log(JiniPlugin.class, Level.SEVERE, "failed to get registrar groups", ex); - } - } - - } - - @Override - public void discarded(DiscoveryEvent arg0) { - - } - - public void addLookupLocators(Collection<String> lookupList) throws MalformedURLException { - LookupLocator[] locators = new LookupLocator[lookupList.size()]; - int i = 0; - for (String lookup : lookupList) { - locators[i++] = new LookupLocator(lookup); - } - lookupDiscoveryManager.addLocators(locators); - } - - public void terminate() { - lookupDiscoveryManager.terminate(); - serviceDiscoveryManager.terminate(); - } - - public static void main(String[] args) { - - ExperimentalLookup ex = new ExperimentalLookup(); - try { - ex.addGroup(new String[] {"LBA_DEVELOPMENT", "net.jini_2.1.0.200803130705"}); - } catch (IOException ex2) { - OseeLog.log(JiniPlugin.class, Level.SEVERE, ex2.toString(), ex2); - } - BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); - try { - String line = reader.readLine(); - while (!line.equals("QUIT")) { - line = reader.readLine(); - } - } catch (Exception ex1) { - OseeLog.log(JiniPlugin.class, Level.SEVERE, ex1.toString(), ex1); - } finally { - ex.terminate(); - - } - } -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/JiniClassServer.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/JiniClassServer.java deleted file mode 100644 index 36424ab3ca8..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/JiniClassServer.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini; - -import java.net.InetAddress; -import org.eclipse.osee.framework.plugin.core.server.ClassServer; -import org.eclipse.osee.framework.plugin.core.server.ResourceFinder; - -/** - * @author David Diepenbrock - */ -public class JiniClassServer { - - private static JiniClassServer myself; - private final ClassServer classServer; - private final String hostName; - private final String url; - - private JiniClassServer() throws Exception { - hostName = InetAddress.getLocalHost().getHostAddress(); - classServer = new ClassServer(0, InetAddress.getLocalHost()); - classServer.start(); - - url = "http://" + hostName + ":" + classServer.getPort() + "/"; - - System.setProperty("java.rmi.server.hostname", hostName); - System.setProperty("java.rmi.server.codebase", url); - - System.out.println("hostname:" + System.getProperty("java.rmi.server.hostname")); - System.out.println("url:" + System.getProperty("java.rmi.server.codebase")); - - } - - public void addResourceFinder(ResourceFinder finder) { - classServer.addResourceFinder(finder); - } - - /** - * @return Return singleton JiniClassServer object reference. - * @throws Exception If there was an error creating a socket on localhost. - */ - public static JiniClassServer getInstance() throws Exception { - if (myself == null || myself.classServer == null) { - myself = new JiniClassServer(); - } - return myself; - } - - // public void addPaths(String[] paths) { - // - // System.out.println("Adding Paths:"); - // for(int i = 0; i < paths.length; i++){ - // System.out.println("\t" + paths[i]); - // } - // classServer.addPaths(paths); - // } - - // public void addPath(String path) { - // addPaths(new String[]{path}); - // } - - // public void addClass(Class classObj) { - //System.out.println("Adding Class: " + classObj.getCanonicalName()); - // addPath(Lib.getClassLoadPath(classObj)); - // } - - /** - * Stops the class server, if one was started - */ - public static void stopServer() { - if (myself != null && myself.classServer != null) { - myself.classServer.terminate(); - } - } - - /** - * @return Returns the url of the class server. - */ - public String getUrl() { - return url; - } -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/JiniLookupPlatformRunnable.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/JiniLookupPlatformRunnable.java deleted file mode 100644 index e731ab08638..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/JiniLookupPlatformRunnable.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.Platform; -import org.eclipse.equinox.app.IApplication; -import org.eclipse.equinox.app.IApplicationContext; -import org.eclipse.osee.framework.jdk.core.util.CmdLineArgs; -import org.eclipse.osee.framework.jini.utility.StartJini; -import org.osgi.framework.Bundle; - -public class JiniLookupPlatformRunnable implements IApplication { - private StartJini jiniService; - - public JiniLookupPlatformRunnable() { - super(); - this.jiniService = null; - } - - private String getJiniHome() throws IOException { - Bundle bundle = Platform.getBundle("net.jini"); - URL url = bundle.getEntry("/"); - url = FileLocator.resolve(url); - return new File(url.getFile()).getAbsolutePath(); - } - - private InputStream getJiniManifest() throws IOException { - Bundle bundle = Platform.getBundle("org.eclipse.osee.framework.jini"); - URL url = bundle.getEntry("META-INF/MANIFEST.MF"); - return url.openStream(); - } - - @Override - public Object start(IApplicationContext context) throws Exception { - String[] inputArgs = Platform.getApplicationArgs(); - CmdLineArgs args = new CmdLineArgs(inputArgs); - - String port = args.get("-port"); - if (port == null) { - port = "8081"; - } - jiniService = null; - jiniService = new StartJini(port, true, false, getJiniHome(), getJiniManifest()); - return IApplication.EXIT_OK; - } - - @Override - public void stop() { - if (jiniService != null) { - jiniService.kill(); - } - } - -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/JiniPlugin.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/JiniPlugin.java index abb7bc09368..6abb87913f6 100644 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/JiniPlugin.java +++ b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/JiniPlugin.java @@ -12,8 +12,6 @@ package org.eclipse.osee.framework.jini; import org.eclipse.core.runtime.Plugin; -import org.eclipse.osee.framework.jini.discovery.EclipseJiniClassloader; -import org.eclipse.osee.framework.jini.discovery.ServiceDataStore; import org.osgi.framework.BundleContext; /** @@ -28,11 +26,6 @@ public class JiniPlugin extends Plugin { */ public JiniPlugin() { JiniPlugin.plugin = this; - try { - JiniClassServer.getInstance(); - } catch (Exception e) { - e.printStackTrace(); - } } /** @@ -42,7 +35,6 @@ public class JiniPlugin extends Plugin { public void stop(BundleContext context) throws Exception { super.stop(context); plugin = null; - JiniClassServer.stopServer(); } /** @@ -52,10 +44,4 @@ public class JiniPlugin extends Plugin { return plugin; } - public void earlyStartup() { - // so that the jini stuff gets started up - ServiceDataStore.getEclipseInstance(EclipseJiniClassloader.getInstance()); - System.out.println("JiniPlugin early startup"); - } - } diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/discovery/EclipseBundleClassloader.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/discovery/EclipseBundleClassloader.java deleted file mode 100644 index e5640922e07..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/discovery/EclipseBundleClassloader.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.discovery; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.logging.Level; -import org.eclipse.core.runtime.Platform; -import org.eclipse.osee.framework.jini.JiniPlugin; -import org.eclipse.osee.framework.logging.OseeLog; -import org.osgi.framework.Bundle; - -/** - * This class assumes that code is not downloaded from services but already resides in the eclipse install as a plugin. - * A result of this is that versions of the service and the plugins being used need to match. - * - * @author Andrew M. Finkbeiner - */ -public class EclipseBundleClassloader extends ClassLoader { - private final Map<String, Class<?>> classesloaded; - private final Map<String, Bundle> bundleLoaded; - - public EclipseBundleClassloader(List<String> bundleNames) { - this(bundleNames, EclipseBundleClassloader.class.getClassLoader()); - } - - public EclipseBundleClassloader(List<String> bundleNames, ClassLoader parent) { - super(parent); - classesloaded = new HashMap<String, Class<?>>(); - bundleLoaded = new HashMap<String, Bundle>(); - for (int i = 0; i < bundleNames.size(); i++) { - String name = bundleNames.get(i); - Bundle bundle = Platform.getBundle(name); - if (bundle == null) { - OseeLog.log(JiniPlugin.class, Level.WARNING, "The bundle " + name + " does not exist"); - } else { - bundleLoaded.put(bundle.getSymbolicName(), bundle); - } - } - } - - public EclipseBundleClassloader(Bundle bundle) { - super(EclipseBundleClassloader.class.getClassLoader()); - classesloaded = new HashMap<String, Class<?>>(); - bundleLoaded = new HashMap<String, Bundle>(); - bundleLoaded.put(bundle.getSymbolicName(), bundle); - } - - @Override - protected synchronized Class<?> findClass(String classname) throws ClassNotFoundException { - Class<?> loadedclass = classesloaded.get(classname); - if (loadedclass != null) { - return loadedclass; - } - Iterator<String> it = bundleLoaded.keySet().iterator(); - while (it.hasNext()) { - String key = it.next(); - Bundle bundle = bundleLoaded.get(key); - try { - Class<?> foundclass = bundle.loadClass(classname); - if (!classesloaded.containsKey(classname)) { - classesloaded.put(classname, foundclass); - } - return foundclass; - } catch (NoClassDefFoundError err) { - OseeLog.log(JiniPlugin.class, Level.SEVERE, "Caught Error: bundle = " + bundle.getSymbolicName(), err); - } catch (ClassNotFoundException ex) { - // Do nothing - } - } - return this.getParent().loadClass(classname); - } - - @Override - @SuppressWarnings("unchecked") - public Class loadClass(String classname) throws ClassNotFoundException { - return loadClass(classname, false); - } - -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/discovery/EclipseJiniClassloader.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/discovery/EclipseJiniClassloader.java deleted file mode 100644 index a8c8348f55b..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/discovery/EclipseJiniClassloader.java +++ /dev/null @@ -1,132 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.discovery; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExtension; -import org.eclipse.core.runtime.IExtensionPoint; -import org.eclipse.core.runtime.Platform; -import org.osgi.framework.Bundle; - -/** - * This class assumes that code is not downloaded from services but already resides in the eclipse install as a plugin. - * A result of this is that versions of the service and the plugins being used need to match. - * - * @author Andrew M. Finkbeiner - */ -public class EclipseJiniClassloader extends ClassLoader { - private static EclipseJiniClassloader singleton; - private final Map<String, Class<?>> classesloaded; - private Map<String, String> registrationMap; - private final List<String> bundleList; - - public static EclipseJiniClassloader getInstance() { - if (singleton == null) { - singleton = new EclipseJiniClassloader(); - } - return singleton; - } - - public EclipseJiniClassloader(ClassLoader parent) { - super(parent); - classesloaded = new HashMap<String, Class<?>>(); - bundleList = new ArrayList<String>(); - bundleList.add("net.jini"); - - IExtensionPoint point = - Platform.getExtensionRegistry().getExtensionPoint("org.eclipse.osee.framework.jini.JiniInterface"); - IExtension[] extensions = point.getExtensions(); - for (IExtension extension : extensions) { - IConfigurationElement[] elements = extension.getConfigurationElements(); - registrationMap = new HashMap<String, String>(); - for (IConfigurationElement el : elements) { - if (el.getName().equals("Interface")) { - String classname = el.getAttribute("classname"); - String bundleName = el.getContributor().getName(); - if (classname != null && bundleName != null) { - registrationMap.put(classname, bundleName); - } - } else if (el.getName().equals("RegisterBundle")) { - bundleList.add(el.getContributor().getName()); - } - } - } - } - - public EclipseJiniClassloader() { - classesloaded = new HashMap<String, Class<?>>(); - bundleList = new ArrayList<String>(); - bundleList.add("net.jini"); - - IExtensionPoint point = - Platform.getExtensionRegistry().getExtensionPoint("org.eclipse.osee.framework.jini.JiniInterface"); - IExtension[] extensions = point.getExtensions(); - for (IExtension extension : extensions) { - IConfigurationElement[] elements = extension.getConfigurationElements(); - registrationMap = new HashMap<String, String>(); - for (IConfigurationElement el : elements) { - if (el.getName().equals("Interface")) { - String classname = el.getAttribute("classname"); - String bundleName = el.getContributor().getName(); - if (classname != null && bundleName != null) { - registrationMap.put(classname, bundleName); - } - } else if (el.getName().equals("RegisterBundle")) { - bundleList.add(el.getContributor().getName()); - } - } - } - } - - @Override - protected synchronized Class<?> findClass(String classname) throws ClassNotFoundException { - Class<?> loadedclass = classesloaded.get(classname); - if (loadedclass != null) { - return loadedclass; - } - - if (registrationMap.containsKey(classname)) { - String bundleName = registrationMap.get(classname); - Bundle bundle = Platform.getBundle(bundleName); - try { - Class<?> foundclass = bundle.loadClass(classname); - if (foundclass != null) { - System.out.println(foundclass.getName()); - classesloaded.put(classname, foundclass); - return foundclass; - } - } catch (Exception ex) { - } - } - - for (int i = 0; i < bundleList.size(); i++) { - try { - Class<?> foundclass = Platform.getBundle(bundleList.get(i)).loadClass(classname); - if (foundclass != null) { - String bundle = bundleList.remove(i); - bundleList.add(0, bundle); - } - if (!classesloaded.containsKey(classname)) { - classesloaded.put(classname, foundclass); - } - return foundclass; - - } catch (Exception ex) { - // Do nothing - } - } - return super.findClass(classname); - } -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/discovery/IRegistrarListener.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/discovery/IRegistrarListener.java deleted file mode 100644 index 8e71ca9bda5..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/discovery/IRegistrarListener.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.discovery; - -import java.util.List; -import net.jini.core.lookup.ServiceRegistrar; - -/** - * @author Andrew M. Finkbeiner - */ -public interface IRegistrarListener { - public void reggieAdded(List<ServiceRegistrar> serviceRegistrars); - - public void reggieRemoved(List<ServiceRegistrar> serviceRegistrars); - - public void reggieChanged(List<ServiceRegistrar> serviceRegistrars); -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/discovery/IServiceLookupListener.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/discovery/IServiceLookupListener.java deleted file mode 100644 index c7c035ccecc..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/discovery/IServiceLookupListener.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.discovery; - -import net.jini.core.lookup.ServiceItem; - -/** - * @author Andrew M. Finkbeiner - */ -public interface IServiceLookupListener { - public void serviceAdded(ServiceItem serviceItem); - - public void serviceChanged(ServiceItem serviceItem); - - public void serviceRemoved(ServiceItem serviceItem); -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/discovery/OseeJiniConfiguration.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/discovery/OseeJiniConfiguration.java deleted file mode 100644 index 60a9ce53395..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/discovery/OseeJiniConfiguration.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.discovery; - -import net.jini.config.Configuration; -import net.jini.config.ConfigurationException; -import net.jini.config.ConfigurationProvider; - -/** - * @author Andrew M. Finkbeiner - */ -public class OseeJiniConfiguration implements Configuration { - private final Configuration config; - - public OseeJiniConfiguration() throws ConfigurationException { - config = ConfigurationProvider.getInstance(null); - - } - - public OseeJiniConfiguration(ClassLoader loader) throws ConfigurationException { - config = ConfigurationProvider.getInstance(null, loader); - - } - - @Override - public Object getEntry(String arg0, String arg1, Class arg2) throws ConfigurationException { - return config.getEntry(arg0, arg1, arg2); - } - - @Override - public Object getEntry(String arg0, String arg1, Class arg2, Object arg3) throws ConfigurationException { - Object o = config.getEntry(arg0, arg1, arg2, arg3); - return o; - } - - @Override - public Object getEntry(String arg0, String arg1, Class arg2, Object arg3, Object arg4) throws ConfigurationException { - return config.getEntry(arg0, arg1, arg2, arg3, arg4); - } - -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/discovery/RelaxedSecurity.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/discovery/RelaxedSecurity.java deleted file mode 100644 index 8a28231407e..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/discovery/RelaxedSecurity.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.discovery; - -import java.net.InetAddress; -import java.security.Permission; - -/** - * @author Andrew M. Finkbeiner - */ -public class RelaxedSecurity extends SecurityManager { - - public RelaxedSecurity() { - super(); - } - - @Override - public void checkPermission(Permission perm) { - return; - } - - @Override - public void checkPermission(Permission perm, Object context) { - return; - } - - @Override - public void checkAccept(String host, int port) { - return; - } - - @Override - public void checkConnect(String host, int port, Object context) { - } - - @Override - public void checkMulticast(InetAddress maddr, byte ttl) { - } - - @Override - public void checkMulticast(InetAddress maddr) { - } - - @Override - public void checkConnect(String host, int port) { - } - - @Override - public void checkPackageAccess(String pkg) { - - } - - @Override - public void checkAccess(Thread arg0) { - - } - - @Override - public void checkAccess(ThreadGroup arg0) { - - } - - @Override - public void checkCreateClassLoader() { - - } - - @Override - public void checkExec(String arg0) { - - } - -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/discovery/ServiceDataStore.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/discovery/ServiceDataStore.java deleted file mode 100644 index 4753972ad10..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/discovery/ServiceDataStore.java +++ /dev/null @@ -1,726 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.discovery; - -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.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; -import net.jini.config.ConfigurationException; -import net.jini.core.discovery.LookupLocator; -import net.jini.core.entry.Entry; -import net.jini.core.lookup.ServiceID; -import net.jini.core.lookup.ServiceItem; -import net.jini.core.lookup.ServiceRegistrar; -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.framework.jdk.core.util.OseeProperties; -import org.eclipse.osee.framework.jini.JiniPlugin; -import org.eclipse.osee.framework.logging.OseeLog; -import org.eclipse.osee.framework.plugin.core.config.JiniLookupGroupConfig; -import org.eclipse.osee.framework.plugin.core.util.ExportClassLoader; - -public class ServiceDataStore implements ServiceDiscoveryListener, DiscoveryListener { - - private static ServiceDataStore theInstance = null; - - private final List<ClassListener> classListeners; - private final Set<IRegistrarListener> registrarListeners; - private final Set<IServiceLookupListener> noFilterServiceListeners; - private final Set<String> locators; - - // private Set allowedGroups; - - private final List<ServiceItem> serviceItemList; - private final Map<ServiceID, ServiceRegistrar> serviceRegistrars; - private LookupDiscoveryManager lookupDiscoveryManager; - private ServiceDiscoveryManager serviceDiscoveryManager; - - // private LookupCache lookupCache; - // private LookupCache lookupCache; - private final Map<Class<?>, LookupCache> lookupCaches; - private final Logger logger = Logger.getLogger("org.eclipse.osee.framework.jini.discovery.ServiceDataStore"); - private LookupCache everythingCache; - - // ************************************************************************* - // Startup - // ************************************************************************* - - private ServiceDataStore(ClassLoader loader) { - lookupCaches = Collections.synchronizedMap(new HashMap<Class<?>, LookupCache>()); - serviceItemList = Collections.synchronizedList(new ArrayList<ServiceItem>()); - classListeners = new ArrayList<ClassListener>(); - registrarListeners = Collections.synchronizedSet(new HashSet<IRegistrarListener>()); - serviceRegistrars = Collections.synchronizedMap(new HashMap<ServiceID, ServiceRegistrar>()); - noFilterServiceListeners = Collections.synchronizedSet(new HashSet<IServiceLookupListener>()); - locators = Collections.synchronizedSet(new HashSet<String>()); - - ClassLoader currentContext = Thread.currentThread().getContextClassLoader(); - try { - Thread.currentThread().setContextClassLoader(ExportClassLoader.getInstance()); - System.setSecurityManager(new RelaxedSecurity()); - registerWithJINI(); - } finally { - Thread.currentThread().setContextClassLoader(currentContext); - } - } - - private void registerWithJINI() { - try { - String[] filterGroups = JiniLookupGroupConfig.getOseeJiniServiceGroups(); - if (filterGroups == null) { - logger.log( - Level.SEVERE, - "[-D" + OseeProperties.getOseeJiniServiceGroups() + "] was not set.\n" + "Please enter the Jini Group this service register with."); - System.exit(1); - } - - LookupLocator[] locator = null; - lookupDiscoveryManager = new LookupDiscoveryManager(filterGroups, locator, this, new OseeJiniConfiguration()); - serviceDiscoveryManager = - new ServiceDiscoveryManager(lookupDiscoveryManager, null, new OseeJiniConfiguration()); - - // We will maintain our own cache, so this call just registers - // ourselves for lookup - // lookupCache = myManager.createLookupCache(null, null, this); - } catch (RemoteException anRE) { - System.err.println("Failed to setup cache - exiting"); - anRE.printStackTrace(System.err); - System.exit(-1); - } catch (IOException anIOE) { - System.err.println("Failed to setup managers - exiting"); - anIOE.printStackTrace(System.err); - System.exit(-1); - } catch (ConfigurationException ex) { - OseeLog.log(JiniPlugin.class, Level.SEVERE, ex); - } catch (Throwable t) { - OseeLog.log(JiniPlugin.class, Level.SEVERE, "failed to setup managers", t); - } - } - - public void addGroup(String... groups) throws IOException { - lookupDiscoveryManager.addGroups(groups); - } - - public String[] getGroups() { - return lookupDiscoveryManager.getGroups(); - } - - /** - * If an existing instance exists, returns the instance. Otherwise, creates a new instance and starts the jini lookup - * service. Note that services are not immediatly available after starting the lookup service, it takes some time for - * discovery. It is recommended that getInstance() is called at the start of a program's execution in order to start - * this lookup. - * - * @return Return singleton ServiceDataStore object instance reference. - */ - public static ServiceDataStore getEclipseInstance(ClassLoader loader) { - if (theInstance == null) { - if (loader == null) { - loader = ServiceDataStore.class.getClassLoader(); - } - theInstance = new ServiceDataStore(loader); - } - return theInstance; - } - - public static ServiceDataStore getNonEclipseInstance() { - if (theInstance == null) { - theInstance = new ServiceDataStore(ServiceDataStore.class.getClassLoader()); - } - return theInstance; - } - - public ServiceRegistrar findRegistrar(String host) throws MalformedURLException, ClassNotFoundException, IOException { - LookupLocator locator = new LookupLocator(host); - return locator.getRegistrar(5000); - /* - * if (lookupDiscoveryManager.getFrom(reg) == LookupDiscoveryManager.FROM_GROUP || compareGroups(reg)) { if (reg - * != null) { return locator; } } return null; - */ - } - - private class LookupList extends Thread { - - private final Collection<String> lookupLocations; - - public LookupList(Collection<String> lookupLocations) { - this.lookupLocations = lookupLocations; - System.setSecurityManager(new RelaxedSecurity()); - } - - @Override - public void run() { - Thread.currentThread().setContextClassLoader(ExportClassLoader.getInstance()); - System.setSecurityManager(new RelaxedSecurity()); - if (lookupLocations != null) { - List<LookupLocator> locatorList = new ArrayList<LookupLocator>(); - for (String location : lookupLocations) { - try { - LookupLocator locator = new LookupLocator(location); - ServiceRegistrar reg = locator.getRegistrar(5000); - if (lookupDiscoveryManager.getFrom(reg) == LookupDiscoveryManager.FROM_GROUP || compareGroups(reg)) { - if (reg != null) { - locatorList.add(locator); - } - } - } catch (MalformedURLException ex) { - OseeLog.log(JiniPlugin.class, Level.SEVERE, ex); - } catch (Exception ex) { - System.out.println(); // ? - } - } - lookupDiscoveryManager.addLocators(locatorList.toArray(new LookupLocator[locatorList.size()])); - } - } - } - - private boolean compareGroups(ServiceRegistrar reg) { - String[] groups; - try { - groups = reg.getGroups(); - String[] groupsToMatch = lookupDiscoveryManager.getGroups(); - for (int i = 0; i < groups.length; i++) { - for (int j = 0; j < groupsToMatch.length; j++) { - if (groups[i].equals(groupsToMatch[j])) { - return true; - } - } - } - } catch (RemoteException ex) { - OseeLog.log(JiniPlugin.class, Level.SEVERE, ex); - } - return false; - } - - // ************************************************************************* - // Immediate Data Access - // ************************************************************************* - - /** - * Returns a list of currently available services that match the class types provided. <br /> - * Note: If this is called immediatly after the first call to getInstance(), the Jini lookup will not have had time - * to complete, and no services will yet be available. - */ - public List<ServiceItem> getAvailableServices(Class<?>[] classTypes) { - List<ServiceItem> serviceList = new ArrayList<ServiceItem>(); - - for (int i = 0; i < classTypes.length; i++) { - // Notify the listener of all existing services that match - synchronized (serviceItemList) { - for (int j = 0; j < serviceItemList.size(); j++) { - ServiceItem serviceItem = serviceItemList.get(j); - if (classTypes[i].isInstance(serviceItem.service)) { - serviceList.add(serviceItem); - } - } - } - } - - return serviceList; - } - - // ************************************************************************* - // Maintaining Listeners - // ************************************************************************* - - /** - * Adds the listener. When any service events happen, the listener will be notified. Note that upon calling - * addListener(), the {@link IServiceLookupListener#serviceAdded(ServiceItem)} method of the listener will be called - * supplying it all existing services - * - * @param listener The listener to be added - */ - public void addListener(IServiceLookupListener listener) { - synchronized (noFilterServiceListeners) { - noFilterServiceListeners.add(listener); - } - - try { - addLookupCache(null); - } catch (RemoteException e) { - - e.printStackTrace(); - } - - synchronized (serviceItemList) { - for (int i = 0; i < serviceItemList.size(); i++) { - ServiceItem serviceItem = serviceItemList.get(i); - listener.serviceAdded(serviceItem); - } - } - } - - private void addLookupCache(Class<?> classType) throws RemoteException { - if (classType == null && everythingCache == null) { - everythingCache = serviceDiscoveryManager.createLookupCache(null, null, this); - } else { - if (lookupCaches.get(classType) == null) { - ClassLoader currentContext = Thread.currentThread().getContextClassLoader(); - try { - Thread.currentThread().setContextClassLoader(ExportClassLoader.getInstance()); - lookupCaches.put(classType, serviceDiscoveryManager.createLookupCache(new ServiceTemplate(null, - new Class[] {classType}, null), null, this)); - } finally { - Thread.currentThread().setContextClassLoader(currentContext); - } - - } - } - } - - private void resetLookupCaches() throws RemoteException { - if (everythingCache != null) { - everythingCache.removeListener(this); - everythingCache = null; - addLookupCache(null); - } - Iterator<Class<?>> it = lookupCaches.keySet().iterator(); - while (it.hasNext()) { - lookupCaches.get(it.next()).removeListener(this); - } - for (int i = 0; i < classListeners.size(); i++) { - addLookupCache(classListeners.get(i).classType); - } - } - - /** - * Adds the listener to the classType specified. When any service events which are instances of the specified - * classType happen, the listener will be notified. If the listener is concerned with multiple types, multiple calls - * to addListener() can be made. Note that upon calling addListener(), the - * {@link IServiceLookupListener#serviceAdded(ServiceItem)} method of the listener will be called supplying it all - * existing services which match the specified classType. - * - * @param listener The listener to be added - * @param classType The Class of the service events of interest - */ - public void addListener(IServiceLookupListener listener, Class<?> classType, Entry[] entries) { - ClassListener classListener; - - try { - addLookupCache(classType); - } catch (RemoteException e) { - - e.printStackTrace(); - } - - synchronized (classListeners) { - classListener = new ClassListener(classType, listener, entries); - classListeners.add(new ClassListener(classType, listener, entries)); - } - - // Notify the listener of all existing services that match - synchronized (serviceItemList) { - for (int i = 0; i < serviceItemList.size(); i++) { - ServiceItem serviceItem = serviceItemList.get(i); - if (classListener.matches(serviceItem)) { - listener.serviceAdded(serviceItem); - } - } - } - } - - public void addListener(IServiceLookupListener listener, Class<?> classType) { - addListener(listener, classType, null); - } - - /** - * Adds a registrar listener. This enables an object to be notified whenever a lookupservice is added removed or has - * a service added to or removed from it. When a listener is added it immediately gets a callback with all of the - * currently discovered lookup services. - * - * @param listener The listener to be added - */ - public void addListener(IRegistrarListener listener) { - synchronized (registrarListeners) { - registrarListeners.add(listener); - // Notify the listener of all existing services that match - Iterator<IRegistrarListener> it = registrarListeners.iterator(); - while (it.hasNext()) { - IRegistrarListener reggie = it.next(); - reggie.reggieAdded(new ArrayList<ServiceRegistrar>(serviceRegistrars.values())); - } - } - } - - /** - * Removes the listener, it will no longer be notified of change events. - * - * @param listener The listener to be removed - */ - public void removeListener(IRegistrarListener listener) { - synchronized (registrarListeners) { - registrarListeners.remove(listener); - } - } - - /** - * Removes the listener, it will no longer be notified of change events. - * - * @param listenerToRemove The listener to be removed - */ - public void removeListener(IServiceLookupListener listenerToRemove) { - ClassListener classListener; - IServiceLookupListener listener; - - synchronized (classListeners) { - Iterator<ClassListener> classIter = classListeners.iterator(); - while (classIter.hasNext()) { - classListener = classIter.next(); - Iterator<IServiceLookupListener> iter = classListener.listeners.iterator(); - while (iter.hasNext()) { - listener = iter.next(); - if (listener.equals(listenerToRemove)) { - iter.remove(); - } - } - - // If this classType has no more listeners, we can remove it - if (classListener.listeners.isEmpty()) { - classIter.remove(); - } - } - } - - synchronized (noFilterServiceListeners) { - noFilterServiceListeners.remove(listenerToRemove); - } - } - - private class ClassListener { - public Class<?> classType; - - public ArrayList<IServiceLookupListener> listeners; - - public Entry[] entries; - - // public ClassListener(Class classType, IServiceLookupListener - // listener) { - // this.classType = classType; - // listeners = new ArrayList(); - // listeners.add(listener); - // } - - public ClassListener(Class<?> classType, IServiceLookupListener listener, Entry[] entries) { - // this(classType, listener); - this.entries = entries; - this.classType = classType; - listeners = new ArrayList<IServiceLookupListener>(); - listeners.add(listener); - } - - public boolean matches(ServiceItem serviceItem) { - - if (classType.isInstance(serviceItem.service)) { - if (entries != null) { - for (int i = 0; i < entries.length; i++) { - boolean foundEntry = false; - for (int j = 0; j < serviceItem.attributeSets.length; j++) { - if (entries[i].getClass().isInstance(serviceItem.attributeSets[j])) { - if (!entries[i].equals(serviceItem.attributeSets[j])) { - return false; - } else { - foundEntry = true; - } - } - } - if (!foundEntry) { - return false; - } - } - } - return true; - } - return false; - } - } - - // ************************************************************************* - // Notifying Service Changes - // ************************************************************************* - - private void notifyServiceAdded(ServiceItem serviceItem) { - synchronized (noFilterServiceListeners) { - Iterator<IServiceLookupListener> iterator = noFilterServiceListeners.iterator(); - while (iterator.hasNext()) { - iterator.next().serviceAdded(serviceItem); - } - } - synchronized (classListeners) { - for (int i = 0; i < classListeners.size(); i++) { - ClassListener classListener = classListeners.get(i); - - if (classListener.matches(serviceItem)) { - for (int j = 0; j < classListener.listeners.size(); j++) { - IServiceLookupListener listener = classListener.listeners.get(j); - - listener.serviceAdded(serviceItem); - } - } - } - } - } - - private void notifyServiceRemoved(ServiceItem serviceItem) { - synchronized (noFilterServiceListeners) { - Iterator<IServiceLookupListener> iterator = noFilterServiceListeners.iterator(); - while (iterator.hasNext()) { - iterator.next().serviceRemoved(serviceItem); - } - } - - synchronized (classListeners) { - for (int i = 0; i < classListeners.size(); i++) { - ClassListener classListener = classListeners.get(i); - if (classListener.matches(serviceItem)) { - for (int j = 0; j < classListener.listeners.size(); j++) { - IServiceLookupListener listener = classListener.listeners.get(j); - listener.serviceRemoved(serviceItem); - } - } - } - } - } - - private void notifyServiceChanged(ServiceItem serviceItem) { - synchronized (noFilterServiceListeners) { - Iterator<IServiceLookupListener> iterator = noFilterServiceListeners.iterator(); - while (iterator.hasNext()) { - iterator.next().serviceChanged(serviceItem); - } - } - - synchronized (classListeners) { - for (int i = 0; i < classListeners.size(); i++) { - ClassListener classListener = classListeners.get(i); - if (classListener.matches(serviceItem)) { - for (int j = 0; j < classListener.listeners.size(); j++) { - IServiceLookupListener listener = classListener.listeners.get(j); - listener.serviceChanged(serviceItem); - } - } - } - } - } - - // ************************************************************************* - // Handling Service Changes - // ************************************************************************* - - // private static boolean findServiceId(Collection<ServiceItem> list, - // ServiceID sid, boolean - // remove) { - private static boolean findServiceId(Collection<ServiceItem> list, ServiceID sid, boolean remove) { - synchronized (list) { - Iterator<ServiceItem> iter = list.iterator(); - while (iter.hasNext()) { - ServiceItem si = iter.next(); - if (si.serviceID.equals(sid)) { - if (remove) { - iter.remove(); - } - return true; - } - } - } - return false; - } - - @Override - public synchronized void serviceAdded(ServiceDiscoveryEvent event) { - try { - if (!findServiceId(serviceItemList, event.getPostEventServiceItem().serviceID, false)) { - synchronized (serviceItemList) { - serviceItemList.add(event.getPostEventServiceItem()); - } - notifyServiceAdded(event.getPostEventServiceItem()); - - synchronized (registrarListeners) { - Iterator<IRegistrarListener> it = registrarListeners.iterator(); - while (it.hasNext()) { - IRegistrarListener reggie = it.next(); - reggie.reggieChanged(new ArrayList<ServiceRegistrar>(serviceRegistrars.values())); - } - } - } - } catch (Exception ex) { - OseeLog.log(JiniPlugin.class, Level.SEVERE, ex); - } - } - - @Override - public void serviceRemoved(ServiceDiscoveryEvent event) { - if (findServiceId(serviceItemList, event.getPreEventServiceItem().serviceID, true)) { - notifyServiceRemoved(event.getPreEventServiceItem()); - - synchronized (registrarListeners) { - Iterator<IRegistrarListener> it = registrarListeners.iterator(); - while (it.hasNext()) { - IRegistrarListener reggie = it.next(); - reggie.reggieChanged(new ArrayList<ServiceRegistrar>(serviceRegistrars.values())); - } - } - } - } - - @Override - public void serviceChanged(ServiceDiscoveryEvent event) { - if (findServiceId(serviceItemList, event.getPostEventServiceItem().serviceID, false)) { - notifyServiceChanged(event.getPostEventServiceItem()); - } - } - - @Override - public void discovered(DiscoveryEvent arg0) { - synchronized (serviceRegistrars) { - ServiceRegistrar[] reggies = arg0.getRegistrars(); - for (int i = 0; i < reggies.length; i++) { - - if (lookupDiscoveryManager.getFrom(reggies[i]) == LookupDiscoveryManager.FROM_GROUP || compareGroups(reggies[i])) { - Object last = serviceRegistrars.put(reggies[i].getServiceID(), reggies[i]); - - synchronized (registrarListeners) { - if (last == null) { - Iterator<IRegistrarListener> it = registrarListeners.iterator(); - while (it.hasNext()) { - IRegistrarListener reggie = it.next(); - reggie.reggieAdded(new ArrayList<ServiceRegistrar>(serviceRegistrars.values())); - } - } else { - Iterator<IRegistrarListener> it = registrarListeners.iterator(); - while (it.hasNext()) { - IRegistrarListener reggie = it.next(); - reggie.reggieChanged(new ArrayList<ServiceRegistrar>(serviceRegistrars.values())); - } - } - } - } - // else { - // try { - // System.out.println("Reject: " - // + reggies[i].getLocator().getHost()); - // } catch (RemoteException ex) { - // ex.printStackTrace(); - // } - // } - } - } - - } - - @Override - public void discarded(DiscoveryEvent arg0) { - synchronized (serviceRegistrars) { - ServiceRegistrar[] reggies = arg0.getRegistrars(); - for (int i = 0; i < reggies.length; i++) { - if (lookupDiscoveryManager.getFrom(reggies[i]) == LookupDiscoveryManager.FROM_GROUP || compareGroups(reggies[i])) { - - Object removedObject = serviceRegistrars.remove(reggies[i].getServiceID()); - if (removedObject == null) { - synchronized (registrarListeners) { - Iterator<IRegistrarListener> it = registrarListeners.iterator(); - while (it.hasNext()) { - IRegistrarListener reggie = it.next(); - reggie.reggieRemoved(new ArrayList<ServiceRegistrar>(serviceRegistrars.values())); - } - } - } - } - } - } - } - - /** - * @return Returns the serviceRegistrars. - */ - public Map<ServiceID, ServiceRegistrar> getServiceRegistrars() { - return serviceRegistrars; - } - - /** - * @param addToLocators - If true, adds the lookupList to the 'global' lookup list such that a refresh will try to - * locate the service again. This is provided primarily as an optimization for when this routine is called from - * refresh(). - */ - private void addLookupLocators(Collection<String> lookupList, boolean addToLocators) { - boolean isEnabled = OseeProperties.isOseeJiniForcedReggieSearchEnabled(); - if (isEnabled) { - - ClassLoader currentContext = Thread.currentThread().getContextClassLoader(); - try { - Thread.currentThread().setContextClassLoader(ExportClassLoader.getInstance()); - if (addToLocators) { - locators.addAll(lookupList); - } - - Thread thread = new LookupList(lookupList); - thread.setContextClassLoader(ExportClassLoader.getInstance()); - thread.start(); - } finally { - Thread.currentThread().setContextClassLoader(currentContext); - } - } - } - - public void addLookupLocators(Collection<String> lookupList) { - addLookupLocators(lookupList, true); - } - - public void addLookupLocators(String[] lookups) { - if (lookups == null) { - throw new IllegalArgumentException("lookups should not be null"); - } - addLookupLocators(Arrays.asList(lookups), true); - } - - public void terminate() { - lookupDiscoveryManager.terminate(); - serviceDiscoveryManager.terminate(); - } - - public void refresh() { - lookupDiscoveryManager.removeDiscoveryListener(this); - // lookupCache.removeListener(this); - serviceItemList.clear(); - serviceRegistrars.clear(); - Iterator<IRegistrarListener> it = registrarListeners.iterator(); - while (it.hasNext()) { - IRegistrarListener reggie = it.next(); - reggie.reggieRemoved(new ArrayList<ServiceRegistrar>(serviceRegistrars.values())); - } - - registerWithJINI(); - try { - resetLookupCaches(); - } catch (RemoteException e) { - e.printStackTrace(); - } - - addLookupLocators(locators, false); - } -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/lease/ILeaseGrantor.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/lease/ILeaseGrantor.java deleted file mode 100644 index 066835ac9eb..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/lease/ILeaseGrantor.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.lease; - -import java.rmi.Remote; -import java.rmi.RemoteException; -import net.jini.core.lease.Lease; -import net.jini.core.lease.LeaseDeniedException; -import net.jini.core.lease.UnknownLeaseException; - -public interface ILeaseGrantor extends Remote { - - /** - * @param lease The existing lease - * @param consumer The "consumer" of the lease (as opposed to the grantor of the lease) - * @param duration The amount of time requested for the renewed lease - * @throws LeaseDeniedException If the lease is denied for any reason - * @throws UnknownLeaseException If the lease type is unknown - */ - public void renewRequest(Lease lease, Object consumer, long duration) throws LeaseDeniedException, UnknownLeaseException, RemoteException; - - /** - * @param lease The existing lease - * @param consumer The "consumer" of the lease (as opposed to the grantor of the lease) - * @throws UnknownLeaseException If the lease type is unknown - */ - public void cancelRequest(Lease lease, Object consumer) throws UnknownLeaseException, RemoteException; - -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/lease/ILeasee.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/lease/ILeasee.java deleted file mode 100644 index aec500ed723..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/lease/ILeasee.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.lease; - -/** - * This interface should be implemented by classes that use the OseeLeaseGrantor class in order to provide information - * about lease events. - * - * @author David Diepenbrock - */ -public interface ILeasee { - - /** - * Called when a lease expires or is canceled. - * - * @param consumer The consumer of the lease - */ - void onLeaseCompleted(Object consumer); -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/lease/LeaseData.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/lease/LeaseData.java deleted file mode 100644 index 4e324e3470d..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/lease/LeaseData.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.lease; - -public class LeaseData { - - private long duration; - private long startTime; - - public LeaseData(long duration) { - super(); - this.duration = duration; - setStartTime(); - } - - /* package */void setDuration(long duration) { - this.duration = duration; - } - - /* package */void setStartTime() { - this.startTime = System.currentTimeMillis(); - } - - public long getDuration() { - return duration; - } - - public long getStartTime() { - return startTime; - } - - public boolean isExpired() { - return System.currentTimeMillis() > startTime + duration; - } - -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/lease/OseeLease.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/lease/OseeLease.java deleted file mode 100644 index ad4c873d08f..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/lease/OseeLease.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.lease; - -import java.io.Serializable; -import java.rmi.RemoteException; -import java.util.Date; -import net.jini.core.lease.Lease; -import net.jini.core.lease.LeaseDeniedException; -import net.jini.core.lease.LeaseMap; -import net.jini.core.lease.UnknownLeaseException; - -public class OseeLease implements Lease, Serializable { - - private static final long serialVersionUID = -2821773288662499183L; - - private final ILeaseGrantor leaseManager; - private final Object myConsumer; - - private int serialFormat = Lease.DURATION; - private long duration; - private long startTime; - - public OseeLease(ILeaseGrantor manager, Object consumer, long duration) { - super(); - this.myConsumer = consumer; - this.duration = duration; - leaseManager = manager; - } - - @Override - public long getExpiration() { - return duration + startTime; - } - - @Override - public void cancel() throws UnknownLeaseException, RemoteException { - leaseManager.cancelRequest(this, myConsumer); - } - - /** - * Requests that the lease be renewed. - */ - @Override - public void renew(long durationFromNow) throws LeaseDeniedException, UnknownLeaseException, RemoteException { - System.out.println("Requesting Lease Renewal: @" + new Date()); - leaseManager.renewRequest(this, myConsumer, duration); - resetStartTime(); - } - - /* package */void setDuration(long duration) { - this.duration = duration; - } - - /* package */void resetStartTime() { - startTime = System.currentTimeMillis(); - } - - @Override - public void setSerialFormat(int leaseFormat) { - if (leaseFormat == Lease.DURATION) { - serialFormat = Lease.DURATION; - } else if (leaseFormat == Lease.ABSOLUTE) { - serialFormat = Lease.ABSOLUTE; - } else { - assert false : leaseFormat; - } - } - - @Override - public int getSerialFormat() { - return serialFormat; - } - - @Override - public LeaseMap createLeaseMap(long duration) { - return null; - } - - @Override - public boolean canBatch(Lease lease) { - return false; - } - - public long getDuration() { - return duration; - } - -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/lease/OseeLeaseGrantor.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/lease/OseeLeaseGrantor.java deleted file mode 100644 index cc785b5898a..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/lease/OseeLeaseGrantor.java +++ /dev/null @@ -1,180 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.lease; - -import java.lang.ref.WeakReference; -import java.rmi.server.ExportException; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.Timer; -import java.util.TimerTask; -import net.jini.core.lease.Lease; -import net.jini.core.lease.LeaseDeniedException; -import net.jini.core.lease.UnknownLeaseException; -import org.eclipse.osee.framework.jini.util.OseeJini; - -/** - * This class manages tasks associated with being a lease grantor. It generates leases, handles renewal & cancelation of - * the leases, and checks the existing leases to determine if any have expired. Provides a callback by way of the - * ILeasee interface to the leasing service to notify it when a lease is canceled or expired. - * - * @author David Diepenbrock - */ -public class OseeLeaseGrantor implements ILeaseGrantor { - - public static final long maxDuration = 10 * 60 * 1000; /* 10 minutes */ - public static final long minDuration = 2 * 60 * 1000; /* 2 minutes */ - private ILeaseGrantor thisRemoteReference; - private final Map<Object, LeaseData> leaseStore; - private final WeakReference<ILeasee> leasee; - private final LeaseChecker leaseChecker; - private final Timer myTimer; - private boolean cancelTimer; - - /** - * Use of this constructor will generate a new timer thread for lease checks - * - * @param leasee The "parent" object to be notified when a lease expires or is canceled. - */ - public OseeLeaseGrantor(ILeasee leasee) { - this(leasee, new Timer()); - // debug = new Debug(false, true, this.getClass().getName()); - cancelTimer = true; // We will need to cancel the timer on shutdown. - } - - /** - * @param leasee The "parent" object to be notified when a lease expires or is canceled - * @param timer An existing Timer thread to schedule lease checks - */ - public OseeLeaseGrantor(ILeasee leasee, Timer timer) { - this.leasee = new WeakReference<ILeasee>(leasee); - myTimer = timer; - cancelTimer = false; // If a timer was provided we don't need to cancel it on shutdown - leaseStore = Collections.synchronizedMap(new HashMap<Object, LeaseData>()); - - try { - thisRemoteReference = (ILeaseGrantor) OseeJini.getRemoteReference(this); - } catch (ExportException ex) { - ex.printStackTrace(); - } - - long leaseCheckFrequency = minDuration / 2; - leaseChecker = new LeaseChecker(); - timer.schedule(leaseChecker, leaseCheckFrequency, leaseCheckFrequency); - } - - /** - * Call this to notify the grantor that we are shutting down. We need to clean up the task for checking the leases. - */ - public void shutdown() { - leaseChecker.cancel(); - if (cancelTimer) { - myTimer.cancel(); - } - } - - /** - * Returns a new lease - * - * @return Return lease reference. - */ - public OseeLease newLease(Object consumer, long duration) throws LeaseDeniedException { - // debug.report("New Lease:" + consumer + " @" + new Date()); - long actualDuration = checkDuration(duration); - OseeLease lease = new OseeLease(thisRemoteReference, consumer, actualDuration); - leaseStore.put(consumer, new LeaseData(actualDuration)); - return lease; - } - - /** - * Note that the consumer must reset their start timer on the lease. The Grantor cannot set the time since the system - * clocks may differ. - * - * @see org.eclipse.osee.framework.jini.lease.ILeaseGrantor#renewRequest - */ - @Override - public void renewRequest(Lease lease, Object consumer, long duration) throws LeaseDeniedException, UnknownLeaseException { - - // debug.report("Lease renewRequest: " + consumer + " @" + new Date()); - - synchronized (leaseStore) { - LeaseData leaseData = leaseStore.get(consumer); - if (leaseData == null) { - throw new LeaseDeniedException("Consumer does not currently hold a lease"); - } - - if (lease instanceof OseeLease) { - long actualDuration = checkDuration(duration); - leaseData.setDuration(actualDuration); - leaseData.setStartTime(); - ((OseeLease) lease).setDuration(actualDuration); - } else { - throw new UnknownLeaseException("Unknown Lease Type"); - } - } - } - - @Override - public void cancelRequest(Lease lease, Object consumer) { - // debug.report("Lease cancelRequest: " + consumer + " @" + new Date()); - if (leaseStore.remove(consumer) != null) { - leasee.get().onLeaseCompleted(consumer); - } - } - - public boolean isLeaseExpired(Object consumer) { - LeaseData leaseData = leaseStore.get(consumer); - if (leaseData != null) { - return leaseData.isExpired(); - } - - return true; - } - - private long checkDuration(long duration) throws LeaseDeniedException { - long actualDuration; - if (duration > maxDuration) { - actualDuration = maxDuration; - } else if (duration >= minDuration) { - actualDuration = duration; - } else if (duration == Lease.ANY) { - actualDuration = maxDuration; - } else { - throw new LeaseDeniedException("Duration too short - must be at least " + minDuration + " milliseconds."); - } - - return actualDuration; - } - - private class LeaseChecker extends TimerTask { - - @Override - public void run() { - synchronized (leaseStore) { - Set<Entry<Object, LeaseData>> set = leaseStore.entrySet(); - Iterator<Entry<Object, LeaseData>> iter = set.iterator(); - while (iter.hasNext()) { - Entry<Object, LeaseData> entry = iter.next(); - if (entry.getValue().isExpired()) { - leasee.get().onLeaseCompleted(entry.getKey()); - iter.remove(); - } - } - } - } - - } - -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/lease/OseeLeaseRenewer.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/lease/OseeLeaseRenewer.java deleted file mode 100644 index 94895259675..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/lease/OseeLeaseRenewer.java +++ /dev/null @@ -1,128 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.lease; - -import java.rmi.RemoteException; -import java.util.HashMap; -import java.util.Map; -import java.util.Timer; -import java.util.TimerTask; -import java.util.logging.Level; -import net.jini.core.lease.Lease; -import net.jini.core.lease.LeaseDeniedException; -import net.jini.core.lease.UnknownLeaseException; -import org.eclipse.osee.framework.jini.JiniPlugin; -import org.eclipse.osee.framework.logging.OseeLog; - -/** - * This class handles the renewal of leases. It is designed such that a lease will be renewed a set amount of time prior - * to expiration, and handles retrying in cases where the renewal fails. Leases are renewed for the maximum amount of - * time the lease will allow. Retries are be scheduled for half of the remaining lease time. For example, if the first - * attempt to renew occurs with 2 minutes left, the first retry will occur with 1 minute, then 30 seconds, until - * STOP_RETRY_TIME is reached. - * - * @author David Diepenbrock - */ -public class OseeLeaseRenewer { - - private Timer timer; - private final Map<OseeLease, Renewer> map; - - /** - * 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 - /** - * When less than this amount of time is remaining in a lease, failed renewal attempts will not be retried. This time - * is specified in milliseconds. - */ - private static final long STOP_RETRY_TIME = 250; // 250 ms - - public OseeLeaseRenewer() { - // debug = new Debug(false, true, this.getClass().getName()); - map = new HashMap<OseeLease, Renewer>(4); - } - - /** - * Attempts to maintain a lease until cancelRenewal is called - */ - public synchronized void startRenewal(OseeLease lease) { - if (timer == null) { - timer = new Timer(true); - } - - lease.resetStartTime(); - Renewer renewer = new Renewer(lease); - map.put(lease, renewer); - - // Pick the larger duration - RENEWAL_TIME before the expiration, or half of the total lease - // time. - long duration = Math.max(lease.getDuration() / 2, lease.getDuration() - RENEWAL_TIME); - timer.schedule(renewer, duration, duration); - } - - /** - * Prevents the lease from being renewed. This does not cancel the lease, only the renewal attempts. - */ - public synchronized void cancelRenewal(OseeLease lease) { - Renewer renewer = map.remove(lease); - if (renewer != null) { - renewer.cancel(); - } else { - OseeLog.log(JiniPlugin.class, Level.WARNING, - this.getClass().getName() + ": Lease Cancel Attempt: Lease Not Found!"); - } - - if (map.isEmpty()) { - timer.cancel(); - timer = null; - } - } - - private class Renewer extends TimerTask { - - private final OseeLease lease; - - public Renewer(OseeLease lease) { - super(); - this.lease = lease; - } - - @Override - public void run() { - try { - // Obtain the longest lease allowed - lease.renew(Lease.FOREVER); - } catch (LeaseDeniedException ex) { - OseeLog.log(JiniPlugin.class, Level.SEVERE, ex); - } catch (UnknownLeaseException ex) { - OseeLog.log(JiniPlugin.class, Level.SEVERE, ex); - } - /* - * If there was a problem with the lease renewal, retry up until there is less than 250 ms remaining in the - * lease, at which point we can give up hope. Assuming leases are renewed with 2 minutes remaining & 250 ms for - * STOP_RETRY_TIME, this will provide 8 attempts. - */ - catch (RemoteException ex) { - long remainingTime = lease.getExpiration() - System.currentTimeMillis(); - if (remainingTime > STOP_RETRY_TIME) { - timer.schedule(new Renewer(lease), remainingTime / 2); - } else { - // debug.report("Canceling Renewals Retries"); - cancelRenewal(lease); - OseeLog.log(JiniPlugin.class, Level.SEVERE, "Unable to renew lease.", ex); - } - } - } - } -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/FormmatedEntry.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/FormmatedEntry.java deleted file mode 100644 index 56e166b171c..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/FormmatedEntry.java +++ /dev/null @@ -1,20 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.service.core; - -import net.jini.entry.AbstractEntry; - -public abstract class FormmatedEntry extends AbstractEntry { - - private static final long serialVersionUID = -8845417112982132038L; - - public abstract String getFormmatedString(); -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/GroupEntry.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/GroupEntry.java deleted file mode 100644 index 9d263fd85ae..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/GroupEntry.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.service.core; - -public class GroupEntry extends FormmatedEntry { - - private static final long serialVersionUID = 132189087526085874L; - public String[] group; - - public GroupEntry() { - group = new String[] {"Public"}; - } - - @Override - public String getFormmatedString() { - String groups = ""; - if (group != null) { - for (int index = 0; index < group.length; index++) { - groups += group[index]; - if (index + 1 < group.length) { - groups += ","; - } - } - } else { - groups = "NULL"; - } - return "Group(s): {" + groups + "}"; - } - - @Override - public boolean equals(Object other) { - if (!(other instanceof GroupEntry)) { - return false; - } - return group.equals(((GroupEntry) other).group); - } -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/HostEntry.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/HostEntry.java deleted file mode 100644 index b4cebcd0342..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/HostEntry.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.service.core; - -import java.net.InetAddress; -import java.net.UnknownHostException; - -public class HostEntry extends FormmatedEntry { - - private static final long serialVersionUID = -2965321047363718068L; - - public String host; - - public HostEntry() { - - try { - host = InetAddress.getLocalHost().getHostName(); - } catch (UnknownHostException ex) { - host = "Error Obtaining Host"; - ex.printStackTrace(); - } - } - - public String getHost() { - return host; - } - - @Override - public String getFormmatedString() { - return "Host : " + host; - } -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/JiniJoinManager.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/JiniJoinManager.java deleted file mode 100644 index 9656b8177b2..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/JiniJoinManager.java +++ /dev/null @@ -1,195 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.service.core; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.rmi.Remote; -import java.rmi.RemoteException; -import java.rmi.server.ExportException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Timer; -import java.util.TimerTask; -import net.jini.core.entry.Entry; -import net.jini.core.lease.Lease; -import net.jini.core.lease.LeaseDeniedException; -import net.jini.core.lease.UnknownLeaseException; -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 org.eclipse.osee.framework.jini.discovery.IRegistrarListener; -import org.eclipse.osee.framework.jini.discovery.ServiceDataStore; -import org.eclipse.osee.framework.jini.service.interfaces.IService; -import org.eclipse.osee.framework.jini.util.OseeJini; - -/** - * @author Andrew M. Finkbeiner - */ -public class JiniJoinManager implements IRegistrarListener { - - /** - * 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 HashMap<ServiceID, ServiceRegistrar> idToReggie; - private final HashMap<ServiceID, ServiceRegistrar> idToReggie; - // private ArrayList<ServiceRegistration> registrations; - private final ArrayList<ServiceRegistration> registrations; - private final Timer renewTimer; - private final Remote proxy; - private final Entry[] entry; - private final ServiceID serviceID; - private final ServiceDataStore serviceDataStore; - - public JiniJoinManager(ServiceID serviceID, JiniService js, Entry[] entry) throws IOException { - proxy = OseeJini.getRemoteReference(js); - this.entry = entry; - this.serviceID = serviceID; - registrations = new ArrayList<ServiceRegistration>(); - idToReggie = new HashMap<ServiceID, ServiceRegistrar>(); - renewTimer = new Timer(); - serviceDataStore = ServiceDataStore.getNonEclipseInstance(); - serviceDataStore.addListener(this); - } - - public JiniJoinManager(ServiceID serviceID, IService service, Entry[] entry) { - proxy = service; - this.entry = entry; - this.serviceID = serviceID; - registrations = new ArrayList<ServiceRegistration>(); - idToReggie = new HashMap<ServiceID, ServiceRegistrar>(); - renewTimer = new Timer(); - serviceDataStore = ServiceDataStore.getNonEclipseInstance(); - serviceDataStore.addListener(this); - } - - public void terminate() throws RemoteException { - renewTimer.cancel(); - for (int i = 0; i < registrations.size(); i++) { - ServiceRegistration registration = registrations.get(i); - try { - registration.getLease().cancel(); - } catch (UnknownLeaseException ex) { - - } - } - } - - public void setAttributes(Entry[] entry) { - for (int i = 0; i < registrations.size(); i++) { - ServiceRegistration registration = registrations.get(i); - try { - registration.setAttributes(entry); - } catch (UnknownLeaseException ex) { - registrations.remove(i); - i--; - // ex.printStackTrace(); - } catch (RemoteException ex) { - registrations.remove(i); - i--; - // ex.printStackTrace(); - } - } - } - - private class RenewLease extends TimerTask { - ServiceRegistration registration; - - public RenewLease(ServiceRegistration registration) { - this.registration = registration; - } - - @Override - public void run() { - try { - // Renew for the maximum amount of time allowed - registration.getLease().renew(Lease.FOREVER); - renewTimer.schedule(new RenewLease(registration), - registration.getLease().getExpiration() - System.currentTimeMillis() - RENEWAL_TIME); - } catch (LeaseDeniedException ex) { - // ex.printStackTrace(); - } catch (UnknownLeaseException ex) { - // ex.printStackTrace(); - } catch (RemoteException ex) { - // ex.printStackTrace(); - } - // finally{ - // renewTimer.schedule(new RenewLease(registration), registration.getLease().getExpiration() - System.currentTimeMillis() - RENEWAL_TIME); - // } - } - - } - - public void addGroup(String... groups) throws IOException { - serviceDataStore.addGroup(groups); - } - - public String[] getGroups() { - return serviceDataStore.getGroups(); - } - - @Override - public void reggieAdded(List<ServiceRegistrar> serviceRegistrars) { - ServiceRegistrar[] reggies = serviceRegistrars.toArray(new ServiceRegistrar[serviceRegistrars.size()]); - try { - for (int i = 0; i < reggies.length; i++) { - ServiceRegistration registration; - registration = reggies[i].register(new ServiceItem(serviceID, proxy, entry), Long.MAX_VALUE); - idToReggie.put(reggies[i].getServiceID(), reggies[i]); - registrations.add(registration); - renewTimer.schedule(new RenewLease(registration), - registration.getLease().getExpiration() - System.currentTimeMillis() - RENEWAL_TIME); - } - } catch (ExportException ex) { - ex.printStackTrace(); - } catch (RemoteException ex) { - ex.printStackTrace(); - } catch (Throwable t) { - t.printStackTrace(); - } - } - - @Override - public void reggieRemoved(List<ServiceRegistrar> serviceRegistrars) { - ServiceRegistrar[] reggies = serviceRegistrars.toArray(new ServiceRegistrar[serviceRegistrars.size()]); - for (int i = 0; i < reggies.length; i++) { - idToReggie.remove(reggies[i].getServiceID()); - } - } - - @Override - public void reggieChanged(List<ServiceRegistrar> serviceRegistrars) { - } - - public Entry[] getEntry() { - return entry; - } - - public Collection<ServiceRegistrar> getRegistrations() { - return Collections.unmodifiableCollection(idToReggie.values()); - } - - public Remote getProxy() { - return proxy; - } - - public ServiceRegistrar findRegistrar(String host) throws MalformedURLException, ClassNotFoundException, IOException { - return serviceDataStore.findRegistrar(host); - } -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/JiniService.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/JiniService.java deleted file mode 100644 index 68a11ccd5af..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/JiniService.java +++ /dev/null @@ -1,244 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.service.core; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.rmi.RemoteException; -import java.util.ArrayList; -import java.util.Dictionary; -import java.util.List; -import net.jini.core.entry.Entry; -import net.jini.core.lookup.ServiceID; -import net.jini.id.Uuid; -import net.jini.id.UuidFactory; -import net.jini.lookup.entry.Comment; -import net.jini.lookup.entry.Name; -import net.jini.lookup.entry.ServiceInfo; -import org.eclipse.osee.framework.jini.discovery.RelaxedSecurity; -import org.eclipse.osee.framework.jini.service.interfaces.IService; -import org.eclipse.osee.framework.plugin.core.config.JiniLookupGroupConfig; -import org.eclipse.osee.framework.plugin.core.server.ClassServer; -import org.eclipse.osee.framework.plugin.core.server.PathResourceFinder; - -public abstract class JiniService implements IService { - protected JiniJoinManager joinManager; - protected Object keepAlive; - protected ClassServer messageClassServer; - protected String codeBase; - protected String hostName; - private final ServiceID serviceID; - - /** - * Creates a Service with the serviceID specified. Note, this does not register the service. - * - * @param serviceID the serviceID to assign to the service. - */ - public JiniService(ServiceID serviceID) { - this.serviceID = serviceID; - } - - /** - * Creates a Service with the serviceID specified. Note, this does not register the service. - * - * @param uuid The unique identifier used for the serviceID. - */ - public JiniService(Uuid uuid) { - Long lsb = new Long(uuid.getLeastSignificantBits()); - Long msb = new Long(uuid.getMostSignificantBits()); - serviceID = new ServiceID(msb.longValue(), lsb.longValue()); - } - - /** - * Creates a Service. The serviceID will be generated automatically. Note, this does not register the service. - */ - public JiniService() { - this(UuidFactory.generate()); - } - - public void stayAlive() { - keepAlive = new Object(); - synchronized (keepAlive) { - try { - keepAlive.wait(); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } - - public void commitSuicide() { - if (keepAlive != null) { - synchronized (keepAlive) { - keepAlive.notify(); - } - } - } - - public Entry[] registerService(Entry[] entry) { - return registerService(entry, null); - } - - public Entry[] registerService(Entry[] entry, Dictionary dictionary) { - try { - System.setSecurityManager(new RelaxedSecurity()); - // find ServiceInfo - List<Entry> entries = new ArrayList<Entry>(); - entries.add(new OwnerEntry()); - GroupEntry group = null; - - if (dictionary != null) { - ServiceInfo info = null; - Name name = null; - Comment comment = null; - VersionEntry version = null; - - if (entry != null) { - for (int i = 0; i < entry.length; i++) { - if (entry[i] instanceof ServiceInfo) { - info = (ServiceInfo) entry[i]; - } - if (entry[i] instanceof Name) { - name = (Name) entry[i]; - } - if (entry[i] instanceof Comment) { - comment = (Comment) entry[i]; - } - if (entry[i] instanceof VersionEntry) { - version = (VersionEntry) entry[i]; - } - if (entry[i] instanceof GroupEntry) { - group = (GroupEntry) entry[i]; - } - entries.add(entry[i]); - } - } - if (info == null) { - info = new ServiceInfo(); - entries.add(info); - } - if (name == null) { - name = new Name(); - entries.add(name); - } - if (comment == null) { - comment = new Comment(); - entries.add(comment); - } - if (version == null) { - version = new VersionEntry(); - entries.add(version); - } - Object obj = null; - obj = dictionary.get("Bundle-Name"); - if (obj != null) { - info.name = obj.toString(); - } - obj = dictionary.get("Bundle-Vendor"); - if (obj != null) { - info.vendor = obj.toString(); - } - obj = dictionary.get("Bundle-Description"); - if (obj != null) { - comment.comment = obj.toString(); - } - info.version = dictionary.get("Bundle-Version").toString(); - info.serialNumber = info.version; - version.version = info.version; - name.name = dictionary.get("Bundle-Name").toString(); - } else { - if (entry != null) { - for (int i = 0; i < entry.length; i++) { - entries.add(entry[i]); - } - } - } - - if (group == null) { - group = new GroupEntry(); - entries.add(group); - } - group.group = JiniLookupGroupConfig.getOseeJiniServiceGroups(); - - entry = new Entry[entries.size()]; - for (int i = 0; i < entries.size(); i++) { - entry[i] = entries.get(i); - } - joinManager = new JiniJoinManager(serviceID, this, entry); - joinManager.addGroup(group.group); - Runtime.getRuntime().addShutdownHook(new KillService(joinManager)); - } catch (UnknownHostException ex) { - ex.printStackTrace(); - System.exit(1); - } catch (Exception ex) { - ex.printStackTrace(); - System.exit(1); - } - return entry; - } - - protected void startClassServer(String[] jarsToServe) throws Exception { - messageClassServer = new ClassServer(0, InetAddress.getLocalHost()); - PathResourceFinder resource = new PathResourceFinder(jarsToServe, true); - messageClassServer.addResourceFinder(resource); - messageClassServer.start(); - codeBase = - "http://" + InetAddress.getLocalHost().getCanonicalHostName() + ":" + messageClassServer.getPort() + "/"; - hostName = InetAddress.getLocalHost().getHostAddress(); - System.setProperty("java.rmi.server.hostname", hostName); - System.setProperty("java.rmi.server.codebase", codeBase); - } - - public void deregisterService() { - try { - if (joinManager != null) { - joinManager.terminate(); - joinManager = null; - - } else { - System.out.println("service already removed JiniService.deregister"); - } - } catch (RemoteException ex) { - ex.printStackTrace(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - - public void cleanup() { - if (messageClassServer != null) { - messageClassServer.terminate(); - } - } - - @Override - public ServiceID getServiceID() { - return serviceID; - } - - @Override - public boolean equals(Object object) { - if (object instanceof JiniService) { - return ((JiniService) object).serviceID.equals(this.serviceID); - } - return false; - } - - @Override - public int hashCode() { - return serviceID.hashCode(); - } - - public JiniJoinManager getJoinManager() { - return joinManager; - } - -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/KillService.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/KillService.java deleted file mode 100644 index 0e01a2631fe..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/KillService.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.service.core; - -/** - * @author Andrew M. Finkbeiner - */ -public class KillService extends Thread { - - private final JiniJoinManager mgr; - - public KillService(JiniJoinManager mgr) { - this.mgr = mgr; - } - - @Override - public void run() { - try { - mgr.terminate(); - } catch (Exception ex) { - System.out.println("KillService - service already terminated"); - } - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/OwnerEntry.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/OwnerEntry.java deleted file mode 100644 index d3e7e97a06f..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/OwnerEntry.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.service.core; - -public class OwnerEntry extends FormmatedEntry { - - private static final long serialVersionUID = 2648767166516408200L; - public String owner; - - public OwnerEntry() { - owner = System.getProperty("user.name"); - } - - public String getOwner() { - return owner; - } - - @Override - public String getFormmatedString() { - return "Owner : " + owner; - } -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/PropertyEntry.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/PropertyEntry.java deleted file mode 100644 index 572d3a15fe0..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/PropertyEntry.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.service.core; - -import java.io.Serializable; -import java.util.HashMap; -import java.util.Map; -import net.jini.entry.AbstractEntry; -import org.eclipse.osee.framework.jdk.core.util.EnhancedProperties; - -/** - * @author Ken J. Aguilar - */ -public class PropertyEntry extends AbstractEntry { - - private static final long serialVersionUID = 8506398896518763116L; - public HashMap<String, Serializable> map; - - public PropertyEntry() { - map = new HashMap<String, Serializable>(64); - } - - public PropertyEntry(Map<String, Serializable> properties) { - this(); - this.map.putAll(properties); - } - - public void setProperty(String key, Serializable value) { - map.put(key, value); - } - - public Serializable getProperty(String key, Serializable defaultValue) { - Serializable value = map.get(key); - return value == null ? defaultValue : value; - } - - /** - * fills the supplied {@link EnhancedProperties} object with all the properties contained in this entry - */ - public void fillProps(Map<String, Serializable> props) { - props.putAll(map); - } - - @Override - public boolean equals(Object other) { - if (other instanceof PropertyEntry) { - return ((PropertyEntry) other).map.equals(map); - } else { - return false; - } - } - -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/SimpleFormattedEntry.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/SimpleFormattedEntry.java deleted file mode 100644 index 9b73f1c9e47..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/SimpleFormattedEntry.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.service.core; - -/** - * @author Robert A. Fisher - */ -public class SimpleFormattedEntry extends FormmatedEntry { - private static final long serialVersionUID = -4511921240754213614L; - public String name; - public String value; - - public SimpleFormattedEntry() { - super(); - } - - public SimpleFormattedEntry(String name, String value) { - this.name = name; - this.value = value; - } - - @Override - public final String getFormmatedString() { - return name + " : " + value + "\n"; - } -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/directory/service/IDirectory.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/directory/service/IDirectory.java deleted file mode 100644 index d2ba1df9a16..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/directory/service/IDirectory.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.service.directory.service; - -import java.rmi.Remote; -import java.rmi.RemoteException; -import java.util.ArrayList; -import org.eclipse.osee.framework.jdk.core.directory.DirectoryPerson; - -public interface IDirectory extends Remote { - - /** - * @return person object - */ - public DirectoryPerson getPerson(int bemsid) throws RemoteException; - - /** - * @return arraylist of people - */ - public ArrayList<String> getGroup(String[] dept) throws RemoteException; - -}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/gssfl/IGssflTaskService.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/gssfl/IGssflTaskService.java deleted file mode 100644 index 4c9b7422c50..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/gssfl/IGssflTaskService.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.service.gssfl; - -import java.rmi.Remote; -import java.rmi.RemoteException; - -public interface IGssflTaskService extends Remote { - - public String executeCmd(String[] cmd) throws RemoteException; - - public String createAllList(String project) throws RemoteException; - - public String copyAuthorizedRpcrs(String project) throws RemoteException; -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/interfaces/IService.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/interfaces/IService.java deleted file mode 100644 index eb9406d6369..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/interfaces/IService.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.service.interfaces; - -import java.rmi.Remote; -import java.rmi.RemoteException; -import net.jini.core.lookup.ServiceID; - -public interface IService extends Remote { - ServiceID getServiceID() throws RemoteException; - - void kill() throws RemoteException; -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/scheduler/IScheduleService.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/scheduler/IScheduleService.java deleted file mode 100644 index 8ea3a2974b6..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/scheduler/IScheduleService.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.service.scheduler; - -import java.rmi.Remote; -import java.rmi.RemoteException; -import java.util.Calendar; -import net.jini.core.lookup.ServiceItem; - -public interface IScheduleService extends Remote { - - public void addTask(int startTime, int interval, Calendar calendar, int type, String path, String dateStr, String bems, ServiceItem serviceItem) throws RemoteException; - - public void removeTask(String taskId) throws RemoteException; - -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/test/interfaces/BuildTargetPair.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/test/interfaces/BuildTargetPair.java deleted file mode 100644 index 583a0c7ef6a..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/test/interfaces/BuildTargetPair.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.service.test.interfaces; - -import java.io.Serializable; - -public class BuildTargetPair implements Serializable { - - private static final long serialVersionUID = 8194125694292612082L; - String buildMachineName; - String buildMachineIP; - String targetMachineName; - String targetMachineIP; - - public BuildTargetPair(String buildMachineName, String buildMachineIP, String targetMachineName, String targetMachineIP) { - this.buildMachineName = buildMachineName; - this.buildMachineIP = buildMachineIP; - this.targetMachineName = targetMachineName; - this.targetMachineIP = targetMachineIP; - } - - public String getBuildMachineIP() { - return buildMachineIP; - } - - public String getBuildMachineName() { - return buildMachineName; - } - - public String getTargetMachineIP() { - return targetMachineIP; - } - - public String getTargetMachineName() { - return targetMachineName; - } - -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/test/interfaces/INabitService.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/test/interfaces/INabitService.java deleted file mode 100644 index 92b764ec9b5..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/test/interfaces/INabitService.java +++ /dev/null @@ -1,27 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.service.test.interfaces; - -import java.rmi.RemoteException; -import java.util.List; -import org.eclipse.osee.framework.jini.service.interfaces.IService; -import org.eclipse.osee.framework.jini.util.IRemotePrintTarget; - -public interface INabitService extends IService { - - void runBashCommands(String[] cmds) throws RemoteException; - - String getServiceName() throws RemoteException; - - List<BuildTargetPair> getBuildTargetPairInfo() throws RemoteException; - - void connectToMachine(String username, String password, String ip, IRemotePrintTarget callback) throws RemoteException; -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/util/IRemotePrintTarget.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/util/IRemotePrintTarget.java deleted file mode 100644 index 42fb3de934d..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/util/IRemotePrintTarget.java +++ /dev/null @@ -1,18 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.util; - -import java.rmi.Remote; -import java.rmi.RemoteException; - -public interface IRemotePrintTarget extends Remote { - void print(String msg) throws RemoteException; -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/util/OseeJini.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/util/OseeJini.java deleted file mode 100644 index 448cc2f257c..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/util/OseeJini.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.util; - -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.rmi.Remote; -import java.rmi.RemoteException; -import java.rmi.server.ExportException; -import java.util.logging.Level; -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.framework.jdk.core.util.Network; -import org.eclipse.osee.framework.jini.JiniPlugin; -import org.eclipse.osee.framework.jini.service.interfaces.IService; -import org.eclipse.osee.framework.logging.OseeLog; - -public class OseeJini { - public static Remote getRemoteReference(Remote object) throws ExportException { - try { - return getRemoteReference(object, Network.getValidIP()); - } catch (UnknownHostException ex) { - OseeLog.log(JiniPlugin.class, Level.SEVERE, "OseeJini.getRemoteReference: ", ex); - return null; - } - } - - public static Remote getRemoteReference(Remote object, InetAddress inetAddress) throws ExportException { - Exporter export = - new BasicJeriExporter(TcpServerEndpoint.getInstance(inetAddress.getHostAddress(), 0), new BasicILFactory(), - false, false); - return export.export(object); - } - - public static void printClassLoaders(Class<?> clazz) { - ClassLoader cl = clazz.getClassLoader(); - do { - OseeLog.log(JiniPlugin.class, Level.INFO, cl.toString()); - cl = cl.getParent(); - } while (cl != null); - } - - public static boolean isServiceAlive(Object obj) { - try { - Thread.sleep(5000); - } catch (InterruptedException e1) { - - e1.printStackTrace(); - } - boolean returnVal = true; - if (obj instanceof IService) { - try { - ((IService) obj).getServiceID(); - } catch (RemoteException e) { - returnVal = false; - } - } - return returnVal; - } -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/util/RemotePrintStream.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/util/RemotePrintStream.java deleted file mode 100644 index 8f67fe3b125..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/util/RemotePrintStream.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.util; - -import java.io.IOException; -import java.io.PipedInputStream; -import java.io.PipedOutputStream; -import java.io.PrintStream; -import java.io.StringWriter; -import java.rmi.RemoteException; - -public class RemotePrintStream extends PrintStream { - - private final IRemotePrintTarget target; - private final PipedInputStream pis; - private final StringWriter writer; - private final byte[] buffer; - - public RemotePrintStream(PipedOutputStream os, IRemotePrintTarget target) throws IOException { - super(os, true); - this.pis = new PipedInputStream(os); - this.target = target; - writer = new StringWriter(); - buffer = new byte[2048]; - } - - @Override - public void flush() { - super.flush(); - int read; - try { - read = pis.available(); - do { - if (read > 2048) { - read = 2048; - } - int readbytes = pis.read(buffer, 0, read); - writer.append(new String(buffer, 0, readbytes)); - read = pis.available(); - } while (read > 0); - } catch (IOException e) { - e.printStackTrace(); - } - - try { - target.print(writer.toString()); - writer.flush(); - writer.getBuffer().delete(0, writer.getBuffer().capacity()); - } catch (RemoteException e) { - e.printStackTrace(); - } - - } -} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/utility/StartJini.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/utility/StartJini.java deleted file mode 100644 index 620893f803c..00000000000 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/utility/StartJini.java +++ /dev/null @@ -1,244 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.framework.jini.utility; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Dictionary; -import java.util.List; -import java.util.logging.Level; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import net.jini.core.entry.Entry; -import net.jini.lookup.entry.Comment; -import net.jini.lookup.entry.ServiceInfo; -import org.eclipse.osee.framework.jdk.core.util.CmdLineArgs; -import org.eclipse.osee.framework.jdk.core.util.Lib; -import org.eclipse.osee.framework.jdk.core.util.OseeProperties; -import org.eclipse.osee.framework.jini.discovery.ServiceDataStore; -import org.eclipse.osee.framework.jini.service.core.JiniService; -import org.eclipse.osee.framework.jini.service.core.SimpleFormattedEntry; -import org.eclipse.osee.framework.logging.OseeLog; -import org.eclipse.osee.framework.plugin.core.config.JiniLookupGroupConfig; -import org.eclipse.osee.framework.plugin.core.config.NonEclipseManifestHeader; - -/** - * @author Andrew M. Finkbeiner - */ -public class StartJini extends JiniService { - - public static final String SPAWNED_REGGIE_SERVICE_ID = "Spawned Reggie Id"; - public static final String SPAWNED_REGGIE_ON_HOST = "On Host"; - - private final List<Process> jiniProcesses; - - public StartJini(String port, boolean nohup, boolean browser, String jiniHome, InputStream manifestFile) { - super(); - - jiniProcesses = new ArrayList<Process>(); - - try { - String javaHome = System.getProperty("java.home"); - String fs = System.getProperty("file.separator"); - - if (jiniHome == null) { - jiniHome = new File(Lib.getBasePath(StartJini.class).replace("bin", "")).getAbsolutePath(); - } - jiniHome = jiniHome.replace('\\', '/'); - - String[] groups = JiniLookupGroupConfig.getOseeJiniServiceGroups(); - String allowedGroups = ""; - if (groups != null) { - allowedGroups = Arrays.toString(groups); - } else { - OseeLog.log( - StartJini.class, - Level.SEVERE, - "[-D" + OseeProperties.getOseeJiniServiceGroups() + "] was not set.\nPlease enter the Group(s) this Lookup Server will register with."); - return; - } - String quote = null; - if (Lib.isWindows()) { - quote = "\""; - } else { - quote = ""; - } - - String host = InetAddress.getLocalHost().getHostAddress(); - System.out.println("Host Address: " + host); - String javaexeBigMem = quote + javaHome + fs + "bin" + fs + "java" + quote + " -Xmx512M "; - String startServices = - javaexeBigMem + " -Dlookupcomponent " + " -Dosee.jini.lookup.groups=" + allowedGroups + " " + " -Dosee.jini.install=" + quote + jiniHome + "/jini2_1" + quote + " " + " -Dosee.jini.config=" + quote + jiniHome + "/jini_config" + quote + " " + " -Dosee.classserver.host=" + host + " " + " -Dosee.classserver.port=" + port + " " + " -Djava.security.policy=" + quote + jiniHome + "/jini_config/jsk-all.policy" + quote + " " + " -jar " + quote + jiniHome + "/jini2_1/lib/start.jar" + quote + " " + quote + jiniHome + "/jini_config/start-transient-jeri-services.config" + quote; - - OseeLog.log(StartJini.class, Level.INFO, "RUN REGGIE ***************************************************"); - OseeLog.log(StartJini.class, Level.INFO, startServices); - Process process = Runtime.getRuntime().exec(startServices); - jiniProcesses.add(process); - String reggieServiceId = catchTheReggieServiceId(process); - Lib.handleProcessNoWait(process, new OutputStreamWriter(System.err)); - - if (reggieServiceId == null || reggieServiceId.length() == 0) { - OseeLog.log(StartJini.class, Level.SEVERE, "\n Jini Initialization Failed. \n"); - killProcesses(); - return; - } - - // Wait for Reggie to come alive before registering Core Jini Service - try { - Thread.sleep(7000); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - - String model = "CJS"; - String description = "Provides means to shutdown spawned Jini Lookup Services"; - - this.registerService(new Entry[] { - new ServiceInfo("", "", "", "", model, ""), - new Comment(description), - new SimpleFormattedEntry(SPAWNED_REGGIE_SERVICE_ID, reggieServiceId), - new SimpleFormattedEntry(SPAWNED_REGGIE_ON_HOST, getHostName())}, getHeaders(manifestFile)); - - OseeLog.log(StartJini.class, Level.INFO, "....................Core Jini Service is Alive...................."); - this.stayAlive(); - - } catch (IOException ex) { - ex.printStackTrace(); - } - - } - - private String catchTheReggieServiceId(Process process) { - Pattern reggieStartPattern = Pattern.compile("INFO: started Reggie: ([a-z|A-Z|0-9|\\-]+).*"); - String reggieFail = "SEVERE: Reggie initialization failed"; - StringBuilder wr = new StringBuilder(); - String toReturn = ""; - BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream())); - String line = null; - try { - while ((line = reader.readLine()) != null) { - wr.append(line); - OseeLog.log(StartJini.class, Level.INFO, "err: " + line + "\n"); - Matcher reggieStartMatcher = reggieStartPattern.matcher(wr); - if (!wr.toString().contains(reggieFail)) { - if (reggieStartMatcher.matches()) { - toReturn = reggieStartMatcher.group(1); - break; - } - } else { - break; - } - wr.delete(0, wr.length()); - } - } catch (IOException ex) { - ex.printStackTrace(); - } - return toReturn; - } - - private String getHostName() { - String host = ""; - try { - host = InetAddress.getLocalHost().getCanonicalHostName(); - } catch (UnknownHostException ex) { - host = "Error Obtaining Host"; - ex.printStackTrace(); - } - return host; - } - - private static InputStream getManifestFile(String[] args) { - InputStream toReturn = null; - CmdLineArgs cmdLineArgs = new CmdLineArgs(args); - String manifestFileString = cmdLineArgs.get("-manifest"); - - if (manifestFileString == null || manifestFileString.length() == 0) { - manifestFileString = "META-INF/MANIFEST.MF"; - } - File file = new File(manifestFileString); - - if (file == null || !file.exists()) { - OseeLog.log(StartJini.class, Level.SEVERE, "The Specified Manifest File does not exist!!"); - System.exit(1); - } - try { - toReturn = new FileInputStream(file); - } catch (FileNotFoundException ex) { - OseeLog.log(StartJini.class, Level.SEVERE, "The Specified Manifest File can not be opened!!", ex); - System.exit(1); - } - return toReturn; - } - - private static Dictionary<Object, Object> getHeaders(InputStream manifestFile) { - try { - return NonEclipseManifestHeader.parseManifest(manifestFile); - } catch (Exception ex) { - ex.printStackTrace(); - } - return null; - } - - public static void main(String[] args) { - OseeLog.log(StartJini.class, Level.INFO, "num args + " + args.length); - InputStream manifestFile = getManifestFile(args); - if (args.length == 1) { - new StartJini(args[0], false, false, null, manifestFile); - } else if (args.length > 1) { - boolean browser = false, nohup = false; - - for (int i = 1; i < args.length; i++) { - if (args[i].equalsIgnoreCase("-nohup")) { - OseeLog.log(StartJini.class, Level.INFO, "nohup!!"); - nohup = true; - } else if (args[i].equalsIgnoreCase("-browser")) { - browser = true; - } - } - - new StartJini(args[0], nohup, browser, null, manifestFile); - } else { - OseeLog.log(StartJini.class, Level.INFO, - "USAGE: -Dosee.jini.lookup.groups=<groups> StartJini <port> ?<-nohup> ?<-browser>"); - } - - OseeLog.log(StartJini.class, Level.INFO, "Exiting..."); - Runtime.getRuntime().exit(0); - } - - private void killProcesses() { - OseeLog.log(StartJini.class, Level.INFO, "Destroying Spawned Processes..."); - for (Process process : jiniProcesses) { - if (process != null) { - process.destroy(); - } - } - } - - @Override - public void kill() { - OseeLog.log(StartJini.class, Level.INFO, "De-registering Core Jini Service..."); - deregisterService(); - killProcesses(); - ServiceDataStore.getNonEclipseInstance().terminate(); - commitSuicide(); - } -} diff --git a/plugins/org.eclipse.osee.framework.ui.plugin/src/org/eclipse/osee/framework/ui/plugin/util/OseeConsole.java b/plugins/org.eclipse.osee.framework.ui.plugin/src/org/eclipse/osee/framework/ui/plugin/util/OseeConsole.java index caa49264ae7..fb9f0f2c092 100644 --- a/plugins/org.eclipse.osee.framework.ui.plugin/src/org/eclipse/osee/framework/ui/plugin/util/OseeConsole.java +++ b/plugins/org.eclipse.osee.framework.ui.plugin/src/org/eclipse/osee/framework/ui/plugin/util/OseeConsole.java @@ -50,13 +50,16 @@ public class OseeConsole { private final Thread thread; + private boolean newline; + public OseeConsole(String title) { - this(title, true); + this(title, true, true); } - private OseeConsole(String title, boolean time) { + public OseeConsole(String title, boolean time, boolean newline) { console = new IOConsole(title, null); this.time = time; + this.newline = newline; this.inputHandler = new HandleInput(); thread = new Thread(inputHandler); @@ -169,8 +172,9 @@ public class OseeConsole { } else { sendToStreams(type, str); } - - sendToStreams(type, "\n"); + if(newline ){ + sendToStreams(type, "\n"); + } if (popup) { popup(); } diff --git a/plugins/org.eclipse.osee.framework.ui.product/plugin.xml b/plugins/org.eclipse.osee.framework.ui.product/plugin.xml index a265a650d54..b2348bdb8f8 100644 --- a/plugins/org.eclipse.osee.framework.ui.product/plugin.xml +++ b/plugins/org.eclipse.osee.framework.ui.product/plugin.xml @@ -8,11 +8,8 @@ <product application="org.eclipse.ui.ide.workbench" description="The Open System Engineering Environment (OSEE) builds upon the strengths of Eclipse (an open, extensible, platform independent, feature-rich, tools platform) to provide a tightly integrated engineering environment that supports lean engineering. Since OSEE integrates all engineering areas, the full lifecycle data for a product is managed by a common platform allowing this data to be seamlessly brought together to form a coherent, accurate view of a project in real-time." - name="Open System Engineering Environment"> - <property name="windowImages" value="images/osee_16.png,images/osee_32.png,images/osee_48.png" /> - <property name="aboutImage" value="images/osee_154_152.png"/> - <property name="aboutText" value="%blurb"/> - <property name="appName" value="OSEE"/> + name="LBA OSEE IDE Client"> + <property name="appName" value="LBA OSEE IDE Client"/> <property name="preferenceCustomization" value="support/plugin_customization.ini" /> <property name="cssTheme" diff --git a/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/db/MessageInstance.java b/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/db/MessageInstance.java index 70de39a7a69..eb55af0df85 100644 --- a/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/db/MessageInstance.java +++ b/plugins/org.eclipse.osee.ote.client.msg/src/org/eclipse/osee/ote/client/msg/core/db/MessageInstance.java @@ -36,7 +36,8 @@ public class MessageInstance { private int refcount = 0; private boolean supported = true; private volatile boolean connected = false; - + private HashSet<DataType> availableTypes = new HashSet<DataType>(); + public MessageInstance(Message msg, MessageMode mode, DataType type) { this.msg = msg; this.mode = mode; @@ -75,6 +76,15 @@ public class MessageInstance { supported = true; msg.setData(details.getCurrentData()); connected = true; + //determine types for message + Set<? extends DataType> envSet = MessageServiceSupport.getAvailablePhysicalTypes(); + Set<DataType> available = msg.getAssociatedMessages().keySet(); + for(DataType type : available.toArray(new DataType[available.size()])){ + if(envSet.contains(type)){ + availableTypes.add(type); + } + } + serverSubscriptionKey = details.getKey(); return serverSubscriptionKey.getId(); } @@ -84,6 +94,7 @@ public class MessageInstance { MessageServiceSupport.unsubscribeToMessage(new UnSubscribeToMessage(msg.getClass().getName(), mode, type, client.getAddressByType(msg.getClass().getName(), type))); } + availableTypes.clear(); connected = false; serverSubscriptionKey = null; } @@ -113,17 +124,7 @@ public class MessageInstance { } public Set<DataType> getAvailableTypes() { - HashSet<DataType> set = new HashSet<DataType>(); - if(connected){ - Set<? extends DataType> envSet = MessageServiceSupport.getAvailablePhysicalTypes(); - Set<DataType> available = msg.getAssociatedMessages().keySet(); - for(DataType type : available.toArray(new DataType[available.size()])){ - if(envSet.contains(type)){ - set.add(type); - } - } - } - return set; + return availableTypes; } public boolean isSupported() { diff --git a/plugins/org.eclipse.osee.ote.client/.classpath b/plugins/org.eclipse.osee.ote.client/.classpath index 751c8f2e504..ad32c83a788 100644 --- a/plugins/org.eclipse.osee.ote.client/.classpath +++ b/plugins/org.eclipse.osee.ote.client/.classpath @@ -1,7 +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.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/plugins/org.eclipse.osee.ote.client/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ote.client/META-INF/MANIFEST.MF index a78ecb32b49..7d01c9f5617 100644 --- a/plugins/org.eclipse.osee.ote.client/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.ote.client/META-INF/MANIFEST.MF @@ -50,10 +50,10 @@ Import-Package: net.jini.activation, org.eclipse.osee.framework.core.exception, org.eclipse.osee.framework.jdk.core.type, org.eclipse.osee.framework.jdk.core.util, - org.eclipse.osee.framework.jini.service.interfaces, org.eclipse.osee.framework.messaging, org.eclipse.osee.framework.messaging.id, org.eclipse.osee.framework.plugin.core.util, + org.eclipse.osee.ote, org.eclipse.osee.ote.connection.jini, org.eclipse.osee.ote.core, org.eclipse.osee.ote.core.enums, diff --git a/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/IEnvironmentConfigurer.java b/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/IEnvironmentConfigurer.java index 6eb79cfb8dd..5950b16117f 100644 --- a/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/IEnvironmentConfigurer.java +++ b/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/IEnvironmentConfigurer.java @@ -10,11 +10,12 @@ *******************************************************************************/ package org.eclipse.osee.ote.service; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.osee.ote.core.environment.interfaces.IHostTestEnvironment; /** * @author Ken J. Aguilar */ public interface IEnvironmentConfigurer { - void configure(IHostTestEnvironment event) throws Exception; + boolean configure(IHostTestEnvironment event, SubProgressMonitor subProgressMonitor) throws Exception; } diff --git a/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/IOteClientService.java b/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/IOteClientService.java index 586d0672741..d29a224c2f5 100644 --- a/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/IOteClientService.java +++ b/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/IOteClientService.java @@ -14,6 +14,7 @@ import java.net.InetAddress; import java.util.List; import java.util.UUID; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.osee.connection.service.IServiceConnector; import org.eclipse.osee.ote.core.OSEEPerson1_4; import org.eclipse.osee.ote.core.environment.TestEnvironmentConfig; @@ -61,10 +62,11 @@ public interface IOteClientService { /** * creates a connection to a test server. <B>NOTE: </B><I>A user must be logged in prior to calling this method.>/I> + * @param monitor * * @see #setUser(OSEEPerson1_4, InetAddress) */ - ConnectionEvent connect(IHostTestEnvironment env, IEnvironmentConfigurer configurer, TestEnvironmentConfig config) throws TestSessionException; + ConnectionEvent connect(IHostTestEnvironment env, IEnvironmentConfigurer configurer, TestEnvironmentConfig config, IProgressMonitor monitor) throws TestSessionException; /** * breaks the current connection to a test server. This will call the diff --git a/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/JmsToJiniBridgeConnector.java b/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/JmsToJiniBridgeConnector.java index ec5b9c2469e..faf3abdd158 100644 --- a/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/JmsToJiniBridgeConnector.java +++ b/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/JmsToJiniBridgeConnector.java @@ -55,6 +55,7 @@ public class JmsToJiniBridgeConnector implements IServiceConnector { private final List<IServicePropertyChangeListener> propertyChangeListeners = new CopyOnWriteArrayList<IServicePropertyChangeListener>(); private final String uniqueServerId; + private boolean connected = false; public JmsToJiniBridgeConnector(ExportClassLoader exportClassLoader, Object service, String id) { this.uniqueServerId = id; @@ -179,5 +180,13 @@ public class JmsToJiniBridgeConnector implements IServiceConnector { public void init(Object service) throws UnknownHostException, ExportException { } + + public void setConnected(boolean connected){ + this.connected = connected; + } + + public boolean isConnected() { + return this.connected; + } } diff --git a/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/JmsToJiniBridgeConnectorLite.java b/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/JmsToJiniBridgeConnectorLite.java index 30d6a0e021f..375492cc6b1 100644 --- a/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/JmsToJiniBridgeConnectorLite.java +++ b/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/JmsToJiniBridgeConnectorLite.java @@ -75,6 +75,7 @@ public class JmsToJiniBridgeConnectorLite implements IServiceConnector, OseeMess public Object service; Object myLock = new Object(); + private boolean connected = false; public JmsToJiniBridgeConnectorLite(ServiceHealth serviceHealth, MessageService messageService) { this.serviceHealth = serviceHealth; @@ -265,5 +266,13 @@ public class JmsToJiniBridgeConnectorLite implements IServiceConnector, OseeMess public void fail(Throwable th) { OseeLog.log(Activator.class, Level.SEVERE, th); } + + public void setConnected(boolean connected){ + this.connected = connected; + } + + public boolean isConnected() { + return this.connected; + } } diff --git a/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/core/ClientSession.java b/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/core/ClientSession.java index 7363287137f..7d25b9694f2 100644 --- a/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/core/ClientSession.java +++ b/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/core/ClientSession.java @@ -45,11 +45,13 @@ public class ClientSession extends AbstractRemoteSession { private SessionDelegate sessionDelegate = null; private final ReentrantLock lock = new ReentrantLock(); private final OteClientEndpointReceive receive; + private UUID id; public ClientSession(OSEEPerson1_4 user, InetAddress address, OteClientEndpointReceive receive) { super(user); this.address = address; this.receive = receive; + this.id = UUID.randomUUID(); Activator.log(Level.INFO, String.format("Created OTE session for %s. Address=%s\n ", user.getName(), address.toString())); } @@ -172,7 +174,8 @@ public class ClientSession extends AbstractRemoteSession { UUID id = UUID.randomUUID(); Thread.currentThread().setContextClassLoader(ExportClassLoader.getInstance()); ConnectionRequestResult result = testHost.requestEnvironment(exportedSession, id, config); - if (result.getStatus().getStatus()) { + if (result != null && result.getStatus().getStatus()) { + connector.setConnected(true); return new TestHostConnection(connector, testHost, result.getEnvironment(), result.getSessionKey()); } else { OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, "Error Connecting to the OTE Test Server.", @@ -191,6 +194,7 @@ public class ClientSession extends AbstractRemoteSession { // intentionally package-private if (lock.tryLock(TIMEOUT, TimeUnit.MINUTES)) { try { + connection.getServiceConnector().setConnected(false); connection.endConnection(); return; } finally { @@ -214,4 +218,9 @@ public class ClientSession extends AbstractRemoteSession { throw new RemoteException("exception initiating prompt", ex); } } + + @Override + public UUID getUserId() throws Exception { + return id; + } } diff --git a/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/core/TestClientServiceImpl.java b/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/core/TestClientServiceImpl.java index 7024cf2a6da..442c658b100 100644 --- a/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/core/TestClientServiceImpl.java +++ b/plugins/org.eclipse.osee.ote.client/src/org/eclipse/osee/ote/service/core/TestClientServiceImpl.java @@ -23,6 +23,8 @@ import java.util.Set; import java.util.UUID; import java.util.logging.Level; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.osee.connection.service.IConnectionService; import org.eclipse.osee.connection.service.IConnectorListener; import org.eclipse.osee.connection.service.IServiceConnector; @@ -85,7 +87,7 @@ public class TestClientServiceImpl implements IOteClientService, IConnectorListe } @Override - public ConnectionEvent connect(IHostTestEnvironment testHost, IEnvironmentConfigurer configurer, TestEnvironmentConfig config) throws IllegalArgumentException, TestSessionException { + public ConnectionEvent connect(IHostTestEnvironment testHost, IEnvironmentConfigurer configurer, TestEnvironmentConfig config, IProgressMonitor monitor) throws IllegalArgumentException, TestSessionException { checkState(); final IServiceConnector connector; final ClientSession localSession; @@ -93,11 +95,9 @@ public class TestClientServiceImpl implements IOteClientService, IConnectorListe if (session == null) { throw new IllegalArgumentException("a user has not been set"); } - if (testConnection != null) { throw new IllegalStateException("already connected"); } - if (testHost == null) { throw new IllegalArgumentException("test host cannot be null"); } @@ -105,22 +105,17 @@ public class TestClientServiceImpl implements IOteClientService, IConnectorListe localSession = session; } try { - - if (connector == null) { throw new IllegalStateException("Unable to find a connection."); } - - configurer.configure(testHost); - - testConnection = localSession.connect(connector, testHost, config); - if (testConnection != null) { - // success - ConnectionEvent event = - new ConnectionEvent(testHost, connector, testConnection.getConnectEnvironment(), - testConnection.getSessionKey()); - listenerNotifier.notifyPostConnection(event); - return event; + if(configurer.configure(testHost, new SubProgressMonitor(monitor, 95)) && !monitor.isCanceled()){ + testConnection = localSession.connect(connector, testHost, config); + if (testConnection != null) { + // success + ConnectionEvent event = new ConnectionEvent(testHost, connector, testConnection.getConnectEnvironment(), testConnection.getSessionKey()); + listenerNotifier.notifyPostConnection(event); + return event; + } } } catch (Exception e) { Activator.log(Level.SEVERE, "failed to establish connection", e); @@ -133,12 +128,14 @@ public class TestClientServiceImpl implements IOteClientService, IConnectorListe public IServiceConnector getConnector(IHostTestEnvironment host) { try { EnhancedProperties properties = host.getProperties(); - String passedInId = (String) properties.getProperty("id"); - for (IServiceConnector connector : testHosts.values()) { - String loopId = (String) connector.getProperty("id", "no"); - if (passedInId != null && loopId != null && loopId.equals(passedInId)) { - return connector; - } + if(properties != null){ + String passedInId = (String) properties.getProperty("id"); + for (IServiceConnector connector : testHosts.values()) { + String loopId = (String) connector.getProperty("id", "no"); + if (passedInId != null && loopId != null && loopId.equals(passedInId)) { + return connector; + } + } } } catch (RemoteException ex) { ex.printStackTrace(); diff --git a/plugins/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/Activator.java b/plugins/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/Activator.java index d7ae023872e..d73c094963f 100644 --- a/plugins/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/Activator.java +++ b/plugins/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/Activator.java @@ -12,19 +12,10 @@ package org.eclipse.osee.ote.connection.jini; import java.util.logging.Level; -import net.jini.config.ConfigurationException; - 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.server.FrameworkResourceFinder; import org.eclipse.osee.framework.plugin.core.util.ExportClassLoader; import org.osgi.framework.BundleContext; -import org.osgi.framework.ServiceRegistration; -import org.osgi.service.packageadmin.PackageAdmin; -import org.osgi.util.tracker.ServiceTracker; /** * The activator class controls the plug-in life cycle @@ -37,11 +28,6 @@ public class Activator extends Plugin { // The shared instance private static Activator plugin; - private ServiceTracker connectionServiceTracker; - private ServiceTracker packageAdminTracker; - private JiniConnectorRegistrar registrar; - - private ServiceRegistration registration; private ExportClassLoader exportClassLoader; @@ -53,63 +39,16 @@ public class Activator extends Plugin { @Override public void start(BundleContext context) throws Exception { - System.setSecurityManager(new RelaxedSecurity()); super.start(context); plugin = this; } - void startJini() throws Exception { - Thread startJini = new Thread(new Runnable() { - @Override - public void run() { - try { - JiniClassServer.getInstance().addResourceFinder(new FrameworkResourceFinder()); - } 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(); - - try { - registrar = new JiniConnectorRegistrar(exportClassLoader, service); - registration = context.registerService(IJiniConnectorRegistrar.class.getName(), registrar, null); - } catch (ConfigurationException e) { - e.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - startJini.setDaemon(true); - startJini.setName("Starting Jini"); - startJini.start(); - } - @Override public void stop(BundleContext context) throws Exception { - registrar.shutdown(); - registration.unregister(); super.stop(context); - connectionServiceTracker.close(); - packageAdminTracker.close(); exportClassLoader = null; - registrar = null; plugin = null; - try { - JiniClassServer.stopServer(); - } catch (Exception e) { - e.printStackTrace(); - } } /** diff --git a/plugins/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/ConnectorContribution.java b/plugins/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/ConnectorContribution.java index a56e2b301c4..17d6fe94676 100644 --- a/plugins/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/ConnectorContribution.java +++ b/plugins/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/ConnectorContribution.java @@ -15,12 +15,10 @@ 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/plugins/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniClientSideConnector.java b/plugins/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniClientSideConnector.java index 6ff799f075d..10ff1b69340 100644 --- a/plugins/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniClientSideConnector.java +++ b/plugins/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniClientSideConnector.java @@ -28,7 +28,6 @@ public class JiniClientSideConnector extends JiniConnector { JiniClientSideConnector(ServiceItem serviceItem) { super(); this.serviceItem = serviceItem; - buildPropertiesFromEntries(serviceItem.attributeSets, getProperties()); link = (IJiniConnectorLink) getProperties().getProperty(LINK_PROPERTY); } diff --git a/plugins/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniConnector.java b/plugins/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniConnector.java index 5bb3064c824..e9b7b2f7251 100644 --- a/plugins/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniConnector.java +++ b/plugins/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniConnector.java @@ -17,16 +17,17 @@ 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 Ken J. Aguilar @@ -37,6 +38,7 @@ public abstract class JiniConnector implements IServiceConnector { private final EnhancedProperties properties; private final HashSet<IServicePropertyChangeListener> propertyChangeListeners = new HashSet<IServicePropertyChangeListener>(); + private boolean connected = false; private static final class ExportInfo { private final Exporter exporter; @@ -98,54 +100,8 @@ public abstract class JiniConnector implements IServiceConnector { 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()]); } @@ -179,11 +135,18 @@ public abstract class JiniConnector implements IServiceConnector { 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)); } } } + + public void setConnected(boolean connected){ + this.connected = connected; + } + + public boolean isConnected() { + return this.connected; + } } diff --git a/plugins/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniConnectorRegistrar.java b/plugins/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniConnectorRegistrar.java deleted file mode 100644 index 9e9155931ba..00000000000 --- a/plugins/org.eclipse.osee.ote.connection.jini/src/org/eclipse/osee/ote/connection/jini/JiniConnectorRegistrar.java +++ /dev/null @@ -1,249 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -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 Ken J. Aguilar - */ -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); - } - } - - @Override - public void onConnectionServiceStopped() { - shutdown(); - } - - @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"); - HashSet<ServiceRegistrar> list = new HashSet<ServiceRegistrar>(serviceRegistrars); - if (connector instanceof JiniServiceSideConnector) { - serverSideConnectors.put((JiniServiceSideConnector) connector, list); - for (ServiceRegistrar registrar : list) { - try { - final ServiceRegistration registration = - registrar.register(((JiniServiceSideConnector) connector).getServiceItem(), Long.MAX_VALUE); - ((JiniServiceSideConnector) connector).addRegistration(registration, registrar); - } catch (RemoteException ex) { - Activator.log(Level.WARNING, "Error registering service", ex); - } - } - } - } - } - } - - public synchronized void shutdown() { - if (!isShutdown) { - 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); - } - - @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, registrar); - 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())); - - } - - @Override - 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); - } - } - } - - @Override - 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/plugins/org.eclipse.osee.ote.connection.service/src/org/eclipse/osee/connection/service/IServiceConnector.java b/plugins/org.eclipse.osee.ote.connection.service/src/org/eclipse/osee/connection/service/IServiceConnector.java index 5fb828c7f82..f74ab3ba466 100644 --- a/plugins/org.eclipse.osee.ote.connection.service/src/org/eclipse/osee/connection/service/IServiceConnector.java +++ b/plugins/org.eclipse.osee.ote.connection.service/src/org/eclipse/osee/connection/service/IServiceConnector.java @@ -65,4 +65,7 @@ public interface IServiceConnector { EnhancedProperties getProperties(); public String getUniqueServerId(); + + void setConnected(boolean b); + boolean isConnected(); } diff --git a/plugins/org.eclipse.osee.ote.connection.service/src/org/eclipse/osee/connection/service/LocalConnector.java b/plugins/org.eclipse.osee.ote.connection.service/src/org/eclipse/osee/connection/service/LocalConnector.java index 835bcf2b2a3..bf81d7f026b 100644 --- a/plugins/org.eclipse.osee.ote.connection.service/src/org/eclipse/osee/connection/service/LocalConnector.java +++ b/plugins/org.eclipse.osee.ote.connection.service/src/org/eclipse/osee/connection/service/LocalConnector.java @@ -29,6 +29,7 @@ public class LocalConnector implements IServiceConnector { private final HashSet<IServicePropertyChangeListener> propertyChangeListeners = new HashSet<IServicePropertyChangeListener>(); + private boolean connected = false; public LocalConnector() { this(null, "", new EnhancedProperties()); @@ -120,4 +121,11 @@ public class LocalConnector implements IServiceConnector { } } + public void setConnected(boolean connected){ + this.connected = connected; + } + + public boolean isConnected() { + return this.connected; + } } diff --git a/plugins/org.eclipse.osee.ote.core.test/src/org/eclipse/osee/ote/endpoint/OteUdpEndpointTest.java b/plugins/org.eclipse.osee.ote.core.test/src/org/eclipse/osee/ote/endpoint/OteUdpEndpointTest.java new file mode 100644 index 00000000000..6caf95b488a --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core.test/src/org/eclipse/osee/ote/endpoint/OteUdpEndpointTest.java @@ -0,0 +1,43 @@ +package org.eclipse.osee.ote.endpoint; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; + +import org.eclipse.osee.framework.jdk.core.util.network.PortUtil; +import org.eclipse.osee.ote.message.event.FileAvailableRequest; +import org.junit.Assert; +import org.junit.Test; + +public class OteUdpEndpointTest { + + @Test + public void testCreation() throws IOException { + int port = PortUtil.getInstance().getValidPort(); + OteUdpEndpointSender sender = new OteUdpEndpointSender(new InetSocketAddress(port)); + Assert.assertNotNull(sender); + port = PortUtil.getInstance().getValidPort(); + OteUdpEndpointReceiverImpl receiver = new OteUdpEndpointReceiverImpl(new InetSocketAddress(port)); + Assert.assertNotNull(receiver); + } + + @Test + public void testSendReceive() throws IOException, InterruptedException { + int port = PortUtil.getInstance().getValidPort(); + OteUdpEndpointReceiverImpl receiver = new OteUdpEndpointReceiverImpl(new InetSocketAddress(InetAddress.getLocalHost(), port)); + receiver.setDebugOutput(true); + receiver.start(); + Thread.sleep(20); + InetSocketAddress address = receiver.getEndpoint(); + OteUdpEndpointSender sender = new OteUdpEndpointSender(address); + sender.start(); + FileAvailableRequest request = new FileAvailableRequest(); + sender.send(request); + + Thread.sleep(20); + + sender.stop(); + receiver.stop(); + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ote.core/META-INF/MANIFEST.MF index 6b162a7e102..581c19d6198 100644 --- a/plugins/org.eclipse.osee.ote.core/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.ote.core/META-INF/MANIFEST.MF @@ -5,6 +5,7 @@ Bundle-SymbolicName: org.eclipse.osee.ote.core;singleton:=true Bundle-Version: 0.21.0.qualifier Bundle-Vendor: Eclipse Open System Engineering Environment Export-Package: org.eclipse.osee.ote, + org.eclipse.osee.ote.classserver, org.eclipse.osee.ote.core, org.eclipse.osee.ote.core.annotations, org.eclipse.osee.ote.core.cmd, @@ -34,6 +35,7 @@ Export-Package: org.eclipse.osee.ote, org.eclipse.osee.ote.core.test.shells, org.eclipse.osee.ote.core.test.tags, org.eclipse.osee.ote.core.testPoint, + org.eclipse.osee.ote.endpoint, org.eclipse.osee.ote.message, org.eclipse.osee.ote.message.commands, org.eclipse.osee.ote.message.condition, @@ -74,6 +76,8 @@ Import-Package: javax.xml.parsers, org.eclipse.osee.framework.messaging, org.eclipse.osee.framework.messaging.id, org.eclipse.osee.framework.plugin.core.util, + org.eclipse.osee.ote.connection.jini, + org.eclipse.osee.ote.io, org.eclipse.osee.ote.messaging.dds, org.eclipse.osee.ote.messaging.dds.condition, org.eclipse.osee.ote.messaging.dds.entity, @@ -83,9 +87,11 @@ Import-Package: javax.xml.parsers, org.eclipse.osee.ote.messaging.dds.status, org.eclipse.osee.ote.messaging.dds.test, org.eclipse.osee.ote.messaging.dds.test.data, + org.eclipse.osee.ote.properties, org.osgi.service.event;version="1.3.0", org.w3c.dom, org.xml.sax, org.xml.sax.ext, org.xml.sax.helpers Service-Component: OSGI-INF/*.xml + diff --git a/plugins/org.eclipse.osee.ote.core/OSGI-INF/org.eclipse.osee.ote.io.xml b/plugins/org.eclipse.osee.ote.core/OSGI-INF/org.eclipse.osee.ote.io.xml new file mode 100644 index 00000000000..315052b5f9a --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/OSGI-INF/org.eclipse.osee.ote.io.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop" name="org.eclipse.osee.ote.core.systemoutconnection"> + <implementation class="org.eclipse.osee.ote.internal.OTESystemOutConnection"/> + <reference bind="bindOteUdpEndpoint" cardinality="1..1" interface="org.eclipse.osee.ote.endpoint.OteUdpEndpoint" name="OteUdpEndpoint" policy="static" unbind="unbindOteUdpEndpoint"/> + <reference bind="bindSystemOutput" cardinality="1..1" interface="org.eclipse.osee.ote.io.SystemOutput" name="SystemOutput" policy="static" unbind="unbindSystemOutput"/> +</scr:component> diff --git a/plugins/org.eclipse.osee.ote.core/OSGI-INF/ote.api.component.xml b/plugins/org.eclipse.osee.ote.core/OSGI-INF/ote.api.component.xml index 76210519a52..63fa06ed328 100644 --- a/plugins/org.eclipse.osee.ote.core/OSGI-INF/ote.api.component.xml +++ b/plugins/org.eclipse.osee.ote.core/OSGI-INF/ote.api.component.xml @@ -5,9 +5,10 @@ <provide interface="org.eclipse.osee.ote.OTEApi"/> </service> <reference bind="bindRuntimeLibraryManager" cardinality="1..1" interface="org.eclipse.osee.ote.core.environment.interfaces.IRuntimeLibraryManager" name="IRuntimeLibraryManager" policy="static" unbind="unbindRuntimeLibraryManager"/> - <reference bind="bindOTEServerFolder" cardinality="1..1" interface="org.eclipse.osee.ote.OTEServerFolder" name="OTEServerFolder" policy="static" unbind="unbindOTEServerFolder"/> + <reference bind="bindOTEServerFolder" cardinality="1..1" interface="org.eclipse.osee.ote.io.OTEServerFolder" name="OTEServerFolder" policy="static" unbind="unbindOTEServerFolder"/> <reference bind="bindOTEServerRuntimeCache" cardinality="1..1" interface="org.eclipse.osee.ote.OTEServerRuntimeCache" name="OTEServerRuntimeCache" policy="static" unbind="unbindOTEServerRuntimeCache"/> <reference bind="bindTestEnvironmentInterface" cardinality="0..1" interface="org.eclipse.osee.ote.core.environment.TestEnvironmentInterface" name="TestEnvironmentInterface" policy="dynamic" unbind="unbindTestEnvironmentInterface"/> <reference bind="bindIModelManager" cardinality="0..1" interface="org.eclipse.osee.ote.core.model.IModelManager" name="IModelManager" policy="dynamic" unbind="unbindIModelManager"/> <reference bind="bindIRemoteMessageService" cardinality="0..1" interface="org.eclipse.osee.ote.message.interfaces.IRemoteMessageService" name="IRemoteMessageService" policy="dynamic" unbind="unbindIRemoteMessageService"/> + <reference bind="bindIHostTestEnvironment" cardinality="0..1" interface="org.eclipse.osee.ote.core.environment.interfaces.IHostTestEnvironment" name="IHostTestEnvironment" policy="dynamic" unbind="unbindIHostTestEnvironment"/> </scr:component> diff --git a/plugins/org.eclipse.osee.ote.core/OSGI-INF/ote.endpoint.component.xml b/plugins/org.eclipse.osee.ote.core/OSGI-INF/ote.endpoint.component.xml new file mode 100644 index 00000000000..d1451990c92 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/OSGI-INF/ote.endpoint.component.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop" immediate="true" name="org.eclipse.osee.ote.endpoint"> + <implementation class="org.eclipse.osee.ote.internal.endpoint.EndpointComponent"/> + <service> + <provide interface="org.eclipse.osee.ote.endpoint.OteUdpEndpoint"/> + </service> + <reference bind="addDataProcessor" cardinality="0..n" interface="org.eclipse.osee.ote.endpoint.EndpointDataProcessor" name="EndpointDataProcessor" policy="dynamic" unbind="removeDataProcessor"/> +</scr:component> diff --git a/plugins/org.eclipse.osee.ote.core/OSGI-INF/ote.server.folder.component.xml b/plugins/org.eclipse.osee.ote.core/OSGI-INF/ote.server.folder.component.xml deleted file mode 100644 index 9b494626781..00000000000 --- a/plugins/org.eclipse.osee.ote.core/OSGI-INF/ote.server.folder.component.xml +++ /dev/null @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop" name="org.eclipse.osee.ote.server.folder"> - <implementation class="org.eclipse.osee.ote.internal.OTEFolderImpl"/> - <service> - <provide interface="org.eclipse.osee.ote.OTEServerFolder"/> - </service> -</scr:component> diff --git a/plugins/org.eclipse.osee.ote.core/OSGI-INF/ote.server.runtime.cache.component.xml b/plugins/org.eclipse.osee.ote.core/OSGI-INF/ote.server.runtime.cache.component.xml index 838367ed575..0f9a7fc2dcb 100644 --- a/plugins/org.eclipse.osee.ote.core/OSGI-INF/ote.server.runtime.cache.component.xml +++ b/plugins/org.eclipse.osee.ote.core/OSGI-INF/ote.server.runtime.cache.component.xml @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop" immediate="true" name="org.eclipse.osee.ote.server.runtime.cache"> <implementation class="org.eclipse.osee.ote.internal.OTEServerRuntimeCacheImpl"/> - <reference bind="bindOTEServerFolder" cardinality="1..1" interface="org.eclipse.osee.ote.OTEServerFolder" name="OTEServerFolder" policy="static" unbind="unbindOTEServerFolder"/> + <reference bind="bindOTEServerFolder" cardinality="1..1" interface="org.eclipse.osee.ote.io.OTEServerFolder" name="OTEServerFolder" policy="static" unbind="unbindOTEServerFolder"/> <service> <provide interface="org.eclipse.osee.ote.OTEServerRuntimeCache"/> </service> diff --git a/plugins/org.eclipse.osee.ote.core/OSGI-INF/oteapi.handler.xml b/plugins/org.eclipse.osee.ote.core/OSGI-INF/oteapi.handler.xml new file mode 100644 index 00000000000..bc4426d8d5f --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/OSGI-INF/oteapi.handler.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop"> + <implementation class="org.eclipse.osee.ote.internal.RemoteOteApiHandler"/> + <reference bind="bindOTEApi" cardinality="1..1" interface="org.eclipse.osee.ote.OTEApi" name="OTEApi" policy="static" unbind="unbindOTEApi"/> + <reference bind="bindEventAdmin" cardinality="1..1" interface="org.osgi.service.event.EventAdmin" name="EventAdmin" policy="static" unbind="unbindEventAdmin"/> + <reference bind="bindOteUdpEndpoint" cardinality="1..1" interface="org.eclipse.osee.ote.endpoint.OteUdpEndpoint" name="OteUdpEndpoint" policy="static" unbind="unbindOteUdpEndpoint"/> +</scr:component> diff --git a/plugins/org.eclipse.osee.ote.core/build.properties b/plugins/org.eclipse.osee.ote.core/build.properties index 692cec0448d..2655a11f095 100644 --- a/plugins/org.eclipse.osee.ote.core/build.properties +++ b/plugins/org.eclipse.osee.ote.core/build.properties @@ -4,7 +4,5 @@ bin.includes = plugin.xml,\ images/,\ .,\ OSGI-INF/,\ - OSGI-INF/ote.server.runtime.cache.component.xml,\ - OSGI-INF/ote.server.folder.component.xml,\ - OSGI-INF/message.service.handler.xml + OSGI-INF/org.eclipse.osee.ote.io.xml source.. = src/ diff --git a/plugins/org.eclipse.osee.ote.core/plugin.xml b/plugins/org.eclipse.osee.ote.core/plugin.xml index 16406f24053..af99d231811 100644 --- a/plugins/org.eclipse.osee.ote.core/plugin.xml +++ b/plugins/org.eclipse.osee.ote.core/plugin.xml @@ -1,25 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <?eclipse version="3.0"?> <plugin> - <extension - id="TestInterface" - name="TestInterface" - point="org.eclipse.osee.framework.jini.JiniInterface"> - <Interface classname="org.eclipse.osee.ote.core.environment.jini.ITestEnvironmentCommandCallback"/> - <Interface classname="org.eclipse.osee.ote.core.environment.interfaces.IRemoteCommandConsole"/> - <Interface - classname="org.eclipse.osee.ote.core.environment.status.IServiceStatusData"> - </Interface> - <Interface - classname="org.eclipse.osee.ote.core.environment.status.IServiceStatusDataCommand"> - </Interface> - </extension> - <extension - id="TestBundle" - name="TestBundle" - point="org.eclipse.osee.framework.jini.JiniInterface"> - <RegisterBundle/> - </extension> + <extension id="server" name="OTE Server" @@ -38,10 +20,10 @@ point="org.eclipse.core.runtime.products"> <product application="org.eclipse.osee.ote.core.server" - name="ote.server"> + name="OteServerStandalone"> <property name="appName" - value="ote.server"> + value="OteServerStandalone"> </property> </product> </extension> diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/Configuration.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/Configuration.java index 82ba43a902d..9b2d60ccf79 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/Configuration.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/Configuration.java @@ -1,5 +1,6 @@ package org.eclipse.osee.ote; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -9,7 +10,9 @@ import java.util.List; * @author Andrew M. Finkbeiner * */ -public class Configuration { +public class Configuration implements Serializable { + + private static final long serialVersionUID = -3395485777990884086L; private ArrayList<ConfigurationItem> items; diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/ConfigurationItem.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/ConfigurationItem.java index 2c435870317..0eb7fa72dcb 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/ConfigurationItem.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/ConfigurationItem.java @@ -1,13 +1,16 @@ package org.eclipse.osee.ote; +import java.io.Serializable; + /** * This defines the bundle to be loaded by the OTE Server. * * @author Andrew M. Finkbeiner * */ -public class ConfigurationItem { +public class ConfigurationItem implements Serializable { + private static final long serialVersionUID = -2805353994429454202L; private String url; private String version; private String symbolicName; diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/ConfigurationStatusCallback.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/ConfigurationStatusCallback.java new file mode 100644 index 00000000000..9458c9a8096 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/ConfigurationStatusCallback.java @@ -0,0 +1,9 @@ +package org.eclipse.osee.ote; + +public interface ConfigurationStatusCallback { + + public void success(); + + public void failure(String errorLog); + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/HostServerProperties.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/HostServerProperties.java new file mode 100644 index 00000000000..5de4765f9b5 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/HostServerProperties.java @@ -0,0 +1,19 @@ +package org.eclipse.osee.ote; + + +public enum HostServerProperties { + name, + station, + version, + type, + maxUsers, + comment, + date, + group, + owner, + id, + activeMq, + appServerURI, + oteUdpEndpoint, + serverLaunchWorkingDir +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/NonRemoteUserSession.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/NonRemoteUserSession.java new file mode 100644 index 00000000000..ef879e987c4 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/NonRemoteUserSession.java @@ -0,0 +1,105 @@ +package org.eclipse.osee.ote; + +import java.io.Serializable; +import java.rmi.RemoteException; +import java.util.UUID; + +import org.eclipse.osee.ote.core.IRemoteUserSession; +import org.eclipse.osee.ote.core.OSEEPerson1_4; +import org.eclipse.osee.ote.core.framework.prompt.IPassFailPromptResponse; +import org.eclipse.osee.ote.core.framework.prompt.IResumeResponse; +import org.eclipse.osee.ote.core.framework.prompt.IUserInputPromptResponse; +import org.eclipse.osee.ote.core.framework.prompt.IYesNoPromptResponse; + +public class NonRemoteUserSession implements IRemoteUserSession, Serializable { + + /** + * + */ + private static final long serialVersionUID = -4094993884862781475L; + + private OSEEPerson1_4 user; + private String address; + + public NonRemoteUserSession(OSEEPerson1_4 user, String address){ + this.user = user; + this.address = address; + } + + @Override + public OSEEPerson1_4 getUser() { + return user; + } + + @Override + public String getAddress() { + return address; + } + + @Override + public byte[] getFile(String workspacePath) { + // TODO Auto-generated method stub + return null; + } + + @Override + public long getFileDate(String workspacePath) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void initiateInformationalPrompt(String message) { + // TODO Auto-generated method stub + + } + + @Override + public void initiatePassFailPrompt(IPassFailPromptResponse prompt) { + // TODO Auto-generated method stub + + } + + @Override + public void initiateYesNoPrompt(IYesNoPromptResponse prompt) throws Exception { + // TODO Auto-generated method stub + + } + + @Override + public void initiateUserInputPrompt(IUserInputPromptResponse prompt) { + // TODO Auto-generated method stub + + } + + @Override + public void initiateResumePrompt(IResumeResponse prompt) { + // TODO Auto-generated method stub + + } + + @Override + public void cancelPrompts() throws Exception { + // TODO Auto-generated method stub + + } + + @Override + public boolean isAlive() { + // TODO Auto-generated method stub + return false; + } + + @Override + public UUID getUserId() throws Exception { + // TODO Auto-generated method stub + return null; + } + + @Override + public void sendMessageToClient(org.eclipse.osee.framework.messaging.Message message) throws RemoteException { + // TODO Auto-generated method stub + + } + +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/OTEApi.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/OTEApi.java index 370ee4ade07..b21c52e7251 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/OTEApi.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/OTEApi.java @@ -4,7 +4,9 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import org.eclipse.osee.ote.core.environment.TestEnvironmentInterface; +import org.eclipse.osee.ote.core.environment.interfaces.IHostTestEnvironment; import org.eclipse.osee.ote.core.model.IModelManager; +import org.eclipse.osee.ote.io.OTEServerFolder; import org.eclipse.osee.ote.message.interfaces.IRemoteMessageService; /** @@ -119,4 +121,12 @@ public interface OTEApi { * @throws ClassNotFoundException */ Class<?> loadFromRuntimeLibraryLoader(String clazz) throws ClassNotFoundException; + + /** + * Get the host test environment. This method will return null if one has not yet been registered, + * so users need to check for null. + * + * @return the host environment or null if one is not created + */ + IHostTestEnvironment getIHostTestEnvironment(); } diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/OTETestEnvironmentClient.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/OTETestEnvironmentClient.java new file mode 100644 index 00000000000..b09e9a79b79 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/OTETestEnvironmentClient.java @@ -0,0 +1,385 @@ +package org.eclipse.osee.ote; + +import java.io.File; +import java.io.FilenameFilter; +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.URISyntaxException; +import java.rmi.RemoteException; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; +import java.util.logging.Level; + +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.osee.framework.jdk.core.type.IPropertyStore; +import org.eclipse.osee.framework.jdk.core.type.PropertyStore; +import org.eclipse.osee.framework.jdk.core.util.EnhancedProperties; +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.framework.jdk.core.util.network.PortUtil; +import org.eclipse.osee.framework.logging.OseeLog; +import org.eclipse.osee.framework.plugin.core.util.ExportClassLoader; +import org.eclipse.osee.ote.classserver.HeadlessClassServer; +import org.eclipse.osee.ote.core.BundleInfo; +import org.eclipse.osee.ote.core.ConnectionRequestResult; +import org.eclipse.osee.ote.core.IRemoteUserSession; +import org.eclipse.osee.ote.core.ServiceUtility; +import org.eclipse.osee.ote.core.environment.TestEnvironmentConfig; +import org.eclipse.osee.ote.core.framework.command.ICommandHandle; +import org.eclipse.osee.ote.core.framework.command.ITestCommandResult; +import org.eclipse.osee.ote.core.framework.command.RunTests; +import org.eclipse.osee.ote.endpoint.OteEndpointUtil; +import org.eclipse.osee.ote.endpoint.OteUdpEndpoint; +import org.eclipse.osee.ote.filetransfer.TcpFileTransfer; +import org.eclipse.osee.ote.filetransfer.TcpFileTransferHandle; +import org.eclipse.osee.ote.message.event.OteEventMessageUtil; +import org.eclipse.osee.ote.message.event.send.OteEndpointSendEventMessage; +import org.eclipse.osee.ote.message.event.send.OteEventMessageFuture; +import org.eclipse.osee.ote.message.event.send.OteSendEventMessage; +import org.eclipse.osee.ote.properties.OtePropertiesCore; +import org.eclipse.osee.ote.remote.messages.BooleanResponse; +import org.eclipse.osee.ote.remote.messages.ConfigurationAndResponse; +import org.eclipse.osee.ote.remote.messages.DisconnectRemoteTestEnvironment; +import org.eclipse.osee.ote.remote.messages.RequestHostEnvironmentProperties; +import org.eclipse.osee.ote.remote.messages.RequestRemoteTestEnvironment; +import org.eclipse.osee.ote.remote.messages.RunTestsCancel; +import org.eclipse.osee.ote.remote.messages.RunTestsGetCommandResultReq; +import org.eclipse.osee.ote.remote.messages.RunTestsGetCommandResultResp; +import org.eclipse.osee.ote.remote.messages.RunTestsIsCancelled; +import org.eclipse.osee.ote.remote.messages.RunTestsIsDone; +import org.eclipse.osee.ote.remote.messages.RunTestsSerialized; +import org.eclipse.osee.ote.remote.messages.SerializedConfigurationAndResponse; +import org.eclipse.osee.ote.remote.messages.SerializedConnectionRequestResult; +import org.eclipse.osee.ote.remote.messages.SerializedDisconnectRemoteTestEnvironment; +import org.eclipse.osee.ote.remote.messages.SerializedEnhancedProperties; +import org.eclipse.osee.ote.remote.messages.SerializedOTEJobStatus; +import org.eclipse.osee.ote.remote.messages.SerializedRequestRemoteTestEnvironment; +import org.eclipse.osee.ote.remote.messages.TestEnvironmentServerShutdown; +import org.eclipse.osee.ote.remote.messages.TestEnvironmentSetBatchMode; +import org.eclipse.osee.ote.remote.messages.TestEnvironmentTransferFile; +import org.osgi.service.event.EventAdmin; + +public class OTETestEnvironmentClient { + + private OteUdpEndpoint service; + private InetSocketAddress destinationAddress; + private ExecutorService pool; + + public static OTETestEnvironmentClient getInstance(String endpoint){ + return new OTETestEnvironmentClient(ServiceUtility.getService(OteUdpEndpoint.class), OteEndpointUtil.getAddress(endpoint)); + } + + public OTETestEnvironmentClient(OteUdpEndpoint service, InetSocketAddress destinationAddress) { + this.service = service; + this.destinationAddress = destinationAddress; + this.pool = Executors.newCachedThreadPool(new ThreadFactory() { + + @Override + public Thread newThread(Runnable arg0) { + Thread th = new Thread(arg0); + th.setName("OTETestEnvironmentClient Thread"); + return th; + } + }); + } + + public void shutdownServer(String serverId){ + TestEnvironmentServerShutdown shutdown = new TestEnvironmentServerShutdown(); + shutdown.SERVER_ID.setValue(serverId); + OteEndpointSendEventMessage sendit = new OteEndpointSendEventMessage(service, destinationAddress); + sendit.asynchSend(shutdown); + } + + public boolean getServerFile(File localFile, File serverFile) throws IOException, ExecutionException, InterruptedException{ + TcpFileTransferHandle receiveFile = TcpFileTransfer.receiveFile(pool, localFile, 0); + TestEnvironmentTransferFile transferFile = new TestEnvironmentTransferFile(); + transferFile.ADDRESS.setAddress(receiveFile.getLocalAddress().getAddress()); + transferFile.ADDRESS.setPort(receiveFile.getLocalAddress().getPort()); + transferFile.FILE_PATH.setValue(serverFile.getAbsolutePath()); + OteEventMessageUtil.sendEvent(transferFile); + return receiveFile.awaitCompletion(); + } + + public void setBatchMode(boolean batchMode) throws URISyntaxException, InterruptedException, ExecutionException, IOException { + TestEnvironmentSetBatchMode setBatchMode = new TestEnvironmentSetBatchMode(); + setBatchMode.SET_BATCH_MODE.setValue(batchMode); + OteEventMessageUtil.postEvent(setBatchMode); + } + + public ICommandHandle runScripts(UUID sessionId, PropertyStore globalProperties, List<IPropertyStore> scriptProperties, boolean useOTEBuilderJars, File rootFolderForOTEBuilderJars, SubProgressMonitor monitor, String serverId, ConfigurationStatusCallback configurationStatusCallback) throws URISyntaxException, InterruptedException, ExecutionException, IOException { + Configuration configuration = null; + if(useOTEBuilderJars){ + configuration = configureEnvironment(serverId, rootFolderForOTEBuilderJars, monitor, configurationStatusCallback); + } + RunTests runTests = new RunTests(UUID.randomUUID().toString(), sessionId, configuration, globalProperties, scriptProperties); + + OteEventMessageUtil.postEvent(new RunTestsSerialized(runTests)); + return new EventRunTestsHandle(runTests.getGUID(), new OteSendEventMessage(ServiceUtility.getService(EventAdmin.class))); + } + + public Configuration configureEnvironment(String serverId, final List<File> bundlesToSend, final boolean installBundles, final SubProgressMonitor monitor, final ConfigurationStatusCallback configurationStatusCallback) { + HeadlessClassServer classServer = null; + Configuration localConfiguration = new Configuration(); + try{ + + classServer = new HeadlessClassServer(PortUtil.getInstance().getValidPort(), InetAddress.getLocalHost(), bundlesToSend); + for (BundleInfo bundleInfo : classServer.getBundles()) { + ConfigurationItem item = new ConfigurationItem(bundleInfo.getServerBundleLocation().toString(),bundleInfo.getVersion(),bundleInfo.getSymbolicName(), bundleInfo.getMd5Digest(), installBundles); + localConfiguration.addItem(item); + } + + if(service != null){ + InetSocketAddress address = service.getLocalEndpoint(); + ConfigurationAndResponse configAndResponse = new ConfigurationAndResponse(address.getAddress().getHostAddress(), address.getPort(), localConfiguration, installBundles, serverId); + SerializedConfigurationAndResponse ser = new SerializedConfigurationAndResponse(); + ser.setObject(configAndResponse); + ser.getHeader().RESPONSE_TOPIC.setValue(SerializedOTEJobStatus.EVENT); + + OteEndpointSendEventMessage sendit = new OteEndpointSendEventMessage(service, destinationAddress); + service.addBroadcast(service.getOteEndpointSender(destinationAddress));//so we can communicate via console before connect + WaitForCompletion completion = new WaitForCompletion(monitor); + final OteEventMessageFuture<SerializedConfigurationAndResponse, SerializedOTEJobStatus> asynchSendAndResponse = sendit.asynchSendAndMultipleResponse(SerializedOTEJobStatus.class, ser, completion, 1000 * 60 * 10); + Thread th = new Thread(new Runnable(){ + public void run() { + while(true){ + if(monitor != null && monitor.isCanceled()){ + asynchSendAndResponse.complete(); + return; + } else if (asynchSendAndResponse.isDone()){ + return; + } else { + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + } + } + } + } + }); + th.setDaemon(true); + th.start(); + asynchSendAndResponse.waitForCompletion(); + if(!asynchSendAndResponse.isTimedOut() && completion.getStatus() != null){ + if(completion.getStatus().isSuccess()){ + configurationStatusCallback.success(); + } else { + String errorLog = completion.getStatus().getErrorLog(); + if(errorLog.length() > 0){ + configurationStatusCallback.failure(errorLog); + } else {//no diff report, must be the same version + configurationStatusCallback.success(); + } + } + } + } + } catch (Throwable th){ + th.printStackTrace(); + } finally { + if(classServer != null){ + classServer.stop(); + } + } + return localConfiguration; + } + + private Configuration configureEnvironment(String serverId, final File oteBuilderRootFolder, final SubProgressMonitor monitor, final ConfigurationStatusCallback configurationStatusCallback) { + HeadlessClassServer classServer = null; + Configuration localConfiguration = new Configuration(); + try{ + List<File> bundlesToSend = new ArrayList<File>(); + bundlesToSend.add(oteBuilderRootFolder); + classServer = new HeadlessClassServer(PortUtil.getInstance().getValidPort(), InetAddress.getLocalHost(), bundlesToSend); + File[] jars = oteBuilderRootFolder.listFiles(new FilenameFilter(){ + @Override + public boolean accept(File arg0, String arg1) { + return arg1.endsWith(".jar"); + } + }); + for (File jar : jars) { + try{ + ConfigurationItem item = new ConfigurationItem(classServer.getHostName() + jar.getName(), "1.0", jar.getName(), Lib.fileToString(new File(jar.getAbsolutePath() + ".md5")), false); + localConfiguration.addItem(item); + } catch (IOException ex) { + OseeLog.log(OTETestEnvironmentClient.class, Level.SEVERE, ex); + } + } + + if(service != null){ + InetSocketAddress address = service.getLocalEndpoint(); + ConfigurationAndResponse configAndResponse = new ConfigurationAndResponse(address.getAddress().getHostAddress(), address.getPort(), localConfiguration, false, serverId); + SerializedConfigurationAndResponse ser = new SerializedConfigurationAndResponse(); + ser.setObject(configAndResponse); + ser.getHeader().RESPONSE_TOPIC.setValue(SerializedOTEJobStatus.EVENT); + + OteEndpointSendEventMessage sendit = new OteEndpointSendEventMessage(service, destinationAddress); + WaitForCompletion completion = new WaitForCompletion(monitor); + final OteEventMessageFuture<SerializedConfigurationAndResponse, SerializedOTEJobStatus> asynchSendAndResponse = sendit.asynchSendAndMultipleResponse(SerializedOTEJobStatus.class, ser, completion, 1000 * 60 * 10); + Thread th = new Thread(new Runnable(){ + public void run() { + while(true){ + if(monitor.isCanceled()){ + asynchSendAndResponse.complete(); + return; + } else if (asynchSendAndResponse.isDone()){ + return; + } else { + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + } + } + } + } + }); + th.setDaemon(true); + th.start(); + asynchSendAndResponse.waitForCompletion(); + if(!asynchSendAndResponse.isTimedOut() && completion.getStatus() != null){ + if(completion.getStatus().isSuccess()){ + configurationStatusCallback.success(); + } else { + String errorLog = completion.getStatus().getErrorLog(); + if(errorLog.length() > 0){ + configurationStatusCallback.failure(errorLog); + } else {//no diff report, must be the same version + configurationStatusCallback.success(); + } + } + } + } + } catch (Throwable th){ + th.printStackTrace(); + } finally { + if(classServer != null){ + classServer.stop(); + } + } + return localConfiguration; + } + + private static class EventRunTestsHandle implements ICommandHandle { + + private String guid; + private OteSendEventMessage sendit; + + public EventRunTestsHandle(String guid, OteSendEventMessage sendit){ + this.guid = guid; + this.sendit = sendit; + } + + @Override + public boolean cancelAll(boolean mayInterruptIfRunning) { + BooleanResponse booleanResponse = new BooleanResponse(); + RunTestsCancel cancel = new RunTestsCancel(); + cancel.CANCEL_ALL.setValue(true); + cancel.GUID.setValue(guid); + booleanResponse = sendit.synchSendAndResponse(booleanResponse, cancel, 20000); + return booleanResponse.VALUE.getValue(); + } + + @Override + public boolean cancelSingle(boolean mayInterruptIfRunning) { + BooleanResponse booleanResponse = new BooleanResponse(); + RunTestsCancel cancel = new RunTestsCancel(); + cancel.CANCEL_ALL.setValue(false); + cancel.GUID.setValue(guid); + booleanResponse = sendit.synchSendAndResponse(booleanResponse, cancel, 20000); + return booleanResponse.VALUE.getValue(); + } + + @Override + public ITestCommandResult get() { + RunTestsGetCommandResultReq req = new RunTestsGetCommandResultReq(); + RunTestsGetCommandResultResp resp = new RunTestsGetCommandResultResp(); + req.GUID.setValue(guid); + resp = sendit.synchSendAndResponse(resp, req, 30000); + ITestCommandResult result = null; + try { + result = resp.getObject(); + } catch (IOException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + return result; + } + + @Override + public boolean isCancelled() { + BooleanResponse booleanResponse = new BooleanResponse(); + RunTestsIsCancelled req = new RunTestsIsCancelled(); + req.GUID.setValue(guid); + booleanResponse = sendit.synchSendAndResponse(booleanResponse, req, 20000); + return booleanResponse.VALUE.getValue(); + } + + @Override + public boolean isDone() { + BooleanResponse booleanResponse = new BooleanResponse(); + RunTestsIsDone req = new RunTestsIsDone(); + req.GUID.setValue(guid); + booleanResponse = sendit.synchSendAndResponse(booleanResponse, req, 20000); + return booleanResponse.VALUE.getValue(); + } + + @Override + public String getCommandKey() { + return guid; + } + + } + + public EnhancedProperties getProperties(long timeout) { + SerializedEnhancedProperties props = new SerializedEnhancedProperties(); + RequestHostEnvironmentProperties req = new RequestHostEnvironmentProperties(); + OteEndpointSendEventMessage sendit = new OteEndpointSendEventMessage(service, destinationAddress); + props = sendit.synchSendAndResponse(props, req, timeout); + EnhancedProperties returnVal = null; + try { + if(props != null){ + returnVal = props.getObject(); + } + } catch (IOException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + return returnVal; + } + + public ConnectionRequestResult requestEnvironment(IRemoteUserSession session, UUID id, TestEnvironmentConfig config) throws RemoteException { + Thread.currentThread().setContextClassLoader(new ExportClassLoader()); + try { + SerializedRequestRemoteTestEnvironment req = new SerializedRequestRemoteTestEnvironment(new RequestRemoteTestEnvironment(session, id, config)); + SerializedConnectionRequestResult result = new SerializedConnectionRequestResult(); + OteEndpointSendEventMessage sendit = new OteEndpointSendEventMessage(service, destinationAddress); + result = sendit.synchSendAndResponse(result, req, OtePropertiesCore.serverConnectionTimeout.getLongValue(1000 * 10)); + if(result != null){ + return result.getObject(); + } + } catch (IOException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + return null; + } + + public void disconnect(UUID sessionId) throws RemoteException { + try { + SerializedDisconnectRemoteTestEnvironment req = new SerializedDisconnectRemoteTestEnvironment(new DisconnectRemoteTestEnvironment(sessionId)); + OteEndpointSendEventMessage sendit = new OteEndpointSendEventMessage(service, destinationAddress); + sendit.asynchSend(req); + } catch (IOException e) { + e.printStackTrace(); + } + } + + + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/WaitForCompletion.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/WaitForCompletion.java new file mode 100644 index 00000000000..883d1208fe5 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/WaitForCompletion.java @@ -0,0 +1,67 @@ +package org.eclipse.osee.ote; + +import java.io.IOException; + +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.osee.ote.message.event.send.OteEventMessageCallable; +import org.eclipse.osee.ote.message.event.send.OteEventMessageFuture; +import org.eclipse.osee.ote.remote.messages.JobStatus; +import org.eclipse.osee.ote.remote.messages.SerializedConfigurationAndResponse; +import org.eclipse.osee.ote.remote.messages.SerializedOTEJobStatus; + +class WaitForCompletion implements OteEventMessageCallable<SerializedConfigurationAndResponse, SerializedOTEJobStatus> { + + private SubProgressMonitor monitor; + private int lastUnitsWorked = 0; + private boolean firstTime = true; + private JobStatus status; + + WaitForCompletion(SubProgressMonitor monitor) { + this.monitor = monitor; + } + + @Override + public void call(SerializedConfigurationAndResponse transmitted, SerializedOTEJobStatus recieved, OteEventMessageFuture<?, ?> future) { + + try { + this.status = recieved.getObject(); + reportStatus(status, future); + } catch (IOException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + + private synchronized void reportStatus(JobStatus status, OteEventMessageFuture<?, ?> future) { + if(monitor != null){ + if(monitor.isCanceled() || status.isJobComplete()){ + monitor.done(); + future.complete(); + return; + } + if(firstTime){ + monitor.beginTask("Configure Test Server", status.getTotalUnitsOfWork()); + firstTime = false; + } else { + monitor.worked(status.getUnitsWorked() - lastUnitsWorked); + lastUnitsWorked = status.getUnitsWorked(); + } + } else { + if(status.isJobComplete()){ + future.complete(); + return; + } + } + } + + @Override + public void timeout(SerializedConfigurationAndResponse transmitted) { + System.out.println("timed out"); + } + + public JobStatus getStatus(){ + return this.status; + } + +} diff --git a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/jarserver/BundleResourceFinder.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/BundleResourceFinder.java index 0ccfd631808..0d01b461b48 100644 --- a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/jarserver/BundleResourceFinder.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/BundleResourceFinder.java @@ -1,10 +1,11 @@ -package org.eclipse.osee.ote.rest.client.internal.jarserver; +package org.eclipse.osee.ote.classserver; import java.io.FileInputStream; import java.io.IOException; import java.util.List; + import org.eclipse.osee.framework.jdk.core.util.Lib; -import org.eclipse.osee.framework.plugin.core.server.ResourceFinder; +import org.eclipse.osee.ote.classserver.ResourceFinder; import org.eclipse.osee.ote.core.BundleInfo; public class BundleResourceFinder extends ResourceFinder { @@ -19,9 +20,9 @@ public class BundleResourceFinder extends ResourceFinder { @Override public byte[] find(String path) throws IOException { for (BundleInfo info : bundleInfo) { - if (info.getSymbolicName().equals(path)) { + if (info.getSymbolicName().equals(path) || info.getFile().getName().equals(path)) { return Lib.inputStreamToBytes(new FileInputStream(info.getFile())); - } + } } return null; } diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/VersionEntry.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/ClassFinder.java index caf50bc75d9..24914a5497c 100644 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/core/VersionEntry.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/ClassFinder.java @@ -8,28 +8,27 @@ * Contributors: * Boeing - initial API and implementation *******************************************************************************/ -package org.eclipse.osee.framework.jini.service.core; +package org.eclipse.osee.ote.classserver; -public class VersionEntry extends FormmatedEntry { +import java.io.IOException; +import org.eclipse.osee.framework.plugin.core.util.ExportClassLoader; +import org.osgi.framework.Bundle; - private static final long serialVersionUID = 132189087526085874L; - public String version; +public class ClassFinder extends ResourceFinder { - public VersionEntry() { - version = "1.0.0"; - } + private final ExportClassLoader loader = new ExportClassLoader(); @Override - public String getFormmatedString() { - return "Version: " + version; + public void dispose() { } @Override - public boolean equals(Object other) { - if (!(other instanceof VersionEntry)) { - return false; + public byte[] find(String path) throws IOException { + Bundle bundle = loader.getExportingBundle(path); + if (bundle != null) { + return getBytes(bundle.getResource(path).openStream()); } - return version.equals(((VersionEntry) other).version); + return null; } } diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/ClassServer.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/ClassServer.java new file mode 100644 index 00000000000..7ce0a6fb490 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/ClassServer.java @@ -0,0 +1,318 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.classserver; + +import java.io.BufferedInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.Inet6Address; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.URL; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; +import java.util.logging.Level; + +import org.eclipse.osee.framework.logging.OseeLog; + +public class ClassServer extends Thread { + private ServerSocket server; + private URL hostName; + private List<ResourceFinder> resourceFinders; + + private ExecutorService socketThreads; + + /** + * Construct a server + * + * @param port the port to use + * @throws IOException if the server socket cannot be created + */ + public ClassServer(int port, InetAddress address) throws IOException { + server = new ServerSocket(port, 50, address); + socketThreads = Executors.newCachedThreadPool(new ThreadFactory() { + + @Override + public Thread newThread(Runnable arg0) { + Thread th = new Thread(arg0, "ClassServer Task"); + th.setDaemon(true); + return th; + } + }); + if(address instanceof Inet6Address){ + hostName = new URL("http://[" + address.getHostAddress() + "]:" + server.getLocalPort() + "/"); + } else { + hostName = new URL("http://" + address.getHostAddress() + ":" + server.getLocalPort() + "/"); + } + this.setName("OSEE ClassServer"); + this.resourceFinders = new ArrayList<ResourceFinder>(); + } + + public void addResourceFinder(ResourceFinder finder) { + this.resourceFinders.add(finder); + } + + /** + * Spawn a thread for each connection requesting service + */ + @Override + public void run() { + + String msg = "ClassServer started ["; + + msg += "port "; + msg += Integer.toString(getPort()); + msg += "]"; + + OseeLog.log(ClassServer.class, Level.INFO, msg); + try { + while (true) { + Socket socket = server.accept(); + socketThreads.submit(new Task(socket)); + } + } catch (IOException e) { + synchronized (this) { + if (!server.isClosed()) { + OseeLog.log(ClassServer.class, Level.SEVERE, "accepting connection", e); + terminate(); + OseeLog.log(ClassServer.class, Level.WARNING, "ClassServer Terminated"); + } + } + } + } + + /** + * Terminate Server - perform cleanup + */ + public synchronized void terminate() { + try { + server.close(); + } catch (IOException e) { + // do nothing + } + final Iterator<ResourceFinder> iter = resourceFinders.iterator(); + while (iter.hasNext()) { + final ResourceFinder resFinder = iter.next(); + resFinder.dispose(); + } + + } + + /** Returns the port on which this server is listening. */ + public int getPort() { + return server.getLocalPort(); + } + + /** Read up to CRLF, return false if EOF */ + private static boolean readLine(InputStream in, StringBuffer buf) throws IOException { + while (true) { + int c = in.read(); + if (c < 0) { + return buf.length() > 0; + } + if (c == '\r') { + in.mark(1); + c = in.read(); + if (c != '\n') { + in.reset(); + } + return true; + } + if (c == '\n') { + return true; + } + buf.append((char) c); + } + } + + /** Read the request/response and return the initial line. */ + private static String getInput(Socket sock, boolean isRequest) throws IOException { + BufferedInputStream in = new BufferedInputStream(sock.getInputStream(), 256); + StringBuffer buf = new StringBuffer(80); + do { + if (!readLine(in, buf)) { + return null; + } + } while (isRequest && buf.length() == 0); + String initial = buf.toString(); + do { + buf.setLength(0); + } while (readLine(in, buf) && buf.length() > 0); + return initial; + } + + /** + * This method provides a way for subclasses to be notified when a file has been completely downloaded. + * + * @param fp The path to the file that was downloaded. + */ + protected void fileDownloaded(String fp, InetAddress addr) { + } + + public URL getHostName() { + return hostName; + } + + private class Task implements Runnable {// Thread { + + private final Socket sock; + + public Task(Socket sock) { + this.sock = sock; + // setDaemon(true); + } + + /** + * Get bytes from path Returns the bytes of the requested file, or null if not found. + */ + private byte[] getBytes(String path) throws IOException { + byte[] bytes = null; + for (int i = 0; i < resourceFinders.size(); i++) { + ResourceFinder finder = resourceFinders.get(i); + bytes = finder.find(path); + if (bytes != null) { + return bytes; + } + } + OseeLog.log(ClassServer.class, Level.INFO, "requested file: '" + path + "' was not found."); + return null; + } + + /** Parse % HEX HEX from s starting at i */ + private char decode(String s, int i) { + return (char) Integer.parseInt(s.substring(i + 1, i + 3), 16); + } + + private String getCanonicalizedPath(String path) { + try { + if (path.regionMatches(true, 0, "http://", 0, 7)) { + int i = path.indexOf('/', 7); + if (i < 0) { + path = "/"; + } else { + path = path.substring(i); + } + } + for (int i = path.indexOf('%'); i >= 0; i = path.indexOf('%', i + 1)) { + char c = decode(path, i); + int n = 3; + if ((c & 0x80) != 0) { + switch (c >> 4) { + case 0xC: + case 0xD: + n = 6; + c = (char) ((c & 0x1F) << 6 | decode(path, i + 3) & 0x3F); + break; + case 0xE: + n = 9; + c = (char) ((c & 0x0f) << 12 | (decode(path, i + 3) & 0x3F) << 6 | decode(path, i + 6) & 0x3F); + break; + default: + return null; + } + } + path = path.substring(0, i) + c + path.substring(i + n); + } + } catch (Exception e) { + return null; + } + if (path.length() == 0 || path.charAt(0) != '/') { + return null; + } + return path.substring(1); + } + + @Override + public void run() { + try { + DataOutputStream out = new DataOutputStream(sock.getOutputStream()); + String req; + try { + req = getInput(sock, true); + } catch (Exception e) { + OseeLog.log(ClassServer.class, Level.INFO, "reading request", e); + return; + } + if (req == null) { + return; + } + if (req.startsWith("SHUTDOWN *")) { + out.writeBytes("HTTP/1.0 403 Forbidden\r\n\r\n"); + out.flush(); + return; + } + String[] args = null; + boolean get = req.startsWith("GET "); + if (!get && !req.startsWith("HEAD ")) { + OseeLog.log(ClassServer.class, Level.FINE, "bad request \"{0}\" from {1}:{2}"); + out.writeBytes("HTTP/1.0 400 Bad Request\r\n\r\n"); + out.flush(); + return; + } + String path = req.substring(get ? 4 : 5); + int i = path.indexOf(' '); + if (i > 0) { + path = path.substring(0, i); + } + path = getCanonicalizedPath(path); + if (path == null) { + OseeLog.log(ClassServer.class, Level.FINE, "bad request \"{0}\" from {1}:{2}"); + out.writeBytes("HTTP/1.0 400 Bad Request\r\n\r\n"); + out.flush(); + return; + } + if (args != null) { + args[0] = path; + } + OseeLog.log(ClassServer.class, Level.FINER, + get ? "{0} requested from {1}:{2}" : "{0} probed from {1}:{2}"); + byte[] bytes; + try { + bytes = getBytes(path); + } catch (Exception e) { + OseeLog.log(ClassServer.class, Level.WARNING, "getting bytes", e); + out.writeBytes("HTTP/1.0 500 Internal Error\r\n\r\n"); + out.flush(); + return; + } + if (bytes == null) { + OseeLog.logf(ClassServer.class, Level.FINE, "%s not found", path); + out.writeBytes("HTTP/1.0 404 Not Found\r\n\r\n"); + out.flush(); + return; + } + out.writeBytes("HTTP/1.0 200 OK\r\n"); + out.writeBytes("Content-Length: " + bytes.length + "\r\n"); + out.writeBytes("Content-Type: application/java\r\n\r\n"); + if (get) { + out.write(bytes); + } + out.flush(); + if (get) { + fileDownloaded(path, sock.getInetAddress()); + } + } catch (Exception e) { + OseeLog.log(ClassServer.class, Level.INFO, "writing response", e); + } finally { + try { + sock.close(); + } catch (IOException e) { + } + } + } + } +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/ClassServerPermissions.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/ClassServerPermissions.java new file mode 100644 index 00000000000..6864208d6a9 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/ClassServerPermissions.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.classserver; + +import java.security.Permission; +import java.security.PermissionCollection; +import java.util.ArrayList; +import java.util.Enumeration; + +/** + * @author Andrew M. Finkbeiner + */ +public class ClassServerPermissions extends PermissionCollection { + + private static final long serialVersionUID = 7752469678730039503L; + private final ArrayList<Permission> list; + + public ClassServerPermissions() { + list = new ArrayList<Permission>(); + } + + @Override + public void add(Permission permission) { + list.add(permission); + } + + @Override + public boolean implies(Permission permission) { + for (int i = 0; i < list.size(); i++) { + if (list.get(i).implies(permission)) { + return true; + } + } + return false; + } + + @Override + public Enumeration<Permission> elements() { + return null; + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/FrameworkResourceFinder.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/FrameworkResourceFinder.java new file mode 100644 index 00000000000..c5260fd863a --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/FrameworkResourceFinder.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.classserver; + +import java.io.IOException; +import java.net.URL; + +import org.osgi.framework.Bundle; +import org.osgi.framework.FrameworkUtil; + +public class FrameworkResourceFinder extends ResourceFinder{ + + @Override + public byte[] find(String path) throws IOException { + for(Bundle bundle:FrameworkUtil.getBundle(getClass()).getBundleContext().getBundles()){ + URL url = bundle.getResource(path); + if (url != null) { + return getBytes(url.openStream()); + } + } + return null; + } + + @Override + public void dispose() { + + } + +} diff --git a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/jarserver/HeadlessClassServer.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/HeadlessClassServer.java index c6abf5c90d6..7b11ae13ea3 100644 --- a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/jarserver/HeadlessClassServer.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/HeadlessClassServer.java @@ -1,4 +1,4 @@ -package org.eclipse.osee.ote.rest.client.internal.jarserver; +package org.eclipse.osee.ote.classserver; import java.io.File; import java.io.FileFilter; @@ -9,7 +9,6 @@ import java.net.URL; import java.util.ArrayList; import java.util.List; -import org.eclipse.osee.framework.plugin.core.server.ClassServer; import org.eclipse.osee.ote.core.BundleInfo; @@ -20,7 +19,7 @@ public class HeadlessClassServer { private List<BundleInfo> jars; public HeadlessClassServer(int port, InetAddress address, List<File> bundleFolders) throws IOException{ - Thread.currentThread().setName("BundleClassServer"); +// Thread.currentThread().setName("BundleClassServer"); classServer = new ClassServer(port, address); jars = new ArrayList<BundleInfo>(); for(File dir:bundleFolders){ diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/PathResourceFinder.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/PathResourceFinder.java new file mode 100644 index 00000000000..1c402fbe38c --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/PathResourceFinder.java @@ -0,0 +1,255 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.classserver; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FilePermission; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.StringTokenizer; +import java.util.jar.Attributes; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; +import java.util.jar.Manifest; +import java.util.logging.Level; +import org.eclipse.osee.framework.logging.OseeLog; + +public class PathResourceFinder extends ResourceFinder { + + private final HashSet<JarFile> jars = new HashSet<JarFile>(128); + private final HashSet<String> dirs = new HashSet<String>(128); + private final HashMap<String, JarFile[]> map = new HashMap<String, JarFile[]>(128); + private final boolean trees; + private final ClassServerPermissions perm; + private static final int NUMBER_OF_FILE_READ_ATTEMPTS = 20; + + public PathResourceFinder(String[] dirsToAdd, boolean trees) { + this.trees = trees; + perm = new ClassServerPermissions(); + if (dirsToAdd != null) { + addPaths(dirsToAdd); + } + } + + @Override + public byte[] find(String path) throws IOException { + + int i = path.indexOf('/'); + if (i > 0) { + JarFile[] jfs = map.get(path.substring(0, i)); + if (jfs != null) { + String jpath = path.substring(i + 1); + for (i = 0; i < jfs.length; i++) { + JarEntry je = jfs[i].getJarEntry(jpath); + if (je != null) { + return getBytes(jfs[i].getInputStream(je), je.getSize()); + } + } + } + } + synchronized (jars) { + Iterator<JarFile> it = jars.iterator(); + while (it.hasNext()) { + JarFile jar = it.next(); + JarEntry je = jar.getJarEntry(path); + if (je != null) { + return getBytes(jar.getInputStream(je), je.getSize()); + } + } + } + boolean exists = false; + File f = null; + synchronized (dirs) { + for (int j = 0; j < NUMBER_OF_FILE_READ_ATTEMPTS; j++) { // we'll retry in case there is a + // compile going on + Iterator<String> it = dirs.iterator(); + while (it.hasNext()) { + String dirString = it.next(); + f = new File(dirString + File.separatorChar + path.replace('/', File.separatorChar)); + if (f.exists()) { + exists = true; + break; + } + } + if (!exists) { + try { + synchronized (this) { + this.wait(1000); + } + System.err.println(String.format("trying to find :%s %d", path, j)); + } catch (InterruptedException ex) { + } + } else { + break; + } + } + } + + if (exists) { + if (perm.implies(new FilePermission(f.getPath(), "read"))) { + try { + return getBytes(new FileInputStream(f), f.length()); + } catch (FileNotFoundException e) { + } + } + } + return null; + } + + public void addPaths(String[] paths) { + + for (int i = 0; i < paths.length; i++) { + String path = paths[i]; + + if (path.startsWith("file:\\")) { + path = path.substring(6); + } + + if (path.endsWith(".jar")) { + try { + synchronized (jars) { + jars.add(new JarFile(new File(path))); + } + } catch (Exception ex) { + ex.printStackTrace(); + continue; + } + } else { + if (dirs.add(path)) { + perm.add(new FilePermission(path + File.separator + '-', "read")); + } + } + + if (trees) { + File fdir = new File(path); + String[] files = fdir.list(); + if (files != null) { + try { + URL base = fdir.toURI().toURL(); + for (int j = 0; j < files.length; j++) { + String jar = files[j]; + if (jar.endsWith(".jar") || jar.endsWith(".zip")) { + ArrayList<JarFile> jfs = new ArrayList<JarFile>(10); + try { + addJar(jar, jfs, base); + map.put(jar.substring(0, jar.length() - 4), jfs.toArray(new JarFile[jfs.size()])); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + } catch (MalformedURLException ex) { + ex.printStackTrace(); + } + } + } + } + } + + /** Add transitive Class-Path JARs to jfs. */ + private void addJar(String jar, ArrayList<JarFile> jfs, URL base) throws IOException { + base = new URL(base, jar); + jar = base.getFile().replace('/', File.separatorChar); + for (int i = jfs.size(); --i >= 0;) { + if (jar.equals(jfs.get(i).getName())) { + return; + } + } + + JarFile jf = new JarFile(jar); + jfs.add(jf); + try { + Manifest man = jf.getManifest(); + if (man == null) { + return; + } + Attributes attrs = man.getMainAttributes(); + if (attrs == null) { + return; + } + String val = attrs.getValue(Attributes.Name.CLASS_PATH); + if (val == null) { + return; + } + for (StringTokenizer st = new StringTokenizer(val); st.hasMoreTokens();) { + addJar(st.nextToken(), jfs, base); + } + } catch (IOException ex) { + jfs.remove(jf); + jf.close(); + throw ex; + } + } + + /** + * Finds the jarFile if it is being served. + * + * @param name The name of the jar file + * @return The jar represented as a File, or null if the jar was not found. + */ + public File getJarFile(String name) { + File jarFileReturn = null; + synchronized (jars) { + Iterator<JarFile> it = jars.iterator(); + while (it.hasNext()) { + JarFile jarFile = it.next(); + if (jarFile.getName().endsWith(File.separator + name)) { + jarFileReturn = new File(jarFile.getName()); + break; + } + } + } + return jarFileReturn; + } + + public void removeJarFile(String name) { + synchronized (jars) { + Iterator<JarFile> it = jars.iterator(); + while (it.hasNext()) { + JarFile jarFile = it.next(); + if (jarFile.getName().endsWith(File.separator + name)) { + try { + OseeLog.log(ClassServer.class, Level.INFO, "removing JAR file " + name); + jarFile.close(); + } catch (IOException ex) { + // do nothing + } + it.remove(); + return; + } + } + } + } + + @Override + public void dispose() { + synchronized (jars) { + OseeLog.log(ClassServer.class, Level.INFO, "disposing path resource finder's cached JAR files"); + Iterator<JarFile> it = jars.iterator(); + while (it.hasNext()) { + JarFile jarFile = it.next(); + try { + jarFile.close(); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + jars.clear(); + } + } +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/ResourceFinder.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/ResourceFinder.java new file mode 100644 index 00000000000..ae6a68d4e93 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/ResourceFinder.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.classserver; + +import java.io.DataInputStream; +import java.io.IOException; +import java.io.InputStream; + +public abstract class ResourceFinder { + + public abstract byte[] find(String path) throws IOException; + + public byte[] getBytes(InputStream in, long length) throws IOException { + DataInputStream din = new DataInputStream(in); + byte[] bytes = new byte[(int) length]; + try { + din.readFully(bytes); + } finally { + din.close(); + } + return bytes; + } + + public byte[] getBytes(InputStream stream) throws IOException { + return getBytes(stream, stream.available()); + } + + public abstract void dispose(); +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/classserver.properties b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/classserver.properties new file mode 100644 index 00000000000..d9c2d56f85e --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/classserver/classserver.properties @@ -0,0 +1,15 @@ + + + +classserver.jar:{0} +classserver.inputerror:exception reading request from {0}:{1} +classserver.request:{0} requested from {1}:{2} +classserver.probe:{0} probed from {1}:{2} +classserver.badrequest:bad request "{0}" from {1}:{2} +classserver.shutdown:shutdown request from {0}:{1} +classserver.notfound:{0} not found +classserver.usage:[-port <port>] [-dir <dir>] [-stoppable] [-verbose] [-trees]\ +\n or\ +\n[-port <port>] -stop +classserver.forbidden:stop request denied +classserver.status:HTTP status code: {0} {1} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/collections/ObjectPool.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/collections/ObjectPool.java new file mode 100644 index 00000000000..5cbd4f6475b --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/collections/ObjectPool.java @@ -0,0 +1,32 @@ +package org.eclipse.osee.ote.collections; + +import java.util.concurrent.ArrayBlockingQueue; + +public class ObjectPool<T> { + + private final ArrayBlockingQueue<T> objs; + private final ObjectPoolConfiguration<T> config; + + public ObjectPool(ObjectPoolConfiguration<T> config) { + this.config = config; + objs = new ArrayBlockingQueue<T>(config.getMaxSize()); + if(config.preallocate()){ + for(int i = 0; i < config.getMaxSize(); i++){ + objs.offer(config.make()); + } + } + } + + public T getObject(){ + T obj = objs.poll(); + if(obj == null){ + obj = config.make(); + } + return obj; + } + + public void returnObj(T obj){ + objs.offer(obj); + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/collections/ObjectPoolConfiguration.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/collections/ObjectPoolConfiguration.java new file mode 100644 index 00000000000..7a4b76b6369 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/collections/ObjectPoolConfiguration.java @@ -0,0 +1,23 @@ +package org.eclipse.osee.ote.collections; + +public abstract class ObjectPoolConfiguration<T> { + + private int maxSize; + private boolean preallocate; + + public ObjectPoolConfiguration(int maxSize, boolean preallocate){ + this.maxSize = maxSize; + this.preallocate = preallocate; + } + + public int getMaxSize(){ + return maxSize; + } + + public boolean preallocate(){ + return preallocate; + } + + abstract public T make(); + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/BaseUdpReceiveRunnable.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/BaseUdpReceiveRunnable.java new file mode 100644 index 00000000000..ad800487ecd --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/BaseUdpReceiveRunnable.java @@ -0,0 +1,88 @@ +package org.eclipse.osee.ote.core; + +import java.io.IOException; +import java.io.InterruptedIOException; +import java.net.BindException; +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; +import java.nio.channels.ClosedByInterruptException; +import java.nio.channels.DatagramChannel; +import java.util.logging.Level; + +import org.eclipse.osee.framework.logging.OseeLog; +import org.eclipse.osee.ote.OTEException; + +public abstract class BaseUdpReceiveRunnable implements Runnable { + + private static final int DATA_SIZE = 65536; + private static final int UDP_TIMEOUT = 240000; // 4 MINUTES + private static final int ONE_MEG = 1024 * 1024; + + private volatile boolean run = true; + private Class<BaseUdpReceiveRunnable> logger = BaseUdpReceiveRunnable.class; + private InetSocketAddress address; + + public BaseUdpReceiveRunnable(InetSocketAddress address){ + this.address = address; + } + + public void stop(){ + run = false; + } + + @Override + public void run() { + ByteBuffer buffer = ByteBuffer.allocateDirect(DATA_SIZE); + DatagramChannel channel = null; + try{ + while(run){ + try { + channel = DatagramChannel.open(); + channel.socket().setReuseAddress(true); + channel.socket().bind(address); + channel.socket().setSoTimeout(UDP_TIMEOUT); + channel.socket().setReceiveBufferSize(ONE_MEG); + channel.configureBlocking(true); + + while (run) { + buffer.clear(); + channel.receive(buffer); + buffer.flip(); + processBuffer(buffer); + } + } catch (BindException ex) { + OseeLog.log(logger, Level.FINEST, ex); + channel.close(); + Thread.sleep(1000); + } + } + }catch (InterruptedIOException ex) { + Thread.interrupted(); + if (run) { + OseeLog.log(logger, Level.WARNING, "Unexpected interruption", ex); + } + } catch (ClosedByInterruptException ie) { + Thread.interrupted(); + if (run) { + OseeLog.log(logger, Level.WARNING, "Unexpected interruption", ie); + } + } catch (Throwable t) { + throw new OTEException(t); + } finally { + try { + if (channel != null) { + channel.close(); + } + } catch (IOException ex) { + ex.printStackTrace(); + } + } + } + + protected abstract void processBuffer(ByteBuffer buffer); + + public InetSocketAddress getAddress() { + return address; + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/IUserSession.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/IUserSession.java index 8c5160fb2e4..90d18e28122 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/IUserSession.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/IUserSession.java @@ -10,6 +10,8 @@ *******************************************************************************/ package org.eclipse.osee.ote.core; +import java.util.UUID; + import org.eclipse.osee.framework.messaging.Message; import org.eclipse.osee.ote.core.framework.prompt.IPassFailPromptResponse; import org.eclipse.osee.ote.core.framework.prompt.IResumeResponse; @@ -46,5 +48,7 @@ public interface IUserSession { public void cancelPrompts() throws Exception; public boolean isAlive() throws Exception; + + public UUID getUserId() throws Exception; } diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/cmd/CommandDistributer.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/cmd/CommandDistributer.java deleted file mode 100644 index 3620b4fdb0b..00000000000 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/cmd/CommandDistributer.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.ote.core.cmd; - -/** - * @author Andrew M. Finkbeiner - */ -public interface CommandDistributer { - void distribute(Command command); - - void registerHandler(CommandHandler commandHandler); - - void unregisterHandler(CommandHandler commandHandler); - - void shutdown(); -} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/cmd/CommandDistributerImpl.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/cmd/CommandDistributerImpl.java deleted file mode 100644 index b0a21492ba4..00000000000 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/cmd/CommandDistributerImpl.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.ote.core.cmd; - -import java.util.Set; -import java.util.concurrent.CopyOnWriteArraySet; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import org.eclipse.osee.framework.logging.OseeLog; - -/** - * @author Andrew M. Finkbeiner - */ -public class CommandDistributerImpl implements CommandDistributer { - private final ExecutorService executor = Executors.newSingleThreadExecutor(); - private final Set<CommandHandler> handlers = new CopyOnWriteArraySet<CommandHandler>(); - - public CommandDistributerImpl() { - - } - - @Override - public void distribute(final Command command) { - executor.submit(new Runnable() { - - @Override - public void run() { - for (CommandHandler handler : handlers) { - try { - if (handler.canHandle(command.getId())) { - handler.handle(command); - } - } catch (RuntimeException e) { - OseeLog.log(CommandDistributerImpl.class, Level.SEVERE, - "Eception in handler for " + command.getId().toString(), e); - } - } - } - }); - } - - @Override - public void registerHandler(CommandHandler commandHandler) { - handlers.add(commandHandler); - } - - @Override - public void unregisterHandler(CommandHandler commandHandler) { - handlers.remove(commandHandler); - } - - @Override - public void shutdown() { - OseeLog.log(CommandDistributerImpl.class, Level.INFO, "Command distributor shutting down..."); - handlers.clear(); - executor.shutdown(); - try { - executor.awaitTermination(30000, TimeUnit.MILLISECONDS); - } catch (InterruptedException ex) { - OseeLog.log(CommandDistributerImpl.class, Level.WARNING, - "Interrupted while shutting down command distributor", ex); - Thread.currentThread().interrupt(); - } - } - -} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/cmd/CommandHandler.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/cmd/CommandHandler.java deleted file mode 100644 index 143a20ae3a5..00000000000 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/cmd/CommandHandler.java +++ /dev/null @@ -1,20 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.ote.core.cmd; - -/** - * @author Andrew M. Finkbeiner - */ -public interface CommandHandler { - void handle(Command cmd); - - boolean canHandle(CommandId id); -} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/cmd/PropertyStoreCommand.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/cmd/PropertyStoreCommand.java deleted file mode 100644 index 70db1cf4a53..00000000000 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/cmd/PropertyStoreCommand.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. - * 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: - * Boeing - initial API and implementation - *******************************************************************************/ -package org.eclipse.osee.ote.core.cmd; - -import java.io.Serializable; -import org.eclipse.osee.framework.jdk.core.type.IPropertyStore; -import org.eclipse.osee.framework.jdk.core.type.PropertyStore; - -/** - * @author Andrew M. Finkbeiner - */ -public class PropertyStoreCommand implements Command, Serializable { - - private static final long serialVersionUID = 7685494212621558501L; - - private final CommandId commandId; - private final Source source; - private final IPropertyStore store; - - public PropertyStoreCommand(CommandId commandId, Source source) { - this.commandId = commandId; - this.source = source; - store = new PropertyStore("org.eclipse.osee.ote.core.cmd.PropertyStoreCommand"); - } - - @Override - public CommandId getId() { - return commandId; - } - - @Override - public Source getSource() { - return source; - } - - public IPropertyStore getPropertyStore() { - return store; - } - -} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/TestEnvironment.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/TestEnvironment.java index 8790ec98cfa..48ecdca956e 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/TestEnvironment.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/TestEnvironment.java @@ -46,7 +46,6 @@ import org.eclipse.osee.ote.core.GCHelper; import org.eclipse.osee.ote.core.OseeTestThread; import org.eclipse.osee.ote.core.OteProperties; import org.eclipse.osee.ote.core.TestScript; -import org.eclipse.osee.ote.core.cmd.Command; import org.eclipse.osee.ote.core.environment.interfaces.IAssociatedObjectListener; import org.eclipse.osee.ote.core.environment.interfaces.ICancelTimer; import org.eclipse.osee.ote.core.environment.interfaces.IEnvironmentFactory; @@ -65,6 +64,7 @@ import org.eclipse.osee.ote.core.framework.command.ICommandHandle; import org.eclipse.osee.ote.core.framework.command.ITestContext; import org.eclipse.osee.ote.core.framework.command.ITestServerCommand; import org.eclipse.osee.ote.core.internal.Activator; +import org.eclipse.osee.ote.properties.OtePropertiesCore; import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceRegistration; @@ -137,7 +137,7 @@ public abstract class TestEnvironment implements TestEnvironmentInterface, ITest } props.setProperty("date", new Date()); props.setProperty("group", "OSEE Test Environment"); - props.setProperty("owner", System.getProperty("user.name")); + props.setProperty("owner", OtePropertiesCore.userName.getValue()); connector = new LocalConnector(this, Integer.toString(this.getUniqueId()), props); } @@ -150,10 +150,6 @@ public abstract class TestEnvironment implements TestEnvironmentInterface, ITest OteServerSideEndpointSender.OTE_SERVER_SIDE_SEND_PROTOCOL)); } - public void sendCommand(Command command) { - Activator.getInstance().getCommandDistributer().distribute(command); - } - public void sendMessageToServer(Message message) { oteServerSideEndpointRecieve.recievedMessage(message); } @@ -290,7 +286,7 @@ public abstract class TestEnvironment implements TestEnvironmentInterface, ITest @Override public URL setBatchLibJar(byte[] batchJar) throws IOException { - String path = System.getProperty("user.home") + File.separator + TestEnvironment.class.getName(); + String path = OtePropertiesCore.userHome.getValue() + File.separator + TestEnvironment.class.getName(); File dir = new File(path, "batchLibCache"); if (!dir.isDirectory()) { diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/TestEnvironmentLogFilter.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/TestEnvironmentLogFilter.java index 44f8f20a3c1..2473861d06a 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/TestEnvironmentLogFilter.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/TestEnvironmentLogFilter.java @@ -12,7 +12,9 @@ package org.eclipse.osee.ote.core.environment; import java.util.logging.Level; import java.util.regex.Pattern; + import org.eclipse.osee.framework.logging.ILoggerFilter; +import org.eclipse.osee.ote.properties.OtePropertiesCore; public class TestEnvironmentLogFilter implements ILoggerFilter { private static Level level; diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/interfaces/IHostTestEnvironment.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/interfaces/IHostTestEnvironment.java index e0f615f19d2..69074b91a77 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/interfaces/IHostTestEnvironment.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/interfaces/IHostTestEnvironment.java @@ -32,4 +32,5 @@ public interface IHostTestEnvironment extends Remote { public NodeInfo getBroker() throws RemoteException; public String getHttpURL() throws RemoteException; + } diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/interfaces/IRuntimeLibraryManager.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/interfaces/IRuntimeLibraryManager.java index b90a8d62595..e8ce60952ca 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/interfaces/IRuntimeLibraryManager.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/interfaces/IRuntimeLibraryManager.java @@ -16,7 +16,7 @@ import org.eclipse.osee.ote.ConfigurationStatus; import org.eclipse.osee.ote.OTEStatusCallback; /** - * An interface for + * An interface for loading and installing bundles in the running test environment. * * @author Andrew M. Finkbeiner * diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/interfaces/ITestEnvironment.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/interfaces/ITestEnvironment.java index b34e97e1046..c4886f71476 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/interfaces/ITestEnvironment.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/environment/interfaces/ITestEnvironment.java @@ -14,7 +14,6 @@ import java.rmi.Remote; import java.rmi.RemoteException; import org.eclipse.osee.framework.messaging.Message; -import org.eclipse.osee.ote.core.cmd.Command; import org.eclipse.osee.ote.core.model.IModelManagerRemote; import org.eclipse.osee.ote.message.IInstrumentationRegistrationListener; @@ -36,8 +35,6 @@ public interface ITestEnvironment extends Remote { public void setBatchMode(boolean isBatched) throws RemoteException; - public void sendCommand(Command command) throws RemoteException; - public void sendMessage(Message message) throws RemoteException; void addInstrumentationRegistrationListener(IInstrumentationRegistrationListener listener) throws RemoteException; diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/command/RunTests.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/command/RunTests.java index a2812bbf769..462dde7ccf0 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/command/RunTests.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/command/RunTests.java @@ -7,6 +7,7 @@ import java.io.Serializable; import java.rmi.server.ExportException; import java.util.ArrayList; import java.util.List; +import java.util.Set; import java.util.UUID; import java.util.concurrent.Future; import java.util.logging.Level; @@ -17,7 +18,6 @@ import org.eclipse.osee.framework.logging.IHealthStatus; import org.eclipse.osee.framework.logging.OseeLog; import org.eclipse.osee.ote.Configuration; import org.eclipse.osee.ote.OTEApi; -import org.eclipse.osee.ote.OTEServerFolder; import org.eclipse.osee.ote.core.ServiceUtility; import org.eclipse.osee.ote.core.environment.TestEnvironment; import org.eclipse.osee.ote.core.environment.status.CommandEndedStatusEnum; @@ -25,6 +25,7 @@ import org.eclipse.osee.ote.core.environment.status.OTEStatusBoard; import org.eclipse.osee.ote.core.framework.IMethodResult; import org.eclipse.osee.ote.core.framework.ReturnCode; import org.eclipse.osee.ote.core.framework.saxparse.ProcessOutfileOverview; +import org.eclipse.osee.ote.io.OTEServerFolder; import org.eclipse.osee.ote.message.IMessageTestContext; public class RunTests implements ITestServerCommand, Serializable { @@ -37,15 +38,15 @@ public class RunTests implements ITestServerCommand, Serializable { private volatile boolean cancelAll = false; private volatile boolean isRunning = false; private final UUID sessionKey; - private final String guid; + private final String commandId; private TestEnvironment environment; private final Configuration configuration; - public RunTests(String guid, UUID uuid, Configuration configuration, IPropertyStore global, List<IPropertyStore> scripts) { + public RunTests(String commandId, UUID sessionKey, Configuration configuration, IPropertyStore global, List<IPropertyStore> scripts) { this.global = global; this.scripts = scripts; - this.sessionKey = uuid; - this.guid = guid; + this.sessionKey = sessionKey; + this.commandId = commandId; this.configuration = configuration; } @@ -114,6 +115,21 @@ public class RunTests implements ITestServerCommand, Serializable { } for (IPropertyStore store : scripts) { + Set<String> arrayKeySet = global.arrayKeySet(); + for(String key:arrayKeySet){ + String[] array = global.getArray(key); + if(array != null ){ + store.put(key, array); + } + } + Set<String> keySet = global.keySet(); + for(String key:keySet){ + String val = global.get(key); + if(val != null ){ + store.put(key, val); + } + } + if (cancelAll) { statusBoard.onTestComplete(store.get(RunTestsKeys.testClass.name()), store.get(RunTestsKeys.serverOutfilePath.name()), @@ -226,7 +242,7 @@ public class RunTests implements ITestServerCommand, Serializable { @Override public String getGUID() { - return guid; + return commandId; } @Override diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/command/RunTestsHandle.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/command/RunTestsHandle.java index a939926a71c..1b1bbe1b6c1 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/command/RunTestsHandle.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/framework/command/RunTestsHandle.java @@ -1,14 +1,10 @@ package org.eclipse.osee.ote.core.framework.command; import java.io.Serializable; -import java.rmi.RemoteException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import org.eclipse.osee.framework.jdk.core.util.GUID; -import org.eclipse.osee.ote.core.framework.command.ICommandHandle; -import org.eclipse.osee.ote.core.framework.command.ITestCommandResult; -import org.eclipse.osee.ote.core.framework.command.ITestContext; public class RunTestsHandle implements ICommandHandle, Serializable { diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/internal/Activator.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/internal/Activator.java index 7fa95059bbe..b9b19b35780 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/internal/Activator.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/internal/Activator.java @@ -18,8 +18,6 @@ import org.eclipse.osee.framework.jdk.core.type.CompositeKeyHashMap; import org.eclipse.osee.framework.logging.OseeLog; import org.eclipse.osee.ote.core.OteProperties; import org.eclipse.osee.ote.core.StandardShell; -import org.eclipse.osee.ote.core.cmd.CommandDistributer; -import org.eclipse.osee.ote.core.cmd.CommandDistributerImpl; import org.eclipse.osee.ote.core.environment.TestEnvironment; import org.eclipse.osee.ote.core.environment.TestEnvironmentInterface; import org.eclipse.osee.ote.core.environment.console.ConsoleCommandManager; @@ -38,7 +36,6 @@ import org.osgi.util.tracker.ServiceTrackerCustomizer; public class Activator implements BundleActivator { private ServiceRegistration testEnvironmentRegistration; - CommandDistributer commandDistributer; private static Activator activator; private BundleContext bundleContext; private final CompositeKeyHashMap<String, ServiceTrackerCustomizer, ServiceTracker> serviceTrackers = @@ -46,7 +43,6 @@ public class Activator implements BundleActivator { private ConsoleCommandManager consoleCommandManager; private StandardShell stdShell; private ServiceRegistration consoleCommandRegistration; - private ServiceRegistration commandDistributerRegistration; private ServiceDependencyTracker serviceDependencyTracker; private MessageIoManagementStarter messageIoManagementStarter; private ServiceTracker testEnvTracker; @@ -65,10 +61,6 @@ public class Activator implements BundleActivator { consoleCommandRegistration = context.registerService(ICommandManager.class.getName(), consoleCommandManager, new Hashtable()); - commandDistributer = new CommandDistributerImpl(); - commandDistributerRegistration = - context.registerService(CommandDistributer.class.getName(), commandDistributer, new Hashtable()); - serviceDependencyTracker = new ServiceDependencyTracker(bundleContext, new StatusBoardRegistrationHandler()); serviceDependencyTracker.open(); @@ -82,7 +74,6 @@ public class Activator implements BundleActivator { @Override public void stop(BundleContext context) throws Exception { serviceDependencyTracker.close(); - commandDistributer.shutdown(); closeAllValidServiceTrackers(); unregisterTestEnvironment(); if (stdShell != null) { @@ -90,7 +81,6 @@ public class Activator implements BundleActivator { } consoleCommandManager.shutdown(); consoleCommandRegistration.unregister(); - commandDistributerRegistration.unregister(); messageIoManagementStarter.close(); testEnvTracker.close(); @@ -100,10 +90,6 @@ public class Activator implements BundleActivator { return activator; } - public CommandDistributer getCommandDistributer() { - return commandDistributer; - } - public void registerTestEnvironment(TestEnvironment env) { if (testEnvironmentRegistration != null) { testEnvironmentRegistration.unregister(); diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/log/record/TestRecord.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/log/record/TestRecord.java index 206d9d001f5..9b53ab4645a 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/log/record/TestRecord.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/log/record/TestRecord.java @@ -32,6 +32,7 @@ import org.eclipse.osee.framework.logging.OseeLog; import org.eclipse.osee.ote.core.environment.TestEnvironment; import org.eclipse.osee.ote.core.environment.interfaces.ITestEnvironmentAccessor; import org.eclipse.osee.ote.message.log.record.MessageJarConfigrecord; +import org.eclipse.osee.ote.properties.OtePropertiesCore; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -55,7 +56,7 @@ public abstract class TestRecord extends LogRecord implements Xmlizable, Xmlizab } static { - filterTheStacktrace = System.getProperty("org.eclipse.osee.ote.core.noStacktraceFilter") == null; + filterTheStacktrace = OtePropertiesCore.noStacktraceFilter.getValue() == null; stacktraceExcludes.add(Pattern.compile("org\\.eclipse\\.osee\\..*")); } diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/AddressBuffer.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/AddressBuffer.java new file mode 100644 index 00000000000..7ea00ea2206 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/AddressBuffer.java @@ -0,0 +1,27 @@ +package org.eclipse.osee.ote.endpoint; + +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; + +public class AddressBuffer { + + private final ByteBuffer buffer; + private InetSocketAddress address; + + public AddressBuffer(){ + buffer = ByteBuffer.allocate(131072); + } + + public ByteBuffer getBuffer(){ + return buffer; + } + + public InetSocketAddress getAddress(){ + return address; + } + + public void setAddress(InetSocketAddress address){ + this.address = address; + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/EndpointDataProcessor.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/EndpointDataProcessor.java new file mode 100644 index 00000000000..a0b8ed3b562 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/EndpointDataProcessor.java @@ -0,0 +1,11 @@ +package org.eclipse.osee.ote.endpoint; + +import java.nio.ByteBuffer; + +public interface EndpointDataProcessor { + + int getTypeId(); + + void processBuffer(ByteBuffer buffer); + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteEndpointReceiveRunnable.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteEndpointReceiveRunnable.java new file mode 100644 index 00000000000..fb324e3808f --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteEndpointReceiveRunnable.java @@ -0,0 +1,139 @@ +package org.eclipse.osee.ote.endpoint; + +import java.io.IOException; +import java.io.InterruptedIOException; +import java.net.BindException; +import java.net.InetSocketAddress; +import java.net.UnknownHostException; +import java.nio.ByteBuffer; +import java.nio.channels.ClosedByInterruptException; +import java.nio.channels.DatagramChannel; +import java.util.Date; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.logging.Level; + +import org.eclipse.osee.framework.logging.OseeLog; +import org.eclipse.osee.ote.OTEException; +import org.eclipse.osee.ote.message.event.OteEventMessage; +import org.eclipse.osee.ote.message.event.OteEventMessageHeader; +import org.eclipse.osee.ote.message.event.OteEventMessageUtil; + +public class OteEndpointReceiveRunnable implements Runnable { + + private static final int DATA_SIZE = 65536; + private static final int UDP_TIMEOUT = 240000; // 4 MINUTES + private static final int ONE_MEG = 1024 * 1024; + + private volatile boolean run = true; + private volatile boolean debugOutput = false; + private Class<OteEndpointReceiveRunnable> logger = OteEndpointReceiveRunnable.class; + private InetSocketAddress address; + + private CopyOnWriteArrayList<EndpointDataProcessor> dataProcessors = new CopyOnWriteArrayList<EndpointDataProcessor>(); + + public OteEndpointReceiveRunnable(InetSocketAddress address){ + this.address = address; + } + + public void stop(){ + run = false; + } + + @Override + public void run() { + ByteBuffer buffer = ByteBuffer.allocate(DATA_SIZE); + DatagramChannel channel = null; + try{ + while(run){ + try { + channel = DatagramChannel.open(); + channel.socket().setReuseAddress(true); + channel.socket().bind(address); + channel.socket().setSoTimeout(UDP_TIMEOUT); + channel.socket().setReceiveBufferSize(ONE_MEG); + channel.configureBlocking(true); + + while (run) { + buffer.clear(); + channel.receive(buffer); + buffer.flip(); + processBuffer(buffer); + } + } catch (BindException ex) { + if(debugOutput){ + OseeLog.log(logger, Level.FINEST, ex); + } + channel.close(); + Thread.sleep(1000); + } + } + }catch (InterruptedIOException ex) { + Thread.interrupted(); + if (run && debugOutput) { + OseeLog.log(logger, Level.WARNING, "Unexpected interruption", ex); + } + } catch (ClosedByInterruptException ie) { + Thread.interrupted(); + if (run && debugOutput) { + OseeLog.log(logger, Level.WARNING, "Unexpected interruption", ie); + } + } catch (Throwable t) { + throw new OTEException(t); + } finally { + try { + if (channel != null) { + channel.close(); + } + } catch (IOException ex) { + if(debugOutput){ + ex.printStackTrace(); + } + } + } + } + + private void processBuffer(ByteBuffer buffer) { + int typeId = buffer.getShort(0) & 0xFFFF; + if(typeId == OteEventMessageHeader.MARKER_VALUE){ + byte[] data = new byte[buffer.remaining()]; + buffer.get(data); + OteEventMessage msg = new OteEventMessage((byte[])data); + msg.getHeader().TTL.setNoLog(1); + if(debugOutput){ + try { + System.out.printf("[%s] received: [%s][%d] from [%s:%d]\n", new Date(), msg.getHeader().TOPIC.getValue(), msg.getData().length, msg.getHeader().ADDRESS.getAddress().getHostAddress(), msg.getHeader().ADDRESS.getPort()); + } catch (UnknownHostException e) { + e.printStackTrace(); + } + } + OteEventMessageUtil.postEvent(msg); + } else { + for(EndpointDataProcessor processor: dataProcessors){ + if(processor.getTypeId() == typeId){ + try{ + processor.processBuffer(buffer); + } catch (Throwable th){ + th.printStackTrace(); + } + } + } + } + } + + public void setDebugOutput(boolean enable) { + debugOutput = enable; + } + + public InetSocketAddress getAddress() { + return address; + } + + public void addDataProcessor(EndpointDataProcessor processor) { + dataProcessors.add(processor); + } + + public void removeDataProcessor(EndpointDataProcessor processor) { + dataProcessors.remove(processor); + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteEndpointSendRunnable.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteEndpointSendRunnable.java new file mode 100644 index 00000000000..d14003c36ac --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteEndpointSendRunnable.java @@ -0,0 +1,119 @@ +package org.eclipse.osee.ote.endpoint; + +import java.io.IOException; +import java.nio.channels.AsynchronousCloseException; +import java.nio.channels.ClosedByInterruptException; +import java.nio.channels.ClosedChannelException; +import java.nio.channels.DatagramChannel; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.logging.Level; + +import org.eclipse.osee.framework.logging.OseeLog; +import org.eclipse.osee.ote.collections.ObjectPool; + +public class OteEndpointSendRunnable implements Runnable { + + private static final int SEND_BUFFER_SIZE = 1024 * 512; + + private ArrayBlockingQueue<AddressBuffer> toSend; + private ObjectPool<AddressBuffer> buffers; + + private boolean debug = false; + + public OteEndpointSendRunnable(ArrayBlockingQueue<AddressBuffer> toSend, ObjectPool<AddressBuffer> buffers, boolean debug) { + this.toSend = toSend; + this.buffers = buffers; + this.debug = debug; + } + + @Override + public void run() { + DatagramChannel threadChannel = null; + try { + threadChannel = openAndInitializeDatagramChannel(); + boolean keepRunning = true; + final List<AddressBuffer> dataToSend = new ArrayList<AddressBuffer>(32); + System.setSecurityManager(null); + while(keepRunning){ + try{ + dataToSend.clear(); + if (toSend.drainTo(dataToSend) < 1) { + try { + // block until something is available + dataToSend.add(toSend.take()); + } catch (InterruptedException e) { + keepRunning = false; + continue; + } + } + int size = dataToSend.size(); + for (int i = 0; i < size; i++) { + AddressBuffer data = dataToSend.get(i); + if (data == OteUdpEndpointSender.POISON_PILL) { + keepRunning = false; + break; + } + threadChannel.send(data.getBuffer(), data.getAddress()); + } + } catch (ClosedByInterruptException ex){ + if(debug){ + OseeLog.log(getClass(), Level.SEVERE, "Error trying to send data", ex); + } + threadChannel = openAndInitializeDatagramChannel(); + } catch (AsynchronousCloseException ex){ + if(debug){ + OseeLog.log(getClass(), Level.SEVERE, "Error trying to send data", ex); + } + closeChannel(threadChannel); + threadChannel = openAndInitializeDatagramChannel(); + } catch (ClosedChannelException ex){ + if(debug){ + OseeLog.log(getClass(), Level.SEVERE, "Error trying to send data", ex); + } + closeChannel(threadChannel); + threadChannel = openAndInitializeDatagramChannel(); + } catch (IOException ex){ + if(debug){ + OseeLog.log(getClass(), Level.SEVERE, "Error trying to send data", ex); + } + } finally { + int size = dataToSend.size(); + for (int i = 0; i < size; i++) { + buffers.returnObj(dataToSend.get(i)); + } + } + } + } catch (IOException ex){ + if(debug){ + OseeLog.log(getClass(), Level.SEVERE, "Error opening DatagramChannel. Ending OteEndpointSendRunnable unexpectedly.", ex); + } + } finally{ + closeChannel(threadChannel); + } + + } + + private void closeChannel(DatagramChannel channel){ + try { + if (channel != null) { + channel.close(); + } + } catch (IOException e) { + if(debug){ + OseeLog.log(getClass(), Level.SEVERE, "Error trying to close channel", e); + } + } + } + + private DatagramChannel openAndInitializeDatagramChannel() throws IOException { + DatagramChannel channel = DatagramChannel.open(); + if (channel.socket().getSendBufferSize() < SEND_BUFFER_SIZE) { + channel.socket().setSendBufferSize(SEND_BUFFER_SIZE); + } + channel.socket().setReuseAddress(true); + channel.configureBlocking(true); + return channel; + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteEndpointUtil.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteEndpointUtil.java new file mode 100644 index 00000000000..761a4054820 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteEndpointUtil.java @@ -0,0 +1,54 @@ +package org.eclipse.osee.ote.endpoint; + +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.UnknownHostException; + +import org.eclipse.osee.ote.OTEException; + +public class OteEndpointUtil { + + /** + * Get the socket address for the OTEUdpEndpoint from an encoded URI. You should catch OTEException and + * handle the case when the sting is not as expected. + * + * @param uriAddress + * @return + */ + public static InetSocketAddress getAddress(final String uriAddress) throws OTEException { + String[] addPort = null; + if(uriAddress.startsWith("tcp://")){ + String add = uriAddress.replaceFirst("tcp://", ""); + addPort = add.split(":"); + } else { + addPort = uriAddress.split(":"); + } + if(addPort != null && addPort.length == 2){ + try { + InetAddress byName = InetAddress.getByName(addPort[0]); + int port = Integer.parseInt(addPort[1]); + return new InetSocketAddress(byName, port); + } catch (UnknownHostException ex){ + throw new OTEException(String.format("Invalid address[%s]", uriAddress), ex); + } catch (NumberFormatException ex){ + throw new OTEException(String.format("Invalid address format[%s], can't determine port", uriAddress), ex); + } + } else { + throw new OTEException(String.format("Invalid address format[%s]", uriAddress)); + } + } + + public static InetSocketAddress getAddress(final String address, final int port) { + try { + InetAddress byName = InetAddress.getByName(address); + return new InetSocketAddress(byName, port); + } catch (UnknownHostException ex){ + throw new OTEException(String.format("Invalid address[%s]", address), ex); + } + } + + public static String getAddressURI(final InetSocketAddress address){ + return String.format("tcp://%s:%d", address.getAddress().getHostAddress(), address.getPort()); + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteUdpEndpoint.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteUdpEndpoint.java new file mode 100644 index 00000000000..aaf726bd9cf --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteUdpEndpoint.java @@ -0,0 +1,17 @@ +package org.eclipse.osee.ote.endpoint; + +import java.net.InetSocketAddress; + +import org.eclipse.osee.ote.core.CopyOnWriteNoIteratorList; + +public interface OteUdpEndpoint { + + public void setDebugOutput(boolean enable); + public InetSocketAddress getLocalEndpoint(); + public OteUdpEndpointSender getOteEndpointSender(InetSocketAddress address); + public void addBroadcast(OteUdpEndpointSender sender); + public void removeBroadcast(OteUdpEndpointSender sender); + public CopyOnWriteNoIteratorList<OteUdpEndpointSender> getBroadcastSenders(); + public void addDataProcessor(EndpointDataProcessor processor); + public void removeDataProcessor(EndpointDataProcessor processor); +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteUdpEndpointReceiverImpl.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteUdpEndpointReceiverImpl.java new file mode 100644 index 00000000000..69748576257 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteUdpEndpointReceiverImpl.java @@ -0,0 +1,42 @@ +package org.eclipse.osee.ote.endpoint; + +import java.net.InetSocketAddress; + +public class OteUdpEndpointReceiverImpl { + + private OteEndpointReceiveRunnable oteEndpointReceiveRunnable; + private Thread th; + + public OteUdpEndpointReceiverImpl(InetSocketAddress address){ + oteEndpointReceiveRunnable = new OteEndpointReceiveRunnable(address); + } + + public void start(){ + th = new Thread(oteEndpointReceiveRunnable); + th.setName("OTE UDP Endpoint Receiver"); + th.setDaemon(true); + th.start(); + } + + public void stop(){ + oteEndpointReceiveRunnable.stop(); + th.interrupt(); + } + + public void setDebugOutput(boolean enable){ + oteEndpointReceiveRunnable.setDebugOutput(enable); + } + + public InetSocketAddress getEndpoint(){ + return oteEndpointReceiveRunnable.getAddress(); + } + + public void addDataProcessor(EndpointDataProcessor processor) { + oteEndpointReceiveRunnable.addDataProcessor(processor); + } + + public void removeDataProcessor(EndpointDataProcessor processor) { + oteEndpointReceiveRunnable.removeDataProcessor(processor); + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteUdpEndpointSender.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteUdpEndpointSender.java new file mode 100644 index 00000000000..099506dd9bf --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/endpoint/OteUdpEndpointSender.java @@ -0,0 +1,82 @@ +package org.eclipse.osee.ote.endpoint; + +import java.net.InetSocketAddress; +import java.util.Date; +import java.util.concurrent.ArrayBlockingQueue; + +import org.eclipse.osee.ote.OTEException; +import org.eclipse.osee.ote.collections.ObjectPool; +import org.eclipse.osee.ote.collections.ObjectPoolConfiguration; +import org.eclipse.osee.ote.message.event.OteEventMessage; + +/** + * Launches a Thread that monitors a queue for data to send to specified UDP endpoints. + * + * @author b1528444 + * + */ +public class OteUdpEndpointSender { + + static final AddressBuffer POISON_PILL = new AddressBuffer(); + + private final ObjectPool<AddressBuffer> buffers; + private final ArrayBlockingQueue<AddressBuffer> toSend; + + private final InetSocketAddress address; + + private boolean debug = false; + + private volatile boolean isClosed = false; + + public OteUdpEndpointSender(InetSocketAddress address){ + toSend = new ArrayBlockingQueue<AddressBuffer>(5000); + buffers = new ObjectPool<AddressBuffer>(new ObjectPoolConfiguration<AddressBuffer>(50,true) { + @Override + public AddressBuffer make() { + return new AddressBuffer(); + } + }); + this.address = address; + } + + public void start(){ + Thread th = new Thread(new OteEndpointSendRunnable(toSend, buffers, debug)); + th.setName(String.format("OTE Endpoint Sender[%s]", address.toString())); + th.setDaemon(true); + th.start(); + } + + public void stop() throws InterruptedException{ + toSend.put(POISON_PILL); + isClosed = true; + } + + public InetSocketAddress getAddress(){ + return address; + } + + public void send(OteEventMessage message) { + if(debug){ + System.out.printf("[%s] sending: [%s] to [%s] [%d]\n", new Date(), message.getHeader().TOPIC.getValue(), address.toString(), message.getData().length); + } + AddressBuffer obj = buffers.getObject(); + obj.getBuffer().clear(); + obj.getBuffer().put(message.getData()); + obj.getBuffer().flip(); + obj.setAddress(address); + try { + toSend.put(obj); + } catch (InterruptedException e) { + throw new OTEException(e); + } + } + + public boolean isClosed() { + return isClosed; + } + + public void setDebug(boolean debug){ + this.debug = debug; + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/filetransfer/TcpFileTransfer.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/filetransfer/TcpFileTransfer.java new file mode 100644 index 00000000000..deb6a41bf8e --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/filetransfer/TcpFileTransfer.java @@ -0,0 +1,282 @@ +package org.eclipse.osee.ote.filetransfer; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.SocketTimeoutException; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.channels.SelectionKey; +import java.nio.channels.Selector; +import java.nio.channels.ServerSocketChannel; +import java.nio.channels.SocketChannel; +import java.util.Set; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; + +public class TcpFileTransfer { + + + + private static final int SECRET_CODE = 0xF17E; + private static final int BLOCK_SIZE = 64*1024; + + public static TcpFileTransferHandle sendFile(ExecutorService service, final File file, final InetSocketAddress address) throws IOException{ + if (!file.exists()) { + throw new IllegalArgumentException("Invalid file specified: " + file.getAbsolutePath()); + } + final TransferProgressMonitor monitor = new TransferProgressMonitor(); + monitor.updateTransferStartTime(System.currentTimeMillis()); + final SocketChannel sendChannel = SocketChannel.open(address); + + final TcpFileTransfer fileTransfer = new TcpFileTransfer(Direction.FILE_TO_CHANNEL, file); + Callable<Boolean> c = new Callable<Boolean>() { + + @Override + public Boolean call() throws Exception { + fileTransfer.openSender(monitor, sendChannel); + monitor.updateTransferCompleteTime(System.currentTimeMillis()); + return true; + } + }; + InetSocketAddress localAddress = (InetSocketAddress) sendChannel.socket().getLocalSocketAddress(); + return new TcpFileTransferHandle(monitor, localAddress, service.submit(c)); + } + + + /** + * + * @param service + * @param file + * @param port + * @return the transfer handle or null if the file to be written to is in use by another process + * @throws IOException + */ + public static TcpFileTransferHandle receiveFile(ExecutorService service, final File file, int port) throws IOException{ + if (service == null) { + throw new NullPointerException("Service cannot be null"); + } + + final TcpFileTransfer fileTransfer; + try { + fileTransfer = new TcpFileTransfer(Direction.CHANNEL_TO_FILE, file); + } catch (FileNotFoundException e) { + // most likely due to file being used by another process + return null; + } + final TransferProgressMonitor monitor = new TransferProgressMonitor(); + monitor.updateTransferStartTime(System.currentTimeMillis()); + + final ServerSocketChannel channel = ServerSocketChannel.open(); + channel.configureBlocking(false); + channel.socket().bind(new InetSocketAddress(InetAddress.getLocalHost(), port)); + InetSocketAddress localAddress = (InetSocketAddress) channel.socket().getLocalSocketAddress(); + + Callable<Boolean> c = new Callable<Boolean>() { + + @Override + public Boolean call() throws Exception { + fileTransfer.openReceiver(monitor, channel); + monitor.updateTransferCompleteTime(System.currentTimeMillis()); + + return true; + + } + }; + return new TcpFileTransferHandle(monitor, localAddress, service.submit(c)); + } + + private static enum Direction { + FILE_TO_CHANNEL { + + @Override + long transfer(FileChannel fileChannel, SocketChannel byteChannel, long position, long count) throws IOException{ + return fileChannel.transferTo(position, count, byteChannel); + } + + @Override + FileChannel createChannel(File file) throws IOException{ + return new FileInputStream(file).getChannel(); + } + + }, + CHANNEL_TO_FILE { + + @Override + long transfer(FileChannel fileChannel, SocketChannel byteChannel, long position, long count) throws IOException{ + return fileChannel.transferFrom(byteChannel, position, count); + } + + @Override + FileChannel createChannel(File file) throws IOException { + FileChannel channel = new FileOutputStream(file).getChannel(); + channel.lock(); + return channel; + } + + + }; + + abstract long transfer(FileChannel fileChannel, SocketChannel byteChannel, long position, long count) throws IOException; + abstract FileChannel createChannel(File file) throws IOException; + } + + private final Direction direction; + private final File file; + + private TcpFileTransfer(Direction direction, File file) throws FileNotFoundException, IOException{ + this.direction = direction; + this.file = file; + } + + + private void openSender(TransferProgressMonitor monitor, SocketChannel sendChannel) throws IOException{ + try { + Selector selector = Selector.open(); + try { + sendChannel.configureBlocking(false); + sendChannel.register(selector, SelectionKey.OP_WRITE); + final File[] files; + if (file.isDirectory()) { + files = file.listFiles(); + } else { + files = new File[]{file}; + } + int fileCounter = 1; + ByteBuffer buffer = ByteBuffer.allocate(1024); + for (File targetFile : files) { + long size = targetFile.length(); + monitor.updateTotalTransferAmount(size); + buffer.clear(); + buffer.putInt(SECRET_CODE); + buffer.putInt(files.length); + buffer.putInt(fileCounter++); + String name = targetFile.getName(); + buffer.putInt(name.length()); + buffer.put(name.getBytes()); + buffer.putLong(size); + buffer.flip(); + sendChannel.write(buffer); + transfer(monitor, sendChannel, selector, size, targetFile); + buffer.clear(); + sendChannel.keyFor(selector).interestOps(SelectionKey.OP_READ); + waitForData(selector, sendChannel, buffer); + sendChannel.keyFor(selector).interestOps(SelectionKey.OP_WRITE); + } + } finally { + selector.close(); + } + } finally { + sendChannel.close(); + } + } + + private void openReceiver(TransferProgressMonitor monitor, ServerSocketChannel serverChannel) throws IOException{ + try { + Selector selector = Selector.open(); + try { + serverChannel.register(selector, SelectionKey.OP_ACCEPT); + // only way to timeout on accept with channels is to use a selector. + // ServerSocketChannel does not honor the socket.setSoTimeout() value + if (selector.select(10000) < 1) { + throw new SocketTimeoutException(); + } + selector.selectedKeys().clear(); + serverChannel.keyFor(selector).cancel(); + + SocketChannel receiveChannel = serverChannel.accept(); + receiveChannel.configureBlocking(false); + receiveChannel.register(selector, SelectionKey.OP_READ); + + // now we need to handle timeouts for the data channel + try { + boolean done = false; + ByteBuffer buffer = ByteBuffer.allocate(1024); + byte[] fileNameBytes = new byte[2048]; + while (!done) { + buffer.clear(); + // we only want to read the next 12 bytes, anything more than 12 is the file data + // and we want that left in the channel to be consumed later + buffer.limit(16); + + waitForData(selector, receiveChannel, buffer); + + buffer.flip(); + int code = buffer.getInt(); + if (code != SECRET_CODE) { + throw new IOException("Unexpected data during transfer negotiation"); + } + int fileCount = buffer.getInt(); + int currentFile = buffer.getInt(); + monitor.updateNumberOfFiles(fileCount); + int fileNameLength = buffer.getInt(); + buffer.clear(); + buffer.limit(fileNameLength + 8); + waitForData(selector, receiveChannel, buffer); + buffer.flip(); + buffer.get(fileNameBytes, 0, fileNameLength); + long fileSize = buffer.getLong(); + monitor.updateTotalTransferAmount(fileSize); + File targetFile = file.isDirectory() ? new File(file, new String(fileNameBytes, 0, fileNameLength)) : file; + transfer(monitor, receiveChannel, selector, fileSize, targetFile); + buffer.clear(); + buffer.putInt(0xF0F0); + buffer.flip(); + receiveChannel.write(buffer); + done = currentFile == fileCount; + + } + } finally { + receiveChannel.close(); + } + } finally { + selector.close(); + } + } finally { + serverChannel.close(); + } + } + + private static void waitForData(Selector selector, SocketChannel channel, ByteBuffer buffer) throws SocketTimeoutException, IOException{ + if (selector.select(10000) < 1) { + throw new SocketTimeoutException(); + } + selector.selectedKeys().clear(); + channel.read(buffer); + } + + + private static void waitForChannel(Selector selector) throws SocketTimeoutException, IOException{ + selector.select(10000); + Set<SelectionKey> set = selector.selectedKeys(); + if (set.size() == 0) { + throw new SocketTimeoutException(); + } + set.clear(); + } + + private void transfer(TransferProgressMonitor monitor, SocketChannel channel, Selector selector, long totalTransferAmount, File targetFile) throws IOException { + // we need a selector to deal with time outs + FileChannel fileChannel = direction.createChannel(targetFile); + try { + long position = 0; + while (position < totalTransferAmount) { + waitForChannel(selector); + long count = direction.transfer(fileChannel, channel, position, Math.min(BLOCK_SIZE, totalTransferAmount - position)); + if (count < 0) { + channel.keyFor(selector).cancel(); + continue; + } + position += count; + monitor.updateAmountTransferred(position); + } + } finally { + fileChannel.close(); + } + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/filetransfer/TcpFileTransferHandle.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/filetransfer/TcpFileTransferHandle.java new file mode 100644 index 00000000000..3175631aa5e --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/filetransfer/TcpFileTransferHandle.java @@ -0,0 +1,54 @@ +package org.eclipse.osee.ote.filetransfer; + +import java.net.InetSocketAddress; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +public class TcpFileTransferHandle { + + private final Future<Boolean> future; + private final TransferProgressMonitor progressMonitor; + + private final InetSocketAddress localAddress; + + TcpFileTransferHandle(TransferProgressMonitor progressMonitor, InetSocketAddress localAddress, + Future<Boolean> future) { + super(); + this.progressMonitor = progressMonitor; + this.future = future; + this.localAddress = localAddress; + } + + public void cancelTransfer() { + future.cancel(true); + } + + public TransferProgressMonitor getProgressMonitor() { + return progressMonitor; + } + + + + /** + * blocks until transfer is complete. + * @return true if transfer was a success or false otherwise + * @throws ExecutionException + * @throws InterruptedException + */ + public boolean awaitCompletion() throws ExecutionException, InterruptedException { + return future.get(); + } + + /** + * returns whether or not the transfer has completed. A transfer is considered complete + * once all bytes have been sent/received or if transfer was aborted due to an error + * @return + */ + public boolean isComplete() { + return future.isDone(); + } + + public InetSocketAddress getLocalAddress() { + return localAddress; + } +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/filetransfer/TransferProgressMonitor.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/filetransfer/TransferProgressMonitor.java new file mode 100644 index 00000000000..b72102c4fda --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/filetransfer/TransferProgressMonitor.java @@ -0,0 +1,61 @@ +package org.eclipse.osee.ote.filetransfer; + +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicLong; + +public class TransferProgressMonitor { + + private final AtomicInteger numberOfFiles = new AtomicInteger(-1); + private final AtomicLong total = new AtomicLong(-1L); + private final AtomicLong current = new AtomicLong(0L); + private final AtomicLong transferStartTime = new AtomicLong(-1L); + private final AtomicLong transferCompleteTime = new AtomicLong(-1L); + + public long getAmountTransferred() { + return current.get(); + } + + public long getTotalTransferAmount() { + return total.get(); + } + + public long getPercentTransferred() { + return (current.get() * 100) / total.get(); + } + + void updateAmountTransferred(long amount) { + current.set(amount); + } + + void updateTotalTransferAmount(long totalAmount) { + total.set(totalAmount); + } + + void updateNumberOfFiles(int files) { + numberOfFiles.set(files); + } + + public int getNumberOfFiles() { + return numberOfFiles.get(); + } + + public long getTransferStartTime() { + return transferStartTime.get(); + } + + public long getTransferCompleteTime() { + return transferCompleteTime.get(); + } + + void updateTransferStartTime(long time) { + transferStartTime.set(time); + } + + void updateTransferCompleteTime(long time) { + transferCompleteTime.set(time); + } + + public long getTotalTransferTime() { + return getTransferCompleteTime() - getTransferStartTime(); + } +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/ConfigureAndResponseListener.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/ConfigureAndResponseListener.java new file mode 100644 index 00000000000..552356b0585 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/ConfigureAndResponseListener.java @@ -0,0 +1,143 @@ +package org.eclipse.osee.ote.internal; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.logging.Level; + +import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.framework.logging.OseeLog; +import org.eclipse.osee.ote.ConfigurationStatus; +import org.eclipse.osee.ote.OTEApi; +import org.eclipse.osee.ote.OTEStatusCallback; +import org.eclipse.osee.ote.endpoint.OteUdpEndpoint; +import org.eclipse.osee.ote.endpoint.OteUdpEndpointSender; +import org.eclipse.osee.ote.message.event.OteEventMessageUtil; +import org.eclipse.osee.ote.remote.messages.ConfigurationAndResponse; +import org.eclipse.osee.ote.remote.messages.JobStatus; +import org.eclipse.osee.ote.remote.messages.SerializedConfigurationAndResponse; +import org.eclipse.osee.ote.remote.messages.SerializedOTEJobStatus; +import org.osgi.service.event.Event; +import org.osgi.service.event.EventAdmin; +import org.osgi.service.event.EventHandler; + +public class ConfigureAndResponseListener implements EventHandler { + + private final OTEApi oteApi; + private final OteUdpEndpoint endpoint; + + public ConfigureAndResponseListener(EventAdmin eventAdmin, OteUdpEndpoint endpoint, OTEApi oteApi) { + this.oteApi = oteApi; + this.endpoint = endpoint; + } + + @Override + public void handleEvent(Event arg0) { + SerializedConfigurationAndResponse serialized = new SerializedConfigurationAndResponse(OteEventMessageUtil.getBytes(arg0)); + try { + ConfigurationAndResponse config = serialized.getObject(); + + OteUdpEndpointSender oteEndpointSender = endpoint.getOteEndpointSender(serialized.getHeader().getSourceInetSocketAddress()); + endpoint.addBroadcast(oteEndpointSender); + try{ + String id = (String) oteApi.getIHostTestEnvironment().getProperties().getProperty("id"); + /* + * Ensure that the id matches so that we are talking with the server we intended to talk to + */ + if(id != null && config.getId().equals(id)){ + if(config.install()){ + oteApi.loadConfiguration(config.getConfiguration(), new Status(oteEndpointSender)); + } else { + oteApi.downloadConfigurationJars(config.getConfiguration(), new Status(oteEndpointSender)); + } + } else { + handleException(new Exception("Bad server id."), oteEndpointSender); + } + } catch (ExecutionException e) { + handleException(e, oteEndpointSender); + } + }catch (Throwable e) { + handleException(e); + } + } + + private void handleException(Throwable e, OteUdpEndpointSender oteEndpointSender) { + SerializedOTEJobStatus message = new SerializedOTEJobStatus(); + JobStatus jobStatus = new JobStatus(); + StringBuilder sb = new StringBuilder(); + sb.append("error: ").append(message).append("\n").append(Lib.exceptionToString(e)).append("\n"); + jobStatus.setErrorLog(sb.toString()); + jobStatus.setSuccess(false); + jobStatus.setJobComplete(true); + try { + message.setObject(jobStatus); + oteEndpointSender.send(message); + } catch (IOException e1) { + e1.printStackTrace(); + } + } + + private void handleException(Throwable e) { + OseeLog.log(getClass(), Level.SEVERE, e); + } + + private static class Status implements OTEStatusCallback<ConfigurationStatus> { + + private OteUdpEndpointSender oteEndpointSender; + private SerializedOTEJobStatus message; + private JobStatus jobStatus; + private StringBuilder sb; + + public Status(OteUdpEndpointSender oteEndpointSender) { + this.oteEndpointSender = oteEndpointSender; + this.message = new SerializedOTEJobStatus(); + this.jobStatus = new JobStatus(); + sb = new StringBuilder(); + } + + private void setAndSend(){ + try { + message.setObject(jobStatus); + oteEndpointSender.send(message); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void complete(ConfigurationStatus done) { + this.jobStatus.setSuccess(done.isSuccess()); + this.jobStatus.setJobComplete(true); + this.jobStatus.setErrorLog(done.getMessage()); + setAndSend(); + } + + @Override + public void setTotalUnitsOfWork(int totalUnitsOfWork) { + jobStatus.setTotalUnitsOfWork(totalUnitsOfWork); + setAndSend(); + } + + @Override + public void incrememtUnitsWorked(int count) { + jobStatus.setUnitsWorked(jobStatus.getUnitsWorked() + count); + setAndSend(); + } + + @Override + public void log(String message) { + sb.append("log: ").append(message).append("\n"); + } + + @Override + public void error(String message, Throwable th) { + sb.append("error: ").append(message).append("\n").append(Lib.exceptionToString(th)).append("\n"); + } + + @Override + public void error(String message) { + sb.append("error: ").append(message).append("\n"); + } + + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/ConnectionListener.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/ConnectionListener.java new file mode 100644 index 00000000000..b0e31bdf937 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/ConnectionListener.java @@ -0,0 +1,58 @@ +package org.eclipse.osee.ote.internal; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.rmi.RemoteException; + +import org.eclipse.osee.ote.OTEApi; +import org.eclipse.osee.ote.core.ConnectionRequestResult; +import org.eclipse.osee.ote.core.environment.interfaces.IHostTestEnvironment; +import org.eclipse.osee.ote.endpoint.OteUdpEndpoint; +import org.eclipse.osee.ote.endpoint.OteUdpEndpointSender; +import org.eclipse.osee.ote.message.event.OteEventMessageUtil; +import org.eclipse.osee.ote.remote.messages.RequestRemoteTestEnvironment; +import org.eclipse.osee.ote.remote.messages.SerializedConnectionRequestResult; +import org.eclipse.osee.ote.remote.messages.SerializedRequestRemoteTestEnvironment; +import org.osgi.service.event.Event; +import org.osgi.service.event.EventAdmin; +import org.osgi.service.event.EventHandler; + +public class ConnectionListener implements EventHandler { + + private OteUdpEndpoint oteEndpoint; + private OTEApi oteApi; + + public ConnectionListener(EventAdmin eventAdmin, OteUdpEndpoint oteEndpoint, OTEApi oteApi) { + this.oteEndpoint = oteEndpoint; + this.oteApi = oteApi; + } + + + @Override + public void handleEvent(Event arg0) { + SerializedRequestRemoteTestEnvironment serialized = new SerializedRequestRemoteTestEnvironment(OteEventMessageUtil.getBytes(arg0)); + RequestRemoteTestEnvironment request; + try { + request = serialized.getObject(); + IHostTestEnvironment hostTestEnvironment = oteApi.getIHostTestEnvironment(); + if(hostTestEnvironment != null){ + try { + InetSocketAddress address = serialized.getHeader().getSourceInetSocketAddress(); + ConnectionRequestResult requestEnvironment = hostTestEnvironment.requestEnvironment(request.getSession(), request.getId(), request.getConfig()); + OteUdpEndpointSender oteEndpointSender = oteEndpoint.getOteEndpointSender(address); + SerializedConnectionRequestResult serializedConnectionRequestResult = new SerializedConnectionRequestResult(requestEnvironment); + serializedConnectionRequestResult.setResponse(serialized); + oteEndpointSender.send(serializedConnectionRequestResult); + oteEndpoint.addBroadcast(oteEndpointSender); + } catch (RemoteException e) { + e.printStackTrace(); + } + } + } catch (IOException e1) { + e1.printStackTrace(); + } catch (ClassNotFoundException e1) { + e1.printStackTrace(); + } + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/DisconnectListener.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/DisconnectListener.java new file mode 100644 index 00000000000..a184a0df13c --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/DisconnectListener.java @@ -0,0 +1,39 @@ +package org.eclipse.osee.ote.internal; + +import java.io.IOException; + +import org.eclipse.osee.ote.OTEApi; +import org.eclipse.osee.ote.endpoint.OteUdpEndpoint; +import org.eclipse.osee.ote.message.event.OteEventMessageUtil; +import org.eclipse.osee.ote.remote.messages.DisconnectRemoteTestEnvironment; +import org.eclipse.osee.ote.remote.messages.SerializedDisconnectRemoteTestEnvironment; +import org.osgi.service.event.Event; +import org.osgi.service.event.EventAdmin; +import org.osgi.service.event.EventHandler; + +public class DisconnectListener implements EventHandler { + + private OTEApi oteApi; + private OteUdpEndpoint oteEndpoint; + + public DisconnectListener(EventAdmin eventAdmin, OteUdpEndpoint oteEndpoint, OTEApi oteApi) { + this.oteApi = oteApi; + this.oteEndpoint = oteEndpoint; + } + + @Override + public void handleEvent(Event arg0) { + SerializedDisconnectRemoteTestEnvironment serializedDisconnectRemoteTestEnvironment = new SerializedDisconnectRemoteTestEnvironment(OteEventMessageUtil.getBytes(arg0)); + DisconnectRemoteTestEnvironment disconnect; + try { + disconnect = serializedDisconnectRemoteTestEnvironment.getObject(); + oteApi.getIHostTestEnvironment().disconnect(disconnect.getId()); + oteEndpoint.removeBroadcast(oteEndpoint.getOteEndpointSender(serializedDisconnectRemoteTestEnvironment.getHeader().getSourceInetSocketAddress())); + } catch (IOException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/GetPropertiesListener.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/GetPropertiesListener.java new file mode 100644 index 00000000000..1f5434a1c3c --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/GetPropertiesListener.java @@ -0,0 +1,48 @@ +package org.eclipse.osee.ote.internal; + +import java.io.IOException; +import java.rmi.RemoteException; + +import org.eclipse.osee.ote.OTEApi; +import org.eclipse.osee.ote.core.environment.interfaces.IHostTestEnvironment; +import org.eclipse.osee.ote.endpoint.OteUdpEndpoint; +import org.eclipse.osee.ote.endpoint.OteUdpEndpointSender; +import org.eclipse.osee.ote.message.event.OteEventMessage; +import org.eclipse.osee.ote.message.event.OteEventMessageUtil; +import org.eclipse.osee.ote.remote.messages.SerializedEnhancedProperties; +import org.osgi.service.event.Event; +import org.osgi.service.event.EventAdmin; +import org.osgi.service.event.EventHandler; + +public class GetPropertiesListener implements EventHandler { + + private final OTEApi oteApi; + private final OteUdpEndpoint endpoint; + + public GetPropertiesListener(EventAdmin eventAdmin, OteUdpEndpoint endpoint, OTEApi oteApi) { + this.oteApi = oteApi; + this.endpoint = endpoint; + } + + @Override + public void handleEvent(Event arg0) { + OteEventMessage oteEventMessage = OteEventMessageUtil.getOteEventMessage(arg0); + SerializedEnhancedProperties properties = new SerializedEnhancedProperties(); + IHostTestEnvironment host = oteApi.getIHostTestEnvironment(); + if(host != null){ + try { + properties.setResponse(oteEventMessage); + OteUdpEndpointSender oteEndpointSender = endpoint.getOteEndpointSender(oteEventMessage.getHeader().getSourceInetSocketAddress()); + properties.setObject(host.getProperties()); + oteEndpointSender.send(properties); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/OTEApiImpl.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/OTEApiImpl.java index 2a715b826e4..d38a15898f2 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/OTEApiImpl.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/OTEApiImpl.java @@ -1,5 +1,7 @@ package org.eclipse.osee.ote.internal; +import java.util.Collections; +import java.util.Comparator; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -8,14 +10,16 @@ import java.util.concurrent.ThreadFactory; import java.util.concurrent.locks.ReentrantLock; import org.eclipse.osee.ote.Configuration; +import org.eclipse.osee.ote.ConfigurationItem; import org.eclipse.osee.ote.ConfigurationStatus; import org.eclipse.osee.ote.OTEApi; -import org.eclipse.osee.ote.OTEServerFolder; import org.eclipse.osee.ote.OTEServerRuntimeCache; import org.eclipse.osee.ote.OTEStatusCallback; import org.eclipse.osee.ote.core.environment.TestEnvironmentInterface; +import org.eclipse.osee.ote.core.environment.interfaces.IHostTestEnvironment; import org.eclipse.osee.ote.core.environment.interfaces.IRuntimeLibraryManager; import org.eclipse.osee.ote.core.model.IModelManager; +import org.eclipse.osee.ote.io.OTEServerFolder; import org.eclipse.osee.ote.message.interfaces.IRemoteMessageService; public final class OTEApiImpl implements OTEApi { @@ -31,6 +35,7 @@ public final class OTEApiImpl implements OTEApi { private TestEnvironmentInterface env; private IModelManager modelManager; private IRemoteMessageService remoteMessageService; + private IHostTestEnvironment host; /** * ds component method @@ -128,6 +133,20 @@ public final class OTEApiImpl implements OTEApi { this.remoteMessageService = null; } + /** + * ds component method + */ + public void bindIHostTestEnvironment(IHostTestEnvironment host){ + this.host = host; + } + + /** + * ds component method + */ + public void unbindIHostTestEnvironment(IHostTestEnvironment host){ + this.host = null; + } + public OTEApiImpl(){ this.configurationLock = new ReentrantLock(); this.emptyConfiguration = new Configuration(); @@ -154,7 +173,7 @@ public final class OTEApiImpl implements OTEApi { status = new OTEFutureImpl(executor.submit(new Configure(runtimeLibraryManager, configuration, callable))); currentConfigurationFuture = status; } else { - status = new OTEFutureImpl(new ConfigurationStatus(configuration, false, "Environment already configured.")); + status = new OTEFutureImpl(new ConfigurationStatus(configuration, false, generateConfigDiff(configuration, currentConfigurationFuture.get().getConfiguration()))); callable.complete(status.get()); } } finally { @@ -163,6 +182,45 @@ public final class OTEApiImpl implements OTEApi { return status; } + private String generateConfigDiff(Configuration configuration, Configuration configuration2) { + Collections.sort(configuration.getItems(), new ConfigurationItemComparator()); + Collections.sort(configuration2.getItems(), new ConfigurationItemComparator()); + StringBuilder missingBundles = new StringBuilder(); + StringBuilder extraBundles = new StringBuilder(); + StringBuilder differentVersion = new StringBuilder(); + for(ConfigurationItem item:configuration.getItems()){ + int i = Collections.binarySearch(configuration2.getItems(), item, new ConfigurationItemComparator()); + if(i >= 0 ){ + ConfigurationItem item2 = configuration2.getItems().get(i); + if(!item2.getVersion().equals(item.getVersion())){ + differentVersion.append(String.format("%s [%s] != [%s]\n", item.getSymbolicName(), item.getVersion(), item2.getVersion())); + } else if(!item2.getMd5Digest().equals(item.getMd5Digest())){ + differentVersion.append(String.format("%s binary contents do not match\n", item.getSymbolicName())); + } + } else { + missingBundles.append(String.format("%s missing\n", item.getSymbolicName())); + } + } + for(ConfigurationItem item:configuration2.getItems()){ + int i = Collections.binarySearch(configuration.getItems(), item, new ConfigurationItemComparator()); + if(i < 0 ){ + extraBundles.append(String.format("%s extra bundle\n", item.getSymbolicName())); + } + } + return differentVersion.toString() + missingBundles.toString() + extraBundles.toString(); + } + + private static class ConfigurationItemComparator implements Comparator<ConfigurationItem> { + + @Override + public int compare(ConfigurationItem arg0, ConfigurationItem arg1) { + return arg0.getSymbolicName().compareTo(arg1.getSymbolicName()); + } + + } + + + @Override public Future<ConfigurationStatus> resetConfiguration(OTEStatusCallback<ConfigurationStatus> callable) throws InterruptedException, ExecutionException { return loadConfiguration(emptyConfiguration, callable); @@ -213,4 +271,8 @@ public final class OTEApiImpl implements OTEApi { return remoteMessageService; } + @Override + public IHostTestEnvironment getIHostTestEnvironment() { + return host; + } } diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/OTEBundleLoader.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/OTEBundleLoader.java index d8843cdcfd6..59e7b1c66ea 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/OTEBundleLoader.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/OTEBundleLoader.java @@ -217,7 +217,6 @@ public class OTEBundleLoader implements IRuntimeLibraryManager{ } installedBundles.clear(); - int count = 0; for (Bundle bundle : runningBundles) { try { String entry = bundle.getHeaders().get("Fragment-Host"); @@ -229,7 +228,6 @@ public class OTEBundleLoader implements IRuntimeLibraryManager{ result = false; statusCallback.error("Failed to stop and uninstall " + bundle.getSymbolicName(), ex); } - count++; } runningBundles.clear(); diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/OTEServerRuntimeCacheImpl.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/OTEServerRuntimeCacheImpl.java index f8038bd6392..99eace740e9 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/OTEServerRuntimeCacheImpl.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/OTEServerRuntimeCacheImpl.java @@ -17,7 +17,7 @@ import java.util.logging.Level; import org.eclipse.osee.framework.jdk.core.util.io.streams.StreamPumper; import org.eclipse.osee.framework.logging.OseeLog; import org.eclipse.osee.ote.OTEServerRuntimeCache; -import org.eclipse.osee.ote.OTEServerFolder; +import org.eclipse.osee.ote.io.OTEServerFolder; public class OTEServerRuntimeCacheImpl implements OTEServerRuntimeCache { diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/OTESystemOutConnection.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/OTESystemOutConnection.java new file mode 100644 index 00000000000..38a799c0ded --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/OTESystemOutConnection.java @@ -0,0 +1,91 @@ +package org.eclipse.osee.ote.internal; + +import java.io.IOException; + +import org.eclipse.osee.ote.endpoint.OteUdpEndpoint; +import org.eclipse.osee.ote.io.SystemOutput; +import org.eclipse.osee.ote.message.event.OteEventMessageUtil; +import org.eclipse.osee.ote.remote.messages.ConsoleInputMessage; +import org.osgi.framework.ServiceRegistration; +import org.osgi.service.event.Event; +import org.osgi.service.event.EventHandler; + +public class OTESystemOutConnection { + + private OteUdpEndpoint endpoint; + private SystemOutput output; + private OTESystemOutputHandler outputHandler; + private ServiceRegistration<EventHandler> subscribe; + + /** + * osgi + */ + public void start(){ + outputHandler = new OTESystemOutputHandler(endpoint); + output.addListener(outputHandler); + subscribe = OteEventMessageUtil.subscribe(ConsoleInputMessage.TOPIC, new ConsoleInputHandler(output)); + } + + /** + * osgi + */ + public void stop(){ + output.removeListener(outputHandler); + if(subscribe != null){ + subscribe.unregister(); + subscribe = null; + } + } + + /** + * osgi + */ + public void bindOteUdpEndpoint(OteUdpEndpoint endpoint){ + this.endpoint = endpoint; + } + + /** + * osgi + */ + public void unbindOteUdpEndpoint(OteUdpEndpoint endpoint){ + this.endpoint = null; + } + + /** + * osgi + */ + public void bindSystemOutput(SystemOutput output){ + this.output = output; + } + + /** + * osgi + */ + public void unbindSystemOutput(SystemOutput output){ + this.output = null; + } + + private static class ConsoleInputHandler implements EventHandler { + + private SystemOutput output; + private ConsoleInputMessage message; + + public ConsoleInputHandler(SystemOutput output) { + this.output = output; + message = new ConsoleInputMessage(); + } + + @Override + public void handleEvent(Event arg0) { + message.setBackingBuffer(OteEventMessageUtil.getBytes(arg0)); + try { + output.write(message.getString()); + } catch (IOException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + + } +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/OTESystemOutputHandler.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/OTESystemOutputHandler.java new file mode 100644 index 00000000000..3b825279d59 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/OTESystemOutputHandler.java @@ -0,0 +1,87 @@ +package org.eclipse.osee.ote.internal; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; + +import org.eclipse.osee.ote.core.CopyOnWriteNoIteratorList; +import org.eclipse.osee.ote.endpoint.OteUdpEndpoint; +import org.eclipse.osee.ote.endpoint.OteUdpEndpointSender; +import org.eclipse.osee.ote.io.SystemOutputListener; +import org.eclipse.osee.ote.remote.messages.ConsoleOutputMessage; + +public class OTESystemOutputHandler implements SystemOutputListener { + + private ByteBuffer buffer = ByteBuffer.allocate(4096); + private OteUdpEndpoint endpoint; + private ConsoleOutputMessage outputMessage; + private ScheduledExecutorService newSingleThreadScheduledExecutor; + + public OTESystemOutputHandler(OteUdpEndpoint endpoint) { + this.endpoint = endpoint; + outputMessage = new ConsoleOutputMessage(); + newSingleThreadScheduledExecutor = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { + @Override + public Thread newThread(Runnable arg0) { + Thread th = new Thread(arg0); + th.setDaemon(true); + th.setName("OTEConsole Send"); + return th; + } + }); + newSingleThreadScheduledExecutor.scheduleAtFixedRate(new Runnable(){ + @Override + public void run() { + send(); + } + }, 1000, 1000, TimeUnit.MILLISECONDS); + } + + @Override + public void close() throws IOException { + flush(); + } + + @Override + public synchronized void flush() throws IOException { + send(); + } + + public synchronized void send(){ + if(buffer.position() > 0){ + try{ + buffer.flip(); + outputMessage.setStringData(buffer); + buffer.clear(); + CopyOnWriteNoIteratorList<OteUdpEndpointSender> broadcastSenders = endpoint.getBroadcastSenders(); + OteUdpEndpointSender[] oteUdpEndpointSenders = broadcastSenders.get(); + for(int i = 0; i < oteUdpEndpointSenders.length; i++){ + oteUdpEndpointSenders[i].send(outputMessage); + } + } catch (Throwable th){ + } + } + } + + @Override + public synchronized void write(byte[] b, int off, int len) throws IOException { + while(len > 0){ + if(buffer.position() > 0 && buffer.remaining() <= len){ + flush(); + } + int length = (buffer.remaining() < len) ? buffer.remaining() : len; + len = len - length; + buffer.put(b, off, length); + off += length; + } + } + + @Override + public synchronized void write(byte[] b) throws IOException { + write(b, 0, b.length); + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/RemoteOteApiHandler.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/RemoteOteApiHandler.java new file mode 100644 index 00000000000..12e976bfcd3 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/RemoteOteApiHandler.java @@ -0,0 +1,103 @@ +package org.eclipse.osee.ote.internal; + +import org.eclipse.osee.ote.OTEApi; +import org.eclipse.osee.ote.endpoint.OteUdpEndpoint; +import org.eclipse.osee.ote.message.event.OteEventMessageUtil; +import org.eclipse.osee.ote.remote.messages.RequestHostEnvironmentProperties; +import org.eclipse.osee.ote.remote.messages.RunTestsSerialized; +import org.eclipse.osee.ote.remote.messages.SerializedConfigurationAndResponse; +import org.eclipse.osee.ote.remote.messages.SerializedDisconnectRemoteTestEnvironment; +import org.eclipse.osee.ote.remote.messages.SerializedRequestRemoteTestEnvironment; +import org.eclipse.osee.ote.remote.messages.TestEnvironmentServerShutdown; +import org.eclipse.osee.ote.remote.messages.TestEnvironmentSetBatchMode; +import org.eclipse.osee.ote.remote.messages.TestEnvironmentTransferFile; +import org.osgi.framework.ServiceRegistration; +import org.osgi.service.event.EventAdmin; +import org.osgi.service.event.EventHandler; + +public class RemoteOteApiHandler { + + private EventAdmin eventAdmin; + private OTEApi oteApi; + private OteUdpEndpoint oteEndpoint; + private ServiceRegistration<EventHandler> configureAndResponse; + private ServiceRegistration<EventHandler> getProperties; + private ServiceRegistration<EventHandler> getConnection; + private ServiceRegistration<EventHandler> disconnect; + private ServiceRegistration<EventHandler> runTests; + private ServiceRegistration<EventHandler> setBatchMode; + private ServiceRegistration<EventHandler> transferFile; + private ServiceRegistration<EventHandler> serverShutdown; + + /** + * osgi + */ + public void bindEventAdmin(EventAdmin eventAdmin){ + this.eventAdmin = eventAdmin; + } + + /** + * osgi + */ + public void unbindEventAdmin(EventAdmin eventAdmin){ + this.eventAdmin = null; + } + + /** + * osgi + */ + public void bindOTEApi(OTEApi oteApi){ + this.oteApi = oteApi; + } + + /** + * osgi + */ + public void unbindOTEApi(OTEApi oteApi){ + this.oteApi = null; + } + + /** + * osgi + */ + public void bindOteUdpEndpoint(OteUdpEndpoint oteEndpoint){ + this.oteEndpoint = oteEndpoint; + } + + /** + * osgi + */ + public void unbindOteUdpEndpoint(OteUdpEndpoint oteEndpoint){ + this.oteEndpoint = null; + } + + + /** + * osgi + */ + public void start(){ + configureAndResponse = OteEventMessageUtil.subscribe(SerializedConfigurationAndResponse.EVENT, new ConfigureAndResponseListener(eventAdmin, oteEndpoint, oteApi)); + getProperties = OteEventMessageUtil.subscribe(RequestHostEnvironmentProperties.TOPIC, new GetPropertiesListener(eventAdmin, oteEndpoint, oteApi)); + getConnection = OteEventMessageUtil.subscribe(SerializedRequestRemoteTestEnvironment.TOPIC, new ConnectionListener(eventAdmin, oteEndpoint, oteApi)); + disconnect = OteEventMessageUtil.subscribe(SerializedDisconnectRemoteTestEnvironment.TOPIC, new DisconnectListener(eventAdmin, oteEndpoint, oteApi)); + runTests = OteEventMessageUtil.subscribe(RunTestsSerialized.RUNTESTS_NAMESPACE + "*", new RunTestListener(eventAdmin, oteEndpoint, oteApi)); + setBatchMode = OteEventMessageUtil.subscribe(TestEnvironmentSetBatchMode.TOPIC, new SetBatchModeListener(eventAdmin, oteEndpoint, oteApi)); + transferFile = OteEventMessageUtil.subscribe(TestEnvironmentTransferFile.TOPIC, new TransferFileToClientListener(eventAdmin, oteEndpoint, oteApi)); + serverShutdown = OteEventMessageUtil.subscribe(TestEnvironmentServerShutdown.TOPIC, new ServerShutdownListener(eventAdmin, oteEndpoint, oteApi)); + } + + /** + * osgi + */ + public void stop(){ + configureAndResponse.unregister(); + getProperties.unregister(); + getConnection.unregister(); + disconnect.unregister(); + runTests.unregister(); + setBatchMode.unregister(); + transferFile.unregister(); + serverShutdown.unregister(); + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/RunTestListener.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/RunTestListener.java new file mode 100644 index 00000000000..9816f6a665d --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/RunTestListener.java @@ -0,0 +1,110 @@ +package org.eclipse.osee.ote.internal; + +import java.io.IOException; +import java.rmi.server.ExportException; +import java.util.concurrent.ConcurrentHashMap; + +import org.eclipse.osee.ote.OTEApi; +import org.eclipse.osee.ote.core.framework.command.ICommandHandle; +import org.eclipse.osee.ote.core.framework.command.ITestCommandResult; +import org.eclipse.osee.ote.core.framework.command.RunTests; +import org.eclipse.osee.ote.endpoint.OteUdpEndpoint; +import org.eclipse.osee.ote.message.event.OteEventMessage; +import org.eclipse.osee.ote.message.event.OteEventMessageUtil; +import org.eclipse.osee.ote.remote.messages.BooleanResponse; +import org.eclipse.osee.ote.remote.messages.RunTestsCancel; +import org.eclipse.osee.ote.remote.messages.RunTestsGetCommandResultReq; +import org.eclipse.osee.ote.remote.messages.RunTestsGetCommandResultResp; +import org.eclipse.osee.ote.remote.messages.RunTestsIsCancelled; +import org.eclipse.osee.ote.remote.messages.RunTestsIsDone; +import org.eclipse.osee.ote.remote.messages.RunTestsSerialized; +import org.osgi.service.event.Event; +import org.osgi.service.event.EventAdmin; +import org.osgi.service.event.EventHandler; + +public class RunTestListener implements EventHandler { + + private OTEApi oteApi; + + private ConcurrentHashMap<String, ICommandHandle> handles; + + public RunTestListener(EventAdmin eventAdmin, OteUdpEndpoint oteEndpoint, OTEApi oteApi) { + this.oteApi = oteApi; + handles = new ConcurrentHashMap<String, ICommandHandle>(); + } + + @Override + public void handleEvent(Event event) { + if(oteApi.getTestEnvironment() == null){ + return; + } + OteEventMessage generic = OteEventMessageUtil.getOteEventMessage(event); + if(RunTestsSerialized.TOPIC.equals(generic.getHeader().TOPIC.getValue())){ + RunTestsSerialized serialized = new RunTestsSerialized(OteEventMessageUtil.getBytes(event)); + try { + RunTests runTests = serialized.getObject(); + String guid = runTests.getGUID(); + ICommandHandle addCommand = oteApi.getTestEnvironment().addCommand(runTests); + handles.put(guid, addCommand); + } catch (ExportException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } else if (RunTestsCancel.TOPIC.equals(generic.getHeader().TOPIC.getValue())){ + BooleanResponse booleanResponse = new BooleanResponse(); + RunTestsCancel cancel = new RunTestsCancel(OteEventMessageUtil.getBytes(event)); + ICommandHandle iCommandHandle = handles.get(cancel.GUID.getValue()); + boolean status = false; + if(iCommandHandle != null){ + if(cancel.CANCEL_ALL.getValue()){ + status = iCommandHandle.cancelAll(true); + } else { + status = iCommandHandle.cancelSingle(true); + } + } + booleanResponse.VALUE.setValue(status); + booleanResponse.setResponse(cancel); + OteEventMessageUtil.postEvent(booleanResponse); + } else if (RunTestsGetCommandResultReq.TOPIC.equals(generic.getHeader().TOPIC.getValue())){ + RunTestsGetCommandResultReq req = new RunTestsGetCommandResultReq(OteEventMessageUtil.getBytes(event)); + ICommandHandle iCommandHandle = handles.get(req.GUID.getValue()); + RunTestsGetCommandResultResp resp = new RunTestsGetCommandResultResp(); + if(iCommandHandle != null){ + ITestCommandResult iTestCommandResult = iCommandHandle.get(); + try { + resp.setObject(iTestCommandResult); + } catch (IOException e) { + e.printStackTrace(); + } + } + resp.setResponse(req); + OteEventMessageUtil.postEvent(resp); + } else if (RunTestsIsCancelled.TOPIC.equals(generic.getHeader().TOPIC.getValue())){ + BooleanResponse booleanResponse = new BooleanResponse(); + RunTestsIsCancelled isCanceled = new RunTestsIsCancelled(OteEventMessageUtil.getBytes(event)); + ICommandHandle iCommandHandle = handles.get(isCanceled.GUID.getValue()); + boolean status = false; + if(iCommandHandle != null){ + status = iCommandHandle.isCancelled(); + } + booleanResponse.VALUE.setValue(status); + booleanResponse.setResponse(isCanceled); + OteEventMessageUtil.postEvent(booleanResponse); + } else if (RunTestsIsDone.TOPIC.equals(generic.getHeader().TOPIC.getValue())){ + BooleanResponse booleanResponse = new BooleanResponse(); + RunTestsIsDone isDone = new RunTestsIsDone(OteEventMessageUtil.getBytes(event)); + ICommandHandle iCommandHandle = handles.get(isDone.GUID.getValue()); + boolean status = false; + if(iCommandHandle != null){ + status = iCommandHandle.isDone(); + } + booleanResponse.VALUE.setValue(status); + booleanResponse.setResponse(isDone); + OteEventMessageUtil.postEvent(booleanResponse); + } + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/ServerShutdownListener.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/ServerShutdownListener.java new file mode 100644 index 00000000000..a70b0f9f3f0 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/ServerShutdownListener.java @@ -0,0 +1,69 @@ +package org.eclipse.osee.ote.internal; + +import java.rmi.RemoteException; + +import org.eclipse.osee.ote.OTEApi; +import org.eclipse.osee.ote.endpoint.OteUdpEndpoint; +import org.eclipse.osee.ote.message.event.OteEventMessageUtil; +import org.eclipse.osee.ote.remote.messages.TestEnvironmentServerShutdown; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; +import org.osgi.framework.FrameworkUtil; +import org.osgi.service.event.Event; +import org.osgi.service.event.EventAdmin; +import org.osgi.service.event.EventHandler; + +public class ServerShutdownListener implements EventHandler { + + private OTEApi oteApi; + + public ServerShutdownListener(EventAdmin eventAdmin, OteUdpEndpoint oteEndpoint, OTEApi oteApi) { + this.oteApi = oteApi; + } + + @Override + public void handleEvent(Event arg0) { + if(oteApi.getIHostTestEnvironment() == null){ + return; + } + TestEnvironmentServerShutdown serverShutdown = new TestEnvironmentServerShutdown(OteEventMessageUtil.getBytes(arg0)); + String id; + try { + id = (String)oteApi.getIHostTestEnvironment().getProperties().getProperty("id", "dontknow"); + if(serverShutdown.SERVER_ID.getValue().equals(id)){ + shutdown(); + } + } catch (RemoteException e) { + e.printStackTrace(); + } + } + + private void shutdown(){ + BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext(); + Bundle systemBundle = context.getBundle(0); + try { + systemBundle.stop(); + boolean canExit = false; + while(!canExit){ + try{ + Thread.sleep(20); + } catch (Throwable th){ + } + canExit = true; + try{ + for(Bundle b:context.getBundles()){ + if(b.getState() != Bundle.ACTIVE){ + canExit = false; + } + } + } catch (Throwable th){ + canExit = true; + } + } + } catch (BundleException e) { + } + System.exit(0); + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/SetBatchModeListener.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/SetBatchModeListener.java new file mode 100644 index 00000000000..1c179c51414 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/SetBatchModeListener.java @@ -0,0 +1,28 @@ +package org.eclipse.osee.ote.internal; + +import org.eclipse.osee.ote.OTEApi; +import org.eclipse.osee.ote.endpoint.OteUdpEndpoint; +import org.eclipse.osee.ote.message.event.OteEventMessageUtil; +import org.eclipse.osee.ote.remote.messages.TestEnvironmentSetBatchMode; +import org.osgi.service.event.Event; +import org.osgi.service.event.EventAdmin; +import org.osgi.service.event.EventHandler; + +public class SetBatchModeListener implements EventHandler { + + private OTEApi oteApi; + + public SetBatchModeListener(EventAdmin eventAdmin, OteUdpEndpoint oteEndpoint, OTEApi oteApi) { + this.oteApi = oteApi; + } + + @Override + public void handleEvent(Event arg0) { + if(oteApi.getTestEnvironment() == null){ + return; + } + TestEnvironmentSetBatchMode testEnvironmentSetBatchMode = new TestEnvironmentSetBatchMode(OteEventMessageUtil.getBytes(arg0)); + oteApi.getTestEnvironment().setBatchMode(testEnvironmentSetBatchMode.SET_BATCH_MODE.getValue()); + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/SubscriptionCommandListener.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/SubscriptionCommandListener.java index 504203577a7..6b8182a3e0f 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/SubscriptionCommandListener.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/SubscriptionCommandListener.java @@ -17,12 +17,10 @@ import org.osgi.service.event.EventHandler; public class SubscriptionCommandListener implements EventHandler { - private final EventAdmin eventAdmin; private final IRemoteMessageService messageService; private final SerializedSubscribeToMessage cmd; public SubscriptionCommandListener(EventAdmin eventAdmin, IRemoteMessageService messageService) { - this.eventAdmin = eventAdmin; this.messageService = messageService; cmd = new SerializedSubscribeToMessage(); } diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/TransferFileToClientListener.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/TransferFileToClientListener.java new file mode 100644 index 00000000000..c376e323bc5 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/TransferFileToClientListener.java @@ -0,0 +1,54 @@ +package org.eclipse.osee.ote.internal; + +import java.io.File; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.UnknownHostException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadFactory; + +import org.eclipse.osee.ote.OTEApi; +import org.eclipse.osee.ote.endpoint.OteUdpEndpoint; +import org.eclipse.osee.ote.filetransfer.TcpFileTransfer; +import org.eclipse.osee.ote.message.event.OteEventMessageUtil; +import org.eclipse.osee.ote.remote.messages.TestEnvironmentTransferFile; +import org.osgi.service.event.Event; +import org.osgi.service.event.EventAdmin; +import org.osgi.service.event.EventHandler; + +public class TransferFileToClientListener implements EventHandler { + + private ExecutorService pool; + private OTEApi oteApi; + + public TransferFileToClientListener(EventAdmin eventAdmin, OteUdpEndpoint oteEndpoint, OTEApi oteApi) { + this.oteApi = oteApi; + pool = Executors.newCachedThreadPool(new ThreadFactory() { + @Override + public Thread newThread(Runnable arg0) { + Thread th = new Thread(arg0); + th.setName("OTE File Transfer"); + return th; + } + }); + } + + @Override + public void handleEvent(Event arg0) { + if(oteApi.getTestEnvironment() == null){ + return; + } + TestEnvironmentTransferFile testEnvironmentTransferFile = new TestEnvironmentTransferFile(OteEventMessageUtil.getBytes(arg0)); + InetSocketAddress inetSocketAddress; + try { + inetSocketAddress = new InetSocketAddress(testEnvironmentTransferFile.ADDRESS.getAddress(), testEnvironmentTransferFile.ADDRESS.getPort()); + TcpFileTransfer.sendFile(pool, new File(testEnvironmentTransferFile.FILE_PATH.getValue()), inetSocketAddress); + } catch (UnknownHostException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/UnSubscribeCommandListener.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/UnSubscribeCommandListener.java index 160621799e1..11d9d55cb0f 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/UnSubscribeCommandListener.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/UnSubscribeCommandListener.java @@ -15,12 +15,10 @@ import org.osgi.service.event.EventHandler; public class UnSubscribeCommandListener implements EventHandler { - private final EventAdmin eventAdmin; private final IRemoteMessageService messageService; private final SerializedUnSubscribeMessage cmd; public UnSubscribeCommandListener(EventAdmin eventAdmin, IRemoteMessageService messageService) { - this.eventAdmin = eventAdmin; this.messageService = messageService; cmd = new SerializedUnSubscribeMessage(); } diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/endpoint/EndpointComponent.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/endpoint/EndpointComponent.java new file mode 100644 index 00000000000..c5a35e56e80 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/endpoint/EndpointComponent.java @@ -0,0 +1,127 @@ +package org.eclipse.osee.ote.internal.endpoint; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.util.HashMap; + +import org.eclipse.osee.framework.jdk.core.util.network.PortUtil; +import org.eclipse.osee.ote.core.CopyOnWriteNoIteratorList; +import org.eclipse.osee.ote.endpoint.EndpointDataProcessor; +import org.eclipse.osee.ote.endpoint.OteUdpEndpoint; +import org.eclipse.osee.ote.endpoint.OteUdpEndpointReceiverImpl; +import org.eclipse.osee.ote.endpoint.OteUdpEndpointSender; +import org.eclipse.osee.ote.properties.OtePropertiesCore; + +public class EndpointComponent implements OteUdpEndpoint { + + private OteUdpEndpointReceiverImpl receiver; + private HashMap<InetSocketAddress, OteUdpEndpointSender> senders = new HashMap<InetSocketAddress, OteUdpEndpointSender>(); + private CopyOnWriteNoIteratorList<OteUdpEndpointSender> broadcast = new CopyOnWriteNoIteratorList<OteUdpEndpointSender>(OteUdpEndpointSender.class); + private boolean debug = false; + + public EndpointComponent(){ + int port; + try { + String strPort = OtePropertiesCore.endpointPort.getValue(Integer.toString(PortUtil.getInstance().getValidPort())); + try{ + port = Integer.parseInt(strPort); + } catch (Throwable th){ + port = PortUtil.getInstance().getValidPort(); + } + receiver = new OteUdpEndpointReceiverImpl(new InetSocketAddress(InetAddress.getLocalHost(), port)); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void start(){ + receiver.start(); + setDebugOutput(false); + } + + public synchronized void stop(){ + receiver.stop(); + for(OteUdpEndpointSender sender: senders.values()){ + try { + sender.stop(); + } catch (Throwable e) { + e.printStackTrace(); + } + } + } + + @Override + public void setDebugOutput(boolean debug) { + String ioRedirect = OtePropertiesCore.ioRedirect.getValue(); + if(ioRedirect != null){ + if(Boolean.parseBoolean(ioRedirect)){ + this.debug = false; + System.out.println("Unable to enable Endpoint debug because -Dote.io.redirect is enabled."); + return; + } + } + this.debug = debug; + receiver.setDebugOutput(debug); + for(OteUdpEndpointSender sender: senders.values()){ + sender.setDebug(debug); + } + } + + @Override + public InetSocketAddress getLocalEndpoint() { + return receiver.getEndpoint(); + } + + @Override + public synchronized OteUdpEndpointSender getOteEndpointSender(InetSocketAddress address) { + OteUdpEndpointSender sender = senders.get(address); + if(sender == null || (sender != null && sender.isClosed())){ + sender = new OteUdpEndpointSender(address); + sender.setDebug(debug); + sender.start(); + senders.put(address, sender); + } + return sender; + } + + @Override + public void addBroadcast(OteUdpEndpointSender sender) { + if(!isAlreadyInBroadcastList(sender)){ + broadcast.add(sender); + } + } + + private boolean isAlreadyInBroadcastList(OteUdpEndpointSender sender) { + OteUdpEndpointSender[] oteUdpEndpointSenders = broadcast.get(); + for(int i = 0; i < oteUdpEndpointSenders.length; i++) { + if(oteUdpEndpointSenders[i].getAddress().getPort() == sender.getAddress().getPort()){ + if(oteUdpEndpointSenders[i].getAddress().getAddress().equals(sender.getAddress().getAddress())){ + return true; + } + } + } + return false; + } + + @Override + public void removeBroadcast(OteUdpEndpointSender sender) { + broadcast.remove(sender); + } + + @Override + public CopyOnWriteNoIteratorList<OteUdpEndpointSender> getBroadcastSenders() { + return broadcast; + } + + @Override + public void addDataProcessor(EndpointDataProcessor processor) { + receiver.addDataProcessor(processor); + } + + @Override + public void removeDataProcessor(EndpointDataProcessor processor) { + receiver.removeDataProcessor(processor); + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/message/event/send/NotifyOnResponse.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/message/event/send/NotifyOnResponse.java index 2c9abe7a58e..ec37344e5e1 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/message/event/send/NotifyOnResponse.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/message/event/send/NotifyOnResponse.java @@ -39,6 +39,7 @@ public class NotifyOnResponse<T extends OteEventMessage> implements EventHandler reg = OteEventMessageUtil.subscribe(responseTopic, this); } + @SuppressWarnings("unchecked") public NotifyOnResponse(T responseMessage, int responseId2, Lock lock2, Condition responseReceived2) { this((Class<T>)responseMessage.getClass(), responseMessage.getHeader().TOPIC.getValue(), responseId2, lock2, responseReceived2); this.responseMessage = responseMessage; diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/message/event/send/OteEventMessageFutureImpl.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/message/event/send/OteEventMessageFutureImpl.java index 6af5857db94..482d799e5db 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/message/event/send/OteEventMessageFutureImpl.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/message/event/send/OteEventMessageFutureImpl.java @@ -32,16 +32,17 @@ import org.osgi.service.event.EventHandler; public class OteEventMessageFutureImpl<T extends OteEventMessage, R extends OteEventMessage> implements OteEventMessageFuture<T, R>, EventHandler{ private final ServiceRegistration<EventHandler> reg; - private final OteEventMessageCallable<T, R> callable; - private final Class<R> recieveClasstype; - private final int responseId; - private final T sentMessage; + protected final OteEventMessageCallable<T, R> callable; + protected final Class<R> recieveClasstype; + protected final int responseId; + protected final T sentMessage; private final ScheduledExecutorService ex; private final ReentrantLock lock; private final Condition condition; private final ScheduledFuture<?> wakeup; private TimeoutRunnable<T, R> timeoutRunnable; - private volatile boolean gotResponse = false; + protected volatile boolean gotResponse = false; + protected volatile boolean isDone = false; public OteEventMessageFutureImpl(Class<R> recieveClasstype, OteEventMessageCallable<T, R> callable, T sentMessage, String responseTopic, int responseId, long timeout) { this.callable = callable; @@ -55,6 +56,7 @@ public class OteEventMessageFutureImpl<T extends OteEventMessage, R extends OteE @Override public Thread newThread(Runnable arg0) { Thread th = new Thread(arg0); + th.setDaemon(true); th.setName("OteEventMessage Timeout"); return th; } @@ -71,13 +73,8 @@ public class OteEventMessageFutureImpl<T extends OteEventMessage, R extends OteE if(msg.getHeader().RESPONSE_ID.getValue() == responseId){ cancel(); gotResponse = true; - callable.call(sentMessage, msg); - lock.lock(); - try{ - condition.signal(); - } finally { - lock.unlock(); - } + callable.call(sentMessage, msg, this); + executeCondition(); } } catch (InstantiationException e) { e.printStackTrace(); @@ -86,6 +83,15 @@ public class OteEventMessageFutureImpl<T extends OteEventMessage, R extends OteE } } + protected final void executeCondition(){ + lock.lock(); + try{ + condition.signal(); + } finally { + lock.unlock(); + } + } + @Override public void cancel(){ dispose(); @@ -117,9 +123,21 @@ public class OteEventMessageFutureImpl<T extends OteEventMessage, R extends OteE return gotResponse ; } + @Override + public void complete(){ + cancel(); + executeCondition(); + } + private void dispose(){ reg.unregister(); wakeup.cancel(false); this.ex.shutdown(); + isDone = true; + } + + @Override + public boolean isDone() { + return isDone; } } diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/message/event/send/OteEventMessageFutureMultipleResponseImpl.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/message/event/send/OteEventMessageFutureMultipleResponseImpl.java new file mode 100644 index 00000000000..fafd13ba4be --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/message/event/send/OteEventMessageFutureMultipleResponseImpl.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.internal.message.event.send; + +import org.eclipse.osee.ote.message.event.OteEventMessage; +import org.eclipse.osee.ote.message.event.OteEventMessageUtil; +import org.eclipse.osee.ote.message.event.send.OteEventMessageCallable; +import org.osgi.service.event.Event; + + +public class OteEventMessageFutureMultipleResponseImpl<T extends OteEventMessage, R extends OteEventMessage> extends OteEventMessageFutureImpl<T, R> { + + + public OteEventMessageFutureMultipleResponseImpl(Class<R> recieveClasstype, OteEventMessageCallable<T, R> callable, T sentMessage, String responseTopic, int responseId, long timeout) { + super(recieveClasstype, callable, sentMessage, responseTopic, responseId, timeout); + } + + @Override + public void handleEvent(Event event) { + try { + R msg = recieveClasstype.newInstance(); + OteEventMessageUtil.putBytes(event, msg); + callable.call(sentMessage, msg, this); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/Message.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/Message.java index f2ee58b3808..2b9541cdae2 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/Message.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/Message.java @@ -81,6 +81,7 @@ public abstract class Message<S extends ITestEnvironmentMessageSystemAccessor, T private boolean regularUnscheduleCalled = false; private boolean isTurnedOff = false; + @SuppressWarnings("rawtypes") private IMessageRequestor messageRequestor = null; private static final double doubleTolerance = 0.000001; private final Set<DataType> memTypeActive = new HashSet<DataType>(); @@ -1141,6 +1142,7 @@ public abstract class Message<S extends ITestEnvironmentMessageSystemAccessor, T /** * @param defaultMessageData the defaultMessageData to set */ + @SuppressWarnings("unchecked") protected void setDefaultMessageData(T defaultMessageData) { checkState(); this.defaultMessageData = defaultMessageData; @@ -1228,10 +1230,12 @@ public abstract class Message<S extends ITestEnvironmentMessageSystemAccessor, T public void switchElementAssociation(Collection<U> messages) { } + @SuppressWarnings("rawtypes") public Map<? extends DataType, Class<? extends Message>[]> getAssociatedMessages() { return new HashMap<DataType, Class<? extends Message>[]>(); } + @SuppressWarnings({ "rawtypes", "unchecked" }) public void postCreateMessageSetup(IMessageManager messageManager, MessageData data) throws Exception { Map<? extends DataType, Class<? extends Message>[]> o = getAssociatedMessages(); messageRequestor = messageManager.createMessageRequestor(getName()); diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/MessageEventLogger.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/MessageEventLogger.java index 13684bb7cc3..0f2b7a06b5d 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/MessageEventLogger.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/MessageEventLogger.java @@ -18,7 +18,6 @@ import org.eclipse.osee.ote.message.enums.DataType; * @author Ken J. Aguilar */ public class MessageEventLogger implements UniversalMessageListener { - private static final String BUNDLE = "org.eclipse.osee.ote.message"; private static final class StackTrace extends RuntimeException { private static final long serialVersionUID = 6805422596135323489L; diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/data/MessageData.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/data/MessageData.java index 879731aaf80..3ebeb8cbac7 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/data/MessageData.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/data/MessageData.java @@ -50,14 +50,15 @@ import org.eclipse.osee.ote.messaging.dds.status.RequestedIncompatibleQosStatus; import org.eclipse.osee.ote.messaging.dds.status.SampleLostStatus; import org.eclipse.osee.ote.messaging.dds.status.SampleRejectedStatus; import org.eclipse.osee.ote.messaging.dds.status.SubscriptionMatchStatus; +import org.eclipse.osee.ote.properties.OtePropertiesCore; /** * @author Andrew M. Finkbeiner */ public abstract class MessageData implements DataReaderListener, DataWriterListener, Data, Key { - private static int debugTimeout = Integer.parseInt(System.getProperty("ote.time.debug.timeout", "250000")); - private static boolean debugTime = Boolean.parseBoolean(System.getProperty("ote.time.debug", "false")); + private static long debugTimeout = OtePropertiesCore.timeDebugTimeout.getLongValue(); + private static boolean debugTime = OtePropertiesCore.timeDebug.getBooleanValue(); private DataWriter writer; private DataReader reader; diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/ADDRESS_TYPE.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/ADDRESS_TYPE.java index f37a177a692..5f0a443f416 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/ADDRESS_TYPE.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/ADDRESS_TYPE.java @@ -1,7 +1,7 @@ /* * PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE */ -package org.eclipse.osee.ote.remote.messages; +package org.eclipse.osee.ote.message.event; import org.eclipse.osee.ote.message.elements.IEnumValue; diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/MyObjectInputStream.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/MyObjectInputStream.java index 24d3f99c9df..caf4936e35f 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/MyObjectInputStream.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/MyObjectInputStream.java @@ -9,9 +9,9 @@ import org.eclipse.osee.framework.plugin.core.util.ExportClassLoader; public class MyObjectInputStream extends ObjectInputStream { + @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { - ClassLoader currentTccl = null; try { return ExportClassLoader.getInstance().loadClass(desc.getName()); } catch (Exception e) { diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/OteEventMessage.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/OteEventMessage.java index f42a814d91f..1975d60e486 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/OteEventMessage.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/OteEventMessage.java @@ -69,4 +69,8 @@ public class OteEventMessage extends Message<MessageSystemTestEnvironment, OteEv return 8*size-1; } + public void setResponse(OteEventMessage msg){ + getHeader().RESPONSE_ID.setValue(msg.getHeader().MESSAGE_SEQUENCE_NUMBER.getValue()); + } + } diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/OteEventMessageHeader.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/OteEventMessageHeader.java index 500ff76519a..cdfc4480ee7 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/OteEventMessageHeader.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/OteEventMessageHeader.java @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.osee.ote.message.event; +import java.net.InetSocketAddress; +import java.net.UnknownHostException; + import org.eclipse.osee.ote.message.IMessageHeader; import org.eclipse.osee.ote.message.data.HeaderData; import org.eclipse.osee.ote.message.data.MemoryResource; @@ -20,7 +23,7 @@ import org.eclipse.osee.ote.message.elements.StringElement; public class OteEventMessageHeader implements IMessageHeader{ - public static final int HEADER_SIZE = 162; + public static final int HEADER_SIZE = 164+53; public static final int MARKER_VALUE = 0xFADE; private final HeaderData headerData; private final Object[] paths; @@ -34,6 +37,8 @@ public class OteEventMessageHeader implements IMessageHeader{ public final IntegerElement TTL; public final StringElement RESPONSE_TOPIC; public final IntegerElement RESPONSE_ID; + public final SOCKET_ADDRESS_RECORD ADDRESS; + private final String name; public OteEventMessageHeader(OteEventMessage msg, String topic, int messageId, MemoryResource data) { @@ -41,14 +46,16 @@ public class OteEventMessageHeader implements IMessageHeader{ headerData = new HeaderData("OteEventMessageHeader", data); paths = new Object[]{(msg == null ? "message" : msg.getClass().getName()), "HEADER(OteEventMessageHeader)"}; MARKER = new IntegerElement(msg, "MARKER", headerData, 0, 0, 15); - TOPIC = new StringElement(msg, "TOPIC", headerData, 2, 0, 8*64); - MESSAGE_ID = new IntegerElement(msg, "MESSAGE_ID", headerData, 66, 0, 31); - MESSAGE_SEQUENCE_NUMBER = new IntegerElement(msg, "MESSAGE_ID", headerData, 66, 0, 31); - UUID_LOW = new LongIntegerElement(msg, "UUID_LOW", headerData, 74, 0, 63); - UUID_HIGH = new LongIntegerElement(msg, "UUID_HIGH", headerData, 82, 0, 63); - TTL = new IntegerElement(msg, "TTL", headerData, 90, 0, 31); - RESPONSE_TOPIC = new StringElement(msg, "TOPIC", headerData, 94, 0, 8*64); - RESPONSE_ID = new IntegerElement(msg, "RESPONSE_ID", headerData, 158, 0, 31); + TOPIC = new StringElement(msg, "TOPIC", headerData, 2, 0, 8*96); + MESSAGE_ID = new IntegerElement(msg, "MESSAGE_ID", headerData, 66+32, 0, 31); + MESSAGE_SEQUENCE_NUMBER = new IntegerElement(msg, "MESSAGE_ID", headerData, 66+32, 0, 31); + UUID_LOW = new LongIntegerElement(msg, "UUID_LOW", headerData, 74+32, 0, 63); + UUID_HIGH = new LongIntegerElement(msg, "UUID_HIGH", headerData, 82+32, 0, 63); + TTL = new IntegerElement(msg, "TTL", headerData, 90+32, 0, 31); + RESPONSE_TOPIC = new StringElement(msg, "TOPIC", headerData, 94+32, 0, 8*64); + RESPONSE_ID = new IntegerElement(msg, "RESPONSE_ID", headerData, 158+32, 0, 31); + ADDRESS = new SOCKET_ADDRESS_RECORD(msg, "ADDRESS", headerData, 164+32, 0, SOCKET_ADDRESS_RECORD.SIZE*8-1); + TOPIC.setValue(topic); MARKER.setValue(MARKER_VALUE); MESSAGE_ID.setValue(messageId); @@ -98,4 +105,8 @@ public class OteEventMessageHeader implements IMessageHeader{ return name; } + public InetSocketAddress getSourceInetSocketAddress() throws UnknownHostException { + return new InetSocketAddress(ADDRESS.getAddress(), ADDRESS.getPort()); + } + } diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/OteEventMessageUtil.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/OteEventMessageUtil.java index 09560126cc7..44590b12312 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/OteEventMessageUtil.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/OteEventMessageUtil.java @@ -17,6 +17,7 @@ import java.util.Map; import java.util.UUID; import org.eclipse.osee.ote.core.ServiceUtility; +import org.eclipse.osee.ote.endpoint.OteUdpEndpointSender; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; import org.osgi.service.event.Event; @@ -27,6 +28,8 @@ public class OteEventMessageUtil { public final static String BYTE_KEY = "oteeventbytes"; + public final static String BYTE_KEY_2 = "bytes"; + private static EventAdmin eventAdmin; private static EventAdmin getEventAdmin(){ @@ -61,6 +64,14 @@ public class OteEventMessageUtil { Event newevent = new Event(message.getHeader().TOPIC.getValue(), data); eventAdmin.postEvent(newevent); } + + public static void sendEvent(OteEventMessage message, OteUdpEndpointSender sender) throws InterruptedException { + sender.send(message); + } + + public static void postEvent(OteEventMessage message, OteUdpEndpointSender sender) throws InterruptedException { + sender.send(message); + } public static UUID getUUID(OteEventMessage msg) { return new UUID(msg.getHeader().UUID_HIGH.getValue(), msg.getHeader().UUID_LOW.getValue()); @@ -93,6 +104,11 @@ public class OteEventMessageUtil { Object obj = event.getProperty(BYTE_KEY); if (obj != null && obj instanceof byte[]) { return new OteEventMessage((byte[]) obj); + } else { + obj = event.getProperty(BYTE_KEY_2); + if(obj != null && obj instanceof byte[]){ + return new OteEventMessage((byte[]) obj); + } } return null; } @@ -102,6 +118,10 @@ public class OteEventMessageUtil { if (obj != null && obj instanceof byte[]) { return (byte[]) obj; } else { + obj = event.getProperty(BYTE_KEY_2); + if (obj != null && obj instanceof byte[]) { + return (byte[]) obj; + } return null; } } diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SOCKET_ADDRESS_RECORD.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/SOCKET_ADDRESS_RECORD.java index a6131be4944..90ced956d01 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SOCKET_ADDRESS_RECORD.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/SOCKET_ADDRESS_RECORD.java @@ -1,4 +1,4 @@ -package org.eclipse.osee.ote.remote.messages; +package org.eclipse.osee.ote.message.event; import java.net.InetAddress; import java.net.UnknownHostException; diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/SerializedClassMessage.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/SerializedClassMessage.java index fa52be90d4b..eda4166610e 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/SerializedClassMessage.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/SerializedClassMessage.java @@ -15,6 +15,8 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.Serializable; +import java.util.zip.GZIPInputStream; +import java.util.zip.GZIPOutputStream; import org.eclipse.osee.ote.message.elements.ArrayElement; @@ -44,8 +46,10 @@ public class SerializedClassMessage<T> extends OteEventMessage { public void setObject(Serializable obj) throws IOException{ ByteArrayOutputStream bos = new ByteArrayOutputStream(); - ObjectOutputStream oos = new ObjectOutputStream(bos); + GZIPOutputStream gos = new GZIPOutputStream(bos); + ObjectOutputStream oos = new ObjectOutputStream(gos); oos.writeObject(obj); + oos.close(); byte[] data = bos.toByteArray(); int offset = OBJECT.getByteOffset() + getHeaderSize(); byte[] newData = new byte[data.length + offset]; @@ -54,11 +58,18 @@ public class SerializedClassMessage<T> extends OteEventMessage { getDefaultMessageData().setNewBackingBuffer(newData); } - public T getObject() throws IOException, ClassNotFoundException{ + @SuppressWarnings("unchecked") + public T getObject() throws IOException, ClassNotFoundException{ int offset = OBJECT.getByteOffset() + getHeaderSize(); ByteArrayInputStream bis = new ByteArrayInputStream(getData(), offset, getData().length - offset); - MyObjectInputStream ois = new MyObjectInputStream(bis); - return (T)ois.readObject(); + GZIPInputStream gis = new GZIPInputStream(bis); + MyObjectInputStream ois = new MyObjectInputStream(gis); + try{ + Object obj = ois.readObject(); + return (T)obj; + } finally { + ois.close(); + } } } diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/send/OteEndpointSendEventMessage.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/send/OteEndpointSendEventMessage.java new file mode 100644 index 00000000000..d818e6b51fb --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/send/OteEndpointSendEventMessage.java @@ -0,0 +1,193 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.message.event.send; + +import java.net.InetSocketAddress; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +import org.eclipse.osee.ote.OTEException; +import org.eclipse.osee.ote.endpoint.OteUdpEndpoint; +import org.eclipse.osee.ote.internal.message.event.send.NotifyOnResponse; +import org.eclipse.osee.ote.internal.message.event.send.OteEventMessageFutureImpl; +import org.eclipse.osee.ote.internal.message.event.send.OteEventMessageFutureMultipleResponseImpl; +import org.eclipse.osee.ote.internal.message.event.send.OteEventMessageResponseFutureImpl; +import org.eclipse.osee.ote.message.event.OteEventMessage; + +public class OteEndpointSendEventMessage { + + private final OteUdpEndpoint endpoint; + private final Lock lock; + private final Condition responseReceived; + private final InetSocketAddress destination; + + public OteEndpointSendEventMessage(OteUdpEndpoint eventAdmin, InetSocketAddress destination){ + this.endpoint = eventAdmin; + this.destination = destination; + lock = new ReentrantLock(); + responseReceived = lock.newCondition(); + } + + /** + * sends a message and returns immediately + */ + public void asynchSend(OteEventMessage message) { + updateHeaderInfo(message); + endpoint.getOteEndpointSender(destination).send(message); + } + + /** + * Registers for a callback of the given message type as specified by the RESPONSE_TOPIC element in the sent message + * and the class type passed in, then sends the given message and returns immediately. The returned value can be used to + * wait for the response using waitForCompletion(). The callback expects you to handle both the response and the timeout case. + * + * @param clazz - Type of OteEventMessage for the response + * @param message - message to send + * @param callable - callback executed when the response is recieved or if a timeout occurs or called immediately after the send if + * no response is expected + * @param timeout - amount of time in milliseconds to wait for response before calling timeout on the passed in OteEventMessageCallable + * @return <T extends OteEventMessage> Future<T> - a future that contains the response message + */ + public <T extends OteEventMessage, R extends OteEventMessage> OteEventMessageFuture<T, R> asynchSendAndResponse(Class<R> clazz, T message, OteEventMessageCallable<T, R> callable, long timeout){ + int responseId = updateHeaderInfo(message); + String responseTopic = message.getHeader().RESPONSE_TOPIC.getValue(); + OteEventMessageFutureImpl<T, R> response = new OteEventMessageFutureImpl<T, R>(clazz, callable, message, responseTopic, responseId, timeout); + endpoint.getOteEndpointSender(destination).send(message); + return response; + } + + /** + * Registers for a callback of the given message type as specified by the RESPONSE_TOPIC element in the sent message + * and the class type passed in, then sends the given message and returns immediately. The returned value can be used to + * wait for the response using waitForCompletion(). The callback expects you to handle both the response and the timeout case and to determine + * when the appropriate number of responses has been received, by specifying it is complete. + * + * @param clazz - Type of OteEventMessage for the response + * @param message - message to send + * @param callable - callback executed when the response is recieved or if a timeout occurs or called immediately after the send if + * no response is expected + * @param timeout - amount of time in milliseconds to wait for response before calling timeout on the passed in OteEventMessageCallable + * @return <T extends OteEventMessage> Future<T> - a future that contains the response message + */ + public <T extends OteEventMessage, R extends OteEventMessage> OteEventMessageFuture<T, R> asynchSendAndMultipleResponse(Class<R> clazz, T message, OteEventMessageCallable<T, R> callable, long timeout){ + int responseId = updateHeaderInfo(message); + String responseTopic = message.getHeader().RESPONSE_TOPIC.getValue(); + OteEventMessageFutureImpl<T, R> response = new OteEventMessageFutureMultipleResponseImpl<T,R>(clazz, callable, message, responseTopic, responseId, timeout); + endpoint.getOteEndpointSender(destination).send(message); + return response; + } + + /** + * Registers for a callback of the given message type and topic. + * + * @param clazz - Type of OteEventMessage for the response + * @param callable - callback executed when the response is recieved + * @return a future that you should cancel when done listening so resources can be cleaned up. + */ + public <R extends OteEventMessage> OteEventMessageResponseFuture<R> asynchResponse(Class<R> clazz, String topic, OteEventMessageResponseCallable<R> callable){ + OteEventMessageResponseFutureImpl<R> response = new OteEventMessageResponseFutureImpl<R>(clazz, callable, topic); + return response; + } + + /** + * Sends a message and waits for a response. + * + * @param class - return type + * @param message - message to send + * @param timeout - timeout in milliseconds + * @return <T extends OteEventMessage> T - NULL if the timeout occurs before a response, otherwise returns the + * message specified by the RESPONSE_TOPIC field in the passed in message header. + * @throws Exception + */ + public <T extends OteEventMessage> T synchSendAndResponse(Class<T> clazz, String responseTopic, OteEventMessage message, long timeout) throws OTEException { + lock.lock(); + try{ + int responseId = updateHeaderInfo(message); + message.getHeader().RESPONSE_TOPIC.setValue(responseTopic); + NotifyOnResponse<T> response = new NotifyOnResponse<T>(clazz, responseTopic, responseId, lock, responseReceived); + try{ + endpoint.getOteEndpointSender(destination).send(message); + long nanos = TimeUnit.MILLISECONDS.toNanos(timeout); + while(nanos > 0 && !response.hasResponse()) { + try { + nanos = responseReceived.awaitNanos(nanos); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } finally { + response.dispose(); + } + return response.getMessage(); + } finally { + lock.unlock(); + } + } + + /** + * Sends a message and waits for a response. + * + * @param T - response Message to populate type + * @param message - message to send + * @param timeout - timeout in milliseconds + * @return <T extends OteEventMessage> T - NULL if the timeout occurs before a response, otherwise returns the + * message specified by the RESPONSE_TOPIC field in the passed in message header. + * @throws Exception + */ + public <T extends OteEventMessage> T synchSendAndResponse(T responseMessage, OteEventMessage sendMessage, long timeout) throws OTEException { + lock.lock(); + try{ + int responseId = updateHeaderInfo(sendMessage); + sendMessage.getHeader().RESPONSE_TOPIC.setValue(responseMessage.getHeader().TOPIC.getValue()); + NotifyOnResponse<T> response = new NotifyOnResponse<T>(responseMessage, responseId, lock, responseReceived); + try{ + endpoint.getOteEndpointSender(destination).send(sendMessage); + long nanos = TimeUnit.MILLISECONDS.toNanos(timeout); + while(nanos > 0 && !response.hasResponse()) { + try { + nanos = responseReceived.awaitNanos(nanos); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } finally { + response.dispose(); + } + return response.getMessage(); + } finally { + lock.unlock(); + } + } + + + /** + * Increment the sequence number and set the source InetSocketAddress + * + * @param message + * @return returns the sequence number that was set + */ + private int updateHeaderInfo(OteEventMessage message){ + int responseId = message.getHeader().MESSAGE_SEQUENCE_NUMBER.getValue(); + if(responseId >= Integer.MAX_VALUE){ + responseId = 1; + } else { + responseId++; + } + message.getHeader().MESSAGE_SEQUENCE_NUMBER.setValue(responseId); + + message.getHeader().ADDRESS.setAddress(endpoint.getLocalEndpoint().getAddress()); + message.getHeader().ADDRESS.setPort(endpoint.getLocalEndpoint().getPort()); + return responseId; + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/send/OteEventMessageCallable.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/send/OteEventMessageCallable.java index 458e02ca000..fc9a2b889b9 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/send/OteEventMessageCallable.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/send/OteEventMessageCallable.java @@ -14,6 +14,6 @@ public interface OteEventMessageCallable<T,R> { void timeout(T transmitted); - void call(T transmitted, R recieved); + void call(T transmitted, R recieved, OteEventMessageFuture<?, ?> future); } diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/send/OteEventMessageFuture.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/send/OteEventMessageFuture.java index 6c41797a716..6b7a461d223 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/send/OteEventMessageFuture.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/event/send/OteEventMessageFuture.java @@ -20,7 +20,11 @@ public interface OteEventMessageFuture<T extends OteEventMessage, R extends OteE void waitForCompletion(); + public boolean isDone(); + public boolean isTimedOut(); public boolean gotResponse(); + + void complete(); } diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/interfaces/ITestEnvironmentMessageSystem.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/interfaces/ITestEnvironmentMessageSystem.java index e93ccafe89c..5060eb1ebc5 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/interfaces/ITestEnvironmentMessageSystem.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/interfaces/ITestEnvironmentMessageSystem.java @@ -19,7 +19,6 @@ import org.eclipse.osee.ote.message.IInstrumentationRegistrationListener; * @author Andrew M. Finkbeiner */ public interface ITestEnvironmentMessageSystem extends ITestEnvironment { -// IRemoteMessageService getMessageToolServiceProxy() throws RemoteException; void addInstrumentationRegistrationListener(IInstrumentationRegistrationListener listener) throws RemoteException; diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/listener/MessageSystemListener.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/listener/MessageSystemListener.java index 6e235e2781e..817cd0dc8b7 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/listener/MessageSystemListener.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/listener/MessageSystemListener.java @@ -31,6 +31,7 @@ import org.eclipse.osee.ote.message.elements.MsgWaitResult; import org.eclipse.osee.ote.message.enums.DataType; import org.eclipse.osee.ote.message.interfaces.IOSEEMessageReaderListener; import org.eclipse.osee.ote.message.interfaces.IOSEEMessageWriterListener; +import org.eclipse.osee.ote.properties.OtePropertiesCore; /** * @author Ryan D. Brooks @@ -38,9 +39,9 @@ import org.eclipse.osee.ote.message.interfaces.IOSEEMessageWriterListener; */ public class MessageSystemListener implements IOSEEMessageReaderListener, IOSEEMessageWriterListener, ITimeout { + private static long debugTimeout = OtePropertiesCore.timeDebugTimeout.getLongValue(); + private static boolean debugTime = OtePropertiesCore.timeDebug.getBooleanValue(); - private static int debugTimeout = Integer.parseInt(System.getProperty("ote.time.debug.timeout", "250000")); - private static boolean debugTime = Boolean.parseBoolean(System.getProperty("ote.time.debug", "false")); private volatile boolean isTimedOut = false; private int masterMessageCount = 0; diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/tool/rec/entry/EnumeratedElementEntry.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/tool/rec/entry/EnumeratedElementEntry.java index f1f931ba196..750a3785e22 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/tool/rec/entry/EnumeratedElementEntry.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/message/tool/rec/entry/EnumeratedElementEntry.java @@ -40,7 +40,7 @@ public class EnumeratedElementEntry implements IElementEntry { public void write(ByteBuffer buffer, MemoryResource mem, int limit) { mem.setOffset(element.getMsgData().getMem().getOffset()); Enum<?> val = element.valueOf(mem); - byte[] bytes = Integer.toString(((IEnumValue) val).getIntValue()).getBytes(); + byte[] bytes = Integer.toString(((IEnumValue<?>) val).getIntValue()).getBytes(); buffer.put(nameAsBytes).put(COMMA).put(valueToBytes[val.ordinal()]); buffer.put(SPACE_LEFT_PAREN).put(bytes).put(RIGHT_PAREN).put(COMMA); diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/BooleanResponse.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/BooleanResponse.java new file mode 100644 index 00000000000..f9a161f5f28 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/BooleanResponse.java @@ -0,0 +1,19 @@ +package org.eclipse.osee.ote.remote.messages; + +import org.eclipse.osee.ote.message.elements.BooleanElement; +import org.eclipse.osee.ote.message.event.OteEventMessage; + +public class BooleanResponse extends OteEventMessage { + + public static String TOPIC = "ote/message/boolresponse"; + + private static int SIZE = 1; + + public BooleanElement VALUE; + + public BooleanResponse() { + super("MESSAGE_META_DATA_STAT", TOPIC, SIZE); + VALUE = new BooleanElement(this, "IS_SCHEDULED", getDefaultMessageData(), 0, 0, 7); + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/ConfigurationAndResponse.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/ConfigurationAndResponse.java new file mode 100644 index 00000000000..44aa10aabe6 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/ConfigurationAndResponse.java @@ -0,0 +1,45 @@ +package org.eclipse.osee.ote.remote.messages; + +import java.io.Serializable; + +import org.eclipse.osee.ote.Configuration; + +public class ConfigurationAndResponse implements Serializable { + + private static final long serialVersionUID = 8496858852630392143L; + + private final String address; + private final int port; + private final boolean install; + private final Configuration configuration; + private final String id; + + public ConfigurationAndResponse(String address, int port, Configuration configuration, boolean install, String id){ + this.address = address; + this.port = port; + this.configuration = configuration; + this.install = install; + this.id = id; + } + + public String getAddress(){ + return address; + } + + public int getPort(){ + return port; + } + + public Configuration getConfiguration(){ + return configuration; + } + + public boolean install(){ + return install; + } + + public String getId(){ + return id; + } + +} diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/report/IReport.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/ConsoleInputMessage.java index e410cccd9f8..7162047b920 100644 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/report/IReport.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/ConsoleInputMessage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. + * Copyright (c) 2013 Boeing. * 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 @@ -8,13 +8,15 @@ * Contributors: * Boeing - initial API and implementation *******************************************************************************/ -package org.eclipse.osee.framework.jini.service.report; +package org.eclipse.osee.ote.remote.messages; -import java.rmi.Remote; -import java.rmi.RemoteException; +public class ConsoleInputMessage extends ConsoleMessage { -public interface IReport extends Remote { + public static String TOPIC = "ote/message/consoleinput"; - public void setReportId(int reportId) throws RemoteException; + public ConsoleInputMessage() { + super(ConsoleInputMessage.class.getSimpleName(), TOPIC); + } +} -} + diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/ConsoleMessage.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/ConsoleMessage.java new file mode 100644 index 00000000000..9038b7ff74e --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/ConsoleMessage.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.remote.messages; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.eclipse.osee.ote.message.elements.ArrayElement; +import org.eclipse.osee.ote.message.event.OteEventMessage; + + +public class ConsoleMessage extends OteEventMessage { + + public static final int _BYTE_SIZE = 0; + public ArrayElement STRINGDATA; + + public ConsoleMessage(String name, String topic) { + super(ConsoleMessage.class.getSimpleName(), topic, _BYTE_SIZE); + STRINGDATA = new ArrayElement(this, "STRINGDATA", getDefaultMessageData(), 0, 0, 0); + addElements(STRINGDATA); + } + + public void setString(String str) throws IOException{ + byte[] data = str.getBytes(); + int offset = STRINGDATA.getByteOffset() + getHeaderSize(); + byte[] newData = new byte[data.length + offset]; + System.arraycopy(getData(), 0, newData, 0, offset); + System.arraycopy(data, 0, newData, offset, data.length); + getDefaultMessageData().setNewBackingBuffer(newData); + } + + public String getString() throws IOException, ClassNotFoundException{ + int offset = STRINGDATA.getByteOffset() + getHeaderSize(); + byte[] stringData = new byte[getData().length - offset]; + System.arraycopy(getData(), offset, stringData, 0, stringData.length); + return new String(stringData); + } + + public void setStringData(ByteBuffer buffer) { + int offset = STRINGDATA.getByteOffset() + getHeaderSize(); + byte[] newData = new byte[buffer.remaining() + offset]; + System.arraycopy(getData(), 0, newData, 0, offset); + buffer.get(newData, offset, buffer.remaining()); + getDefaultMessageData().setNewBackingBuffer(newData); + } +} + + diff --git a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/scheduler/IScheduler.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/ConsoleOutputMessage.java index fb5b1e8b109..40cfcea7c61 100644 --- a/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/service/scheduler/IScheduler.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/ConsoleOutputMessage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. + * Copyright (c) 2013 Boeing. * 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 @@ -8,16 +8,17 @@ * Contributors: * Boeing - initial API and implementation *******************************************************************************/ -package org.eclipse.osee.framework.jini.service.scheduler; +package org.eclipse.osee.ote.remote.messages; -import java.rmi.Remote; -import java.rmi.RemoteException; -public interface IScheduler extends Remote { +public class ConsoleOutputMessage extends ConsoleMessage { - /** - * method is called by the scheduler - */ - public void run() throws RemoteException; + public static String TOPIC = "ote/message/consoleoutput"; -} + public ConsoleOutputMessage() { + super(ConsoleOutputMessage.class.getSimpleName(), TOPIC); + } + +} + + diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/DisconnectRemoteTestEnvironment.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/DisconnectRemoteTestEnvironment.java new file mode 100644 index 00000000000..5f02abb23f0 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/DisconnectRemoteTestEnvironment.java @@ -0,0 +1,19 @@ +package org.eclipse.osee.ote.remote.messages; + +import java.io.Serializable; +import java.util.UUID; + +public class DisconnectRemoteTestEnvironment implements Serializable { + + private static final long serialVersionUID = 1100894850334052780L; + + private UUID id; + + public DisconnectRemoteTestEnvironment(UUID id){ + this.id = id; + } + + public UUID getId() { + return id; + } +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/GET_INET_ADDRESS_RESP.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/GET_INET_ADDRESS_RESP.java index ddb58070339..75c51b457ff 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/GET_INET_ADDRESS_RESP.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/GET_INET_ADDRESS_RESP.java @@ -2,6 +2,7 @@ package org.eclipse.osee.ote.remote.messages; import org.eclipse.osee.ote.message.elements.EnumeratedElement; import org.eclipse.osee.ote.message.event.OteEventMessage; +import org.eclipse.osee.ote.message.event.SOCKET_ADDRESS_RECORD; public class GET_INET_ADDRESS_RESP extends OteEventMessage { diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/JobStatus.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/JobStatus.java new file mode 100644 index 00000000000..4096e0bab1c --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/JobStatus.java @@ -0,0 +1,90 @@ +package org.eclipse.osee.ote.remote.messages; + +import java.io.Serializable; +import java.net.URL; + +public class JobStatus implements Serializable { + + private static final long serialVersionUID = -5316721802558614714L; + private URL updatedJobStatus; + private String jobId; + + private int totalUnitsOfWork; + private int unitsWorked; + private String errorLog; + private boolean jobComplete; + private boolean success; + + public JobStatus(){ + errorLog = ""; + jobComplete = false; + success = true; + totalUnitsOfWork = 0; + unitsWorked = 0; + } + + public int getTotalUnitsOfWork() { + return totalUnitsOfWork; + } + + public int getUnitsWorked() { + return unitsWorked; + } + + public String getErrorLog() { + return errorLog; + } + + public boolean isJobComplete() { + return jobComplete; + } + + public void setTotalUnitsOfWork(int i) { + totalUnitsOfWork = i; + } + + public void jobComplete() { + jobComplete = true; + } + + public void incrememtUnitsWorked() { + unitsWorked++; + } + + public void setUnitsWorked(int unitsWorked) { + this.unitsWorked = unitsWorked; + } + + public void setErrorLog(String log) { + this.errorLog = log; + } + + public void setJobComplete(boolean jobComplete) { + this.jobComplete = jobComplete; + } + + public boolean isSuccess() { + return success; + } + + public void setSuccess(boolean success) { + this.success = success; + } + + public URL getUpdatedJobStatus() { + return updatedJobStatus; + } + + public void setUpdatedJobStatus(URL updatedJobStatus) { + this.updatedJobStatus = updatedJobStatus; + } + + public String getJobId() { + return jobId; + } + + public void setJobId(String jobId) { + this.jobId = jobId; + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RequestHostEnvironmentProperties.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RequestHostEnvironmentProperties.java new file mode 100644 index 00000000000..052e615ad05 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RequestHostEnvironmentProperties.java @@ -0,0 +1,15 @@ +package org.eclipse.osee.ote.remote.messages; + +import org.eclipse.osee.ote.message.event.OteEventMessage; + +public class RequestHostEnvironmentProperties extends OteEventMessage { + + public static String TOPIC = "ote/message/propertiesreq"; + + public RequestHostEnvironmentProperties() { + super("RequestHostEnvironmentProperties", TOPIC, 1); + + getDefaultMessageData().getMsgHeader().RESPONSE_TOPIC.setValue(SerializedEnhancedProperties.EVENT); + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RequestRemoteTestEnvironment.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RequestRemoteTestEnvironment.java new file mode 100644 index 00000000000..a3f4a8309e6 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RequestRemoteTestEnvironment.java @@ -0,0 +1,35 @@ +package org.eclipse.osee.ote.remote.messages; + +import java.io.Serializable; +import java.util.UUID; + +import org.eclipse.osee.ote.core.IRemoteUserSession; +import org.eclipse.osee.ote.core.environment.TestEnvironmentConfig; + +public class RequestRemoteTestEnvironment implements Serializable { + + private static final long serialVersionUID = -6720107128761044291L; + + private IRemoteUserSession session; + private UUID id; + private TestEnvironmentConfig config; + + public RequestRemoteTestEnvironment(IRemoteUserSession session, UUID id, TestEnvironmentConfig config){ + this.session = session; + this.id = id; + this.config = config; + } + + public IRemoteUserSession getSession() { + return session; + } + + public UUID getId() { + return id; + } + + public TestEnvironmentConfig getConfig() { + return config; + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RunTestsCancel.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RunTestsCancel.java new file mode 100644 index 00000000000..d4889eab263 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RunTestsCancel.java @@ -0,0 +1,29 @@ +package org.eclipse.osee.ote.remote.messages; + +import org.eclipse.osee.ote.message.elements.BooleanElement; +import org.eclipse.osee.ote.message.elements.StringElement; +import org.eclipse.osee.ote.message.event.OteEventMessage; + +public class RunTestsCancel extends OteEventMessage { + + public static String TOPIC = "ote/message/runtests/cancel"; + + private static int SIZE = 256+1; + + public StringElement GUID; + public BooleanElement CANCEL_ALL; + + public RunTestsCancel() { + super("MESSAGE_META_DATA_STAT", TOPIC, SIZE); + GUID = new StringElement(this, "GUID", getDefaultMessageData(), 0, 0, OteEventMessage.sizeBytesBits(256)); + CANCEL_ALL = new BooleanElement(this, "CANCEL_ALL", getDefaultMessageData(), GUID.getByteOffset()+GUID.getBitLength()/8, 0, 7); + + getDefaultMessageData().getMsgHeader().RESPONSE_TOPIC.setValue(BooleanResponse.TOPIC); + } + + public RunTestsCancel(byte[] bytes) { + this(); + setData(bytes); + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RunTestsGetCommandResultReq.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RunTestsGetCommandResultReq.java new file mode 100644 index 00000000000..d5e2f4a4a29 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RunTestsGetCommandResultReq.java @@ -0,0 +1,25 @@ +package org.eclipse.osee.ote.remote.messages; + +import org.eclipse.osee.ote.message.elements.StringElement; +import org.eclipse.osee.ote.message.event.OteEventMessage; + +public class RunTestsGetCommandResultReq extends OteEventMessage { + + public static String TOPIC = "ote/message/runtests/commandresultreq"; + + private static int SIZE = 256; + + public StringElement GUID; + + public RunTestsGetCommandResultReq() { + super("MESSAGE_META_DATA_STAT", TOPIC, SIZE); + GUID = new StringElement(this, "MESSAGE", getDefaultMessageData(), 0, 0, OteEventMessage.sizeBytesBits(256)); + getDefaultMessageData().getMsgHeader().RESPONSE_TOPIC.setValue(BooleanResponse.TOPIC); + } + + public RunTestsGetCommandResultReq(byte[] bytes) { + this(); + setData(bytes); + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RunTestsGetCommandResultResp.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RunTestsGetCommandResultResp.java new file mode 100644 index 00000000000..cfc1c6e549a --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RunTestsGetCommandResultResp.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.remote.messages; + +import java.io.IOException; + +import org.eclipse.osee.ote.core.framework.command.ITestCommandResult; +import org.eclipse.osee.ote.message.event.SerializedClassMessage; + +public class RunTestsGetCommandResultResp extends SerializedClassMessage<ITestCommandResult> { + + public static final String TOPIC = "ote/message/runtests/commandresultresp"; + + public RunTestsGetCommandResultResp() { + super(TOPIC); + } + + public RunTestsGetCommandResultResp(ITestCommandResult commandAdded) throws IOException { + super(TOPIC, commandAdded); + } + + public RunTestsGetCommandResultResp(byte[] bytes){ + super(bytes); + } +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RunTestsIsCancelled.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RunTestsIsCancelled.java new file mode 100644 index 00000000000..cc8aec621a1 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RunTestsIsCancelled.java @@ -0,0 +1,26 @@ +package org.eclipse.osee.ote.remote.messages; + +import org.eclipse.osee.ote.message.elements.StringElement; +import org.eclipse.osee.ote.message.event.OteEventMessage; + +public class RunTestsIsCancelled extends OteEventMessage { + + public static String TOPIC = "ote/message/runtests/iscanceled"; + + private static int SIZE = 256; + + public StringElement GUID; + + public RunTestsIsCancelled() { + super("MESSAGE_META_DATA_STAT", TOPIC, SIZE); + GUID = new StringElement(this, "MESSAGE", getDefaultMessageData(), 0, 0, OteEventMessage.sizeBytesBits(256)); + + getDefaultMessageData().getMsgHeader().RESPONSE_TOPIC.setValue(BooleanResponse.TOPIC); + } + + public RunTestsIsCancelled(byte[] bytes) { + this(); + setData(bytes); + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RunTestsIsDone.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RunTestsIsDone.java new file mode 100644 index 00000000000..5ad7b3cfdfe --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RunTestsIsDone.java @@ -0,0 +1,26 @@ +package org.eclipse.osee.ote.remote.messages; + +import org.eclipse.osee.ote.message.elements.StringElement; +import org.eclipse.osee.ote.message.event.OteEventMessage; + +public class RunTestsIsDone extends OteEventMessage { + + public static String TOPIC = "ote/message/runtests/isdone"; + + private static int SIZE = 256; + + public StringElement GUID; + + public RunTestsIsDone() { + super("MESSAGE_META_DATA_STAT", TOPIC, SIZE); + GUID = new StringElement(this, "MESSAGE", getDefaultMessageData(), 0, 0, OteEventMessage.sizeBytesBits(256)); + + getDefaultMessageData().getMsgHeader().RESPONSE_TOPIC.setValue(BooleanResponse.TOPIC); + } + + public RunTestsIsDone(byte[] bytes) { + this(); + setData(bytes); + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RunTestsSerialized.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RunTestsSerialized.java new file mode 100644 index 00000000000..12c3a6ebebf --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/RunTestsSerialized.java @@ -0,0 +1,34 @@ +/******************************************************************************* +ConfigurationAndResponse * Copyright (c) 2013 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.remote.messages; + +import java.io.IOException; + +import org.eclipse.osee.ote.core.framework.command.RunTests; +import org.eclipse.osee.ote.message.event.SerializedClassMessage; + +public class RunTestsSerialized extends SerializedClassMessage<RunTests> { + + public static final String RUNTESTS_NAMESPACE = "ote/message/runtests/"; + public static final String TOPIC = RUNTESTS_NAMESPACE + "serialized"; + + public RunTestsSerialized() { + super(TOPIC); + } + + public RunTestsSerialized(RunTests commandAdded) throws IOException { + super(TOPIC, commandAdded); + } + + public RunTestsSerialized(byte[] bytes){ + super(bytes); + } +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SerializedAvailablePhysicalTypesMessage.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SerializedAvailablePhysicalTypesMessage.java index 92db0e61bad..24b8a1b45fc 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SerializedAvailablePhysicalTypesMessage.java +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SerializedAvailablePhysicalTypesMessage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013 Boeing. +ConfigurationAndResponse * Copyright (c) 2013 Boeing. * 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 diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SerializedConfigurationAndResponse.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SerializedConfigurationAndResponse.java new file mode 100644 index 00000000000..c53cb9e79b3 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SerializedConfigurationAndResponse.java @@ -0,0 +1,32 @@ +/******************************************************************************* +ConfigurationAndResponse * Copyright (c) 2013 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.remote.messages; + +import java.io.IOException; + +import org.eclipse.osee.ote.message.event.SerializedClassMessage; + +public class SerializedConfigurationAndResponse extends SerializedClassMessage<ConfigurationAndResponse> { + + public static final String EVENT = "ote/message/serialconfigandresponse"; + + public SerializedConfigurationAndResponse() { + super(EVENT); + } + + public SerializedConfigurationAndResponse(ConfigurationAndResponse commandAdded) throws IOException { + super(EVENT, commandAdded); + } + + public SerializedConfigurationAndResponse(byte[] bytes){ + super(bytes); + } +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SerializedConnectionRequestResult.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SerializedConnectionRequestResult.java new file mode 100644 index 00000000000..1fed3167976 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SerializedConnectionRequestResult.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.remote.messages; + +import java.io.IOException; + +import org.eclipse.osee.ote.core.ConnectionRequestResult; +import org.eclipse.osee.ote.message.event.SerializedClassMessage; + +public class SerializedConnectionRequestResult extends SerializedClassMessage<ConnectionRequestResult> { + + public static final String EVENT = "ote/message/connectionrequestresult"; + + public SerializedConnectionRequestResult() { + super(EVENT); + } + + public SerializedConnectionRequestResult(ConnectionRequestResult commandAdded) throws IOException { + super(EVENT, commandAdded); + } + + public SerializedConnectionRequestResult(byte[] bytes){ + super(bytes); + } +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SerializedDisconnectRemoteTestEnvironment.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SerializedDisconnectRemoteTestEnvironment.java new file mode 100644 index 00000000000..c9f0c396cf9 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SerializedDisconnectRemoteTestEnvironment.java @@ -0,0 +1,22 @@ +package org.eclipse.osee.ote.remote.messages; + +import java.io.IOException; + +import org.eclipse.osee.ote.message.event.SerializedClassMessage; + +public class SerializedDisconnectRemoteTestEnvironment extends SerializedClassMessage<DisconnectRemoteTestEnvironment> { + + public static final String TOPIC = "ote/message/serialdisconnecttestenv"; + + public SerializedDisconnectRemoteTestEnvironment() { + super(TOPIC); + } + + public SerializedDisconnectRemoteTestEnvironment(DisconnectRemoteTestEnvironment commandAdded) throws IOException { + super(TOPIC, commandAdded); + } + + public SerializedDisconnectRemoteTestEnvironment(byte[] bytes){ + super(bytes); + } +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SerializedEnhancedProperties.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SerializedEnhancedProperties.java new file mode 100644 index 00000000000..9552f8f091d --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SerializedEnhancedProperties.java @@ -0,0 +1,33 @@ +/******************************************************************************* +ConfigurationAndResponse * Copyright (c) 2013 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.remote.messages; + +import java.io.IOException; + +import org.eclipse.osee.framework.jdk.core.util.EnhancedProperties; +import org.eclipse.osee.ote.message.event.SerializedClassMessage; + +public class SerializedEnhancedProperties extends SerializedClassMessage<EnhancedProperties> { + + public static final String EVENT = "ote/message/enhancedproperties"; + + public SerializedEnhancedProperties() { + super(EVENT); + } + + public SerializedEnhancedProperties(EnhancedProperties commandAdded) throws IOException { + super(EVENT, commandAdded); + } + + public SerializedEnhancedProperties(byte[] bytes){ + super(bytes); + } +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SerializedOTEJobStatus.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SerializedOTEJobStatus.java new file mode 100644 index 00000000000..8fbf3de278f --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SerializedOTEJobStatus.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2013 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.remote.messages; + +import java.io.IOException; + +import org.eclipse.osee.ote.message.event.SerializedClassMessage; + +public class SerializedOTEJobStatus extends SerializedClassMessage<JobStatus> { + + public static final String EVENT = "ote/message/otejobstatus"; + + public SerializedOTEJobStatus() { + super(EVENT); + } + + public SerializedOTEJobStatus(JobStatus commandAdded) throws IOException { + super(EVENT, commandAdded); + } + + public SerializedOTEJobStatus(byte[] bytes){ + super(bytes); + } +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SerializedRequestRemoteTestEnvironment.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SerializedRequestRemoteTestEnvironment.java new file mode 100644 index 00000000000..b321c215123 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/SerializedRequestRemoteTestEnvironment.java @@ -0,0 +1,24 @@ +package org.eclipse.osee.ote.remote.messages; + +import java.io.IOException; + +import org.eclipse.osee.ote.message.event.SerializedClassMessage; + +public class SerializedRequestRemoteTestEnvironment extends SerializedClassMessage<RequestRemoteTestEnvironment> { + + public static final String TOPIC = "ote/message/serialrequesttestenv"; + + public SerializedRequestRemoteTestEnvironment() { + super(TOPIC); + + getHeader().RESPONSE_TOPIC.setValue(SerializedConnectionRequestResult.EVENT); + } + + public SerializedRequestRemoteTestEnvironment(RequestRemoteTestEnvironment commandAdded) throws IOException { + super(TOPIC, commandAdded); + } + + public SerializedRequestRemoteTestEnvironment(byte[] bytes){ + super(bytes); + } +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/TestEnvironmentServerShutdown.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/TestEnvironmentServerShutdown.java new file mode 100644 index 00000000000..83c3fa2512b --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/TestEnvironmentServerShutdown.java @@ -0,0 +1,24 @@ +package org.eclipse.osee.ote.remote.messages; + +import org.eclipse.osee.ote.message.elements.StringElement; +import org.eclipse.osee.ote.message.event.OteEventMessage; + +public class TestEnvironmentServerShutdown extends OteEventMessage { + + public static String TOPIC = "ote/message/servershutdown"; + + private static int SIZE = 512; + + public StringElement SERVER_ID; + + public TestEnvironmentServerShutdown() { + super("TestEnvironmentSetBatchMode", TOPIC, SIZE); + SERVER_ID = new StringElement(this, "SERVER_ID", getDefaultMessageData(), 0, 0, 512*8-1); + } + + public TestEnvironmentServerShutdown(byte[] bytes) { + this(); + setBackingBuffer(bytes); + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/TestEnvironmentSetBatchMode.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/TestEnvironmentSetBatchMode.java new file mode 100644 index 00000000000..3a496ee2f48 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/TestEnvironmentSetBatchMode.java @@ -0,0 +1,24 @@ +package org.eclipse.osee.ote.remote.messages; + +import org.eclipse.osee.ote.message.elements.BooleanElement; +import org.eclipse.osee.ote.message.event.OteEventMessage; + +public class TestEnvironmentSetBatchMode extends OteEventMessage { + + public static String TOPIC = "ote/message/setbatchmode"; + + private static int SIZE = 1; + + public BooleanElement SET_BATCH_MODE; + + public TestEnvironmentSetBatchMode() { + super("TestEnvironmentSetBatchMode", TOPIC, SIZE); + SET_BATCH_MODE = new BooleanElement(this, "SET_BATCH_MODE", getDefaultMessageData(), 0, 0, 7); + } + + public TestEnvironmentSetBatchMode(byte[] bytes) { + this(); + setBackingBuffer(bytes); + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/TestEnvironmentTransferFile.java b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/TestEnvironmentTransferFile.java new file mode 100644 index 00000000000..6fb5e9e161f --- /dev/null +++ b/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/remote/messages/TestEnvironmentTransferFile.java @@ -0,0 +1,27 @@ +package org.eclipse.osee.ote.remote.messages; + +import org.eclipse.osee.ote.message.elements.StringElement; +import org.eclipse.osee.ote.message.event.OteEventMessage; +import org.eclipse.osee.ote.message.event.SOCKET_ADDRESS_RECORD; + +public class TestEnvironmentTransferFile extends OteEventMessage { + + public static String TOPIC = "ote/message/transferfile"; + + private static int SIZE = SOCKET_ADDRESS_RECORD.SIZE + 1024; + + public SOCKET_ADDRESS_RECORD ADDRESS; + public StringElement FILE_PATH; + + public TestEnvironmentTransferFile() { + super("TestEnvironmentSetBatchMode", TOPIC, SIZE); + ADDRESS = new SOCKET_ADDRESS_RECORD(this, "ADDRESS", getDefaultMessageData(), 0, 0, SOCKET_ADDRESS_RECORD.SIZE*8-1); + FILE_PATH = new StringElement(this, "FILE_PATH", getDefaultMessageData(), SOCKET_ADDRESS_RECORD.SIZE, 0, 1024*8-1); + } + + public TestEnvironmentTransferFile(byte[] bytes) { + this(); + setBackingBuffer(bytes); + } + +} diff --git a/plugins/org.eclipse.osee.ote.io/.classpath b/plugins/org.eclipse.osee.ote.io/.classpath new file mode 100644 index 00000000000..ad32c83a788 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.io/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/org.eclipse.osee.ote.io/.project b/plugins/org.eclipse.osee.ote.io/.project new file mode 100644 index 00000000000..4a01453740b --- /dev/null +++ b/plugins/org.eclipse.osee.ote.io/.project @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.osee.ote.io</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> + <buildCommand> + <name>org.eclipse.pde.ds.core.builder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/plugins/org.eclipse.osee.ote.io/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ote.io/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..07210ab9dae --- /dev/null +++ b/plugins/org.eclipse.osee.ote.io/META-INF/MANIFEST.MF @@ -0,0 +1,14 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: OTE IO (Incubation) +Bundle-SymbolicName: org.eclipse.osee.ote.io;singleton:=true +Bundle-Version: 0.19.0.qualifier +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Import-Package: org.eclipse.osee.framework.logging, + org.eclipse.osee.ote.properties, + org.osgi.framework +Export-Package: org.eclipse.osee.ote.io +Bundle-ActivationPolicy: lazy +Service-Component: OSGI-INF/*.xml +Bundle-Vendor: Eclipse Open System Engineering Environment +Bundle-Activator: org.eclipse.osee.ote.io.internal.EarlyIORedirect diff --git a/plugins/org.eclipse.osee.ote.io/OSGI-INF/org.eclipse.osee.ote.io.xml b/plugins/org.eclipse.osee.ote.io/OSGI-INF/org.eclipse.osee.ote.io.xml new file mode 100644 index 00000000000..dc70ecff839 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.io/OSGI-INF/org.eclipse.osee.ote.io.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop" immediate="true" name="org.eclipse.osee.ote.io"> + <implementation class="org.eclipse.osee.ote.io.internal.SystemOutputImpl"/> + <service> + <provide interface="org.eclipse.osee.ote.io.SystemOutput"/> + </service> + <reference bind="bindOTEServerFolder" cardinality="1..1" interface="org.eclipse.osee.ote.io.OTEServerFolder" name="OTEServerFolder" policy="static" unbind="unbindOTEServerFolder"/> +</scr:component> diff --git a/plugins/org.eclipse.osee.ote.io/OSGI-INF/ote.server.folder.component.xml b/plugins/org.eclipse.osee.ote.io/OSGI-INF/ote.server.folder.component.xml new file mode 100644 index 00000000000..53410ca446b --- /dev/null +++ b/plugins/org.eclipse.osee.ote.io/OSGI-INF/ote.server.folder.component.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" activate="start" deactivate="stop" immediate="true" name="org.eclipse.osee.ote.io.server.folder"> + <implementation class="org.eclipse.osee.ote.io.internal.OTEFolderImpl"/> + <service> + <provide interface="org.eclipse.osee.ote.io.OTEServerFolder"/> + </service> +</scr:component> diff --git a/plugins/org.eclipse.osee.ote.io/build.properties b/plugins/org.eclipse.osee.ote.io/build.properties new file mode 100644 index 00000000000..6210e849b59 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.io/build.properties @@ -0,0 +1,5 @@ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + OSGI-INF/ +source.. = src/ diff --git a/plugins/org.eclipse.osee.ote.io/pom.xml b/plugins/org.eclipse.osee.ote.io/pom.xml new file mode 100644 index 00000000000..4e5473bb4d4 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.io/pom.xml @@ -0,0 +1,35 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.eclipse.osee</groupId> + <artifactId>org.eclipse.osee.ote.parent</artifactId> + <version>0.19.0-SNAPSHOT</version> + <relativePath>../../plugins/org.eclipse.osee.ote.parent</relativePath> + </parent> + + <artifactId>org.eclipse.osee.ote.io</artifactId> + <packaging>eclipse-plugin</packaging> + <name>OTE IO</name> + + <build> + <!-- workaround for https://issues.sonatype.org/browse/TYCHO-168 --> + <resources> + <resource> + <directory>src</directory> + <excludes> + <exclude>**/*.java</exclude> + </excludes> + </resource> + </resources> + <plugins> + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-source-plugin</artifactId> + </plugin> + </plugins> + </build> + +</project>
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/OTEServerFolder.java b/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/OTEServerFolder.java index 25f149fe2d3..735dae1c6be 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/OTEServerFolder.java +++ b/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/OTEServerFolder.java @@ -1,6 +1,7 @@ -package org.eclipse.osee.ote; +package org.eclipse.osee.ote.io; import java.io.File; +import java.util.List; /** * This class is used to help manage the OTE Server Folder area. This includes the runtime cache and @@ -18,6 +19,8 @@ public interface OTEServerFolder { */ public void cleanOldBatchFolders(); + public File getRootFolder(); + public File getServerFolder(); /** @@ -54,6 +57,10 @@ public interface OTEServerFolder { */ public File getNewBatchFolder(String suffix); + public File getNewServerFolder(); + + public File getCurrentServerFolder(); + public void markFolderForDelete(File folder); public void unmarkFolderForDelete(File folder); @@ -86,4 +93,8 @@ public interface OTEServerFolder { */ public File getBatchRunList(File batchFolder); + public List<File> getRunningServerFolders(); + + public void removeServerRunningFile(File serverFolder); + } diff --git a/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/SystemOutput.java b/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/SystemOutput.java new file mode 100644 index 00000000000..2be2268fc81 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/SystemOutput.java @@ -0,0 +1,7 @@ +package org.eclipse.osee.ote.io; + +public interface SystemOutput { + public void addListener(SystemOutputListener listener); + public void removeListener(SystemOutputListener listener); + public void write(String input); +} diff --git a/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/SystemOutputListener.java b/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/SystemOutputListener.java new file mode 100644 index 00000000000..f84a633faaf --- /dev/null +++ b/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/SystemOutputListener.java @@ -0,0 +1,15 @@ +package org.eclipse.osee.ote.io; + +import java.io.IOException; + +public interface SystemOutputListener { + + public void close() throws IOException; + + public void flush() throws IOException; + + public void write(byte[] b, int off, int len) throws IOException; + + public void write(byte[] b) throws IOException; + +} diff --git a/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/internal/EarlyIORedirect.java b/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/internal/EarlyIORedirect.java new file mode 100644 index 00000000000..7e020cf9fac --- /dev/null +++ b/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/internal/EarlyIORedirect.java @@ -0,0 +1,77 @@ +package org.eclipse.osee.ote.io.internal; + +import java.io.InputStream; +import java.io.PrintStream; + +import org.eclipse.osee.ote.io.SystemOutputListener; +import org.eclipse.osee.ote.properties.OtePropertiesCore; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class EarlyIORedirect implements BundleActivator { + + private static EarlyIORedirect instance; + + public static EarlyIORedirect getInstance(){ + return instance; + } + + private PrintStream oldErr; + private PrintStream oldOut; + private InputStream oldIn; + private SpecializedOut out; + private SpecializedInputStream in; + private String newline; + + @Override + public void start(BundleContext context) throws Exception { + instance = this; + oldErr = System.err; + oldOut = System.out; + oldIn = System.in; + if(OtePropertiesCore.ioRedirect.getBooleanValue(false)){ + out = new SpecializedOut(new SpecializedOutputStream());//outputStream == null ? oldOut : outputStream)); + newline = OtePropertiesCore.lineSeparator.getValue(); + in = new SpecializedInputStream(oldIn); + if(!OtePropertiesCore.ioRedirectFile.getBooleanValue(false)){ + out.addListener(new SystemOutputListerImpl(System.out)); + } + System.setIn(in); + System.setOut(out); + System.setErr(out); + } + } + + @Override + public void stop(BundleContext context) throws Exception { + if(out != null){ + out.flush(); + } + } + + public void addListener(SystemOutputListener listener){ + if(out != null){ + out.addListener(listener); + } + } + + public void removeListener(SystemOutputListener listener){ + if(out != null){ + out.removeListener(listener); + } + } + + public void write(String input){ + if(in != null){ +// System.out.println(input); + in.add(input+newline); + } + } + + public void resetIO(){ + System.setIn(oldIn); + System.setOut(oldOut); + System.setErr(oldErr); + } + +} diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/OTEFolderImpl.java b/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/internal/OTEFolderImpl.java index 91fec31d683..db170ed3d31 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/internal/OTEFolderImpl.java +++ b/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/internal/OTEFolderImpl.java @@ -1,4 +1,4 @@ -package org.eclipse.osee.ote.internal; +package org.eclipse.osee.ote.io.internal; import java.io.File; import java.io.FileNotFoundException; @@ -6,18 +6,21 @@ import java.io.FileOutputStream; import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import java.util.logging.Level; import org.eclipse.osee.framework.logging.OseeLog; -import org.eclipse.osee.ote.OTEServerFolder; +import org.eclipse.osee.ote.io.OTEServerFolder; +import org.eclipse.osee.ote.properties.OtePropertiesCore; public class OTEFolderImpl implements OTEServerFolder{ private static int DAYS; static { - String strDays = System.getProperty("ote.batchfolder.days"); + String strDays = OtePropertiesCore.batchFolderDays.getValue(); if(strDays!=null){ try{ DAYS = Integer.parseInt(strDays); @@ -34,17 +37,28 @@ public class OTEFolderImpl implements OTEServerFolder{ private static final String STATUS_FILE = ".status"; private static final String RUNLIST_FILE = ".runlist"; private static final String RESULTS_FILE = ".result"; + private static final String RUNNING_MARKER = ".running"; - private static File OTESERVER = new File(System.getProperty("user.home") + File.separator + "OTESERVER"); + private static File OTESERVER = new File(OtePropertiesCore.userHome.getValue() + File.separator + "OTESERVER"); private static File BATCHES = new File(OTESERVER, "batches"); private static File JARCACHE = new File(OTESERVER, "runtimeCache"); + private static File SERVERS = new File(OTESERVER, "servers"); private static SimpleDateFormat format = new SimpleDateFormat("yyyy_MM_dd___kk_mm_ss"); + private File currentServerFolder; + + public OTEFolderImpl(){ + currentServerFolder = getNewServerFolder(); + String serverIOPath = OtePropertiesCore.ioRedirectPath.getValue(currentServerFolder.getAbsolutePath()); + currentServerFolder = new File(serverIOPath); + } + /** * ds component method */ public void start(){ cleanOldBatchFolders(); + cleanOldServerFolders(); } /** @@ -105,12 +119,69 @@ public class OTEFolderImpl implements OTEServerFolder{ } } + public void cleanOldServerFolders(){ + Date dateBefore = new Date(new Date().getTime() -(DAYS * 24 * 3600 * 1000)); + Date dateNoMatterwhat = new Date(new Date().getTime() -(28L * 24L * 3600L * 1000L));//4 weeks + if(SERVERS.exists()){ + File[] files = SERVERS.listFiles(); + if(files != null){ + for(File file:files){ + if(file.isDirectory()){ + boolean olderFileOrUnknown = true; + boolean removeNoMatterWhat = false; + try { + Date fileDate = format.parse(file.getName()); + if(fileDate == null){ + OseeLog.log(getClass(), Level.WARNING, "Failed to parse a date from the Dir name "+ file.getAbsolutePath()); + } else { + olderFileOrUnknown = fileDate.before(dateBefore); + removeNoMatterWhat = fileDate.before(dateNoMatterwhat); + } + } catch (ParseException e) { + int index = file.getName().lastIndexOf("__"); + if(index > 1){ + try{ + Date fileDate = format.parse(file.getName().substring(0, index-1)); + if(fileDate == null){ + OseeLog.log(getClass(), Level.WARNING, "Failed to parse a date from the Dir name "+ file.getAbsolutePath()); + } else { + olderFileOrUnknown = fileDate.before(dateBefore); + } + } catch (ParseException e2){ + OseeLog.log(getClass(), Level.SEVERE, e2); + } + } else { + OseeLog.log(getClass(), Level.SEVERE, e); + } + } + File running = new File(file, RUNNING_MARKER); + boolean deleteFolder = !running.exists(); + if((deleteFolder && olderFileOrUnknown) || removeNoMatterWhat){ + File[] toDelete = file.listFiles(); + for(File f:toDelete){ + f.delete(); + } + file.delete(); + } + } + } + } + } + } + + + @Override - public File getServerFolder(){ + public File getRootFolder(){ return OTESERVER; } @Override + public File getServerFolder(){ + return SERVERS; + } + + @Override public File getBatchesFolder(){ return BATCHES; } @@ -119,6 +190,16 @@ public class OTEFolderImpl implements OTEServerFolder{ public File getCacheFolder(){ return JARCACHE; } + + @Override + public File getNewServerFolder() { + return new File(getServerFolder(), format.format(new Date())); + } + + @Override + public File getCurrentServerFolder() { + return currentServerFolder; + } @Override public File getNewBatchFolder() { @@ -146,7 +227,7 @@ public class OTEFolderImpl implements OTEServerFolder{ folder.mkdirs(); fos = new FileOutputStream(new File(folder, DELETE_MARKER)); } catch (FileNotFoundException e) { - e.printStackTrace(); + OseeLog.log(getClass(), Level.SEVERE, e); } finally { if(fos != null){ try { @@ -181,4 +262,24 @@ public class OTEFolderImpl implements OTEServerFolder{ return new File(batchFolder, RUNLIST_FILE); } + @Override + public List<File> getRunningServerFolders() { + List<File> files = new ArrayList<File>(); + for(File serverDir:SERVERS.listFiles()){ + File running = new File(serverDir, RUNNING_MARKER); + if(running.exists()){ + files.add(serverDir); + } + } + return files; + } + + @Override + public void removeServerRunningFile(File serverFolder) { + File file = new File(serverFolder, RUNNING_MARKER); + if(file.exists()){ + file.delete(); + } + } + } diff --git a/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/internal/SpecializedInputStream.java b/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/internal/SpecializedInputStream.java new file mode 100644 index 00000000000..520ab0a58ca --- /dev/null +++ b/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/internal/SpecializedInputStream.java @@ -0,0 +1,76 @@ +package org.eclipse.osee.ote.io.internal; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.ReentrantLock; + +public class SpecializedInputStream extends InputStream { + + private StringBuffer buffer = new StringBuffer(); + private ReentrantLock lock; + private Condition newData; + private InputStream monitorIn; + private Thread th; + + public SpecializedInputStream(InputStream in){ + monitorIn = in; + lock = new ReentrantLock(); + newData = lock.newCondition(); + th = new Thread(new Runnable(){ + + @Override + public void run() { + InputStreamReader isr=new InputStreamReader(monitorIn); + BufferedReader br=new BufferedReader(isr); + boolean validSystemIn = true; + while(validSystemIn){ + try{ + String line = br.readLine(); + if(line != null){ + add(line); + } else { + validSystemIn = false; + } + } catch (Throwable th){ + + } + } + } + + }); + th.setDaemon(true); + th.setName("OTE System.in monitor"); + th.start(); + } + + @Override + public int read() throws IOException { + int mychar = 0; + lock.lock(); + try{ + if(buffer.length() == 0){ + newData.awaitUninterruptibly(); + } + mychar = buffer.charAt(0) & 0xFF; + buffer.deleteCharAt(0); + } catch (Throwable th){ + } finally { + lock.unlock(); + } + return mychar; + } + + public void add(String str){ + lock.lock(); + try{ + buffer.append(str); + newData.signalAll(); + } finally { + lock.unlock(); + } + } + +} diff --git a/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/internal/SpecializedOut.java b/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/internal/SpecializedOut.java new file mode 100644 index 00000000000..51be19aa92a --- /dev/null +++ b/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/internal/SpecializedOut.java @@ -0,0 +1,23 @@ +package org.eclipse.osee.ote.io.internal; + +import java.io.PrintStream; + +import org.eclipse.osee.ote.io.SystemOutputListener; + +public class SpecializedOut extends PrintStream { + + private SpecializedOutputStream specialOut; + + public SpecializedOut(SpecializedOutputStream out) { + super(out); + this.specialOut = out; + } + + public void addListener(SystemOutputListener listener){ + specialOut.add(listener); + } + + public void removeListener(SystemOutputListener listener){ + specialOut.remove(listener); + } +} diff --git a/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/internal/SpecializedOutputStream.java b/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/internal/SpecializedOutputStream.java new file mode 100644 index 00000000000..63ce67f50b8 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/internal/SpecializedOutputStream.java @@ -0,0 +1,58 @@ +package org.eclipse.osee.ote.io.internal; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.eclipse.osee.ote.io.SystemOutputListener; + +public class SpecializedOutputStream extends OutputStream { + + private CopyOnWriteArrayList<SystemOutputListener> listeners; + + public SpecializedOutputStream() { + this.listeners = new CopyOnWriteArrayList<SystemOutputListener>(); + } + + public void add(SystemOutputListener listener){ + listeners.add(listener); + } + + public void remove(SystemOutputListener listner){ + listeners.remove(listner); + } + + @Override + public void write(int arg0) throws IOException { + + } + + @Override + public void close() throws IOException { + for(SystemOutputListener listner:listeners){ + listner.close(); + } + } + + @Override + public void flush() throws IOException { + for(SystemOutputListener listner:listeners){ + listner.flush(); + } + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + for(SystemOutputListener listner:listeners){ + listner.write(b, off, len); + } + } + + @Override + public void write(byte[] b) throws IOException { + for(SystemOutputListener listner:listeners){ + listner.write(b); + } + } + +} diff --git a/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/internal/SystemOutputImpl.java b/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/internal/SystemOutputImpl.java new file mode 100644 index 00000000000..8c28e99d0b8 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/internal/SystemOutputImpl.java @@ -0,0 +1,69 @@ +package org.eclipse.osee.ote.io.internal; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; + +import org.eclipse.osee.ote.io.OTEServerFolder; +import org.eclipse.osee.ote.io.SystemOutput; +import org.eclipse.osee.ote.io.SystemOutputListener; +import org.eclipse.osee.ote.properties.OtePropertiesCore; + +public class SystemOutputImpl implements SystemOutput { + + private static final String SYSTEM_OUT_FILE = "systemout.txt"; + + private BufferedOutputStream outputStream; + + private OTEServerFolder serverFolder; + + public void start() { + if(OtePropertiesCore.ioRedirect.getBooleanValue(false)){ + if(OtePropertiesCore.ioRedirectFile.getBooleanValue(false)){ + File wd = serverFolder.getCurrentServerFolder(); + wd.mkdirs(); + if(wd.exists() && wd.isDirectory()){ + try { + outputStream = new BufferedOutputStream(new FileOutputStream(new File(wd, SYSTEM_OUT_FILE))); + EarlyIORedirect.getInstance().addListener(new SystemOutputListerImpl(outputStream)); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + } + } + } + + public void stop(){ + try { + outputStream.flush(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public void bindOTEServerFolder(OTEServerFolder folder) { + this.serverFolder = folder; + } + + public void unbindOTEServerFolder(OTEServerFolder folder) { + this.serverFolder = null; + } + + @Override + public void addListener(SystemOutputListener listener){ + EarlyIORedirect.getInstance().addListener(listener); + } + + @Override + public void removeListener(SystemOutputListener listener){ + EarlyIORedirect.getInstance().removeListener(listener); + } + + @Override + public synchronized void write(String input){ + EarlyIORedirect.getInstance().write(input); + } +} diff --git a/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/internal/SystemOutputListerImpl.java b/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/internal/SystemOutputListerImpl.java new file mode 100644 index 00000000000..ccc651fc7ab --- /dev/null +++ b/plugins/org.eclipse.osee.ote.io/src/org/eclipse/osee/ote/io/internal/SystemOutputListerImpl.java @@ -0,0 +1,36 @@ +package org.eclipse.osee.ote.io.internal; + +import java.io.IOException; +import java.io.OutputStream; + +import org.eclipse.osee.ote.io.SystemOutputListener; + +public class SystemOutputListerImpl implements SystemOutputListener { + + private OutputStream outputStream; + + public SystemOutputListerImpl(OutputStream outputStream) { + this.outputStream = outputStream; + } + + @Override + public void close() throws IOException { + outputStream.close(); + } + + @Override + public void flush() throws IOException { + outputStream.flush(); + } + + @Override + public void write(byte[] b, int off, int len) throws IOException { + outputStream.write(b, off, len); + } + + @Override + public void write(byte[] b) throws IOException { + outputStream.write(b); + } + +} diff --git a/plugins/org.eclipse.osee.ote.jms/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ote.jms/META-INF/MANIFEST.MF index 498bc97fdf4..74d7b443ec1 100644 --- a/plugins/org.eclipse.osee.ote.jms/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.ote.jms/META-INF/MANIFEST.MF @@ -11,7 +11,11 @@ Import-Package: org.eclipse.osee.connection.service, org.eclipse.osee.framework.jdk.core.util;resolution:=optional, org.eclipse.osee.framework.logging, org.eclipse.osee.framework.messaging, + org.eclipse.osee.ote, + org.eclipse.osee.ote.core, org.eclipse.osee.ote.core.environment, + org.eclipse.osee.ote.core.environment.interfaces, + org.eclipse.osee.ote.endpoint, org.eclipse.osee.ote.message, org.eclipse.osee.ote.message.elements, org.eclipse.osee.ote.message.event, diff --git a/plugins/org.eclipse.osee.ote.jms/OSGI-INF/ClientSideConnectionNodeLifecycleController.xml b/plugins/org.eclipse.osee.ote.jms/OSGI-INF/ClientSideConnectionNodeLifecycleController.xml index fc2f52cad94..12952fd82f2 100644 --- a/plugins/org.eclipse.osee.ote.jms/OSGI-INF/ClientSideConnectionNodeLifecycleController.xml +++ b/plugins/org.eclipse.osee.ote.jms/OSGI-INF/ClientSideConnectionNodeLifecycleController.xml @@ -11,4 +11,5 @@ interface="org.eclipse.osee.framework.messaging.MessageService" name="MessageService" policy="dynamic"/> + <reference bind="bindOteUdpEndpoint" cardinality="1..1" interface="org.eclipse.osee.ote.endpoint.OteUdpEndpoint" name="OteUdpEndpoint" policy="dynamic"/> </scr:component> diff --git a/plugins/org.eclipse.osee.ote.jms/OSGI-INF/ServerSideConnectionNodeProvider.xml b/plugins/org.eclipse.osee.ote.jms/OSGI-INF/ServerSideConnectionNodeProvider.xml index bb3c9a0c519..cfdc3ca1111 100644 --- a/plugins/org.eclipse.osee.ote.jms/OSGI-INF/ServerSideConnectionNodeProvider.xml +++ b/plugins/org.eclipse.osee.ote.jms/OSGI-INF/ServerSideConnectionNodeProvider.xml @@ -14,7 +14,4 @@ policy="static" bind="setMessageService" unbind="unsetMessageService"/> - <service> - <provide interface="org.eclipse.osee.ote.jms.OteServerJmsNodeProvider"/> - </service> </scr:component> diff --git a/plugins/org.eclipse.osee.ote.jms/OSGI-INF/ote.endpoint.bridge.component.xml b/plugins/org.eclipse.osee.ote.jms/OSGI-INF/ote.endpoint.bridge.component.xml new file mode 100644 index 00000000000..8593ec6c14f --- /dev/null +++ b/plugins/org.eclipse.osee.ote.jms/OSGI-INF/ote.endpoint.bridge.component.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" immediate="true" name="org.eclipse.osee.ote.jms.bridge.endpoint"> + <property name="event.topics" type="String" value="ote/*"/> + <implementation class="org.eclipse.osee.ote.jms.bridge.EventToEndpoint"/> + <service> + <provide interface="org.osgi.service.event.EventHandler"/> + </service> + <reference bind="bindOteUdpEndpoint" cardinality="1..1" interface="org.eclipse.osee.ote.endpoint.OteUdpEndpoint" name="OteUdpEndpoint" policy="static" unbind="unbindOteUdpEndpoint"/> +</scr:component> diff --git a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/cmd/Command.java b/plugins/org.eclipse.osee.ote.jms/src/org/eclipse/osee/ote/jms/OteConnectedEndpointNodeProvider.java index e4eeefdb2e6..2b41a7ba7a1 100644 --- a/plugins/org.eclipse.osee.ote.core/src/org/eclipse/osee/ote/core/cmd/Command.java +++ b/plugins/org.eclipse.osee.ote.jms/src/org/eclipse/osee/ote/jms/OteConnectedEndpointNodeProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 Boeing. + * Copyright (c) 2013 Boeing. * 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 @@ -8,13 +8,10 @@ * Contributors: * Boeing - initial API and implementation *******************************************************************************/ -package org.eclipse.osee.ote.core.cmd; +package org.eclipse.osee.ote.jms; -/** - * @author Andrew M. Finkbeiner - */ -public interface Command { - Source getSource(); +import org.eclipse.osee.framework.messaging.ConnectionNode; - CommandId getId(); +public interface OteConnectedEndpointNodeProvider { + ConnectionNode getConnectionNode(); } diff --git a/plugins/org.eclipse.osee.ote.jms/src/org/eclipse/osee/ote/jms/bridge/EventToEndpoint.java b/plugins/org.eclipse.osee.ote.jms/src/org/eclipse/osee/ote/jms/bridge/EventToEndpoint.java new file mode 100644 index 00000000000..da4e6f76438 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.jms/src/org/eclipse/osee/ote/jms/bridge/EventToEndpoint.java @@ -0,0 +1,45 @@ +package org.eclipse.osee.ote.jms.bridge; + +import java.util.logging.Level; + +import org.eclipse.osee.framework.logging.OseeLog; +import org.eclipse.osee.ote.OTEException; +import org.eclipse.osee.ote.core.CopyOnWriteNoIteratorList; +import org.eclipse.osee.ote.endpoint.OteUdpEndpoint; +import org.eclipse.osee.ote.endpoint.OteUdpEndpointSender; +import org.eclipse.osee.ote.message.event.OteEventMessage; +import org.eclipse.osee.ote.message.event.OteEventMessageUtil; +import org.osgi.service.event.Event; +import org.osgi.service.event.EventHandler; + +public class EventToEndpoint implements EventHandler { + + private OteUdpEndpoint endpoint; + + public void bindOteUdpEndpoint(OteUdpEndpoint endpoint){ + this.endpoint = endpoint; + } + + public void unbindOteUdpEndpoint(OteUdpEndpoint endpoint){ + this.endpoint = null; + } + + @Override + public void handleEvent(Event arg0) { + OteEventMessage oteEventMessage = OteEventMessageUtil.getOteEventMessage(arg0); + if(oteEventMessage != null && oteEventMessage.getHeader().TTL.getValue().intValue() == 0){ + oteEventMessage.getHeader().ADDRESS.setAddress(endpoint.getLocalEndpoint().getAddress()); + oteEventMessage.getHeader().ADDRESS.setPort(endpoint.getLocalEndpoint().getPort()); + CopyOnWriteNoIteratorList<OteUdpEndpointSender> broadcastSenders = endpoint.getBroadcastSenders(); + OteUdpEndpointSender[] oteUdpEndpointSenders = broadcastSenders.get(); + for(int i = 0; i < oteUdpEndpointSenders.length; i++){ + try{ + oteUdpEndpointSenders[i].send(oteEventMessage); + } catch (OTEException ex){ + OseeLog.log(getClass(), Level.SEVERE, ex); + } + } + } + } + +} diff --git a/plugins/org.eclipse.osee.ote.jms/src/org/eclipse/osee/ote/jms/internal/ClientSideConnectionNodeLifecycleController.java b/plugins/org.eclipse.osee.ote.jms/src/org/eclipse/osee/ote/jms/internal/ClientSideConnectionNodeLifecycleController.java index 14929890e41..a814f830b79 100644 --- a/plugins/org.eclipse.osee.ote.jms/src/org/eclipse/osee/ote/jms/internal/ClientSideConnectionNodeLifecycleController.java +++ b/plugins/org.eclipse.osee.ote.jms/src/org/eclipse/osee/ote/jms/internal/ClientSideConnectionNodeLifecycleController.java @@ -11,8 +11,10 @@ package org.eclipse.osee.ote.jms.internal; import java.io.Serializable; +import java.net.InetSocketAddress; import java.util.Map.Entry; import java.util.logging.Level; + import org.eclipse.osee.connection.service.IServiceConnector; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; import org.eclipse.osee.framework.jdk.core.util.EnhancedProperties; @@ -20,6 +22,10 @@ import org.eclipse.osee.framework.logging.OseeLog; import org.eclipse.osee.framework.messaging.ConnectionNode; import org.eclipse.osee.framework.messaging.MessageService; import org.eclipse.osee.framework.messaging.NodeInfo; +import org.eclipse.osee.ote.OTEException; +import org.eclipse.osee.ote.endpoint.OteEndpointUtil; +import org.eclipse.osee.ote.endpoint.OteUdpEndpoint; +import org.eclipse.osee.ote.endpoint.OteUdpEndpointSender; import org.eclipse.osee.ote.jms.OteServerJmsNodeProvider; import org.eclipse.osee.ote.service.ConnectionEvent; import org.eclipse.osee.ote.service.IOteClientService; @@ -38,6 +44,8 @@ public final class ClientSideConnectionNodeLifecycleController implements ITestC private IOteClientService clientService; private BundleContext context; private ServiceRegistration<?> registration; + private OteUdpEndpointSender oteEndpointSender; + private OteUdpEndpoint oteEndpoint; public void start(BundleContext context) { this.context = context; @@ -61,6 +69,10 @@ public final class ClientSideConnectionNodeLifecycleController implements ITestC public void setClientService(IOteClientService clientService) { this.clientService = clientService; } + + public void bindOteUdpEndpoint(OteUdpEndpoint oteEndpoint) { + this.oteEndpoint = oteEndpoint; + } @Override public void onPostConnect(ConnectionEvent event) { @@ -76,20 +88,33 @@ public final class ClientSideConnectionNodeLifecycleController implements ITestC * @param connector */ private void registerConnectionNode(IServiceConnector connector) { - Object obj = connector.getProperty("OTEEmbeddedBroker", null); - if (obj != null && obj instanceof NodeInfo) { - debug("Registering client connection service"); - NodeInfo nodeInfo = (NodeInfo) obj; - registerConnectionNode(nodeInfo); + Object obj = connector.getProperty("oteUdpEndpoint", null); + if (obj != null) { + try{ + InetSocketAddress address = OteEndpointUtil.getAddress(obj.toString()); + if(!oteEndpoint.getLocalEndpoint().equals(address)){ + oteEndpointSender = oteEndpoint.getOteEndpointSender(address); + oteEndpoint.addBroadcast(oteEndpointSender); + } + } catch (OTEException ex){ + OseeLog.log(getClass(), Level.SEVERE, ex); + } } else { - debug(String.format("Problem using connector...%s:%s", obj.getClass(), obj)); - EnhancedProperties properties = connector.getProperties(); - for( Entry<String, Serializable> entry : properties.entrySet() ) { - debug(String.format("\t%s = %s", entry.getKey(), entry.getValue())); + obj = connector.getProperty("OTEEmbeddedBroker", null); + if (obj != null && obj instanceof NodeInfo) { + debug("Registering client connection service"); + NodeInfo nodeInfo = (NodeInfo) obj; + registerConnectionNode(nodeInfo); + } else { + debug(String.format("Problem using connector...%s:%s", obj.getClass(), obj)); + EnhancedProperties properties = connector.getProperties(); + for( Entry<String, Serializable> entry : properties.entrySet() ) { + debug(String.format("\t%s = %s", entry.getKey(), entry.getValue())); + } } } } - + /** * @param nodeInfo */ @@ -105,7 +130,23 @@ public final class ClientSideConnectionNodeLifecycleController implements ITestC @Override public void onConnectionLost(IServiceConnector connector) { - unregisterConnectionNode(); + Object obj = connector.getProperty("oteUdpEndpoint", null); + if (obj != null) { + try{ + InetSocketAddress address = OteEndpointUtil.getAddress(obj.toString()); + if(!oteEndpoint.getLocalEndpoint().equals(address)){ + oteEndpointSender = oteEndpoint.getOteEndpointSender(address); + oteEndpoint.removeBroadcast(oteEndpointSender); + oteEndpointSender.stop(); + } + } catch (OTEException ex){ + OseeLog.log(getClass(), Level.SEVERE, ex); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } else { + unregisterConnectionNode(); + } } @@ -119,7 +160,23 @@ public final class ClientSideConnectionNodeLifecycleController implements ITestC @Override public void onPreDisconnect(ConnectionEvent event) { - unregisterConnectionNode(); + Object obj = event.getConnector().getProperty("oteUdpEndpoint", null); + if (obj != null) { + try{ + InetSocketAddress address = OteEndpointUtil.getAddress(obj.toString()); + if(!oteEndpoint.getLocalEndpoint().equals(address)){ + oteEndpointSender = oteEndpoint.getOteEndpointSender(address); + oteEndpoint.removeBroadcast(oteEndpointSender); + oteEndpointSender.stop(); + } + } catch (OTEException ex){ + OseeLog.log(getClass(), Level.SEVERE, ex); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } else { + unregisterConnectionNode(); + } } private void debug(String msg ) { diff --git a/plugins/org.eclipse.osee.ote.master.product/org.eclipse.osee.ote.master.product b/plugins/org.eclipse.osee.ote.master.product/org.eclipse.osee.ote.master.product index 14d90d2a0b8..414208d68e1 100644 --- a/plugins/org.eclipse.osee.ote.master.product/org.eclipse.osee.ote.master.product +++ b/plugins/org.eclipse.osee.ote.master.product/org.eclipse.osee.ote.master.product @@ -8,7 +8,7 @@ <launcherArgs> <programArgs>-console</programArgs> - <vmArgs>-Dorg.osgi.service.http.port=8008 + <vmArgs>-Dorg.osgi.service.http.port=8010 -Ddequinox.ds.debug=true -Ddequinox.ds.print=true -Dcm.config.uri="etc/ote.server.config.json"</vmArgs> diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ote.master.rest.client/META-INF/MANIFEST.MF index 537aa2d4e0e..1f63c91d2cc 100644 --- a/plugins/org.eclipse.osee.ote.master.rest.client/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.ote.master.rest.client/META-INF/MANIFEST.MF @@ -6,10 +6,15 @@ Bundle-Version: 0.21.0.qualifier Require-Bundle: org.eclipse.core.runtime Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Import-Package: javax.ws.rs;version="2.0.0", +Import-Package: com.google.inject, + com.google.inject.binder, + com.google.inject.matcher, + com.google.inject.spi, + javax.ws.rs;version="2.0.0", javax.ws.rs.client;version="2.0.0", - javax.ws.rs.core, + javax.ws.rs.core;version="2.0.0", org.eclipse.osee.framework.jdk.core.type, + org.eclipse.osee.jaxrs, org.eclipse.osee.jaxrs.client, org.eclipse.osee.ote.master.rest.model Export-Package: org.eclipse.osee.ote.master.rest.client diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/AddServer.java b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/AddServer.java index 0dc70eee8c7..eb08691b6d8 100644 --- a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/AddServer.java +++ b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/AddServer.java @@ -2,9 +2,11 @@ package org.eclipse.osee.ote.master.rest.client.internal; import java.net.URI; import java.util.concurrent.Callable; + import javax.ws.rs.client.Entity; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriBuilder; + import org.eclipse.osee.jaxrs.client.JaxRsClient; import org.eclipse.osee.ote.master.rest.client.OTEMasterServerResult; import org.eclipse.osee.ote.master.rest.model.OTEServer; diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/OTEMasterServerImpl.java b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/OTEMasterServerImpl.java index 685fb888a02..2a5e334b02f 100644 --- a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/OTEMasterServerImpl.java +++ b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/OTEMasterServerImpl.java @@ -6,6 +6,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.ThreadFactory; + import org.eclipse.osee.jaxrs.client.JaxRsClient; import org.eclipse.osee.ote.master.rest.client.OTEMasterServer; import org.eclipse.osee.ote.master.rest.client.OTEMasterServerAvailableNodes; @@ -26,7 +27,7 @@ public class OTEMasterServerImpl implements OTEMasterServer { public Thread newThread(Runnable arg0) { Thread th = new Thread(arg0); th.setName("OTE Master Client " + th.getId()); - th.setDaemon(true); + th.setDaemon(false); return th; } }); diff --git a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/RemoveServer.java b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/RemoveServer.java index 764e541678f..84bd404078b 100644 --- a/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/RemoveServer.java +++ b/plugins/org.eclipse.osee.ote.master.rest.client/src/org/eclipse/osee/ote/master/rest/client/internal/RemoveServer.java @@ -4,7 +4,6 @@ import java.net.URI; import java.util.concurrent.Callable; import javax.ws.rs.HttpMethod; -import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriBuilder; import org.eclipse.osee.jaxrs.client.JaxRsClient; @@ -27,12 +26,12 @@ public class RemoveServer implements Callable<OTEMasterServerResult> { public OTEMasterServerResult call() throws Exception { OTEMasterServerResult result = new OTEMasterServerResult(); try { - URI targetUri = UriBuilder.fromUri(uri).path(OTEMasterServerImpl.CONTEXT_NAME).path(OTEMasterServerImpl.CONTEXT_SERVERS).path(server.getUUID().toString()).build(); - webClientProvider.target(targetUri).request(MediaType.APPLICATION_XML).method(HttpMethod.DELETE); + URI targetUri = + UriBuilder.fromUri(uri).path(OTEMasterServerImpl.CONTEXT_NAME).path(OTEMasterServerImpl.CONTEXT_SERVERS).path(server.getUUID().toString()).build(); + webClientProvider.target(targetUri).request().method(HttpMethod.DELETE); } catch (Throwable th) { result.setSuccess(false); result.setThrowable(th); - th.printStackTrace(); } return result; } diff --git a/plugins/org.eclipse.osee.ote.parent/pom.xml b/plugins/org.eclipse.osee.ote.parent/pom.xml index 9c1624be424..4d63dd04233 100644 --- a/plugins/org.eclipse.osee.ote.parent/pom.xml +++ b/plugins/org.eclipse.osee.ote.parent/pom.xml @@ -29,6 +29,8 @@ <module>../../plugins/org.eclipse.osee.ote.rest</module> <module>../../plugins/org.eclipse.osee.ote.rest.client</module> <module>../../plugins/org.eclipse.osee.ote.rest.model</module> + <module>../../plugins/org.eclipse.osee.ote.properties</module> + <module>../../plugins/org.eclipse.osee.ote.io</module> <module>../../plugins/org.eclipse.osee.ote.client</module> <module>../../plugins/org.eclipse.osee.ote.client.msg</module> <module>../../plugins/org.eclipse.osee.ote.connection.jini</module> diff --git a/plugins/org.eclipse.osee.ote.properties/.classpath b/plugins/org.eclipse.osee.ote.properties/.classpath new file mode 100644 index 00000000000..ad32c83a788 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.properties/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/plugins/org.eclipse.osee.ote.properties/.project b/plugins/org.eclipse.osee.ote.properties/.project new file mode 100644 index 00000000000..0b97c2ca621 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.properties/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.eclipse.osee.ote.properties</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/plugins/org.eclipse.osee.ote.properties/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ote.properties/META-INF/MANIFEST.MF new file mode 100644 index 00000000000..4d6dd03d8ab --- /dev/null +++ b/plugins/org.eclipse.osee.ote.properties/META-INF/MANIFEST.MF @@ -0,0 +1,8 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: OTE Properties +Bundle-SymbolicName: org.eclipse.osee.ote.properties +Bundle-Version: 0.19.0.qualifier +Require-Bundle: org.eclipse.core.runtime +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Export-Package: org.eclipse.osee.ote.properties diff --git a/plugins/org.eclipse.osee.ote.properties/build.properties b/plugins/org.eclipse.osee.ote.properties/build.properties new file mode 100644 index 00000000000..34d2e4d2dad --- /dev/null +++ b/plugins/org.eclipse.osee.ote.properties/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/plugins/org.eclipse.osee.ote.properties/pom.xml b/plugins/org.eclipse.osee.ote.properties/pom.xml new file mode 100644 index 00000000000..9af17ce1d3b --- /dev/null +++ b/plugins/org.eclipse.osee.ote.properties/pom.xml @@ -0,0 +1,35 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.eclipse.osee</groupId> + <artifactId>org.eclipse.osee.ote.parent</artifactId> + <version>0.19.0-SNAPSHOT</version> + <relativePath>../../plugins/org.eclipse.osee.ote.parent</relativePath> + </parent> + + <artifactId>org.eclipse.osee.ote.properties</artifactId> + <packaging>eclipse-plugin</packaging> + <name>OTE Properties</name> + + <build> + <!-- workaround for https://issues.sonatype.org/browse/TYCHO-168 --> + <resources> + <resource> + <directory>src</directory> + <excludes> + <exclude>**/*.java</exclude> + </excludes> + </resource> + </resources> + <plugins> + <plugin> + <groupId>org.eclipse.tycho</groupId> + <artifactId>tycho-source-plugin</artifactId> + </plugin> + </plugins> + </build> + +</project>
\ No newline at end of file diff --git a/plugins/org.eclipse.osee.ote.properties/src/org/eclipse/osee/ote/properties/OteProperties.java b/plugins/org.eclipse.osee.ote.properties/src/org/eclipse/osee/ote/properties/OteProperties.java new file mode 100644 index 00000000000..869ef86ca3e --- /dev/null +++ b/plugins/org.eclipse.osee.ote.properties/src/org/eclipse/osee/ote/properties/OteProperties.java @@ -0,0 +1,8 @@ +package org.eclipse.osee.ote.properties; + +public interface OteProperties { + String getKey(); + void setValue(String value); + String getValue(); + String getValue(String defaultValue); +} diff --git a/plugins/org.eclipse.osee.ote.properties/src/org/eclipse/osee/ote/properties/OtePropertiesCore.java b/plugins/org.eclipse.osee.ote.properties/src/org/eclipse/osee/ote/properties/OtePropertiesCore.java new file mode 100644 index 00000000000..d2a0c4340ce --- /dev/null +++ b/plugins/org.eclipse.osee.ote.properties/src/org/eclipse/osee/ote/properties/OtePropertiesCore.java @@ -0,0 +1,127 @@ +package org.eclipse.osee.ote.properties; + +public enum OtePropertiesCore implements OteProperties { + + batchFolderDays("ote.batchfolder.days"), + brokerUriPort("ote.server.broker.uri.port"), + endpointPort("ote.endpoint.port"), + httpPort("org.osgi.service.http.port"), + ioRedirectFile("ote.io.redirect.file"), + ioRedirect("ote.io.redirect"), + ioRedirectPath("ote.io.redirect.path"), + javaIoTmpdir("java.io.tmpdir"), + lineSeparator("line.separator"), + masterURI("ote.master.uri"), + noStacktraceFilter("org.eclipse.osee.ote.core.noStacktraceFilter"), + outfilesLocation("osee.ote.outfiles"), + pingTimeout("ote.client.pingTimeout"), + serverConnectionTimeout("ote.server.connection.timeout"), + serverFactoryClass("osee.ote.server.factory.class"), + serverKeepalive("osee.ote.server.keepAlive"), + serverTitle("osee.ote.server.title"), + timeDebug("ote.time.debug", false), + timeDebugTimeout("ote.time.debug.timeout", 250000), + userHome("user.home"), + userName("user.name"), + useLookup("osee.ote.use.lookup"); + + private String key; + private long defaultLong; + private boolean defaultBoolean; + private String defaultString; + + private final boolean defaultValueSet; + + OtePropertiesCore(String key){ + this.key = key; + this.defaultValueSet = false; + } + + OtePropertiesCore(String key, long defaultLong){ + this.key = key; + this.defaultLong = defaultLong; + this.defaultValueSet = true; + } + + OtePropertiesCore(String key, boolean defaultBoolean){ + this.key = key; + this.defaultBoolean = defaultBoolean; + this.defaultValueSet = true; + } + + OtePropertiesCore(String key, String defaultString){ + this.key = key; + this.defaultString = defaultString; + this.defaultValueSet = true; + } + + @Override + public String getKey() { + return key; + } + + @Override + public void setValue(String value) { + System.setProperty(key, value); + } + + @Override + public String getValue() { + return System.getProperty(key); + } + + @Override + public String getValue(String defaultValue) { + return System.getProperty(key, defaultValue); + } + + public long getLongValue(long defaultValue) { + long value = defaultValue; + String valueStr = System.getProperty(key); + try{ + value = Long.parseLong(valueStr); + } catch (Throwable th){ + } + return value; + } + + public long getLongValue() { + if(!defaultValueSet){ + throw new IllegalStateException("No default value set."); + } + long value = defaultLong; + String valueStr = System.getProperty(key); + try{ + value = Long.parseLong(valueStr); + } catch (Throwable th){ + } + return value; + } + + public boolean getBooleanValue(boolean defaultValue) { + boolean value = defaultValue; + String valueStr = System.getProperty(key); + if(valueStr != null){ + try{ + value = Boolean.parseBoolean(valueStr); + } catch (Throwable th){ + } + } + return value; + } + + public boolean getBooleanValue() { + if(!defaultValueSet){ + throw new IllegalStateException("No default value set."); + } + boolean value = defaultBoolean; + String valueStr = System.getProperty(key); + if(valueStr != null){ + try{ + value = Boolean.parseBoolean(valueStr); + } catch (Throwable th){ + } + } + return value; + } +} diff --git a/plugins/org.eclipse.osee.ote.rest.client/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ote.rest.client/META-INF/MANIFEST.MF index e352e7d10bb..b2d52943919 100644 --- a/plugins/org.eclipse.osee.ote.rest.client/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.ote.rest.client/META-INF/MANIFEST.MF @@ -20,8 +20,8 @@ Import-Package: javax.ws.rs;version="2.0.0", org.eclipse.osee.framework.jdk.core.util, org.eclipse.osee.framework.jdk.core.util.network, org.eclipse.osee.framework.logging, - org.eclipse.osee.framework.plugin.core.server, org.eclipse.osee.jaxrs.client, + org.eclipse.osee.ote.classserver, org.eclipse.osee.ote.core Export-Package: org.eclipse.osee.ote.rest.client Bundle-ActivationPolicy: lazy diff --git a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/Cancel.java b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/Cancel.java deleted file mode 100644 index 243de6e7bca..00000000000 --- a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/Cancel.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.eclipse.osee.ote.rest.client.internal; - -public interface Cancel { - - boolean cancelAll(); - - boolean cancelSingle(); - -} diff --git a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/ConfigureOteServer.java b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/ConfigureOteServer.java index 7ac8af368f2..397fb3eb04a 100644 --- a/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/ConfigureOteServer.java +++ b/plugins/org.eclipse.osee.ote.rest.client/src/org/eclipse/osee/ote/rest/client/internal/ConfigureOteServer.java @@ -4,15 +4,17 @@ import java.io.File; import java.net.InetAddress; import java.net.URI; import java.util.List; + import javax.ws.rs.client.Entity; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriBuilder; + import org.eclipse.osee.framework.jdk.core.util.network.PortUtil; import org.eclipse.osee.jaxrs.client.JaxRsClient; import org.eclipse.osee.jaxrs.client.JaxRsWebTarget; +import org.eclipse.osee.ote.classserver.HeadlessClassServer; import org.eclipse.osee.ote.core.BundleInfo; import org.eclipse.osee.ote.rest.client.Progress; -import org.eclipse.osee.ote.rest.client.internal.jarserver.HeadlessClassServer; import org.eclipse.osee.ote.rest.model.OTEConfiguration; import org.eclipse.osee.ote.rest.model.OTEConfigurationIdentity; import org.eclipse.osee.ote.rest.model.OTEConfigurationItem; diff --git a/plugins/org.eclipse.osee.ote.rest/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ote.rest/META-INF/MANIFEST.MF index 07b64b69ffc..fc2b06dbbd3 100644 --- a/plugins/org.eclipse.osee.ote.rest/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.ote.rest/META-INF/MANIFEST.MF @@ -15,6 +15,7 @@ Import-Package: javax.ws.rs, org.eclipse.osee.ote.core, org.eclipse.osee.ote.core.environment, org.eclipse.osee.ote.core.framework.command, + org.eclipse.osee.ote.io, org.eclipse.osee.ote.rest.model Require-Bundle: org.eclipse.osee.framework.jdk.core, org.eclipse.core.runtime diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteBatchesResource.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteBatchesResource.java index b92e6089ac4..b490478ff8b 100644 --- a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteBatchesResource.java +++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteBatchesResource.java @@ -24,7 +24,6 @@ import javax.ws.rs.core.UriInfo; import org.eclipse.osee.framework.jdk.core.type.OseeCoreException; import org.eclipse.osee.ote.OTEApi; -import org.eclipse.osee.ote.OTEServerFolder; import org.eclipse.osee.ote.core.ServiceUtility; /** diff --git a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteRootResource.java b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteRootResource.java index dc5fce02f14..e91c5855cd8 100644 --- a/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteRootResource.java +++ b/plugins/org.eclipse.osee.ote.rest/src/org/eclipse/osee/ote/rest/internal/OteRootResource.java @@ -11,16 +11,11 @@ package org.eclipse.osee.ote.rest.internal; import java.io.File; -import java.io.IOException; -import java.io.OutputStream; import java.util.Arrays; -import java.util.Comparator; import javax.ws.rs.GET; import javax.ws.rs.Path; -import javax.ws.rs.PathParam; import javax.ws.rs.Produces; -import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Request; @@ -49,7 +44,7 @@ public class OteRootResource { public String getConfiguration() throws OseeCoreException { String url = uriInfo.getAbsolutePath().toASCIIString(); OTEApi ote = ServiceUtility.getService(OTEApi.class); - File serverFolder = ote.getServerFolder().getServerFolder(); + File serverFolder = ote.getServerFolder().getRootFolder(); HTMLBuilder builder = new HTMLBuilder(); builder.open("OTE Server"); builder.commonHeader(serverFolder); diff --git a/plugins/org.eclipse.osee.ote.runtimeManager/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ote.runtimeManager/META-INF/MANIFEST.MF index 792e8fed71d..4796d70ec1c 100644 --- a/plugins/org.eclipse.osee.ote.runtimeManager/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.ote.runtimeManager/META-INF/MANIFEST.MF @@ -15,11 +15,11 @@ Import-Package: org.eclipse.core.resources, org.eclipse.osee.framework.jdk.core.util, org.eclipse.osee.framework.logging, org.eclipse.osee.framework.plugin.core, - org.eclipse.osee.framework.plugin.core.server, org.eclipse.osee.framework.plugin.core.util, org.eclipse.osee.framework.ui.plugin.workspace, org.eclipse.osee.framework.ui.swt, org.eclipse.osee.framework.ui.workspacebundleloader, + org.eclipse.osee.ote.classserver, org.eclipse.osee.ote.core, org.eclipse.swt, org.eclipse.swt.layout, diff --git a/plugins/org.eclipse.osee.ote.runtimeManager/src/org/eclipse/osee/ote/runtimemanager/UserLibResourceFinder.java b/plugins/org.eclipse.osee.ote.runtimeManager/src/org/eclipse/osee/ote/runtimemanager/UserLibResourceFinder.java index d24c0a8ba07..c176b4cc6ac 100644 --- a/plugins/org.eclipse.osee.ote.runtimeManager/src/org/eclipse/osee/ote/runtimemanager/UserLibResourceFinder.java +++ b/plugins/org.eclipse.osee.ote.runtimeManager/src/org/eclipse/osee/ote/runtimemanager/UserLibResourceFinder.java @@ -14,13 +14,14 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; + import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.JavaCore; -import org.eclipse.osee.framework.plugin.core.server.ResourceFinder; +import org.eclipse.osee.ote.classserver.ResourceFinder; /** * Finds resources that diff --git a/plugins/org.eclipse.osee.ote.runtimeManager/src/org/eclipse/osee/ote/runtimemanager/internal/RuntimeBundleServer.java b/plugins/org.eclipse.osee.ote.runtimeManager/src/org/eclipse/osee/ote/runtimemanager/internal/RuntimeBundleServer.java index 5fbe4b11d5b..2cdd500c4ba 100644 --- a/plugins/org.eclipse.osee.ote.runtimeManager/src/org/eclipse/osee/ote/runtimemanager/internal/RuntimeBundleServer.java +++ b/plugins/org.eclipse.osee.ote.runtimeManager/src/org/eclipse/osee/ote/runtimemanager/internal/RuntimeBundleServer.java @@ -17,8 +17,8 @@ import java.util.logging.Level; import org.eclipse.osee.framework.logging.OseeLog; import org.eclipse.osee.framework.plugin.core.CorePreferences; -import org.eclipse.osee.framework.plugin.core.server.ClassServer; -import org.eclipse.osee.framework.plugin.core.server.ResourceFinder; +import org.eclipse.osee.ote.classserver.ClassServer; +import org.eclipse.osee.ote.classserver.ResourceFinder; import org.eclipse.osee.ote.runtimemanager.RuntimeManager; import org.eclipse.osee.ote.runtimemanager.SafeWorkspaceTracker; diff --git a/plugins/org.eclipse.osee.ote.runtimeManager/src/org/eclipse/osee/ote/runtimemanager/internal/RuntimeLibResourceFinder.java b/plugins/org.eclipse.osee.ote.runtimeManager/src/org/eclipse/osee/ote/runtimemanager/internal/RuntimeLibResourceFinder.java index 239b431f494..79c858f4a13 100644 --- a/plugins/org.eclipse.osee.ote.runtimeManager/src/org/eclipse/osee/ote/runtimemanager/internal/RuntimeLibResourceFinder.java +++ b/plugins/org.eclipse.osee.ote.runtimeManager/src/org/eclipse/osee/ote/runtimemanager/internal/RuntimeLibResourceFinder.java @@ -13,9 +13,10 @@ package org.eclipse.osee.ote.runtimemanager.internal; import java.io.FileInputStream; import java.io.IOException; import java.util.Collection; + import org.eclipse.core.runtime.CoreException; import org.eclipse.osee.framework.jdk.core.util.Lib; -import org.eclipse.osee.framework.plugin.core.server.ResourceFinder; +import org.eclipse.osee.ote.classserver.ResourceFinder; import org.eclipse.osee.ote.core.BundleInfo; import org.eclipse.osee.ote.runtimemanager.SafeWorkspaceTracker; diff --git a/plugins/org.eclipse.osee.ote.server/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ote.server/META-INF/MANIFEST.MF index a10c4e89aef..9c9d807471e 100644 --- a/plugins/org.eclipse.osee.ote.server/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.ote.server/META-INF/MANIFEST.MF @@ -16,7 +16,6 @@ Import-Package: org.apache.felix.service.command;status=provisional;version="0.8 org.eclipse.osee.framework.jdk.core.util, org.eclipse.osee.framework.jdk.core.util.io.streams, org.eclipse.osee.framework.jdk.core.util.network, - org.eclipse.osee.framework.jini.service.interfaces, org.eclipse.osee.framework.logging, org.eclipse.osee.framework.messaging, org.eclipse.osee.framework.messaging.services, @@ -32,11 +31,14 @@ Import-Package: org.apache.felix.service.command;status=provisional;version="0.8 org.eclipse.osee.ote.core.environment.status, org.eclipse.osee.ote.core.framework.command, org.eclipse.osee.ote.core.model, + org.eclipse.osee.ote.endpoint, + org.eclipse.osee.ote.io, org.eclipse.osee.ote.master.rest.client, org.eclipse.osee.ote.master.rest.model, org.eclipse.osee.ote.message, org.eclipse.osee.ote.message.instrumentation, org.eclipse.osee.ote.message.interfaces, + org.eclipse.osee.ote.properties, org.osgi.framework, org.osgi.service.packageadmin, org.osgi.util.tracker diff --git a/plugins/org.eclipse.osee.ote.server/OSGI-INF/ote.service.starter.xml b/plugins/org.eclipse.osee.ote.server/OSGI-INF/ote.service.starter.xml index 1055ac4893a..b0aa234d71d 100644 --- a/plugins/org.eclipse.osee.ote.server/OSGI-INF/ote.service.starter.xml +++ b/plugins/org.eclipse.osee.ote.server/OSGI-INF/ote.service.starter.xml @@ -10,4 +10,5 @@ <reference unbind="unbindPackageAdmin" bind="bindPackageAdmin" cardinality="1..1" interface="org.osgi.service.packageadmin.PackageAdmin" name="PackageAdmin" policy="static"/> <reference bind="bindOTESessionManager" cardinality="1..1" interface="org.eclipse.osee.ote.core.OTESessionManager" name="OTESessionManager" policy="static" unbind="unbindOTESessionManager"/> <reference bind="bindOTEMasterServer" cardinality="1..1" interface="org.eclipse.osee.ote.master.rest.client.OTEMasterServer" name="OTEMasterServer" policy="static" unbind="unbindOTEMasterServer"/> + <reference bind="bindOteUdpEndpoint" cardinality="1..1" interface="org.eclipse.osee.ote.endpoint.OteUdpEndpoint" name="OteUdpEndpoint" policy="static" unbind="unbindOteUdpEndpoint"/> </scr:component> diff --git a/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/OteClose.java b/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/OteClose.java index 5fe6e447d68..a1ac2d3dd2c 100644 --- a/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/OteClose.java +++ b/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/OteClose.java @@ -15,6 +15,7 @@ import java.util.Hashtable; import org.apache.felix.service.command.CommandProcessor; import org.apache.felix.service.command.Descriptor; +import org.eclipse.osee.ote.core.ServiceUtility; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; @@ -32,6 +33,10 @@ public class OteClose { @Descriptor ("Shutdown the OTE Server") public void x() throws Exception { + OteServiceStarter service = ServiceUtility.getService(OteServiceStarter.class); + if(service != null){ + service.stop(); + } BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext(); Bundle systemBundle = context.getBundle(0); systemBundle.stop(); diff --git a/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OTEServerCreationComponent.java b/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OTEServerCreationComponent.java index f9c79c7fe51..126c52f344a 100644 --- a/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OTEServerCreationComponent.java +++ b/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OTEServerCreationComponent.java @@ -16,6 +16,7 @@ import java.util.logging.Level; import org.eclipse.osee.framework.logging.OseeLog; import org.eclipse.osee.ote.connection.jini.JiniServiceSideConnector; +import org.eclipse.osee.ote.properties.OtePropertiesCore; import org.eclipse.osee.ote.server.OteServiceStarter; import org.eclipse.osee.ote.server.PropertyParamter; import org.eclipse.osee.ote.server.TestEnvironmentServiceConfigImpl; @@ -36,16 +37,17 @@ public class OTEServerCreationComponent { } public void start() { - final String oteServerFactoryClass = System.getProperty("osee.ote.server.factory.class"); + + final String oteServerFactoryClass = OtePropertiesCore.serverFactoryClass.getValue(); if (oteServerFactoryClass != null) { try{ - String outfileLocation = System.getProperty("osee.ote.outfiles"); + String outfileLocation = OtePropertiesCore.outfilesLocation.getValue(); if (outfileLocation == null) { - outfileLocation = System.getProperty("java.io.tmpdir"); + outfileLocation = OtePropertiesCore.javaIoTmpdir.getValue(); } - String title = System.getProperty("osee.ote.server.title"); - String name = System.getProperty("user.name"); - String keepEnvAliveWithNoUsersStr = System.getProperty("osee.ote.server.keepAlive"); + String title = OtePropertiesCore.serverTitle.getValue(); + String name = OtePropertiesCore.userName.getValue(); + String keepEnvAliveWithNoUsersStr = OtePropertiesCore.serverKeepalive.getValue(); boolean keepEnvAliveWithNoUsers = true; if (keepEnvAliveWithNoUsersStr != null) { keepEnvAliveWithNoUsers = Boolean.parseBoolean(keepEnvAliveWithNoUsersStr); @@ -69,7 +71,7 @@ public class OTEServerCreationComponent { } catch (UnknownHostException ex) { OseeLog.log(OTEServerCreationComponent.class, Level.SEVERE, ex); } - boolean useJiniLookup = System.getProperty("osee.ote.use.lookup") != null; + boolean useJiniLookup = OtePropertiesCore.useLookup.getValue() != null; boolean isLocalConnector = false; int index = oteServerFactoryClass.indexOf('.'); diff --git a/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OteService.java b/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OteService.java index 769c3dd548f..821509785ca 100644 --- a/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OteService.java +++ b/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OteService.java @@ -10,11 +10,13 @@ *******************************************************************************/ package org.eclipse.osee.ote.server.internal; -import java.net.InetAddress; +import java.io.File; +import java.io.FileOutputStream; import java.rmi.RemoteException; import java.util.Collection; import java.util.Date; import java.util.LinkedList; +import java.util.Properties; import java.util.UUID; import java.util.logging.Level; @@ -23,24 +25,28 @@ import net.jini.id.Uuid; import net.jini.id.UuidFactory; import org.eclipse.osee.framework.jdk.core.util.EnhancedProperties; -import org.eclipse.osee.framework.jini.service.interfaces.IService; import org.eclipse.osee.framework.logging.OseeLog; import org.eclipse.osee.framework.messaging.NodeInfo; import org.eclipse.osee.framework.messaging.services.RegisteredServiceReference; +import org.eclipse.osee.ote.HostServerProperties; import org.eclipse.osee.ote.core.ConnectionRequestResult; import org.eclipse.osee.ote.core.IRemoteUserSession; import org.eclipse.osee.ote.core.IUserSession; import org.eclipse.osee.ote.core.OSEEPerson1_4; import org.eclipse.osee.ote.core.OTESessionManager; import org.eclipse.osee.ote.core.ReturnStatus; +import org.eclipse.osee.ote.core.ServiceUtility; import org.eclipse.osee.ote.core.environment.TestEnvironmentConfig; import org.eclipse.osee.ote.core.environment.interfaces.IHostTestEnvironment; import org.eclipse.osee.ote.core.environment.interfaces.IRuntimeLibraryManager; import org.eclipse.osee.ote.core.environment.interfaces.ITestEnvironment; +import org.eclipse.osee.ote.endpoint.OteUdpEndpoint; +import org.eclipse.osee.ote.io.OTEServerFolder; import org.eclipse.osee.ote.message.MessageSystemTestEnvironment; +import org.eclipse.osee.ote.properties.OtePropertiesCore; import org.eclipse.osee.ote.server.PropertyParamter; -public class OteService implements IHostTestEnvironment, IService { +public class OteService implements IHostTestEnvironment { private final ServiceID serviceID; private final EnhancedProperties enhancedProperties; @@ -52,7 +58,7 @@ public class OteService implements IHostTestEnvironment, IService { private OTESessionManager oteSessions; - public OteService(IRuntimeLibraryManager runtimeLibraryManager, EnvironmentCreationParameter environmentCreation, OTESessionManager oteSessions, PropertyParamter parameterObject, EnhancedProperties properties) { + public OteService(IRuntimeLibraryManager runtimeLibraryManager, EnvironmentCreationParameter environmentCreation, OTESessionManager oteSessions, PropertyParamter parameterObject, EnhancedProperties properties, OteUdpEndpoint receiver) { this.runtimeLibraryManager = runtimeLibraryManager; this.environmentCreation = environmentCreation; this.oteSessions = oteSessions; @@ -63,25 +69,46 @@ public class OteService implements IHostTestEnvironment, IService { serviceID = new ServiceID(msb.longValue(), lsb.longValue()); enhancedProperties = properties; - enhancedProperties.setProperty("name", environmentCreation.getServerTitle()); - enhancedProperties.setProperty("station", parameterObject.getStation()); - enhancedProperties.setProperty("version", parameterObject.getVersion()); - enhancedProperties.setProperty("type", parameterObject.getType()); - enhancedProperties.setProperty("maxUsers", Integer.toString(environmentCreation.getMaxUsersPerEnvironment())); - enhancedProperties.setProperty("comment", parameterObject.getComment()); - enhancedProperties.setProperty("date", new Date().toString()); - enhancedProperties.setProperty("group", "OSEE Test Environment"); - enhancedProperties.setProperty("owner", System.getProperty("user.name")); - enhancedProperties.setProperty("id", serviceID.toString()); + enhancedProperties.setProperty(HostServerProperties.name.name(), environmentCreation.getServerTitle()); + enhancedProperties.setProperty(HostServerProperties.station.name(), parameterObject.getStation()); + enhancedProperties.setProperty(HostServerProperties.version.name(), parameterObject.getVersion()); + enhancedProperties.setProperty(HostServerProperties.type.name(), parameterObject.getType()); + enhancedProperties.setProperty(HostServerProperties.maxUsers.name(), Integer.toString(environmentCreation.getMaxUsersPerEnvironment())); + enhancedProperties.setProperty(HostServerProperties.comment.name(), parameterObject.getComment()); + enhancedProperties.setProperty(HostServerProperties.date.name(), new Date().toString()); + enhancedProperties.setProperty(HostServerProperties.group.name(), "OSEE Test Environment"); + enhancedProperties.setProperty(HostServerProperties.owner.name(), OtePropertiesCore.userName.getValue()); + enhancedProperties.setProperty(HostServerProperties.id.name(), serviceID.toString()); + enhancedProperties.setProperty(HostServerProperties.activeMq.name(), environmentCreation.getBroker().getUri().toString()); try { - if(System.getProperty("org.osgi.service.http.port") == null){ - enhancedProperties.setProperty("appServerURI", String.format("http://%s:%s", InetAddress.getLocalHost().getHostAddress(), 80)); + String format = String.format("tcp://%s:%d", receiver.getLocalEndpoint().getAddress().getHostAddress(), receiver.getLocalEndpoint().getPort()); + if(OtePropertiesCore.httpPort.getValue() == null){ + enhancedProperties.setProperty(HostServerProperties.appServerURI.name(), format); } else { - enhancedProperties.setProperty("appServerURI", String.format("http://%s:%s", InetAddress.getLocalHost().getHostAddress(), Integer.parseInt(System.getProperty("org.osgi.service.http.port")))); + enhancedProperties.setProperty(HostServerProperties.appServerURI.name(), format); } + enhancedProperties.setProperty(HostServerProperties.oteUdpEndpoint.name(), format); } catch (Exception e) { OseeLog.log(OteService.class, Level.SEVERE, "Failed to set the appServerURI", e); } + + OTEServerFolder service = ServiceUtility.getService(OTEServerFolder.class); + if(service != null){ + File dir = service.getCurrentServerFolder(); + dir.mkdirs(); + if(dir.exists() && dir.isDirectory()){ + try{ + Properties serverProperties = new Properties(); + serverProperties.putAll(enhancedProperties.asMap()); + serverProperties.store(new FileOutputStream(new File(dir, "server.properties")), ""); + File running = new File(dir, ".running"); + running.createNewFile(); + running.deleteOnExit(); + } catch (Throwable th){ + th.printStackTrace(); + } + } + } } @Override @@ -132,7 +159,7 @@ public class OteService implements IHostTestEnvironment, IService { try { userList.add(session.getUser()); } catch (Exception e) { - OseeLog.log(OteService.class, Level.SEVERE, e); + OseeLog.log(OteService.class, Level.WARNING, e); } } } @@ -151,12 +178,10 @@ public class OteService implements IHostTestEnvironment, IService { } } - @Override public ServiceID getServiceID() throws RemoteException { return serviceID; } - @Override public void kill() throws RemoteException { if(currentEnvironment != null){ currentEnvironment.shutdown(); diff --git a/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OteServiceStarterImpl.java b/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OteServiceStarterImpl.java index b8cd5ed3ce6..2ab67b08978 100644 --- a/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OteServiceStarterImpl.java +++ b/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/OteServiceStarterImpl.java @@ -50,12 +50,15 @@ import org.eclipse.osee.framework.messaging.services.messages.ServiceDescription import org.eclipse.osee.framework.plugin.core.util.ExportClassLoader; import org.eclipse.osee.ote.core.OTESessionManager; import org.eclipse.osee.ote.core.OteBaseMessages; +import org.eclipse.osee.ote.core.ServiceUtility; import org.eclipse.osee.ote.core.environment.interfaces.IHostTestEnvironment; import org.eclipse.osee.ote.core.environment.interfaces.IRuntimeLibraryManager; import org.eclipse.osee.ote.core.environment.interfaces.ITestEnvironmentServiceConfig; +import org.eclipse.osee.ote.endpoint.OteUdpEndpoint; import org.eclipse.osee.ote.master.rest.client.OTEMasterServer; import org.eclipse.osee.ote.master.rest.client.OTEMasterServerResult; import org.eclipse.osee.ote.master.rest.model.OTEServer; +import org.eclipse.osee.ote.properties.OtePropertiesCore; import org.eclipse.osee.ote.server.OteServiceStarter; import org.eclipse.osee.ote.server.PropertyParamter; import org.eclipse.osee.ote.server.TestEnvironmentFactory; @@ -66,7 +69,7 @@ import org.osgi.service.packageadmin.PackageAdmin; * @author Andrew M. Finkbeiner */ public class OteServiceStarterImpl implements OteServiceStarter, ServiceInfoPopulator, OseeMessagingStatusCallback { - + private PackageAdmin packageAdmin; private IRuntimeLibraryManager runtimeLibraryManager; private IConnectionService connectionService; @@ -87,6 +90,8 @@ public class OteServiceStarterImpl implements OteServiceStarter, ServiceInfoPopu private URI masterURI; private NodeInfo nodeInfo; private int brokerPort = 0; + private OteUdpEndpoint receiver; + private boolean ENABLE_BROKER; public OteServiceStarterImpl() { listenForHostRequest = new ListenForHostRequest(); @@ -151,6 +156,14 @@ public class OteServiceStarterImpl implements OteServiceStarter, ServiceInfoPopu this.packageAdmin = null; } + public void bindOteUdpEndpoint(OteUdpEndpoint receiver){ + this.receiver = receiver; + } + + public void unbindOteUdpEndpoint(OteUdpEndpoint receiver){ + this.receiver = receiver; + } + @Override public IHostTestEnvironment start(IServiceConnector serviceSideConnector, ITestEnvironmentServiceConfig config, PropertyParamter propertyParameter, String environmentFactoryClass) throws Exception { return start(serviceSideConnector, config, propertyParameter, null, environmentFactoryClass); @@ -166,44 +179,45 @@ public class OteServiceStarterImpl implements OteServiceStarter, ServiceInfoPopu throw new OseeStateException("An ote Server has already been started."); } this.serviceSideConnector = serviceSideConnector; - if(System.getProperty("org.osgi.service.http.port") == null){ - System.out.println("Property org.osgi.service.http.port was not set, it will default to port 80."); - } else { - System.out.printf("BETA SERVER URL[http://%s:%s/ote]\n", InetAddress.getLocalHost().getHostAddress(), Integer.parseInt(System.getProperty("org.osgi.service.http.port"))); - } - brokerService = new BrokerService(); + ENABLE_BROKER = Boolean.parseBoolean(System.getProperty("ote.enable.broker", "true")); + if(ENABLE_BROKER){ + brokerService = new BrokerService(); - String strUri; - try { - String addressAsString = getAddress(); - if(brokerPort <= 0){ - brokerPort = getServerPort(); - } - strUri = String.format("tcp://%s:%d", addressAsString, brokerPort); - try { - brokerService.addConnector(strUri); - OseeLog.log(getClass(), Level.INFO, "Added TCP connector: " + strUri); - } catch (Exception e) { - OseeLog.log(getClass(), Level.SEVERE, "could not add connector for " + strUri, e); - strUri = "vm://localhost?broker.persistent=false"; - } - } catch (Exception e) { - OseeLog.log(getClass(), Level.SEVERE, "could acquire a TCP address", e); - strUri = "vm://localhost?broker.persistent=false"; - } - //necessary for rmi/jini classloading - Thread.currentThread().setContextClassLoader(ExportClassLoader.getInstance()); - - brokerService.setEnableStatistics(false); - brokerService.setBrokerName("OTEServer"); - brokerService.setPersistent(false); - brokerService.setUseJmx(false); - brokerService.start(); - URI uri = new URI(strUri); - - System.out.printf("SERVER CONNECTION(ACTIVEMQ) URI[\n\t%s\n]\n", strUri); + String strUri; + try { + String addressAsString = getAddress(); + if(brokerPort <= 0){ + brokerPort = getServerPort(); + } + strUri = String.format("tcp://%s:%d", addressAsString, brokerPort); + try { + brokerService.addConnector(strUri); + OseeLog.log(getClass(), Level.INFO, "Added TCP connector: " + strUri); + } catch (Exception e) { + OseeLog.log(getClass(), Level.SEVERE, "could not add connector for " + strUri, e); + strUri = "vm://localhost?broker.persistent=false"; + } + } catch (Exception e) { + OseeLog.log(getClass(), Level.SEVERE, "could acquire a TCP address", e); + strUri = "vm://localhost?broker.persistent=false"; + } + //necessary for rmi/jini classloading + Thread.currentThread().setContextClassLoader(ExportClassLoader.getInstance()); - nodeInfo = new NodeInfo("OTEEmbeddedBroker", uri); + brokerService.setEnableStatistics(false); + brokerService.setBrokerName("OTEServer"); + brokerService.setPersistent(false); + brokerService.setUseJmx(false); + brokerService.start(); + URI uri = new URI(strUri); + + nodeInfo = new NodeInfo("OTEEmbeddedBroker", uri); + } else { + URI uri = new URI(String.format("tcp://%s:%d", "nohost", 0)); + nodeInfo = new NodeInfo("OTEEmbeddedBroker", uri); + } + OteUdpEndpoint oteEndpoint = ServiceUtility.getService(OteUdpEndpoint.class); + System.out.printf("SERVER CONNECTION URI[\n\ttcp://%s:%d\n]\n", oteEndpoint.getLocalEndpoint().getAddress().getHostAddress(), oteEndpoint.getLocalEndpoint().getPort()); EnvironmentCreationParameter environmentCreationParameter = new EnvironmentCreationParameter(runtimeLibraryManager, nodeInfo, serviceSideConnector, config, factory, @@ -211,20 +225,19 @@ public class OteServiceStarterImpl implements OteServiceStarter, ServiceInfoPopu service = new OteService(runtimeLibraryManager, environmentCreationParameter, oteSessions, propertyParameter, - serviceSideConnector.getProperties()); + serviceSideConnector.getProperties(), receiver); serviceSideConnector.init(service); - if (propertyParameter.isLocalConnector() || propertyParameter.useJiniLookup()) { + if (propertyParameter.isLocalConnector()) { connectionService.addConnector(serviceSideConnector); } if (!propertyParameter.isLocalConnector()) { - String masterURIStr = System.getProperty("ote.master.uri"); + String masterURIStr = OtePropertiesCore.masterURI.getValue(); if(masterURIStr != null){ try{ - messageService.get(nodeInfo).subscribe(OteBaseMessages.RequestOteHost, listenForHostRequest, this); masterURI = new URI(masterURIStr); oteServerEntry = createOTEServer(nodeInfo, environmentCreationParameter, propertyParameter, service.getServiceID().toString()); lookupRegistration = new LookupRegistration(masterURI, masterServer, oteServerEntry, service); @@ -232,8 +245,8 @@ public class OteServiceStarterImpl implements OteServiceStarter, ServiceInfoPopu } catch(Throwable th){ OseeLog.log(getClass(), Level.SEVERE, th); } - } else { //user old lookup - OseeLog.log(getClass(), Level.SEVERE, "'ote.master.uri' was not set. You must use direct connect from the client."); + } else { + OseeLog.log(getClass(), Level.WARNING, "'ote.master.uri' was not set. You must use direct connect from the client."); } } else { @@ -253,19 +266,15 @@ public class OteServiceStarterImpl implements OteServiceStarter, ServiceInfoPopu server.setType(propertyParameter.getType()); server.setComment(propertyParameter.getComment()); server.setStartTime(new Date().toString()); - server.setOwner(System.getProperty("user.name")); + server.setOwner(OtePropertiesCore.userName.getValue()); server.setUUID(uuid); - if(System.getProperty("org.osgi.service.http.port") == null){ - server.setOteRestServer(String.format("http://%s:%s", InetAddress.getLocalHost().getHostAddress(), 80)); - } else { - server.setOteRestServer(String.format("http://%s:%s", InetAddress.getLocalHost().getHostAddress(), Integer.parseInt(System.getProperty("org.osgi.service.http.port")))); - } + server.setOteRestServer(String.format("tcp://%s:%d", receiver.getLocalEndpoint().getAddress().getHostAddress(), receiver.getLocalEndpoint().getPort())); server.setOteActivemqServer(nodeInfo.getUri().toString()); return server; } private int getServerPort() throws IOException { - String portFromLaunch = System.getProperty("ote.server.broker.uri.port"); + String portFromLaunch = OtePropertiesCore.brokerUriPort.getValue(); int port = 0; if (portFromLaunch != null) { try { @@ -281,7 +290,7 @@ public class OteServiceStarterImpl implements OteServiceStarter, ServiceInfoPopu @Override public void stop() { - if(messageService != null && nodeInfo != null){ + if(messageService != null && nodeInfo != null && service != null){ try { messageService.get(nodeInfo).send(OteBaseMessages.OteHostShutdown, service.getServiceID().toString()); } catch (OseeCoreException e) { @@ -323,8 +332,11 @@ public class OteServiceStarterImpl implements OteServiceStarter, ServiceInfoPopu try { removeServer.get(1000, TimeUnit.MILLISECONDS); } catch (InterruptedException e) { + OseeLog.log(getClass(), Level.INFO, e); } catch (ExecutionException e) { + OseeLog.log(getClass(), Level.INFO, e); } catch (TimeoutException e) { + OseeLog.log(getClass(), Level.INFO, e); } } } diff --git a/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/RemoteTestEnvironment.java b/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/RemoteTestEnvironment.java index 93544192109..a801c5d30b6 100644 --- a/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/RemoteTestEnvironment.java +++ b/plugins/org.eclipse.osee.ote.server/src/org/eclipse/osee/ote/server/internal/RemoteTestEnvironment.java @@ -21,7 +21,6 @@ import org.eclipse.osee.connection.service.IServiceConnector; import org.eclipse.osee.framework.logging.OseeLog; import org.eclipse.osee.framework.messaging.Message; import org.eclipse.osee.ote.core.ServiceUtility; -import org.eclipse.osee.ote.core.cmd.Command; import org.eclipse.osee.ote.core.environment.console.ICommandManager; import org.eclipse.osee.ote.core.environment.interfaces.IRemoteCommandConsole; import org.eclipse.osee.ote.core.model.IModel; @@ -235,11 +234,6 @@ public class RemoteTestEnvironment implements ITestEnvironmentMessageSystem { } @Override - public void sendCommand(Command command) throws RemoteException { - env.sendCommand(command); - } - - @Override public void sendMessage(Message message) throws RemoteException { env.sendMessageToServer(message); } diff --git a/plugins/org.eclipse.osee.ote.ui.builder/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ote.ui.builder/META-INF/MANIFEST.MF index 8cadb35f20b..8859cc42d6e 100644 --- a/plugins/org.eclipse.osee.ote.ui.builder/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.ote.ui.builder/META-INF/MANIFEST.MF @@ -12,7 +12,6 @@ Bundle-ActivationPolicy: lazy Import-Package: org.eclipse.core.resources, org.eclipse.osee.framework.jdk.core.util, org.eclipse.osee.framework.logging, - org.eclipse.osee.framework.plugin.core.server, org.eclipse.osee.framework.plugin.core.util Bundle-Vendor: Eclipse Open System Engineering Environment Export-Package: org.eclipse.osee.ote.ui.builder diff --git a/plugins/org.eclipse.osee.ote.ui.test.manager/src/org/eclipse/osee/ote/ui/test/manager/core/TestManagerEditorInput.java b/plugins/org.eclipse.osee.ote.ui.test.manager/src/org/eclipse/osee/ote/ui/test/manager/core/TestManagerEditorInput.java index f16a52dc442..1bac0070f78 100644 --- a/plugins/org.eclipse.osee.ote.ui.test.manager/src/org/eclipse/osee/ote/ui/test/manager/core/TestManagerEditorInput.java +++ b/plugins/org.eclipse.osee.ote.ui.test.manager/src/org/eclipse/osee/ote/ui/test/manager/core/TestManagerEditorInput.java @@ -12,10 +12,14 @@ package org.eclipse.osee.ote.ui.test.manager.core; import java.io.File; import java.io.InputStream; + import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IStorage; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.osee.framework.ui.ws.AWorkspace; import org.eclipse.ui.IFileEditorInput; @@ -28,13 +32,23 @@ public class TestManagerEditorInput implements IFileEditorInput, IPersistableEle private final IFile iFile; public TestManagerEditorInput(File file) { - this(AWorkspace.fileToIFile(file)); + this(getIFile(file)); } public TestManagerEditorInput(IFile iFile) { super(); this.iFile = iFile; } + + private static IFile getIFile(File file){ + IFile ifile = AWorkspace.fileToIFile(file); + if(ifile == null){ + IWorkspace workspace= ResourcesPlugin.getWorkspace(); + IPath location= Path.fromOSString(file.getAbsolutePath()); + ifile= workspace.getRoot().getFileForLocation(location); + } + return ifile; + } /* * @see java.lang.Object#equals(java.lang.Object) @@ -102,6 +116,9 @@ public class TestManagerEditorInput implements IFileEditorInput, IPersistableEle */ @Override public String getName() { + if(iFile == null){ + return "TestManager"; + } return iFile.getName(); } diff --git a/plugins/org.eclipse.osee.ote.ui.test.manager/src/org/eclipse/osee/ote/ui/test/manager/core/TestManagerEditorInputFactory.java b/plugins/org.eclipse.osee.ote.ui.test.manager/src/org/eclipse/osee/ote/ui/test/manager/core/TestManagerEditorInputFactory.java index b8a4b81251d..6eefd9b1040 100644 --- a/plugins/org.eclipse.osee.ote.ui.test.manager/src/org/eclipse/osee/ote/ui/test/manager/core/TestManagerEditorInputFactory.java +++ b/plugins/org.eclipse.osee.ote.ui.test.manager/src/org/eclipse/osee/ote/ui/test/manager/core/TestManagerEditorInputFactory.java @@ -23,8 +23,12 @@ public class TestManagerEditorInputFactory implements IElementFactory { @Override public IAdaptable createElement(IMemento memento) { String path = memento.getString("path"); - File file = new File(path); - TestManagerEditorInput input = new TestManagerEditorInput(file); - return input; + if(path != null){ + File file = new File(path); + TestManagerEditorInput input = new TestManagerEditorInput(file); + return input; + } else { + return null; + } } } diff --git a/plugins/org.eclipse.osee.ote.ui.test.manager/src/org/eclipse/osee/ote/ui/test/manager/util/ClassServerInst.java b/plugins/org.eclipse.osee.ote.ui.test.manager/src/org/eclipse/osee/ote/ui/test/manager/util/ClassServerInst.java index 54204a98ffc..6eee0601b7e 100644 --- a/plugins/org.eclipse.osee.ote.ui.test.manager/src/org/eclipse/osee/ote/ui/test/manager/util/ClassServerInst.java +++ b/plugins/org.eclipse.osee.ote.ui.test.manager/src/org/eclipse/osee/ote/ui/test/manager/util/ClassServerInst.java @@ -27,10 +27,10 @@ import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jdt.core.JavaCore; import org.eclipse.osee.framework.logging.OseeLog; import org.eclipse.osee.framework.plugin.core.CorePreferences; -import org.eclipse.osee.framework.plugin.core.server.ClassServer; -import org.eclipse.osee.framework.plugin.core.server.PathResourceFinder; import org.eclipse.osee.framework.ui.ws.AJavaProject; import org.eclipse.osee.framework.ui.ws.AWorkspace; +import org.eclipse.osee.ote.classserver.ClassServer; +import org.eclipse.osee.ote.classserver.PathResourceFinder; import org.eclipse.osee.ote.runtimemanager.UserLibResourceFinder; public class ClassServerInst { diff --git a/plugins/org.eclipse.osee.ote.ui.test.manager/src/org/eclipse/osee/ote/ui/test/manager/util/OTEBuilderResourceFinder.java b/plugins/org.eclipse.osee.ote.ui.test.manager/src/org/eclipse/osee/ote/ui/test/manager/util/OTEBuilderResourceFinder.java index b1e43657af0..de094c5fd18 100644 --- a/plugins/org.eclipse.osee.ote.ui.test.manager/src/org/eclipse/osee/ote/ui/test/manager/util/OTEBuilderResourceFinder.java +++ b/plugins/org.eclipse.osee.ote.ui.test.manager/src/org/eclipse/osee/ote/ui/test/manager/util/OTEBuilderResourceFinder.java @@ -7,7 +7,7 @@ import java.util.logging.Level; import org.eclipse.osee.framework.jdk.core.util.Lib; import org.eclipse.osee.framework.logging.OseeLog; -import org.eclipse.osee.framework.plugin.core.server.ResourceFinder; +import org.eclipse.osee.ote.classserver.ResourceFinder; import org.eclipse.osee.ote.ui.builder.OTEPackagingBuilder; /** diff --git a/plugins/org.eclipse.osee.ote.ui/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.ote.ui/META-INF/MANIFEST.MF index 237b55c1ccb..e0f7bc45fc9 100644 --- a/plugins/org.eclipse.osee.ote.ui/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.ote.ui/META-INF/MANIFEST.MF @@ -28,10 +28,15 @@ Import-Package: org.eclipse.core.resources, org.eclipse.osee.framework.ui.plugin.workspace, org.eclipse.osee.framework.ui.plugin.xnavigate, org.eclipse.osee.framework.ui.swt, + org.eclipse.osee.ote.core, org.eclipse.osee.ote.core.environment.interfaces, + org.eclipse.osee.ote.message, + org.eclipse.osee.ote.message.event, + org.eclipse.osee.ote.remote.messages, org.eclipse.osee.ote.service, org.eclipse.swt, org.eclipse.swt.widgets, org.osgi.framework, + org.osgi.service.event;version="1.3.0", org.osgi.util.tracker Require-Bundle: org.eclipse.ui diff --git a/plugins/org.eclipse.osee.ote.ui/src/org/eclipse/osee/ote/ui/internal/OteServerConsole.java b/plugins/org.eclipse.osee.ote.ui/src/org/eclipse/osee/ote/ui/internal/OteServerConsole.java new file mode 100644 index 00000000000..9290154d214 --- /dev/null +++ b/plugins/org.eclipse.osee.ote.ui/src/org/eclipse/osee/ote/ui/internal/OteServerConsole.java @@ -0,0 +1,86 @@ +/******************************************************************************* + * Copyright (c) 2004, 2007 Boeing. + * 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: + * Boeing - initial API and implementation + *******************************************************************************/ +package org.eclipse.osee.ote.ui.internal; + +import java.io.IOException; + +import org.eclipse.osee.framework.jdk.core.util.IConsoleInputListener; +import org.eclipse.osee.framework.ui.plugin.util.OseeConsole; +import org.eclipse.osee.ote.message.event.OteEventMessageUtil; +import org.eclipse.osee.ote.remote.messages.ConsoleInputMessage; +import org.eclipse.osee.ote.remote.messages.ConsoleOutputMessage; +import org.osgi.framework.ServiceRegistration; +import org.osgi.service.event.Event; +import org.osgi.service.event.EventHandler; + +public class OteServerConsole { + + private final OseeConsole console = new OseeConsole("OTE Server", false, false); + private ServiceRegistration<EventHandler> registration; + + public OteServerConsole() { + console.addInputListener(new OTEServerConsoleInputListener()); + registration = OteEventMessageUtil.subscribe(ConsoleOutputMessage.TOPIC, new ConsoleOutputHandler(console)); + } + + private OseeConsole getConsole() { + return console; + } + + public void close() { + getConsole().shutdown(); + if(registration != null){ + registration.unregister(); + registration = null; + } + } + + private static class ConsoleOutputHandler implements EventHandler { + + private OseeConsole console; + private ConsoleOutputMessage output; + + public ConsoleOutputHandler(OseeConsole console) { + this.console = console; + this.output = new ConsoleOutputMessage(); + } + + @Override + public void handleEvent(Event arg0) { + output.setBackingBuffer(OteEventMessageUtil.getBytes(arg0)); + try { + console.write(output.getString()); + } catch (IOException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + + } + + } + + private static class OTEServerConsoleInputListener implements IConsoleInputListener { + + private ConsoleInputMessage input = new ConsoleInputMessage(); + + @Override + public void lineRead(String line) { + try { + input.setString(line); + OteEventMessageUtil.sendEvent(input); + } catch (IOException e) { + e.printStackTrace(); + } + } + + } +} diff --git a/plugins/org.eclipse.osee.ote.ui/src/org/eclipse/osee/ote/ui/internal/TestCoreGuiPlugin.java b/plugins/org.eclipse.osee.ote.ui/src/org/eclipse/osee/ote/ui/internal/TestCoreGuiPlugin.java index ca976631f8a..19ff552b3a0 100644 --- a/plugins/org.eclipse.osee.ote.ui/src/org/eclipse/osee/ote/ui/internal/TestCoreGuiPlugin.java +++ b/plugins/org.eclipse.osee.ote.ui/src/org/eclipse/osee/ote/ui/internal/TestCoreGuiPlugin.java @@ -43,6 +43,8 @@ public class TestCoreGuiPlugin implements BundleActivator { private OteConsoleServiceImpl oteConsoleService; private BundleContext context; + protected OteServerConsole oteServerConsole; + @Override public void start(final BundleContext context) throws Exception { this.context = context; @@ -80,6 +82,7 @@ public class TestCoreGuiPlugin implements BundleActivator { @Override public Object addingService(ServiceReference reference) { oteConsoleService = new OteConsoleServiceImpl(); + oteServerConsole = new OteServerConsole(); oteConsoleServiceRegistration = context.registerService(IOteConsoleService.class.getName(), oteConsoleService, null); if (System.getProperty("NO_OTE_REMOTE_CONSOLE") == null) { diff --git a/plugins/org.eclipse.osee.ote.version.svn/build.properties b/plugins/org.eclipse.osee.ote.version.svn/build.properties index a606ca75f23..f8831f941be 100644 --- a/plugins/org.eclipse.osee.ote.version.svn/build.properties +++ b/plugins/org.eclipse.osee.ote.version.svn/build.properties @@ -1,5 +1,6 @@ output.. = bin/ bin.includes = META-INF/,\ .,\ - OSGI-INF/svnFileVersionInformationComponent.xml + OSGI-INF/svnFileVersionInformationComponent.xml,\ + OSGI-INF/ source.. = src/ |