]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db/src/org/simantics/db/service/QueryControl.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db / src / org / simantics / db / service / QueryControl.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.db.service;\r
13 \r
14 import java.util.Collection;\r
15 \r
16 import org.simantics.db.AsyncReadGraph;\r
17 import org.simantics.db.ReadGraph;\r
18 import org.simantics.db.Resource;\r
19 import org.simantics.db.WriteGraph;\r
20 import org.simantics.db.procedure.AsyncContextMultiProcedure;\r
21 import org.simantics.db.procedure.AsyncMultiProcedure;\r
22 import org.simantics.db.request.ExternalRead;\r
23 \r
24 \r
25 /**\r
26  * @author Antti Villberg\r
27  */\r
28 public interface QueryControl {\r
29 \r
30     interface ControlProcedure {\r
31         void execute(AsyncReadGraph graph);\r
32     }\r
33 \r
34     /**\r
35      * \r
36      * @return current amount of queries\r
37      */\r
38     int count();\r
39     \r
40     /**\r
41      * @return The amount of fixed queries after best effort flush\r
42      */\r
43     int flush();\r
44     int flush(ReadGraph graph);\r
45     \r
46     /**\r
47      * \r
48      * @param allowedTimeInMs The amount of allowed time use in ms.\r
49      */\r
50     void gc(ReadGraph graph, int allowedTimeInMs);\r
51 \r
52     /**\r
53      * Collects all external read requests and their parent queries that are no\r
54      * longer listened to. Needs to perform exclusive locking of the database\r
55      * client internally so do not invoke this from within a graph read or write\r
56      * request but use {@link #gc(WriteGraph, Collection)} instead.\r
57      * \r
58      * @param reads\r
59      */\r
60     void gc(Collection<ExternalRead<?>> reads);\r
61 \r
62     /**\r
63      * Collects all external read requests and their parent queries that are no\r
64      * longer listened to. The write graph argument is used to ensure that the\r
65      * invocation is performed from within a write request with exclusive\r
66      * locking.\r
67      * \r
68      * @param graph write request handle\r
69      * @param reads the external read requests to attempt garbage collection for\r
70      */\r
71     void gc(WriteGraph graph, Collection<ExternalRead<?>> reads);\r
72 \r
73     int getAmountOfQueryThreads();\r
74 \r
75     int getGraphThread(AsyncReadGraph graph);\r
76     \r
77     boolean resume(AsyncReadGraph graph);\r
78 \r
79     void schedule(AsyncReadGraph graph, int targetThread, ControlProcedure procedure);\r
80 \r
81     boolean scheduleByCluster(AsyncReadGraph graph, Resource resource, AsyncMultiProcedure<Resource> procedure);\r
82     <C> boolean scheduleByCluster(AsyncReadGraph graph, Resource resource, C context, AsyncContextMultiProcedure<C, Resource> procedure);\r
83 \r
84     /**\r
85      * Returns a new ReadGraph based on the specified ReadGraph. The returned\r
86      * ReadGraph does not accumulate query dependencies into the requests\r
87      * performed with the specified ReadGraph. DB listeners are therefore not\r
88      * triggered by anything that is performed with the returned ReadGraph.\r
89      * \r
90      * @param graph read transaction handle to clone for listener-independent\r
91      *        use\r
92      * @return read transaction handle that is independent of the requests\r
93      *         performed with the parameter\r
94      */\r
95     ReadGraph getIndependentGraph(ReadGraph graph);\r
96     boolean hasParentRequest(ReadGraph graph);\r
97 \r
98 }\r