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.AsyncMultiProcedure;
21 public class CallWrappedQueryProcedure4<Result> implements AsyncMultiProcedure<Result> {
23 final private AsyncMultiProcedure<Result> procedure;
24 final private AsyncBarrier barrier;
25 final private AtomicBoolean latch;
27 public CallWrappedQueryProcedure4(AsyncMultiProcedure<Result> procedure, AsyncBarrier barrier) {
28 this.procedure = procedure;
29 this.barrier = barrier;
30 latch = new AtomicBoolean(false);
34 public void execute(AsyncReadGraph graph, Result result) {
36 procedure.execute(graph, result);
37 } catch (Throwable t) {
38 Logger.defaultLogError("AsyncMultiProcedure.execute failed for " + procedure, t);
43 public void finished(AsyncReadGraph graph) {
44 if(latch.compareAndSet(false, true)) {
46 procedure.finished(graph);
47 } catch (Throwable t) {
48 Logger.defaultLogError("AsyncMultiProcedure.exception failed for " + procedure, t);
53 Logger.defaultLogError("Finished or exception was called many times (this time is finished)");
58 public void exception(AsyncReadGraph graph, Throwable t) {
59 if(latch.compareAndSet(false, true)) {
61 procedure.exception(graph, t);
62 } catch (Throwable throwable) {
63 Logger.defaultLogError("AsyncMultiProcedure.exception failed for " + procedure, throwable);
68 Logger.defaultLogError("Finished or exception was called many times (this time is exception)");