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.query.QueryProcessor.AsyncBarrier;
19 import org.simantics.db.procedure.AsyncProcedure;
20 import org.simantics.db.procedure.Procedure;
22 public class ResultCallWrappedSingleQueryProcedure45<Result> implements AsyncProcedure<Result> {
24 private Result result = null;
25 private Throwable exception = null;
26 final private Procedure<Result> procedure;
27 final private AsyncBarrier barrier;
28 final private AtomicBoolean latch;
30 public ResultCallWrappedSingleQueryProcedure45(Procedure<Result> procedure, AsyncBarrier barrier) {
31 assert(procedure != null);
32 this.procedure = procedure;
33 this.barrier = barrier;
34 latch = new AtomicBoolean(false);
38 public void execute(AsyncReadGraph graph, Result result) {
40 if(latch.compareAndSet(false, true)) {
42 procedure.execute(result);
43 } catch (Throwable throwable) {
44 Logger.defaultLogError("AsyncProcedure.execute threw for " + procedure, throwable);
49 Logger.defaultLogError("Procedure was called many times (this time is execute)");
54 public void exception(AsyncReadGraph graph, Throwable t) {
56 if(latch.compareAndSet(false, true)) {
58 procedure.exception(t);
59 } catch (Throwable throwable) {
60 Logger.defaultLogError("AsyncProcedure.exception threw for " + procedure, throwable);
65 Logger.defaultLogError("Procedure was called many times (this time is exception)");
70 public Result getResult() {
74 public Throwable getException() {