s-u / REngine

General Java interface to R supporting multiple back-ends such as JRI and Rserve
Other
67 stars 47 forks source link

Timeouts #15

Open AndreGuerra123 opened 7 years ago

AndreGuerra123 commented 7 years ago

Let's say that I have a long task in R. If the connection breaks and times-out is there a way to reconnect? What I want to do is a dialog that waits for a new connection. For instance:

RConnection r = ConnectionFactoryR.getConnection(ServerRHost, ServerRPort, ServerRUser, ServerRPass); try { r.parseAndEval("A<-0"); } catch (REngineException | REXPMismatchException e2) { }
while(true){ try { int a = r.parseAndEval("A<-A+1").asInteger(); System.out.println(a); if(a>30000) break; } catch (Exception e1) { //Should be a specific exception. ConnectionRFailureDialog dialog = new ConnectionRFailureDialog(e1,ServerRHost,ServerRPort,ServerRUser,ServerRPass); r = dialog.returning(); // Applied this way keeps on executing the function although the error may not be from the REngine or Missmatch...usually is a SocketTimeOutException thrown deep on a Native method. try { r.parseAndEval("A<-0;"); } catch (REngineException | REXPMismatchException e) {
}; }