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