]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.impl/src/org/simantics/db/impl/procedure/CallWrappedSingleQueryProcedure4.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / procedure / CallWrappedSingleQueryProcedure4.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.db.impl.procedure;\r
13 \r
14 import java.util.concurrent.atomic.AtomicBoolean;\r
15 \r
16 import org.simantics.db.AsyncReadGraph;\r
17 import org.simantics.db.common.utils.Logger;\r
18 import org.simantics.db.impl.graph.AsyncBarrierImpl;\r
19 import org.simantics.db.procedure.AsyncProcedure;\r
20 \r
21 public class CallWrappedSingleQueryProcedure4<Result> implements AsyncProcedure<Result> {\r
22 \r
23         final private Object key;\r
24     final private AsyncProcedure<Result> procedure;\r
25     final private AtomicBoolean latch = new AtomicBoolean(false);\r
26     \r
27     public CallWrappedSingleQueryProcedure4(AsyncProcedure<Result> procedure, Object key) {\r
28         this.procedure = procedure;\r
29         this.key = key;\r
30     }\r
31     \r
32     @Override\r
33     public void execute(AsyncReadGraph graph, Result result) {\r
34         if(latch.compareAndSet(false, true)) {\r
35                 try {\r
36                         procedure.execute(graph, result);\r
37                 } catch (Throwable t) {\r
38                         Logger.defaultLogError("AsyncProcedure.exception failed for " + procedure, t);\r
39                 } finally {\r
40                 }\r
41         } else {\r
42                 Logger.defaultLogError("Execute or exception was called many times (this time is execute)");\r
43         }\r
44     }\r
45 \r
46     @Override\r
47     public void exception(AsyncReadGraph graph, Throwable t) {\r
48         if(latch.compareAndSet(false, true)) {\r
49                 try {\r
50                         procedure.exception(graph, t);\r
51                 } catch (Throwable throwable) {\r
52                         Logger.defaultLogError("AsyncProcedure.exception failed for " + procedure, throwable);\r
53                 } finally {\r
54                 }\r
55         } else {\r
56                 Logger.defaultLogError("Execute or exception was called many times (this time is exception)");\r
57         }\r
58     }\r
59         \r
60 }\r