[Remoterengine-commits] r193 - in pkg/RemoteREngine/inst/java_src/src: common/org/rosuda/REngine/remote/common common/org/rosuda/REngine/remote/common/console server/org/rosuda/REngine/remote/server server/org/rosuda/REngine/remote/server/console
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Oct 1 17:44:43 CEST 2009
Author: ian_long
Date: 2009-10-01 17:44:43 +0200 (Thu, 01 Oct 2009)
New Revision: 193
Modified:
pkg/RemoteREngine/inst/java_src/src/common/org/rosuda/REngine/remote/common/InputHandler.java
pkg/RemoteREngine/inst/java_src/src/common/org/rosuda/REngine/remote/common/Launcher.java
pkg/RemoteREngine/inst/java_src/src/common/org/rosuda/REngine/remote/common/RemoteREngineConstants.java
pkg/RemoteREngine/inst/java_src/src/common/org/rosuda/REngine/remote/common/ServerShutDown.java
pkg/RemoteREngine/inst/java_src/src/common/org/rosuda/REngine/remote/common/console/Command.java
pkg/RemoteREngine/inst/java_src/src/server/org/rosuda/REngine/remote/server/REngineServer.java
pkg/RemoteREngine/inst/java_src/src/server/org/rosuda/REngine/remote/server/RemoteREngine_Server.java
pkg/RemoteREngine/inst/java_src/src/server/org/rosuda/REngine/remote/server/RemoteRMainLoopCallbacks.java
pkg/RemoteREngine/inst/java_src/src/server/org/rosuda/REngine/remote/server/console/ConsoleThread.java
Log:
Added logging statements
Modified: pkg/RemoteREngine/inst/java_src/src/common/org/rosuda/REngine/remote/common/InputHandler.java
===================================================================
--- pkg/RemoteREngine/inst/java_src/src/common/org/rosuda/REngine/remote/common/InputHandler.java 2009-10-01 15:43:48 UTC (rev 192)
+++ pkg/RemoteREngine/inst/java_src/src/common/org/rosuda/REngine/remote/common/InputHandler.java 2009-10-01 15:44:43 UTC (rev 193)
@@ -54,15 +54,17 @@
while (run) {
try{
res = in.readLine() ;
- if (res.equals("Quit")) {
- System.out.println(this.getClass().getName() + " preparing to close");
- run = false;
+ if (res == null) {
+ if (res.equals("Quit")) {
+ System.out.println(this.getClass().getName() + " preparing to close");
+ run = false;
+ }
+ res = res + "\n"; // Put on the line feed because readLine strips it off
+ if (output != null) { // output may be null if there is a start up problem
+ output.write(res.getBytes());
+ output.flush();
+ }
}
- res = res + "\n"; // Put on the line feed because readLine strips it off
- if (output != null) { // output may be null if there is a start up problem
- output.write(res.getBytes());
- output.flush();
- }
} catch( IOException e){
System.err.println(this.getClass().getName() + " ERROR: " + e.getMessage());
}
Modified: pkg/RemoteREngine/inst/java_src/src/common/org/rosuda/REngine/remote/common/Launcher.java
===================================================================
--- pkg/RemoteREngine/inst/java_src/src/common/org/rosuda/REngine/remote/common/Launcher.java 2009-10-01 15:43:48 UTC (rev 192)
+++ pkg/RemoteREngine/inst/java_src/src/common/org/rosuda/REngine/remote/common/Launcher.java 2009-10-01 15:44:43 UTC (rev 193)
@@ -35,6 +35,9 @@
import java.util.StringTokenizer;
import java.util.Vector;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* Helper class to set the environment and then launch the server process
* @author $Author$
@@ -42,6 +45,8 @@
* <p>URL : $HeadURL$
*/
public class Launcher {
+ final Logger logger = LoggerFactory.getLogger(Launcher.class);
+
/** Key for the JAVA_HOME environment variable / system property */
public static final String JAVA_HOME = "JAVA_HOME";
/** Key for the system property identifying the java executable */
@@ -72,6 +77,9 @@
/** Default list of packages to be loaded when the server starts */
public static final String[] DEFAULT_PACKAGES = new String[] {"utils", "stats", "rJava", "methods", "grDevices",
"graphics", "datasets"};
+ public static final String[] loggingJars = new String[] { "slf4j-api-1.5.8.jar",
+ "slf4j-log4j12-1.5.8.jar",
+ "log4j-1.2.15.jar"};
/** Internal cache of the system properties */
protected Properties systemProps = System.getProperties();
/** Internal store for the command line arguments from the launcher */
@@ -98,6 +106,7 @@
menu.append("\n\t-c: Class to be launched; default " + DEFAULT_STARTCLASS);
menu.append("\n\t-D<propertyname>=<propertyvalue>: Set System property");
menu.append("\n\t-t: Test mode - write out the launch command but do not execute it");
+ logger.info(menu.toString());
System.out.println(menu.toString());
if (exit) System.exit(0);
}
@@ -176,18 +185,18 @@
warning.append(R_HOME + " environment must be set to a valid directory; currently set to '" + rHomeString + "'\n");
}
}
- if (verbose) System.out.println("R_HOME: " + rHomeString);
+ logger.debug("R_HOME: {}", rHomeString);
// Define R_SHARE_DIR, R_INCLUDE_DIR,R_DOC_DIR
String rShare = filePath(new String[] {rHomeString,"share"});
systemProps.setProperty(R_SHARE, rShare);
- if (verbose) System.out.println(R_SHARE + ": " + rShare);
+ logger.debug("{} : {}",R_SHARE, rShare);
String rInclude = filePath(new String[]{rHomeString, "include"});
systemProps.setProperty(R_INCLUDE_DIR, rInclude);
- if (verbose) System.out.println(R_INCLUDE_DIR + ": " + rInclude);
+ logger.debug("{}: {}",R_INCLUDE_DIR, rInclude);
String rDoc = filePath(new String[]{rHomeString, "doc"});
systemProps.setProperty(R_DOC_DIR, rDoc);
- if (verbose) System.out.println(R_DOC_DIR + ": " + rDoc);
+ logger.debug("{}: {}",R_DOC_DIR, rDoc);
// Define R_DEFAULT_PACKAGES
StringBuilder packages = new StringBuilder();
@@ -197,7 +206,7 @@
String rPackages = "";
if (packages.length() > 0) rPackages = packages.substring(0, packages.length() - 1);
systemProps.setProperty(R_DEFAULT_PACKAGES, rPackages);
- if (verbose) System.out.println(R_DEFAULT_PACKAGES + ": " + rPackages);
+ logger.debug( "{}: {}",R_DEFAULT_PACKAGES, rPackages);
// Set JRI_LD_PATH
String jriPath = "";
@@ -213,12 +222,12 @@
// TODO Ensure jriPath is only included in the path once
String fullLDPath = (ldPath == null || ldPath.length()==0) ? jriPaths : mergePaths(jriPaths,ldPath);
systemProps.setProperty(LD_LIBRARY_PATH, fullLDPath);
- if (verbose) System.out.println(LD_LIBRARY_PATH + ": " + fullLDPath);
+ logger.debug( "{}: {}", LD_LIBRARY_PATH, fullLDPath);
systemProps.setProperty(LC_NUMERIC, "C");
- if (verbose) System.out.println(LC_NUMERIC + ": " + findProperty(LC_NUMERIC));
+ logger.debug("{}: {}",LC_NUMERIC , findProperty(LC_NUMERIC));
systemProps.setProperty(NO_SIG,"1");
- if (verbose) System.out.println(NO_SIG + ": " + findProperty(NO_SIG));
+ logger.debug("{}: {}", NO_SIG, findProperty(NO_SIG));
String rLibrary = "";
String rJava = "";
@@ -234,20 +243,22 @@
String classpath = buildClasspath(rHomeString, rJava, useJarFiles, buildDirPath, false);
String codebase = buildClasspath(rHomeString, rJava, useJarFiles, buildDirPath, true);
- if (verbose) System.out.println("Classpath: " + classpath);
- if (verbose) System.out.println("RMI Codebase: " + codebase);
+ logger.debug("Classpath: {}", classpath);
+ logger.debug("RMI Codebase: {}", codebase);
String policyFile = "";
try {
policyFile = locateFile("server.policy", remoteRServer);
} catch (IOException e) {
warning.append(e.getClass().getName() + " while locating security policy file\n");
+ logger.error(" while locating security policy file\n{}", e.getClass().getName(), e.getMessage());
}
- if (verbose) System.out.println("Policy file: " + policyFile);
+ logger.debug("Policy file: {}", policyFile);
if (warning.length() > 0) {
System.err.println("Environment set up failed:\n");
System.err.println(warning.toString());
+ logger.error("Environment set up failed: \n{}", warning.toString());
return new Vector<String>(0);
}
@@ -267,6 +278,10 @@
command.add("-D" + newProperty + "=" + newProperties.getProperty((String)newProperty));
}
}
+ if (!findProperty(RemoteREngineConstants.LOG4JCONFIGURATIONKEY).equals("")) {
+ command.add("-D" + RemoteREngineConstants.LOG4JCONFIGURATIONKEY + "=" +
+ findProperty(RemoteREngineConstants.LOG4JCONFIGURATIONKEY));
+ }
command.add(startClass);
if (arguments.length > 0) {
for (String arg : arguments) command.add(arg);
@@ -283,26 +298,30 @@
String javaHomeString = findProperty(JAVA_HOME);
if (javaHomeString == null) {
warning.append(JAVA_HOME + " must be set to the path of the Java installation\n");
+ logger.error("{} must be set to the path of the Java installation",JAVA_HOME);
} else {
File javahome = new File(javaHomeString);
if (!javahome.exists()) {
warning.append(JAVA_HOME + " environment must be set to a valid directory; currently set to '" + javaHomeString + "'\n");
+ logger.error("{} environment must be set to a valid directory; currently set to '{}'", JAVA_HOME, javaHomeString );
}
}
- if (verbose) System.out.println(JAVA_HOME + ": " + javaHomeString);
+ logger.debug("{}: ",JAVA_HOME, javaHomeString);
String javaCmd = "";
try {
javaCmd = locateJava(javaHomeString);
} catch (IOException e) {
warning.append(e.getClass().getName() + " while locating Java command relative to '" + javaHomeString + "'\n");
+ logger.error("{} while locating Java command relative to '{}'",e.getClass().getName(),javaHomeString);
}
if (javaCmd.length() == 0) {
warning.append("Unable to locate java executable, searching below '" + javaHomeString + "'\n");
+ logger.error("Unable to locate java executable, searching below '{}'",javaHomeString);
}
systemProps.setProperty(JAVACMD, javaCmd);
- if (verbose) System.out.println(JAVACMD + ": " + javaCmd);
+ logger.debug("{}: {}", JAVACMD, javaCmd);
return javaCmd;
}
@@ -325,6 +344,7 @@
return rJavaClasspath;
} catch (FileNotFoundException e) {
warning.append("Unable to locate rJava classpath directories\n");
+ logger.error("Unable to locate rJava classpath directories");
}
return "";
}
@@ -351,8 +371,13 @@
classpath.add((convertToCodebase ? "file:" : "") + locateFile("stubs",buildDirPath) + "\\");
classpath.add((convertToCodebase ? "file:" : "") + buildDirPath + "\\");
}
+ // include the logging jars
+ for (String loggingjar : loggingJars) {
+ classpath.add(loggingjar);
+ }
} catch (IOException e) {
warning.append(e.getClass().getName() + " while building classpath\n");
+ logger.error("{} while building classpath",e.getClass().getName());
}
// We don't need to include the rJava path within the RMI Codebase
@@ -419,12 +444,21 @@
* @throws IOException Error interpreting path information
*/
private String locateFile(String[] targets, String[] start) throws FileNotFoundException, IOException {
- if (targets == null || targets.length == 0) throw new FileNotFoundException("Target not defined");
- if (start == null || start.length == 0) throw new FileNotFoundException("Start not defined");
+ if (targets == null || targets.length == 0) {
+ logger.error("Target not defined");
+ throw new FileNotFoundException("Target not defined");
+ }
+ if (start == null || start.length == 0) {
+ logger.error("Start not defined");
+ throw new FileNotFoundException("Start not defined");
+ }
Stack<File>directoriesToCheck = new Stack<File>();
File startingPoint = new File(filePath(start));
directoriesToCheck.push(startingPoint);
- if (startingPoint == null || !startingPoint.exists()) throw new FileNotFoundException("Unable to find '" + startingPoint +"'");
+ if (startingPoint == null || !startingPoint.exists()) {
+ logger.error("Unable to find '{}'",startingPoint);
+ throw new FileNotFoundException("Unable to find '" + startingPoint +"'");
+ }
boolean found = false;
while (directoriesToCheck.size() > 0 && !found) {
File currentDir = directoriesToCheck.pop();
@@ -438,6 +472,7 @@
if (file.isDirectory()) directoriesToCheck.push(file);
}
}
+ logger.error("Unable to locate '{}' beneath '{}'",targets, start);
throw new FileNotFoundException("Unable to locate '" + targets + "' beneath '" + start + "'");
}
@@ -483,6 +518,7 @@
return filePath(elements, findProperty("file.separator"),false);
} catch (FileNotFoundException e) {
// we should never get here
+ logger.error("Unknown error within filePath",e);
throw new RuntimeException("Unknown error within filePath",e);
}
}
@@ -517,22 +553,26 @@
String fullPath = (path.length() > 0)? path.substring(0, path.length()-1) : "";
if (check) {
File file = new File(fullPath);
- if (!file.exists()) throw new FileNotFoundException(fullPath + " does not exist");
+ if (!file.exists()) {
+ logger.error("{} does not exist",fullPath);
+ throw new FileNotFoundException(fullPath + " does not exist");
+ }
}
return fullPath;
}
-
+
+ /**
+ * Search for a property within the System properties. If it can't be found within
+ * the System properties, search within the environment variables
+ * @param propertyName Name of the property to be located
+ * @return Property value or empty string if property can't be found
+ */
private String findProperty(String propertyName) {
if (systemProps.containsKey(propertyName)) return systemProps.getProperty(propertyName);
Map<String, String> environment = System.getenv();
-/* if (verbose) {
- for (String key : environment.keySet())
- System.out.println(key + ": " + environment.get(key));
- }
-*/
if (environment.containsKey(propertyName)) return environment.get(propertyName);
- if (verbose) System.out.println("Unable to find property for '" + propertyName + "'");
+ logger.debug("Unable to find property for '{}'", propertyName );
return "";
}
@@ -541,9 +581,26 @@
* @param args Command line arguments @see #buildLaunchCommand()
*/
public static void main(String[] args) {
+ // Set the logging configuration properties
+ if (System.getProperty(RemoteREngineConstants.LOG4JCONFIGURATIONKEY) == null || System.getProperty(RemoteREngineConstants.LOG4JCONFIGURATIONKEY).equals("")) {
+ System.setProperty(RemoteREngineConstants.LOG4JCONFIGURATIONKEY,RemoteREngineConstants.DEFAULTLOGCONFIGURATION);
+ }
+
Launcher launcher = new Launcher(args);
String javaCmd = launcher.findJava();
Vector<String> launchCommand = launcher.buildLaunchCommand(javaCmd);
+ Logger logger = LoggerFactory.getLogger(Launcher.class);
+
+ // Set up a remote debugger for the server process
+ boolean debugServerProcess = Boolean.getBoolean(RemoteREngineConstants.ATTACHREMOTEDEBUGGERKEY);
+ logger.debug("Remote debugging is set to {}",debugServerProcess);
+ if (debugServerProcess) {
+ launchCommand.add("-Xdebug");
+ launchCommand.add("-Xrunjdwp:transport=dt_socket,address=8001,server=y,suspend=n");
+ }
+
+ logger.debug("Java executable: {}",javaCmd);
+ logger.debug("Launchcommand: {}", launchCommand);
if (launcher.verbose) {
System.out.println("\nCommand: ");
for (String component : launchCommand) {
@@ -559,24 +616,12 @@
System.out.println(component);
builder.append(component + " ");
}
- File launchfile = null;
- BufferedWriter bw = null;
- try {
- launchfile = new File("launchcommand.txt");
- bw = new BufferedWriter(new FileWriter(launchfile));
- bw.write(builder.toString() + "\n");
- } catch (IOException e) {
- System.err.println(e.getClass().getName() + " writing command to " + launchfile.getAbsolutePath() +
- ": " + e.getMessage());
- } finally {
- try {
- bw.flush();
- bw.close();
- } catch (Exception e) {}
- }
+
+ launcher.writeCommandToFile(builder, "launchcommand.txt");
}
} else {
System.out.println("Launcher classpath: " + System.getProperty("java.class.path"));
+ logger.info("Launcher classpath: {}", System.getProperty("java.class.path"));
Runtime runtime = Runtime.getRuntime();
ProcessStreamHandler stdOutHandler = null;
ProcessStreamHandler stdErrHandler = null;
@@ -585,8 +630,10 @@
BufferedReader in = new BufferedReader(new InputStreamReader(System.in) );
Process process = runtime.exec(launchCommand.toArray(new String[0]));
- stdOutHandler = new ProcessStreamHandler(process.getInputStream());
- stdErrHandler = new ProcessStreamHandler(process.getErrorStream());
+
+ // TODO make the output files system properties
+ stdOutHandler = new ProcessStreamHandler(process.getInputStream(),"RServerOut.log",false);
+ stdErrHandler = new ProcessStreamHandler(process.getErrorStream(),"RServerErr.log",false);
stdInHandler = new InputHandler(process.getOutputStream());
OutputStream os = process.getOutputStream();
@@ -600,9 +647,10 @@
int exitVal = process.waitFor();
System.out.println("ExitValue: " + exitVal);
-
+ logger.info("ExitValue: {}",exitVal);
} catch (Throwable e) {
System.err.println(e.getClass().getName() + " while running server; " + e.getMessage());
+ logger.error(e.getClass().getName() + " while running server; " + e.getMessage(),e);
} finally {
if (stdOutHandler != null) stdOutHandler.close();
if (stdErrHandler != null) stdErrHandler.close();
@@ -627,4 +675,24 @@
public boolean isTestMode() {
return testMode;
}
+
+ public void writeCommandToFile(StringBuilder builder, String filename) {
+ File launchfile = null;
+ BufferedWriter bw = null;
+ try {
+ launchfile = new File(filename);
+ bw = new BufferedWriter(new FileWriter(launchfile));
+ bw.write(builder.toString() + "\n");
+ System.out.println("Launch command written out to " + launchfile.getAbsolutePath());
+ } catch (IOException e) {
+ System.err.println(e.getClass().getName() + " writing command to " + launchfile.getAbsolutePath() +
+ ": " + e.getMessage());
+ logger.error("{} writing command to: {}; {}",new String[] {e.getClass().getName(),launchfile.getAbsolutePath(), e.getMessage()});
+ } finally {
+ try {
+ bw.flush();
+ bw.close();
+ } catch (Exception e) {}
+ }
+ }
}
Modified: pkg/RemoteREngine/inst/java_src/src/common/org/rosuda/REngine/remote/common/RemoteREngineConstants.java
===================================================================
--- pkg/RemoteREngine/inst/java_src/src/common/org/rosuda/REngine/remote/common/RemoteREngineConstants.java 2009-10-01 15:43:48 UTC (rev 192)
+++ pkg/RemoteREngine/inst/java_src/src/common/org/rosuda/REngine/remote/common/RemoteREngineConstants.java 2009-10-01 15:44:43 UTC (rev 193)
@@ -43,4 +43,10 @@
public static final int DEFAULTSERVERPORT = 0; // RMI Dynamically allocates a port number
/** Representation of the NA string returned by REngine */
public static final String NAN = "NaN";
+ /** Key to define the name of the system property for the log4j configuration file */
+ public static final String LOG4JCONFIGURATIONKEY = "log4j.configuration";
+ /** Default logging configuration file */
+ public static final String DEFAULTLOGCONFIGURATION = "logging.xml";
+ /** Key to a System property to determine whether remote debugging should be enabled on the server */
+ public static final String ATTACHREMOTEDEBUGGERKEY = "DebugRemoteREngine";
}
Modified: pkg/RemoteREngine/inst/java_src/src/common/org/rosuda/REngine/remote/common/ServerShutDown.java
===================================================================
--- pkg/RemoteREngine/inst/java_src/src/common/org/rosuda/REngine/remote/common/ServerShutDown.java 2009-10-01 15:43:48 UTC (rev 192)
+++ pkg/RemoteREngine/inst/java_src/src/common/org/rosuda/REngine/remote/common/ServerShutDown.java 2009-10-01 15:44:43 UTC (rev 193)
@@ -27,6 +27,8 @@
import org.rosuda.REngine.remote.common.RemoteREngineConstants;
import org.rosuda.REngine.remote.common.RemoteREngineInterface;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* @author $Author$
@@ -34,13 +36,15 @@
* <p>URL : $HeadURL$
*/
public class ServerShutDown extends Thread {
+ final Logger logger = LoggerFactory.getLogger(org.rosuda.REngine.remote.common.ServerShutDown.class);
+
/** Name of the server within the RMI Registry */
private String serverName;
/** Hostname or IP Address of the RMI Registry */
private String registryHost;
/** Port number of the RMI Registry */
private int registryPort;
-
+
/**
* Create an instance of the ServerShutDown
* @param serverName Name of the RMI Service to be shut down
@@ -60,11 +64,16 @@
*/
public void run() {
try {
+ logger.info("Attempting to shut down {} bound within {}:{}",new Object[]{serverName,registryHost,new Integer(registryPort)});
Registry reg = LocateRegistry.getRegistry(registryHost, registryPort);
RemoteREngineInterface engine = (RemoteREngineInterface) reg.lookup(serverName);
- if (engine != null) engine.shutdown();
+ if (engine != null) {
+ logger.info("Calling shutdown");
+ engine.shutdown();
+ logger.debug("Returned from shutdown");
+ }
} catch (NotBoundException nb) {
- System.err.println("Unable to locate " + serverName + " bound within " + registryHost + ":" + registryPort );
+ logger.error("Unable to locate " + serverName + " bound within " + registryHost + ":" + registryPort, nb);
} catch (RemoteException e) {
// Expect to get a RemoteException here because if the method has succeeded, then
// it can't return!
Modified: pkg/RemoteREngine/inst/java_src/src/common/org/rosuda/REngine/remote/common/console/Command.java
===================================================================
--- pkg/RemoteREngine/inst/java_src/src/common/org/rosuda/REngine/remote/common/console/Command.java 2009-10-01 15:43:48 UTC (rev 192)
+++ pkg/RemoteREngine/inst/java_src/src/common/org/rosuda/REngine/remote/common/console/Command.java 2009-10-01 15:44:43 UTC (rev 193)
@@ -2,10 +2,15 @@
import java.io.Serializable;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class Command implements Serializable {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = -2117203565343969787L;
+ private final Logger logger = LoggerFactory.getLogger(org.rosuda.REngine.remote.common.console.Command.class);
+
protected String command;
protected CommandSender sender ;
@@ -15,6 +20,7 @@
}
public Command( String command, CommandSender sender){
+ logger.debug("{} set '{}'",sender.getClass().getName(),command);
this.command = command ;
this.sender = sender;
}
Modified: pkg/RemoteREngine/inst/java_src/src/server/org/rosuda/REngine/remote/server/REngineServer.java
===================================================================
--- pkg/RemoteREngine/inst/java_src/src/server/org/rosuda/REngine/remote/server/REngineServer.java 2009-10-01 15:43:48 UTC (rev 192)
+++ pkg/RemoteREngine/inst/java_src/src/server/org/rosuda/REngine/remote/server/REngineServer.java 2009-10-01 15:44:43 UTC (rev 193)
@@ -31,19 +31,29 @@
import org.rosuda.REngine.REngineException;
import org.rosuda.REngine.remote.common.CommandLineArgs;
+import org.rosuda.REngine.remote.common.Launcher;
import org.rosuda.REngine.remote.common.RemoteREngineConstants;
import org.rosuda.REngine.remote.common.tools.ServiceManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* This is an utility class to start the server
*/
public class REngineServer {
+ final Logger logger = LoggerFactory.getLogger(org.rosuda.REngine.remote.server.REngineServer.class);
+
/**
* Main method to start the R server
*/
public static void main(String[] args) {
+ // Set the logging configuration properties
+ if (System.getProperty(RemoteREngineConstants.LOG4JCONFIGURATIONKEY) == null || System.getProperty(RemoteREngineConstants.LOG4JCONFIGURATIONKEY).equals("")) {
+ System.setProperty(RemoteREngineConstants.LOG4JCONFIGURATIONKEY,RemoteREngineConstants.DEFAULTLOGCONFIGURATION);
+ }
+ Logger logger = LoggerFactory.getLogger(org.rosuda.REngine.remote.server.REngineServer.class);
/* init the services */
ServiceManager.init();
@@ -66,6 +76,7 @@
rmiPort = Integer.parseInt( arguments.get("registryPort") ) ;
} catch (NumberFormatException e) {
System.err.println("Unable to parse " + arguments.get("registryPort") + " as an Integer");
+ logger.error("Unable to parse {} as an Integer",arguments.get("registryPort"));
printMenu();
}
}
@@ -74,6 +85,7 @@
servicePort = Integer.parseInt( arguments.get("servicePort") ) ;
} catch (NumberFormatException e) {
System.err.println("Unable to parse " + arguments.get("servicePort") + " as an Integer");
+ logger.error("Unable to parse {} as an Integer",arguments.get("servicePort"));
printMenu();
}
}
@@ -91,32 +103,44 @@
Registry registry = null ;
RemoteREngine_Server engine = null;
try {
+ logger.debug("About to start R Server using: rmiName {}; servicePort {}; rmiPort {}; args null",
+ new Object[] {rmiName,servicePort,new Integer(rmiPort)});
engine = new RemoteREngine_Server(rmiName, servicePort, rmiPort, null);
} catch (REngineException e) {
System.err.println(e.getClass().getName() +": While creating the R Engine, " + e.getMessage());
+ logger.error(e.getClass().getName() + " while creating the R Engine",e);
e.printStackTrace();
} catch (AccessException e) {
System.err.println("Access to RMI Registry denied, " + e.getMessage());
+ logger.error("Access to RMI Registry denied",e);
e.printStackTrace();
} catch (RemoteException e) {
/* TODO: factor rmi tools in a separate class */
System.err.println(e.getClass().getName() + ": while binding to the RMI registry on " +
" port " + rmiPort + ", " + e.getMessage());
+ logger.error(e.getClass().getName() + ": while binding to the RMI registry on " +
+ " port " + rmiPort,e);
e.printStackTrace();
String[] names = new String[0];
try {
registry = LocateRegistry.getRegistry( null, rmiPort ) ;
names = registry.list();
} catch (RemoteException re) {
- if (names.length == 0) System.err.println("Is RMI Registry running on port " + rmiPort + "?");
+ if (names.length == 0) {
+ System.err.println("Is RMI Registry running on port " + rmiPort + "?");
+ logger.error("Is RMI Registry running on port {}?", rmiPort);
+ }
}
if (names.length > 0) {
System.err.println("Existing bound services are:");
+ logger.error("Existing bound services are:");
for (String name : names) {
System.err.println(name);
+ logger.error(name);
}
} else {
System.err.println("No existing services located within RMI Registry");
+ logger.error("No existing services located within RMI Registry");
}
}
@@ -124,6 +148,8 @@
engine.startConsoleThread();
} else {
System.err.println("Null RemoteREngine_Server returned from startup.");
+ logger.error("Null RemoteREngine_Server returned from startup.");
+ System.exit(1);
}
}
Modified: pkg/RemoteREngine/inst/java_src/src/server/org/rosuda/REngine/remote/server/RemoteREngine_Server.java
===================================================================
--- pkg/RemoteREngine/inst/java_src/src/server/org/rosuda/REngine/remote/server/RemoteREngine_Server.java 2009-10-01 15:43:48 UTC (rev 192)
+++ pkg/RemoteREngine/inst/java_src/src/server/org/rosuda/REngine/remote/server/RemoteREngine_Server.java 2009-10-01 15:44:43 UTC (rev 193)
@@ -65,6 +65,8 @@
import org.rosuda.REngine.remote.server.console.ConsoleThread;
import org.rosuda.REngine.remote.server.files.RemoteFileInputStream_Server;
import org.rosuda.REngine.remote.server.files.RemoteFileOutputStream_Server;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* The main class of the server side part of the RemoteREngine project
@@ -74,6 +76,8 @@
*/
public class RemoteREngine_Server implements RemoteREngineInterface {
+ private final Logger logger = LoggerFactory.getLogger(org.rosuda.REngine.remote.server.RemoteREngine_Server.class);
+
private static boolean DEBUG = false;
public static void setDebug( boolean debug){
@@ -148,6 +152,7 @@
/* inform the clients that the jvm of the server is dying */
shutdownHook = new RemoteREngineServerShutdownHook() ;
+ logger.debug("Adding shutdownhook for R server process");
Runtime.getRuntime().addShutdownHook( shutdownHook );
clients = new Vector<RemoteREngineClient>();
@@ -159,7 +164,8 @@
consoleCallbackHandler = new ConsoleCallbackHandler(this);
callbackSender = new CallbackSender(this) ;
addCallbackListener( consoleCallbackHandler ) ;
-
+
+ logger.debug("About to construct JRIEngine");
r = new JRIEngine( args, callbackLoop ) ;
/* TODO: forbid the q function */
@@ -177,29 +183,28 @@
registry = LocateRegistry.getRegistry(null, registryPort);
} catch (RemoteException r) {
// Unable to locate the registry, so try and create one
- System.out.println("Unable to locate registry, so creating a new RMI Registry locally");
+ logger.error("Unable to locate registry, so creating a new RMI Registry locally",r);
}
try {
if (registry==null) registry = LocateRegistry.createRegistry(registryPort);
} catch (RemoteException e) {
- System.err.println(e.getClass().getName() + ": While trying to create registry on port " + registryPort +
- ": " + e.getMessage());
- System.err.println(e.getCause());
+ logger.error(e.getClass().getName() + ": While trying to create registry on port " + registryPort,e);
throw e;
}
try {
stub = (RemoteREngineInterface)UnicastRemoteObject.exportObject(this,servicePort);
} catch (RemoteException e) {
- System.err.println("Unable to serialize server on " + servicePort + ": " + e.getMessage());
+ logger.error("Unable to serialize server on " + servicePort + ": " + e.getMessage(),e);
throw e;
}
try {
registry.bind(name, stub);
} catch (AlreadyBoundException e) {
- debug(name + " already bound, attempting to shut down previous server");
-
+// debug(name + " already bound, attempting to shut down previous server");
+// logger.info(name + " already bound, attempting to shut down previous server");
+//
// try {
// RemoteREngineInterface previousServer = (RemoteREngineInterface)registry.lookup(name);
// previousServer.shutdown();
@@ -212,21 +217,24 @@
try {
// Note, by automatically rebinding we risk orphaning the previous server and leaving
// process leaks
+ logger.info("Trying to rebind {}",name);
registry.rebind(name, stub);
} catch (AccessException ae) {
- System.err.println("AccessException while rebinding server to registry: " + ae.getMessage());
+ logger.error("AccessException while rebinding server to registry: " + ae.getMessage(),ae);
throw ae;
}catch (RemoteException re) {
- System.err.println("Unable to rebind server to port " + servicePort + ": " + re.getMessage());
+ logger.error("Unable to rebind server to port " + servicePort + ": " + re.getMessage(),re);
throw re;
}
} catch (RemoteException e) {
- System.err.println("Unable to bind server(" + name + ") to port " + servicePort + ": " + e.getMessage());
+ logger.error("Unable to bind server(" + name + ") to port " + servicePort + ": " + e.getMessage(),e);
throw e;
}
System.out.println( "R Engine bound as `"+ name +"` as a service on port " + servicePort +
" to local RMIRegistry running on port " + registryPort + ", running under Id: " + getPID());
+ logger.info("R Engine bound as `"+ name +"` as a service on port " + servicePort +
+ " to local RMIRegistry running on port " + registryPort + ", running under Id: " + getPID());
running = true;
}
@@ -276,7 +284,10 @@
*/
private class RemoteREngineServerShutdownHook extends Thread{
public void run(){
- if( !running ) shutdown() ;
+ if( !running ) {
+ logger.info("Calling shutdown");
+ shutdown() ;
+ }
}
}
@@ -284,11 +295,12 @@
* Shutdown the server
*/
public synchronized void shutdown(){
- System.err.println( "R Server: shutdown" ) ;
+ logger.info( "R Server: shutdown" ) ;
if( !running ) return;
running = false;
+ // TODO implement a version of consoleThread that won't block on input
if (consoleThread != null) consoleThread.requestStop() ;
if (consoleThread != null) consoleThread.interrupt() ;
@@ -298,18 +310,18 @@
}
/* TODO: empty the clients and listeners ? */
- System.err.println("Unbinding " + name );
+ logger.info("Unbinding " + name );
try {
if (registry != null) {
registry.unbind( name );
- System.out.println(name + " unbound from registry ");
+ logger.debug(name + " unbound from registry ");
}
if (stub != null) {
if (UnicastRemoteObject.unexportObject(stub, false)) {
- System.out.println(name + " successfully unexported");
+ logger.debug(name + " successfully unexported");
} else {
- System.out.println("Unable to Unexport " + name);
+ logger.debug("Unable to Unexport " + name);
}
}
} catch (NotBoundException e) {
@@ -322,28 +334,29 @@
if (cause != null) {
buf.append(cause.getClass().getName() + ": " + cause.getMessage());
}
- System.err.println( buf.toString());
+ logger.error( buf.toString(),e);
}
System.out.println("Stopping R");
+ logger.info("Stopping R");
/* : shutdown R cleanly as well */
try {
RTermination rterminator = new RTermination();
+ logger.debug("Start R termination thread");
rterminator.start();
} catch (Exception e) {
System.err.println(e.getClass().getName() + " while closing R session; " + e.getMessage());
}
System.out.println("\n" + Calendar.getInstance().getTime() + ": Stopping the JVM in 3 seconds.");
- int seconds = 3000;
- for (int i=0; i < seconds; i+=100) {
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {}
- System.out.print(".");
- }
- System.out.println("\nJava Shut down");
+// int seconds = 3000;
+// for (int i=0; i < seconds; i+=100) {
+// try {
+// Thread.sleep(100);
+// } catch (InterruptedException e) {}
+// System.out.print(".");
+// }
+ System.out.println("\nCalling System.exit(0)");
+ logger.info("Calling System.exit(0)");
System.exit(0);
-
-
}
/**
@@ -352,12 +365,12 @@
private class RTermination extends Thread{
public void run(){
try {
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/remoterengine -r 193
More information about the Remoterengine-commits
mailing list