Merge branch 'master' of github.com:SpringSource/spring-gemfire

Conflicts:
	src/test/java/org/springframework/data/gemfire/ForkUtil.java
This commit is contained in:
Costin Leau
2011-08-26 20:45:29 +03:00

View File

@@ -17,6 +17,7 @@
package org.springframework.data.gemfire;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
@@ -30,6 +31,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
*/
public class ForkUtil {
private static OutputStream os;
private static String TEMP_DIR = System.getProperty("java.io.tmpdir");
public static OutputStream cloneJVM(String argument) {
String cp = System.getProperty("java.class.path");
@@ -98,11 +100,26 @@ public class ForkUtil {
}
public static OutputStream cacheServer() {
OutputStream os = cloneJVM("org.springframework.data.gemfire.fork.CacheServerProcess");
try {
Thread.sleep(8000);
} catch (InterruptedException ex) {
// ignore and move on
String className = "org.springframework.data.gemfire.fork.CacheServerProcess";
if (controlFileExists(className)) {
deleteControlFile(className);
}
OutputStream os = cloneJVM(className);
int maxTime = 30000;
int time = 0;
while (!controlFileExists(className) && time < maxTime) {
try {
Thread.sleep(500);
time += 500;
} catch (InterruptedException ex) {
// ignore and move on
}
}
if (controlFileExists(className)) {
System.out.println("[FORK] Started cache server");
}
else {
throw new RuntimeException("could not fork cache server");
}
return os;
}
@@ -115,4 +132,19 @@ public class ForkUtil {
throw new IllegalStateException("Cannot communicate with forked VM", ex);
}
}
public static boolean deleteControlFile(String name) {
String path = TEMP_DIR + File.separator + name;
return new File(path).delete();
}
public static boolean createControlFile(String name) throws IOException {
String path = TEMP_DIR + File.separator + name;
return new File(path).createNewFile();
}
public static boolean controlFileExists(String name) {
String path = TEMP_DIR + File.separator + name;
return new File(path).exists();
}
}