--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.db.service;\r
+\r
+import java.util.Collection;\r
+\r
+import org.simantics.db.AsyncReadGraph;\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.WriteGraph;\r
+import org.simantics.db.procedure.AsyncContextMultiProcedure;\r
+import org.simantics.db.procedure.AsyncMultiProcedure;\r
+import org.simantics.db.request.ExternalRead;\r
+\r
+\r
+/**\r
+ * @author Antti Villberg\r
+ */\r
+public interface QueryControl {\r
+\r
+ interface ControlProcedure {\r
+ void execute(AsyncReadGraph graph);\r
+ }\r
+\r
+ /**\r
+ * \r
+ * @return current amount of queries\r
+ */\r
+ int count();\r
+ \r
+ /**\r
+ * @return The amount of fixed queries after best effort flush\r
+ */\r
+ int flush();\r
+ int flush(ReadGraph graph);\r
+ \r
+ /**\r
+ * \r
+ * @param allowedTimeInMs The amount of allowed time use in ms.\r
+ */\r
+ void gc(ReadGraph graph, int allowedTimeInMs);\r
+\r
+ /**\r
+ * Collects all external read requests and their parent queries that are no\r
+ * longer listened to. Needs to perform exclusive locking of the database\r
+ * client internally so do not invoke this from within a graph read or write\r
+ * request but use {@link #gc(WriteGraph, Collection)} instead.\r
+ * \r
+ * @param reads\r
+ */\r
+ void gc(Collection<ExternalRead<?>> reads);\r
+\r
+ /**\r
+ * Collects all external read requests and their parent queries that are no\r
+ * longer listened to. The write graph argument is used to ensure that the\r
+ * invocation is performed from within a write request with exclusive\r
+ * locking.\r
+ * \r
+ * @param graph write request handle\r
+ * @param reads the external read requests to attempt garbage collection for\r
+ */\r
+ void gc(WriteGraph graph, Collection<ExternalRead<?>> reads);\r
+\r
+ int getAmountOfQueryThreads();\r
+\r
+ int getGraphThread(AsyncReadGraph graph);\r
+ \r
+ boolean resume(AsyncReadGraph graph);\r
+\r
+ void schedule(AsyncReadGraph graph, int targetThread, ControlProcedure procedure);\r
+\r
+ boolean scheduleByCluster(AsyncReadGraph graph, Resource resource, AsyncMultiProcedure<Resource> procedure);\r
+ <C> boolean scheduleByCluster(AsyncReadGraph graph, Resource resource, C context, AsyncContextMultiProcedure<C, Resource> procedure);\r
+\r
+ /**\r
+ * Returns a new ReadGraph based on the specified ReadGraph. The returned\r
+ * ReadGraph does not accumulate query dependencies into the requests\r
+ * performed with the specified ReadGraph. DB listeners are therefore not\r
+ * triggered by anything that is performed with the returned ReadGraph.\r
+ * \r
+ * @param graph read transaction handle to clone for listener-independent\r
+ * use\r
+ * @return read transaction handle that is independent of the requests\r
+ * performed with the parameter\r
+ */\r
+ ReadGraph getIndependentGraph(ReadGraph graph);\r
+ boolean hasParentRequest(ReadGraph graph);\r
+\r
+}\r