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