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
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.db.impl.procedure;
\r
14 import java.util.concurrent.atomic.AtomicBoolean;
\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
21 public class CallWrappedSingleQueryProcedure4<Result> implements AsyncProcedure<Result> {
\r
23 final private Object key;
\r
24 final private AsyncProcedure<Result> procedure;
\r
25 final private AtomicBoolean latch = new AtomicBoolean(false);
\r
27 public CallWrappedSingleQueryProcedure4(AsyncProcedure<Result> procedure, Object key) {
\r
28 this.procedure = procedure;
\r
33 public void execute(AsyncReadGraph graph, Result result) {
\r
34 if(latch.compareAndSet(false, true)) {
\r
36 procedure.execute(graph, result);
\r
37 } catch (Throwable t) {
\r
38 Logger.defaultLogError("AsyncProcedure.exception failed for " + procedure, t);
\r
42 Logger.defaultLogError("Execute or exception was called many times (this time is execute)");
\r
47 public void exception(AsyncReadGraph graph, Throwable t) {
\r
48 if(latch.compareAndSet(false, true)) {
\r
50 procedure.exception(graph, t);
\r
51 } catch (Throwable throwable) {
\r
52 Logger.defaultLogError("AsyncProcedure.exception failed for " + procedure, throwable);
\r
56 Logger.defaultLogError("Execute or exception was called many times (this time is exception)");
\r