[Remoterengine-commits] r130 - pkg/RemoteREngine/inst/java_src/src/server/org/rosuda/REngine/remote/server

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Sep 15 12:19:45 CEST 2009


Author: ian_long
Date: 2009-09-15 12:19:45 +0200 (Tue, 15 Sep 2009)
New Revision: 130

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/RemoteREngine_Server.java
Log:
Changed the parameter used to specify the registry Port to avoid confusion with the service port
Enabled the user to specify the port the RMI service listens on

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-09-15 10:18:19 UTC (rev 129)
+++ pkg/RemoteREngine/inst/java_src/src/server/org/rosuda/REngine/remote/server/REngineServer.java	2009-09-15 10:19:45 UTC (rev 130)
@@ -31,6 +31,7 @@
 
 import org.rosuda.REngine.REngineException;
 import org.rosuda.REngine.remote.common.CommandLineArgs;
+import org.rosuda.REngine.remote.common.RemoteREngineConstants;
 import org.rosuda.REngine.remote.common.tools.ServiceManager;
 
 /**
@@ -49,6 +50,7 @@
 		
 		String rmiName = DEFAULTNAME;
 		int rmiPort = RMIPORT;
+		int servicePort = RemoteREngineConstants.DEFAULTSERVERPORT;
 		
 		/* print the help if see the -h or --help flags */
 		if (args.length > 0) {
@@ -59,9 +61,22 @@
 		}
 		Map<String,String> arguments = CommandLineArgs.arguments(args) ;
 		
-		if( arguments.containsKey( "port" )){
-			rmiPort = Integer.parseInt( arguments.get("port") )  ;
+		if( arguments.containsKey( "registryPort" )){
+			try {
+			rmiPort = Integer.parseInt( arguments.get("registryPort") )  ;
+			} catch (NumberFormatException e) {
+				System.err.println("Unable to parse " + arguments.get("registryPort") + " as an Integer");
+				printMenu();
+			}
 		}
+		if( arguments.containsKey( "servicePort" )){
+			try {
+				servicePort = Integer.parseInt( arguments.get("servicePort") )  ;
+			} catch (NumberFormatException e) {
+				System.err.println("Unable to parse " + arguments.get("servicePort") + " as an Integer");
+				printMenu();
+			}
+		}
 		if( arguments.containsKey( "name" )){
 			rmiName = arguments.get("name") ;
 		}
@@ -76,7 +91,7 @@
 	    Registry registry = null ; 
 	    RemoteREngine_Server engine = null;
 	    try {
-	    	engine = new RemoteREngine_Server(rmiName, rmiPort, null);
+	    	engine = new RemoteREngine_Server(rmiName, servicePort, rmiPort, null);
 	    } catch (REngineException e) {
 	    	System.err.println(e.getClass().getName() +": While creating the R Engine, " + e.getMessage());
 	    	e.printStackTrace();
@@ -115,12 +130,18 @@
 	private static void printMenu() {
 		System.out.println("Expected arguments are:");
 		
-		System.out.println("  [--name name]    : RMI name to register server under");
-		System.out.println("                     default: 'RemoteREngine' ");
+		System.out.println("  [--name name]    		: RMI name to register server under");
+		System.out.println("                     	default: '" + RemoteREngineConstants.DEFAULTNAME+ "' ");
 		
-		System.out.println("  [--port port]    : RMI Registry port number");
-		System.out.println("                     default: '1099' ");
+		System.out.println("  [--servicePort port]	: Service port number");
+		System.out.println("                     	default: '" + RemoteREngineConstants.DEFAULTSERVERPORT + "' ");
 		
+		System.out.println("  [--registryPort port] : RMI Registry port number");
+		System.out.println("                     	default: '" + RemoteREngineConstants.RMIPORT + "' ");
+		
+		System.out.println("  [--debug]    			: Print out additional debug information");
+		System.out.println("                     	default: 'No' ");
+		
 	}
 	
     

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-09-15 10:18:19 UTC (rev 129)
+++ pkg/RemoteREngine/inst/java_src/src/server/org/rosuda/REngine/remote/server/RemoteREngine_Server.java	2009-09-15 10:19:45 UTC (rev 130)
@@ -131,15 +131,16 @@
 	 * Constructor. Initiates the local R engine that this engine shadows
 	 * 
 	 * @param name name of this engine in the RMI registry
-	 * @param port port used by the RMI registry
+	 * @param servicePort Port number for this service to use for recieving requests
+	 * @param registryPort port used by the RMI registry
 	 * @param args arguments for R 
 	 * 
 	 * @throws REngineException Error creating the R instance
 	 */ 
-	public RemoteREngine_Server(String name, int port, String[] args) throws REngineException, RemoteException, AccessException {
+	public RemoteREngine_Server(String name, int servicePort, int registryPort, String[] args) throws REngineException, RemoteException, AccessException {
 		super();
 		this.name = name ; 
-		this.registryPort = port ;
+		this.registryPort = registryPort ;
 		
 		/* inform the clients that the jvm of the server is dying */
 		shutdownHook = new RemoteREngineServerShutdownHook() ;
@@ -170,15 +171,15 @@
 		
 		try {
 			// Locate a local registry as RMI Servers can't register with Remote Registries
-			registry = LocateRegistry.getRegistry(null, port);
+			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");
 		}
 		try {
-			if (registry==null) registry = LocateRegistry.createRegistry(port);
+			if (registry==null) registry = LocateRegistry.createRegistry(registryPort);
 		} catch (RemoteException e) {
-			System.err.println(e.getClass().getName() + ": While trying to create registery on port " + port + 
+			System.err.println(e.getClass().getName() + ": While trying to create registery on port " + registryPort + 
 					": " + e.getMessage());
 			System.err.println(e.getCause());
 			throw e;
@@ -210,12 +211,12 @@
 			throw e;
 		}
 
-		debug( "R Engine bound as `"+ name +"` on port " + port ) ;
+		System.out.println( "R Engine bound as `"+ name +"` as a service on port " + serverPort + " to local RMIRegistry running on port " + registryPort );
 		running = true; 
 	}
 
 	/**
-	 * Constructor initializing R with the default arguments
+	 * Constructor initializing R with the default arguments - service will run on a randomly assigned port
 	 * 
 	 * @param name name of this engine in the MRI registry
  	 * @param port port used by the RMI registry
@@ -225,10 +226,25 @@
 	 * @throws AccessException
 	 */
 	public RemoteREngine_Server(String name, int port) throws REngineException, RemoteException, AccessException{
-		this( name, port, null) ;
+		this( name, 0, port, null) ;
 	}
 	
 	/**
+	 * Constructor initializing R with the default arguments - service will run on a randomly assigned port
+	 * 
+	 * @param name name of this engine in the MRI registry
+	 * @param servicePort Port used by the service to receive requests
+ 	 * @param registryPort port used by the RMI registry
+ 	 * 
+	 * @throws REngineException
+	 * @throws RemoteException
+	 * @throws AccessException
+	 */
+
+	public RemoteREngine_Server(String name, int servicePort, int registryPort) throws REngineException, RemoteException, AccessException{
+		this( name, servicePort, registryPort, null) ;
+	}
+	/**
 	 * Shutdown hook that indicates to clients of this server 
 	 * that the server is dying 
 	 * 



More information about the Remoterengine-commits mailing list