]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/IModificationQueue.java
Some enhancements to GraphLayer-related utilities for Diagram layers
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / synchronization / IModificationQueue.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.diagram.synchronization;
13
14 import org.simantics.utils.threads.IThreadWorkQueue;
15
16 /**
17  * An abstraction for a queue of modifications to be performed into a backend
18  * model for synchronization with the diagram model.
19  * 
20  * @author Tuukka Lehtonen
21  */
22 public interface IModificationQueue {
23
24     /**
25      * Asynchronously perform the specified modification, using the specified
26      * thread for the modification completion event. This method will <b>not</b>
27      * cause any write request invocations to the backend, it merely offers the
28      * modifications up for execution. After several modifications have been
29      * offered, {@link #flush()} may be invoked to execute the offered
30      * modifications to execute multiple modifications in one transaction.
31      * 
32      * <p>
33      * This method should be equal to calling
34      * {@link #offer(IModification, IThreadWorkQueue)} with a null
35      * IThreadWorkQueue argument.
36      * 
37      * @param m the modification to execute
38      * @return <code>true</code> if the modification was added to the queue
39      */
40     boolean offer(IModification m);
41
42     /**
43      * Asynchronously perform the specified modification, using the specified
44      * thread for the modification completion event. This method will <b>not</b>
45      * cause any write request invocations to the backend, it merely offers the
46      * modifications up for execution. After several modifications have been
47      * offered, {@link #flush()} may be invoked to execute the offered
48      * modifications to execute multiple modifications in one transaction.
49      * 
50      * @param m the modification to execute
51      * @param completionThread the thread to be used for running the
52      *        modification completion event or <code>null</code> to not care
53      *        about the thread.
54      * @return <code>true</code> if the modification was added to the queue
55      */
56     boolean offer(IModification m, IThreadWorkQueue completionThread);
57
58     /**
59      * Flushes the queue of modifications. All modifications shall be dispatched
60      * to be executed but this method can return at any time before the
61      * modifications have been performed.
62      */
63     void flush();
64
65     /**
66      * Finishes the queue of modifications gathered so far. This method will
67      * block until all current modifications have been ran to completion.
68      * 
69      * @throws InterruptedException if the waiting thread is interrupted
70      */
71     void finish() throws InterruptedException;
72
73 }