Package org.math.R
Class StartRserve
- java.lang.Object
-
- org.math.R.StartRserve
-
public class StartRserve extends Object
simple class that start Rserve locally if it's not running already - see mainlycheckLocalRservemethod. It spits out quite some debugging outout of the console, so feel free to modify it for your application if desired.Important: All applications should shutdown every Rserve that they started! Never leave Rserve running if you started it after your application quits since it may pose a security risk. Inform the user if you started an Rserve instance.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classStartRserve.ProcessToKill
-
Field Summary
Fields Modifier and Type Field Description static longTIMEOUT
-
Constructor Summary
Constructors Constructor Description StartRserve()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancheckLocalRserve(int port)checks whether Rserve is running and if that's not the case it attempts to start it using the defaults for the platform where it is run on.This method is meant to be set-and-forget and cover most default setups.static StringdoInR(String todo, String Rcmd, String rargs, File out)attempt to start Rserve.static int[]getRservePIDs()static booleaninstallBundledRserve(String Rcmd)R batch to install Rserve from included jar resourcesstatic booleaninstallRserve(String Rcmd, String http_proxy, String repository)R batch to install Rserve from netstatic booleaninstallRserveFromLocalLibrary(String Rcmd)R batch to install Rservestatic booleanisRserveInstalled()R batch to check Rserve is installed in RserveDaemon.app_dir()static booleanisRserveListening(int port)check whether Rserve is currently running (on local machine and default port).static booleanKill(int pid)static booleanKillAll(String taskname)static StartRserve.ProcessToKilllaunchRserve(String Rcmd, String rargs, String rsrvargs, boolean debug, ServerSocket lock)attempt to start Rserve.Note: parameters are not quoted, so avoid using any quotes in argumentsstatic ServerSocketlockPort(int p)static voidmain(String[] args)just a demo main method which starts Rserve and shuts it down againstatic Processsystem(String command, File redirect, boolean waitFor)
-
-
-
Method Detail
-
isRserveInstalled
public static boolean isRserveInstalled() throws IOExceptionR batch to check Rserve is installed in RserveDaemon.app_dir()- Returns:
- Rserve is already installed
- Throws:
IOException
-
installRserveFromLocalLibrary
public static boolean installRserveFromLocalLibrary(String Rcmd) throws InterruptedException, IOException
R batch to install Rserve- Parameters:
Rcmd- command to start R- Returns:
- success
- Throws:
IOExceptionInterruptedException
-
installRserve
public static boolean installRserve(String Rcmd, String http_proxy, String repository) throws IOException
R batch to install Rserve from net- Parameters:
Rcmd- command necessary to start Rhttp_proxy- http://login:password@proxy:port string to enable internet access to rforge serverrepository- from which R repo ?- Returns:
- success
- Throws:
IOException
-
installBundledRserve
public static boolean installBundledRserve(String Rcmd) throws InterruptedException, IOException
R batch to install Rserve from included jar resources- Parameters:
Rcmd- command necessary to start R- Returns:
- success
- Throws:
IOExceptionInterruptedException
-
doInR
public static String doInR(String todo, String Rcmd, String rargs, File out) throws IOException
attempt to start Rserve. Note: parameters are not quoted, so avoid using any quotes in arguments- Parameters:
todo- command to execute in RRcmd- command necessary to start Rrargs- arguments are are to be passed to R (e.g. --vanilla -q)out- file to redirect R output. If null set a default name.- Returns:
trueif Rserve is running or was successfully started,falseotherwise.- Throws:
IOException
-
KillAll
public static boolean KillAll(String taskname)
-
Kill
public static boolean Kill(int pid)
-
launchRserve
public static StartRserve.ProcessToKill launchRserve(String Rcmd, String rargs, String rsrvargs, boolean debug, ServerSocket lock) throws IOException
attempt to start Rserve.Note: parameters are not quoted, so avoid using any quotes in arguments- Parameters:
Rcmd- command necessary to start Rrargs- arguments are are to be passed to Rrsrvargs- arguments to be passed to Rservedebug- Rserve debug mode ?lock- ServerSocket locker. Should be closed before using Rserve- Returns:
trueif Rserve is running or was successfully started,falseotherwise.- Throws:
IOException
-
getRservePIDs
public static int[] getRservePIDs()
-
lockPort
public static ServerSocket lockPort(int p)
-
checkLocalRserve
public static boolean checkLocalRserve(int port)
checks whether Rserve is running and if that's not the case it attempts to start it using the defaults for the platform where it is run on.This method is meant to be set-and-forget and cover most default setups. For special setups you may get more control over R withlaunchRserveinstead.- Parameters:
port- Rserve port to check- Returns:
- is ok ?
-
isRserveListening
public static boolean isRserveListening(int port)
check whether Rserve is currently running (on local machine and default port).- Parameters:
port- Rserve port to check- Returns:
trueif local Rserve instance is running,falseotherwise
-
main
public static void main(String[] args)
just a demo main method which starts Rserve and shuts it down again- Parameters:
args- ...
-
-