1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.impl.procedure;
14 import java.util.concurrent.atomic.AtomicBoolean;
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;
21 public class ResultCallWrappedSingleQueryProcedure4<Result> implements AsyncProcedure<Result> {
23 final private Object key;
24 private Result result = null;
25 private Throwable exception = null;
26 final private AsyncProcedure<Result> procedure;
27 final private AtomicBoolean latch;
29 public ResultCallWrappedSingleQueryProcedure4(AsyncProcedure<Result> procedure, Object key) {
30 assert(procedure != null);
32 this.procedure = procedure;
33 latch = new AtomicBoolean(false);
37 public void execute(AsyncReadGraph graph, Result result) {
39 if(latch.compareAndSet(false, true)) {
41 procedure.execute(graph, result);
42 } catch (Throwable throwable) {
43 Logger.defaultLogError("AsyncProcedure.execute threw for " + procedure, throwable);
45 // System.err.println("ResultCallWrappedSingleQueryProcedure4 dec " + key);
48 Logger.defaultLogError("Procedure was called many times (this time is execute)");
53 public void exception(AsyncReadGraph graph, Throwable t) {
55 if(latch.compareAndSet(false, true)) {
57 procedure.exception(graph, t);
58 } catch (Throwable throwable) {
59 Logger.defaultLogError("AsyncProcedure.exception threw for " + procedure, throwable);
63 Logger.defaultLogError("Procedure was called many times (this time is exception)");
68 public Result getResult() {
72 public Throwable getException() {
77 public String toString() {
78 return "." + procedure;