
org.zeroturnaround.process.OrProcess Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zt-process-killer Show documentation
Show all versions of zt-process-killer Show documentation
A library for stopping external processes from Java.
package org.zeroturnaround.process;
import java.io.IOException;
import java.util.List;
/**
* Represents a single system process containing alternative {@link SystemProcess} implementations for controlling it.
* Children are expected to throw {@link UnsupportedOperationException} for certain operations.
*
* For any operation we try each children until it doesn't throw {@link UnsupportedOperationException}.
* If all of them throw it, we throw it as well.
*
*
* If it has only one child it acts the same as invoking the same method directly on the child.
*
*/
public class OrProcess extends CompositeProcess {
public OrProcess(List extends SystemProcess> children) {
super(children);
}
public boolean isAlive() throws IOException, InterruptedException {
for (SystemProcess child : children) {
try {
return child.isAlive();
}
catch (UnsupportedOperationException e) {
// continue
}
}
throw new UnsupportedOperationException();
}
@Override
public void waitFor() throws InterruptedException {
for (SystemProcess child : children) {
try {
child.waitFor();
return;
}
catch (UnsupportedOperationException e) {
// continue
}
}
throw new UnsupportedOperationException();
}
@Override
public void destroy(boolean forceful) throws IOException, InterruptedException {
for (SystemProcess child : children) {
try {
invokeDestroy(child, forceful);
return;
}
catch (UnsupportedOperationException e) {
// continue
}
}
throw new UnsupportedOperationException();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy