]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.diagram/src/org/simantics/diagram/synchronization/ThreadingModificationProxy.java
Fixed route graph splitting and diagram mapping race condition problem
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / synchronization / ThreadingModificationProxy.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.db.WriteGraph;
15 import org.simantics.utils.threads.IThreadWorkQueue;
16 import org.simantics.utils.threads.ThreadUtils;
17
18 /**
19  * @author Tuukka Lehtonen
20  */
21 public class ThreadingModificationProxy extends ModificationAdapter {
22     private final IModification    m;
23     private final IThreadWorkQueue completionThread;
24     private final boolean          syncCompletion;
25
26     public ThreadingModificationProxy(IModification m, IThreadWorkQueue completionThread, boolean syncCompletion) {
27         super(m.getPriority());
28         this.m = m;
29         this.completionThread = completionThread;
30         this.syncCompletion = syncCompletion;
31     }
32     @Override
33     public void completed() {
34         if (completionThread != null) {
35             Runnable r = new Runnable() {
36                 @Override
37                 public void run() {
38                     m.completed();
39                 }
40             };
41             if (syncCompletion)
42                 ThreadUtils.syncExec(completionThread, r);
43             else
44                 ThreadUtils.asyncExec(completionThread, r);
45         } else {
46             m.completed();
47         }
48     }
49     @Override
50     public boolean isComplete() {
51         return m.isComplete();
52     }
53     @Override
54     public void markComplete() {
55         m.markComplete();
56     }
57     @Override
58     public void perform(WriteGraph g) throws Exception {
59         m.perform(g);
60     }
61     @Override
62     public Throwable getException() {
63         return m.getException();
64     }
65     @Override
66     public void setException(Throwable t) {
67         m.setException(t);
68     }
69     @Override
70     public String toString() {
71         return getClass().getSimpleName() + "[" + m + "]";
72     }
73 }