From 4ed8bddc791fda93940f238c5135556a07041dc0 Mon Sep 17 00:00:00 2001 From: rbrooks Date: Sat, 24 Jul 2010 08:02:08 +0000 Subject: converted all line terminators to unix style --- plugins/org.eclipse.osee.framework.jini/.classpath | 14 +- .../META-INF/MANIFEST.MF | 56 +-- .../build.properties | 16 +- plugins/org.eclipse.osee.framework.jini/plugin.xml | 36 +- .../release/JINIMANIFEST.MF | 30 +- .../framework/jini/service/core/PropertyEntry.java | 132 +++--- .../osee/framework/jini/utility/StartJini.java | 488 ++++++++++----------- 7 files changed, 386 insertions(+), 386 deletions(-) (limited to 'plugins/org.eclipse.osee.framework.jini') diff --git a/plugins/org.eclipse.osee.framework.jini/.classpath b/plugins/org.eclipse.osee.framework.jini/.classpath index 6e16b23d695..16d067f284a 100644 --- a/plugins/org.eclipse.osee.framework.jini/.classpath +++ b/plugins/org.eclipse.osee.framework.jini/.classpath @@ -1,7 +1,7 @@ - - - - - - - + + + + + + + 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 43129a915c4..2b92f81bf75 100644 --- a/plugins/org.eclipse.osee.framework.jini/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.osee.framework.jini/META-INF/MANIFEST.MF @@ -1,28 +1,28 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: Core Jini Service (Incubation) -Bundle-SymbolicName: org.eclipse.osee.framework.jini;singleton:=true -Bundle-Version: 0.9.5.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.event, - org.eclipse.osee.framework.jini.event.old, - 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 -Require-Bundle: org.eclipse.osee.framework.jdk.core, - org.eclipse.core.runtime, - net.jini, - org.eclipse.osee.framework.plugin.core -Bundle-ActivationPolicy: lazy -Bundle-RequiredExecutionEnvironment: JavaSE-1.6 -Import-Package: org.eclipse.osee.framework.logging +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Core Jini Service (Incubation) +Bundle-SymbolicName: org.eclipse.osee.framework.jini;singleton:=true +Bundle-Version: 0.9.5.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.event, + org.eclipse.osee.framework.jini.event.old, + 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 +Require-Bundle: org.eclipse.osee.framework.jdk.core, + org.eclipse.core.runtime, + net.jini, + org.eclipse.osee.framework.plugin.core +Bundle-ActivationPolicy: lazy +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Import-Package: org.eclipse.osee.framework.logging diff --git a/plugins/org.eclipse.osee.framework.jini/build.properties b/plugins/org.eclipse.osee.framework.jini/build.properties index 4e75e926181..35721c1a506 100644 --- a/plugins/org.eclipse.osee.framework.jini/build.properties +++ b/plugins/org.eclipse.osee.framework.jini/build.properties @@ -1,8 +1,8 @@ -bin.includes = plugin.xml,\ - oseejinilookup.zip,\ - META-INF/,\ - src/,\ - . -jars.compile.order = . -source.. = src/ -output.. = bin/ +bin.includes = plugin.xml,\ + oseejinilookup.zip,\ + META-INF/,\ + src/,\ + . +jars.compile.order = . +source.. = src/ +output.. = bin/ diff --git a/plugins/org.eclipse.osee.framework.jini/plugin.xml b/plugins/org.eclipse.osee.framework.jini/plugin.xml index 31e40a0545c..56fac984397 100644 --- a/plugins/org.eclipse.osee.framework.jini/plugin.xml +++ b/plugins/org.eclipse.osee.framework.jini/plugin.xml @@ -1,18 +1,18 @@ - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/plugins/org.eclipse.osee.framework.jini/release/JINIMANIFEST.MF b/plugins/org.eclipse.osee.framework.jini/release/JINIMANIFEST.MF index af6b4e179cb..8f08711aef1 100644 --- a/plugins/org.eclipse.osee.framework.jini/release/JINIMANIFEST.MF +++ b/plugins/org.eclipse.osee.framework.jini/release/JINIMANIFEST.MF @@ -1,15 +1,15 @@ -Manifest-Version: 1.0 -Ant-Version: Apache Ant 1.7.0 -Created-By: 1.6.0_01-b06 (Sun Microsystems Inc.) -Main-Class: osee/jini/utility/StartJini -Class-Path: lib/jini-core.jar lib/jini-ext.jar lib/tools.jar oseecore. - jar - -Name: common -Specification-Title: Example -Specification-Version: ${version} -Specification-Vendor: Example Organization -Implementation-Title: common -Implementation-Version: ${version} ${TODAY} -Implementation-Vendor: Example Corp. - +Manifest-Version: 1.0 +Ant-Version: Apache Ant 1.7.0 +Created-By: 1.6.0_01-b06 (Sun Microsystems Inc.) +Main-Class: osee/jini/utility/StartJini +Class-Path: lib/jini-core.jar lib/jini-ext.jar lib/tools.jar oseecore. + jar + +Name: common +Specification-Title: Example +Specification-Version: ${version} +Specification-Vendor: Example Organization +Implementation-Title: common +Implementation-Version: ${version} ${TODAY} +Implementation-Vendor: Example Corp. + 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 index 006085f6e44..4ec4ae35430 100644 --- 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 @@ -1,66 +1,66 @@ -/******************************************************************************* - * 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 map; - - public PropertyEntry() { - map = new HashMap(64); - } - - public PropertyEntry(Map 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 - * - * @param props - */ - public void fillProps(Map props) { - props.putAll(map); - } - - @Override - public boolean equals(Object other) { - if (other instanceof PropertyEntry) { - return ((PropertyEntry) other).map.equals(map); - } else { - return false; - } - } - -} +/******************************************************************************* + * 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 map; + + public PropertyEntry() { + map = new HashMap(64); + } + + public PropertyEntry(Map 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 + * + * @param props + */ + public void fillProps(Map 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/utility/StartJini.java b/plugins/org.eclipse.osee.framework.jini/src/org/eclipse/osee/framework/jini/utility/StartJini.java index 592f7b539f2..b9b7923a7b1 100644 --- 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 @@ -1,244 +1,244 @@ -/******************************************************************************* - * 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.rmi.RemoteException; -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 jiniProcesses; - - public StartJini(String port, boolean nohup, boolean browser, String jiniHome, InputStream manifestFile) { - super(); - - jiniProcesses = new ArrayList(); - - 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 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= StartJini ?<-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(); - } - } - } - - public void kill() throws RemoteException { - OseeLog.log(StartJini.class, Level.INFO, "De-registering Core Jini Service..."); - deregisterService(); - killProcesses(); - ServiceDataStore.getNonEclipseInstance().terminate(); - commitSuicide(); - } -} +/******************************************************************************* + * 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.rmi.RemoteException; +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 jiniProcesses; + + public StartJini(String port, boolean nohup, boolean browser, String jiniHome, InputStream manifestFile) { + super(); + + jiniProcesses = new ArrayList(); + + 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 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= StartJini ?<-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(); + } + } + } + + public void kill() throws RemoteException { + OseeLog.log(StartJini.class, Level.INFO, "De-registering Core Jini Service..."); + deregisterService(); + killProcesses(); + ServiceDataStore.getNonEclipseInstance().terminate(); + commitSuicide(); + } +} -- cgit v1.2.3