use of org.neo4j.scheduler.CancelListener in project neo4j by neo4j.
the class PooledJobHandle method cancel.
@Override
public void cancel() {
future.cancel(false);
for (CancelListener cancelListener : cancelListeners) {
cancelListener.cancelled();
}
registry.remove(registryKey);
}
use of org.neo4j.scheduler.CancelListener in project neo4j by neo4j.
the class CentralJobSchedulerTest method scheduledTasksCanBeTheirOwnCancellationListeners.
@Test
void scheduledTasksCanBeTheirOwnCancellationListeners() {
life.start();
AtomicInteger cancelled = new AtomicInteger();
class CancelCallback implements CancelListener {
@Override
public void cancelled() {
cancelled.incrementAndGet();
}
}
class RunnableAndCancellable extends CancelCallback implements Runnable {
@Override
public void run() {
}
}
class CallableAndCancellable extends CancelCallback implements Callable<Void> {
@Override
public Void call() throws Exception {
return null;
}
}
scheduler.schedule(Group.CHECKPOINT, NOT_MONITORED, new RunnableAndCancellable()).cancel();
assertThat(cancelled).hasValue(1);
cancelled.set(0);
scheduler.schedule(Group.CHECKPOINT, NOT_MONITORED, new RunnableAndCancellable(), 1, SECONDS).cancel();
assertThat(cancelled).hasValue(1);
cancelled.set(0);
scheduler.scheduleRecurring(Group.CHECKPOINT, NOT_MONITORED, new RunnableAndCancellable(), 1, SECONDS).cancel();
assertThat(cancelled).hasValue(1);
cancelled.set(0);
scheduler.scheduleRecurring(Group.CHECKPOINT, NOT_MONITORED, new RunnableAndCancellable(), 1, 1, SECONDS).cancel();
assertThat(cancelled).hasValue(1);
cancelled.set(0);
scheduler.schedule(Group.CHECKPOINT, NOT_MONITORED, new CallableAndCancellable()).cancel();
assertThat(cancelled).hasValue(1);
}
use of org.neo4j.scheduler.CancelListener in project neo4j by neo4j.
the class ScheduledJobHandle method cancel.
@Override
public void cancel() {
monitoredJobs.remove(this);
state.set(FAILED);
JobHandle handle = latestHandle;
if (handle != null) {
handle.cancel();
}
for (CancelListener cancelListener : cancelListeners) {
cancelListener.cancelled();
}
scheduler.cancelTask(this);
// Release the handle to allow waitTermination() to observe the cancellation.
handleRelease.release();
}
Aggregations