use of org.neo4j.helpers.Cancelable in project neo4j by neo4j.
the class InterruptSignalHandler method install.
@Override
public Cancelable install(final Runnable action) {
if (!actionRef.compareAndSet(null, action)) {
throw new RuntimeException("An action has already been registered");
}
final SignalHandler oldHandler = Signal.handle(signal, this);
final InterruptSignalHandler self = this;
return new Cancelable() {
@Override
public void cancel() {
SignalHandler handle = Signal.handle(signal, oldHandler);
if (self != handle) {
throw new RuntimeException("Error uninstalling ShellSignalHandler: " + "another handler interjected in the mean time");
}
if (!self.actionRef.compareAndSet(action, null)) {
throw new RuntimeException("Popping a action that has not been pushed before");
}
}
};
}
use of org.neo4j.helpers.Cancelable in project neo4j by neo4j.
the class AbstractClient method grabPrompt.
public void grabPrompt() {
init();
Runnable ctrlcAction = getTerminateAction();
while (!end) {
String command = readLine(getPrompt());
Cancelable cancelable = null;
try {
cancelable = signalHandler.install(ctrlcAction);
evaluate(command);
} catch (Exception e) {
printStackTrace(e);
} finally {
if (cancelable != null) {
cancelable.cancel();
}
}
}
this.shutdown();
}
Aggregations