]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.impl/src/org/simantics/db/impl/procedure/CallWrappedSingleQueryProcedure4.java
Fail safe import fixes made by Antti
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / procedure / CallWrappedSingleQueryProcedure4.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.impl.procedure;
13
14 import java.util.concurrent.atomic.AtomicBoolean;
15
16 import org.simantics.db.AsyncReadGraph;
17 import org.simantics.db.common.utils.Logger;
18 import org.simantics.db.impl.graph.AsyncBarrierImpl;
19 import org.simantics.db.procedure.AsyncProcedure;
20
21 public class CallWrappedSingleQueryProcedure4<Result> implements AsyncProcedure<Result> {
22
23         final private Object key;
24     final private AsyncProcedure<Result> procedure;
25     final private AtomicBoolean latch = new AtomicBoolean(false);
26     
27     public CallWrappedSingleQueryProcedure4(AsyncProcedure<Result> procedure, Object key) {
28         this.procedure = procedure;
29         this.key = key;
30     }
31     
32     @Override
33     public void execute(AsyncReadGraph graph, Result result) {
34         if(latch.compareAndSet(false, true)) {
35                 try {
36                         procedure.execute(graph, result);
37                 } catch (Throwable t) {
38                         Logger.defaultLogError("AsyncProcedure.exception failed for " + procedure, t);
39                 } finally {
40                 }
41         } else {
42                 Logger.defaultLogError("Execute or exception was called many times (this time is execute)");
43         }
44     }
45
46     @Override
47     public void exception(AsyncReadGraph graph, Throwable t) {
48         if(latch.compareAndSet(false, true)) {
49                 try {
50                         procedure.exception(graph, t);
51                 } catch (Throwable throwable) {
52                         Logger.defaultLogError("AsyncProcedure.exception failed for " + procedure, throwable);
53                 } finally {
54                 }
55         } else {
56                 Logger.defaultLogError("Execute or exception was called many times (this time is exception)");
57         }
58     }
59         
60 }