Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
62 lines (51 sloc) 1.79 KB
package org.neo4j.ratpack
import groovy.transform.CompileStatic
import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
import groovy.util.logging.Log
import org.neo4j.kernel.guard.Guard
import ratpack.session.SessionIdGenerator
import java.util.concurrent.ConcurrentHashMap
class QueryRegistry {
private final ConcurrentHashMap<String, QueryMapEntry> runningQueries = new ConcurrentHashMap<String, QueryMapEntry>()
private final SessionIdGenerator sessionIdGenerator
private final Guard guard
public QueryRegistry(SessionIdGenerator sessionIdGenerator, Guard guard) {
this.sessionIdGenerator = sessionIdGenerator
this.guard = guard
public String registerQuery(String cypher) {
String key = sessionIdGenerator.generateSessionId(null)
VetoGuard vetoGuard = new VetoGuard()
runningQueries.put(key, new QueryMapEntry(cypher: cypher, vetoGuard: vetoGuard)) "registered query $cypher ($key)"
public QueryMapEntry unregisterQuery(String key) {
guard.stop() "unregistered query ($key)"
QueryMapEntry abortQuery(String key) {
QueryMapEntry entry = runningQueries[key]
if (entry==null) {
throw new IllegalArgumentException("no query running with key $key")
entry.vetoGuard.abort = true "aborted query ($key)"
@EqualsAndHashCode //(includes = ["query", "started", "thread"])
static class QueryMapEntry {
String cypher
Date started = new Date()
Thread thread = Thread.currentThread()
VetoGuard vetoGuard