[Remoterengine-commits] r157 - pkg/RemoteREngine/inst/java_src/src/client/org/rosuda/REngine/remote/client

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Sep 18 08:49:28 CEST 2009


Author: ian_long
Date: 2009-09-18 08:49:28 +0200 (Fri, 18 Sep 2009)
New Revision: 157

Modified:
   pkg/RemoteREngine/inst/java_src/src/client/org/rosuda/REngine/remote/client/RemoteREngine.java
Log:
--Resturctured fetchFile
--Removed hardcoded default registry port

Modified: pkg/RemoteREngine/inst/java_src/src/client/org/rosuda/REngine/remote/client/RemoteREngine.java
===================================================================
--- pkg/RemoteREngine/inst/java_src/src/client/org/rosuda/REngine/remote/client/RemoteREngine.java	2009-09-18 06:42:29 UTC (rev 156)
+++ pkg/RemoteREngine/inst/java_src/src/client/org/rosuda/REngine/remote/client/RemoteREngine.java	2009-09-18 06:49:28 UTC (rev 157)
@@ -30,6 +30,7 @@
 import java.rmi.registry.LocateRegistry;
 import java.rmi.registry.Registry;
 import java.rmi.server.UnicastRemoteObject;
+import java.util.Map;
 
 import org.rosuda.REngine.REXP;
 import org.rosuda.REngine.REXPMismatchException;
@@ -39,6 +40,7 @@
 import org.rosuda.REngine.REngineException;
 import org.rosuda.REngine.REnginePool;
 import org.rosuda.REngine.remote.client.callbacks.ClientCallbackDispatcher;
+import org.rosuda.REngine.remote.common.CommandLineArgs;
 import org.rosuda.REngine.remote.common.JRIEngineGlobalVariables;
 import org.rosuda.REngine.remote.common.RemoteREngineClient;
 import org.rosuda.REngine.remote.common.RemoteREngineConstants;
@@ -186,7 +188,7 @@
 	 * @param registryHost host name
 	 */
 	public RemoteREngine(String name, String registryHost ){
-		this( name, registryHost, 1099 ) ;
+		this( name, registryHost, RemoteREngineConstants.RMIPORT ) ;
 	}
 
 	/**                                                    
@@ -381,22 +383,37 @@
 	 * @param client_file the name of the file in the client to write into
 	 * @param server_file the name of the server file to fetch
 	 * @param delete delete the file after fetching it ?
+	 * @return true if the file transfer has completed successfully
 	 * @throws IOException 
 	 */
-	public void fetchFile( String client_file, String server_file, boolean delete ) throws IOException, ServerSideIOException {
-		BufferedOutputStream client_out = new BufferedOutputStream( new FileOutputStream( client_file ) ) ;
-		RemoteFileInputStream server_in = engine.openFile(server_file) ;
-
-		FileChunk chunk = server_in.readNextChunk() ;
-		while( ! chunk.isEmpty() ){
-			client_out.write(chunk.buffer, 0, chunk.size ) ;
-			chunk = server_in.readNextChunk() ;
+	public boolean fetchFile( String client_file, String server_file, boolean delete ) throws IOException, ServerSideIOException {
+		BufferedOutputStream client_out = null;
+		RemoteFileInputStream server_in = null;
+		boolean success = false;
+		try {
+			client_out = new BufferedOutputStream( new FileOutputStream( client_file ) ) ;
+			server_in = engine.openFile(server_file) ;
+		
+			FileChunk chunk = server_in.readNextChunk() ;
+			while( ! chunk.isEmpty() ){
+				client_out.write(chunk.buffer, 0, chunk.size ) ;
+				chunk = server_in.readNextChunk() ;
+			}
+			success = true;
+		} finally {
+			try {
+				server_in.close() ;
+			} catch (Exception e) {}
+			try {
+				client_out.close(); 
+			} catch (Exception e) {}
+			if( delete ){
+				server_in.delete(); 
+			}
+			server_in = null;
+			client_out = null;
 		}
-		server_in.close() ;
-		client_out.close(); 
-		if( delete ){
-			server_in.delete(); 
-		}
+		return success;
 	}
 
 	/** 
@@ -515,6 +532,5 @@
 			/* what now */
 		} 
 	}
-	
 }
 



More information about the Remoterengine-commits mailing list