Search in sources :

Example 1 with Cancelable

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");
            }
        }
    };
}
Also used : SignalHandler(sun.misc.SignalHandler) Cancelable(org.neo4j.helpers.Cancelable)

Example 2 with Cancelable

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();
}
Also used : Cancelable(org.neo4j.helpers.Cancelable) NoSuchObjectException(java.rmi.NoSuchObjectException) RemoteException(java.rmi.RemoteException) ShellException(org.neo4j.shell.ShellException)

Aggregations

Cancelable (org.neo4j.helpers.Cancelable)2 NoSuchObjectException (java.rmi.NoSuchObjectException)1 RemoteException (java.rmi.RemoteException)1 ShellException (org.neo4j.shell.ShellException)1 SignalHandler (sun.misc.SignalHandler)1