org.enodeframework.common.threading.ManualResetEvent Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of enode Show documentation
Show all versions of enode Show documentation
The enodeframework core implementation.
package org.enodeframework.common.threading;
import org.enodeframework.common.exception.EnodeInterruptException;
/**
* @author [email protected]
*/
public class ManualResetEvent {
private final Object monitor = new Object();
private volatile boolean open = false;
public ManualResetEvent(boolean initialState) {
open = initialState;
}
public boolean waitOne() {
synchronized (monitor) {
if (!open) {
try {
monitor.wait();
} catch (InterruptedException e) {
throw new EnodeInterruptException(e);
}
}
return open;
}
}
public boolean waitOne(long timeout) {
synchronized (monitor) {
if (!open) {
try {
monitor.wait(timeout);
} catch (InterruptedException e) {
throw new EnodeInterruptException(e);
}
}
return open;
}
}
public void set() {
synchronized (monitor) {
open = true;
monitor.notifyAll();
}
}
public void reset() {
open = false;
}
}