use of org.neo4j.graphdb.event.KernelEventHandler in project neo4j by neo4j.
the class TestKernelEvents method testShutdownEvents.
@Test
public void testShutdownEvents() {
GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
DummyKernelEventHandler handler1 = new DummyKernelEventHandler(RESOURCE1) {
@Override
public ExecutionOrder orderComparedTo(KernelEventHandler other) {
if (((DummyKernelEventHandler) other).resource == RESOURCE2) {
return ExecutionOrder.AFTER;
}
return ExecutionOrder.DOESNT_MATTER;
}
};
DummyKernelEventHandler handler2 = new DummyKernelEventHandler(RESOURCE1) {
@Override
public ExecutionOrder orderComparedTo(KernelEventHandler other) {
if (((DummyKernelEventHandler) other).resource == RESOURCE1) {
return ExecutionOrder.BEFORE;
}
return ExecutionOrder.DOESNT_MATTER;
}
};
graphDb.registerKernelEventHandler(handler1);
graphDb.registerKernelEventHandler(handler2);
graphDb.shutdown();
assertEquals(Integer.valueOf(0), handler2.beforeShutdown);
assertEquals(Integer.valueOf(1), handler1.beforeShutdown);
}
use of org.neo4j.graphdb.event.KernelEventHandler in project neo4j-mobile-android by neo4j-contrib.
the class EmbeddedGraphDbImpl method registerKernelEventHandler.
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 EmbeddedGraphDbImpl method registerKernelEventHandler.
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 testShutdownEvents.
@Test
public void testShutdownEvents() {
GraphDatabaseService graphDb = new EmbeddedGraphDatabase("target/var/neodb");
DummyKernelEventHandler handler1 = new DummyKernelEventHandler(RESOURCE1) {
public ExecutionOrder orderComparedTo(KernelEventHandler other) {
if (((DummyKernelEventHandler) other).resource == RESOURCE2) {
return ExecutionOrder.AFTER;
}
return ExecutionOrder.DOESNT_MATTER;
}
};
DummyKernelEventHandler handler2 = new DummyKernelEventHandler(RESOURCE1) {
public ExecutionOrder orderComparedTo(KernelEventHandler other) {
if (((DummyKernelEventHandler) other).resource == RESOURCE1) {
return ExecutionOrder.BEFORE;
}
return ExecutionOrder.DOESNT_MATTER;
}
};
graphDb.registerKernelEventHandler(handler1);
graphDb.registerKernelEventHandler(handler2);
graphDb.shutdown();
assertEquals(Integer.valueOf(0), handler2.beforeShutdown);
assertEquals(Integer.valueOf(1), handler1.beforeShutdown);
}
use of org.neo4j.graphdb.event.KernelEventHandler in project graphdb by neo4j-attic.
the class TestShutdownSequence method canInvokeShutdownFromShutdownHandler.
@Test
public void canInvokeShutdownFromShutdownHandler() {
graphDb.registerKernelEventHandler(new KernelEventHandler() {
public void beforeShutdown() {
graphDb.shutdown();
}
public Object getResource() {
return null;
}
public void kernelPanic(ErrorState error) {
// do nothing
}
public ExecutionOrder orderComparedTo(KernelEventHandler other) {
return ExecutionOrder.DOESNT_MATTER;
}
});
graphDb.shutdown();
}
Aggregations