From 4cd7d3f8966102742d75cc60a9e93308b44026cf Mon Sep 17 00:00:00 2001 From: lythesia Date: Thu, 19 Feb 2015 21:51:44 +0800 Subject: [PATCH] retry backend connection --- pkg/R/sparkR.R | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/R/sparkR.R b/pkg/R/sparkR.R index 2218170fef104..7d42842dc8847 100644 --- a/pkg/R/sparkR.R +++ b/pkg/R/sparkR.R @@ -110,9 +110,19 @@ sparkR.init <- function( mainClass = "edu.berkeley.cs.amplab.sparkr.SparkRBackend", args = as.character(sparkRBackendPort), javaOpts = paste("-Xmx", sparkMem, sep = "")) - Sys.sleep(2) # Wait for backend to come up + + cat("Waiting JVM bring up ...\n") + while(TRUE) { + if(!connExists(.sparkREnv)) { + Sys.sleep(1) + cat(".") + connectBackend("localhost", sparkRBackendPort) # Connect to it + } else { + cat(" ok.\n") + break + } + } .sparkREnv$sparkRBackendPort <- sparkRBackendPort - connectBackend("localhost", sparkRBackendPort) # Connect to it if (nchar(sparkHome) != 0) { sparkHome <- normalizePath(sparkHome)