]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db/src/org/simantics/db/service/QueryControl.java
AsyncBarrier.dec runs into refcounting problem
[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.exception.DatabaseException;
21 import org.simantics.db.procedure.AsyncContextMultiProcedure;
22 import org.simantics.db.procedure.AsyncMultiProcedure;
23 import org.simantics.db.request.ExternalRead;
24 import org.simantics.db.request.Read;
25
26
27 /**
28  * @author Antti Villberg
29  */
30 public interface QueryControl {
31
32     interface ControlProcedure {
33         void execute(AsyncReadGraph graph);
34     }
35
36     /**
37      * 
38      * @return current amount of queries
39      */
40     int count();
41     
42     /**
43      * @return The amount of fixed queries after best effort flush
44      */
45     int flush();
46     int flush(ReadGraph graph);
47     
48     /**
49      * 
50      * @param allowedTimeInMs The amount of allowed time use in ms.
51      */
52     void gc(ReadGraph graph, int allowedTimeInMs);
53
54     /**
55      * Collects all external read requests and their parent queries that are no
56      * longer listened to. Needs to perform exclusive locking of the database
57      * client internally so do not invoke this from within a graph read or write
58      * request but use {@link #gc(WriteGraph, Collection)} instead.
59      * 
60      * @param reads
61      */
62     void gc(Collection<ExternalRead<?>> reads);
63
64     /**
65      * Collects all external read requests and their parent queries that are no
66      * longer listened to. The write graph argument is used to ensure that the
67      * invocation is performed from within a write request with exclusive
68      * locking.
69      * 
70      * @param graph write request handle
71      * @param reads the external read requests to attempt garbage collection for
72      */
73     void gc(WriteGraph graph, Collection<ExternalRead<?>> reads);
74
75     int getAmountOfQueryThreads();
76
77     int getGraphThread(AsyncReadGraph graph);
78     
79     boolean resume(ReadGraph graph);
80
81     void schedule(AsyncReadGraph graph, int targetThread, ControlProcedure procedure);
82
83     boolean scheduleByCluster(AsyncReadGraph graph, Resource resource, AsyncMultiProcedure<Resource> procedure);
84     <C> boolean scheduleByCluster(AsyncReadGraph graph, Resource resource, C context, AsyncContextMultiProcedure<C, Resource> procedure);
85
86     /**
87      * Returns a new ReadGraph based on the specified ReadGraph. The returned
88      * ReadGraph does not accumulate query dependencies into the requests
89      * performed with the specified ReadGraph. DB listeners are therefore not
90      * triggered by anything that is performed with the returned ReadGraph.
91      * 
92      * @Deprecated In favor of syncRequestIndependent 
93      * @param graph read transaction handle to clone for listener-independent
94      *        use
95      * @return read transaction handle that is independent of the requests
96      *         performed with the parameter
97      */
98     ReadGraph getIndependentGraph(ReadGraph graph);
99     
100     /**
101      * Performs the given request without accumulating query dependencies.
102      * DB listeners are therefore not triggered by anything that is performed within the request.
103      * 
104      * @param graph read transaction handle to clone for listener-independent
105      *        use
106      * @param request the request to perform
107      * @return the result of the request evaluation
108      */
109     <T> T syncRequestIndependent(ReadGraph graph, Read<T> request) throws DatabaseException;
110     
111     boolean hasParentRequest(ReadGraph graph);
112
113 }