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;
20 import org.simantics.db.procedure.MultiProcedure;
22 public class CallWrappedQueryProcedure45<Result> implements AsyncMultiProcedure<Result> {
24 final private MultiProcedure<Result> procedure;
25 final private AsyncBarrier barrier;
26 final private AtomicBoolean latch;
28 public CallWrappedQueryProcedure45(MultiProcedure<Result> procedure, AsyncBarrier barrier) {
29 this.procedure = procedure;
30 this.barrier = barrier;
31 latch = new AtomicBoolean(false);
35 public void execute(AsyncReadGraph graph, Result result) {
37 procedure.execute(result);
38 } catch (Throwable t) {
39 Logger.defaultLogError("AsyncMultiProcedure.execute failed for " + procedure, t);
44 public void finished(AsyncReadGraph graph) {
45 if(latch.compareAndSet(false, true)) {
48 } catch (Throwable t) {
49 Logger.defaultLogError("AsyncMultiProcedure.exception failed for " + procedure, t);
54 Logger.defaultLogError("Finished or exception was called many times (this time is finished)");
59 public void exception(AsyncReadGraph graph, Throwable t) {
60 if(latch.compareAndSet(false, true)) {
62 procedure.exception(t);
63 } catch (Throwable throwable) {
64 Logger.defaultLogError("AsyncMultiProcedure.exception failed for " + procedure, throwable);
69 Logger.defaultLogError("Finished or exception was called many times (this time is exception)");