]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db/src/org/simantics/db/procedure/SyncContextMultiProcedure.java
Multiple reader thread support for db client
[simantics/platform.git] / bundles / org.simantics.db / src / org / simantics / db / procedure / SyncContextMultiProcedure.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2018 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  *     Semantum Oy - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.procedure;
13
14 import org.simantics.db.AsyncReadGraph;
15 import org.simantics.db.ReadGraph;
16 import org.simantics.db.exception.DatabaseException;
17
18 /**
19  * @author Antti Villberg
20  * 
21  * First execute is called k times. After this finished or exception is called exactly once.
22  *
23  * @param <Result> the result object type accepted by the procedure
24  */
25 public interface SyncContextMultiProcedure<Context, Result> {
26
27     /**
28      * Invoked once for each separate result of the request with potentially
29      * multiple results. It shall be guaranteed that all <code>execute</code>
30      * invocations have been completed when either
31      * {@link #finished(AsyncReadGraph)} or
32      * {@link #exception(AsyncReadGraph, Throwable)} are called and that no
33      * <code>execute</code> invocations will follow afterwards.
34      * 
35      * @param graph asynchronous graph access
36      * @param result a single result of the multiresult procedure
37      */
38     void execute(ReadGraph graph, Context context, Result result) throws DatabaseException;
39
40     /**
41      * Invoked after all {@link #execute(AsyncReadGraph, Object)} calls have
42      * been finished successfully. This method will not be invoked if case of
43      * errors in {@link #execute(AsyncReadGraph, Object)} or the performed
44      * request that provides the results to this procedure.
45      * 
46      * @param graph asynchronous graph access
47      */
48     void finished(ReadGraph graph, Context context) throws DatabaseException;
49
50     /**
51      * If an error occurs in the processing of the database request that
52      * produces the results for this procedure.
53      * 
54      * @param graph asynchronous graph access
55      * @param throwable the exception that occurred
56      */
57     void exception(ReadGraph graph, Throwable throwable) throws DatabaseException;
58
59 }