Skip to content

ProcessWrapper changes to launch locators and servers #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<snappy.version>0.4</snappy.version>
<springdata.commons>2.3.0.BUILD-SNAPSHOT</springdata.commons>
<spring-shell.version>1.2.0.RELEASE</spring-shell.version>
<awaitility.version>3.1.2</awaitility.version>
</properties>

<repositories>
Expand Down
14 changes: 14 additions & 0 deletions spring-data-geode/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,20 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>${awaitility.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.sun.java</groupId>
<artifactId>tools</artifactId>
<version>${java.version}</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import org.springframework.data.gemfire.test.support.FileSystemUtils;
Expand Down Expand Up @@ -56,10 +57,21 @@ public static ProcessWrapper launch(Class<?> type, String... args) throws IOExce
}

public static ProcessWrapper launch(File workingDirectory, Class<?> type, String... args) throws IOException {
return launch(workingDirectory, JAVA_CLASSPATH, type, args);
return launch("FORK", workingDirectory, JAVA_CLASSPATH, type, args);
}

public static ProcessWrapper launch(File workingDirectory, String classpath, Class<?> type, String... args)
public static ProcessWrapper launch(File workingDirectory, String classpath, Class<?> type, String... args) throws IOException {
return launch("FORK", workingDirectory, classpath, type, args);
}

public static ProcessWrapper launch(String name, File workingDirectory, String classpath,
Class<?> type, String... args)
throws IOException {
return launch(name, workingDirectory, classpath, type, x -> {}, y -> {}, args);
}

public static ProcessWrapper launch(String name, File workingDirectory, String classpath,
Class<?> type, Consumer<String> logConsumer, Consumer<ProcessWrapper> waitFunction, String... args)
throws IOException {

ProcessBuilder processBuilder = new ProcessBuilder()
Expand All @@ -71,7 +83,10 @@ public static ProcessWrapper launch(File workingDirectory, String classpath, Cla

ProcessWrapper processWrapper = new ProcessWrapper(process, ProcessConfiguration.create(processBuilder));

//processWrapper.register((input) -> System.err.printf("[FORK] - %s%n", input));
processWrapper.register(logConsumer);
processWrapper.init();

waitFunction.accept(processWrapper);

return processWrapper;
}
Expand Down Expand Up @@ -115,7 +130,9 @@ protected static Collection<? extends String> getSpringGemFireSystemProperties()
}

protected static boolean isJvmOption(String option) {
return StringUtils.hasText(option) && (option.startsWith("-D") || option.startsWith("-X"));
return StringUtils.hasText(option) && (option.startsWith("-D")
|| option.startsWith("-X")
|| option.startsWith("-agent"));
}

protected static File validateDirectory(File workingDirectory) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -60,7 +61,7 @@ public class ProcessWrapper {

protected static final long DEFAULT_WAIT_TIME_MILLISECONDS = TimeUnit.SECONDS.toMillis(5);

private final List<ProcessInputStreamListener> listeners = new CopyOnWriteArrayList<>();
private final List<Consumer<String>> listeners = new CopyOnWriteArrayList<>();

protected final Logger log = Logger.getLogger(getClass().getName());

Expand All @@ -77,11 +78,9 @@ public ProcessWrapper(Process process, ProcessConfiguration processConfiguration

this.process = process;
this.processConfiguration = processConfiguration;

init();
}

private void init() {
public void init() {

newThread("Process OUT Stream Reader Thread",
newProcessInputStreamReaderRunnable(process.getInputStream())).start();
Expand All @@ -101,8 +100,8 @@ protected Runnable newProcessInputStreamReaderRunnable(InputStream in) {

try {
for (String input = inputReader.readLine(); input != null; input = inputReader.readLine()) {
for (ProcessInputStreamListener listener : listeners) {
listener.onInput(input);
for (Consumer<String> listener : listeners) {
listener.accept(input);
}
}
}
Expand Down Expand Up @@ -213,7 +212,7 @@ public String readLogFile(File log) throws IOException {
return FileUtils.read(log);
}

public boolean register(ProcessInputStreamListener listener) {
public boolean register(Consumer<String> listener) {
return (listener != null && listeners.add(listener));
}

Expand Down Expand Up @@ -323,7 +322,7 @@ public int shutdown() {
return stop();
}

public boolean unregister(ProcessInputStreamListener listener) {
public boolean unregister(Consumer<String> listener) {
return listeners.remove(listener);
}

Expand Down
Loading