use of org.neo4j.graphdb.event.KernelEventHandler in project neo4j by neo4j.
the class KernelEventHandlers method registerKernelEventHandler.
public KernelEventHandler registerKernelEventHandler(KernelEventHandler handler) {
if (this.kernelEventHandlers.contains(handler)) {
return handler;
}
// Some algo for putting it in the right place
for (KernelEventHandler registeredHandler : this.kernelEventHandlers) {
KernelEventHandler.ExecutionOrder order = handler.orderComparedTo(registeredHandler);
int index = this.kernelEventHandlers.indexOf(registeredHandler);
if (order == KernelEventHandler.ExecutionOrder.BEFORE) {
this.kernelEventHandlers.add(index, handler);
return handler;
} else if (order == KernelEventHandler.ExecutionOrder.AFTER) {
this.kernelEventHandlers.add(index + 1, handler);
return handler;
}
}
this.kernelEventHandlers.add(handler);
return handler;
}
use of org.neo4j.graphdb.event.KernelEventHandler in project graphdb by neo4j-attic.
the class TestKernelEvents method testRegisterUnregisterHandlers.
@Test
public void testRegisterUnregisterHandlers() {
GraphDatabaseService graphDb = new EmbeddedGraphDatabase(PATH);
KernelEventHandler handler1 = new DummyKernelEventHandler(RESOURCE1) {
public ExecutionOrder orderComparedTo(KernelEventHandler other) {
return ExecutionOrder.DOESNT_MATTER;
}
};
KernelEventHandler handler2 = new DummyKernelEventHandler(RESOURCE2) {
public ExecutionOrder orderComparedTo(KernelEventHandler other) {
return ExecutionOrder.DOESNT_MATTER;
}
};
try {
graphDb.unregisterKernelEventHandler(handler1);
fail("Shouldn't be able to do unregister on a " + "unregistered handler");
} catch (IllegalStateException e) {
/* Good */
}
assertTrue(handler1 == graphDb.registerKernelEventHandler(handler1));
assertTrue(handler1 == graphDb.registerKernelEventHandler(handler1));
assertTrue(handler1 == graphDb.unregisterKernelEventHandler(handler1));
try {
graphDb.unregisterKernelEventHandler(handler1);
fail("Shouldn't be able to do unregister on a " + "unregistered handler");
} catch (IllegalStateException e) {
/* Good */
}
assertTrue(handler1 == graphDb.registerKernelEventHandler(handler1));
assertTrue(handler2 == graphDb.registerKernelEventHandler(handler2));
assertTrue(handler1 == graphDb.unregisterKernelEventHandler(handler1));
assertTrue(handler2 == graphDb.unregisterKernelEventHandler(handler2));
graphDb.shutdown();
}
use of org.neo4j.graphdb.event.KernelEventHandler in project graphdb by neo4j-attic.
the class TestShutdownSequence method eventHandlersAreOnlyInvokedOnceDuringShutdown.
@Test
public void eventHandlersAreOnlyInvokedOnceDuringShutdown() {
final AtomicInteger counter = new AtomicInteger();
graphDb.registerKernelEventHandler(new KernelEventHandler() {
public void beforeShutdown() {
counter.incrementAndGet();
}
public Object getResource() {
return null;
}
public void kernelPanic(ErrorState error) {
// do nothing
}
public ExecutionOrder orderComparedTo(KernelEventHandler other) {
return ExecutionOrder.DOESNT_MATTER;
}
});
graphDb.shutdown();
graphDb.shutdown();
assertEquals(1, counter.get());
}
use of org.neo4j.graphdb.event.KernelEventHandler in project neo4j by neo4j.
the class TestShutdownSequence method canInvokeShutdownFromShutdownHandler.
@Test
public void canInvokeShutdownFromShutdownHandler() {
graphDb.registerKernelEventHandler(new KernelEventHandler() {
@Override
public void beforeShutdown() {
graphDb.shutdown();
}
@Override
public Object getResource() {
return null;
}
@Override
public void kernelPanic(ErrorState error) {
// do nothing
}
@Override
public ExecutionOrder orderComparedTo(KernelEventHandler other) {
return ExecutionOrder.DOESNT_MATTER;
}
});
graphDb.shutdown();
}
use of org.neo4j.graphdb.event.KernelEventHandler in project neo4j by neo4j.
the class TestShutdownSequence method eventHandlersAreOnlyInvokedOnceDuringShutdown.
@Test
public void eventHandlersAreOnlyInvokedOnceDuringShutdown() {
final AtomicInteger counter = new AtomicInteger();
graphDb.registerKernelEventHandler(new KernelEventHandler() {
@Override
public void beforeShutdown() {
counter.incrementAndGet();
}
@Override
public Object getResource() {
return null;
}
@Override
public void kernelPanic(ErrorState error) {
// do nothing
}
@Override
public ExecutionOrder orderComparedTo(KernelEventHandler other) {
return ExecutionOrder.DOESNT_MATTER;
}
});
graphDb.shutdown();
graphDb.shutdown();
assertEquals(1, counter.get());
}
Aggregations