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.ArrayList;
15 import java.util.concurrent.atomic.AtomicBoolean;
17 import org.simantics.db.AsyncReadGraph;
18 import org.simantics.db.common.utils.Logger;
19 import org.simantics.db.impl.query.QueryProcessor.AsyncBarrier;
20 import org.simantics.db.procedure.AsyncMultiProcedure;
21 import org.simantics.db.procedure.MultiProcedure;
23 public class ResultCallWrappedQueryProcedure45<Result> implements AsyncMultiProcedure<Result> {
25 final private ArrayList<Result> result;
26 private Throwable exception = null;
27 final private MultiProcedure<Result> procedure;
28 final private AsyncBarrier barrier;
29 final private AtomicBoolean latch;
31 public ResultCallWrappedQueryProcedure45(MultiProcedure<Result> procedure, AsyncBarrier barrier) {
32 this.procedure = procedure;
33 this.barrier = barrier;
34 latch = new AtomicBoolean(false);
35 result = new ArrayList<Result>();
39 public void execute(AsyncReadGraph graph, Result result) {
41 synchronized(this.result) {
42 this.result.add(result);
44 procedure.execute(result);
45 } catch (Throwable t) {
46 Logger.defaultLogError("AsyncMultiProcedure.execute failed for " + procedure, t);
51 public void finished(AsyncReadGraph graph) {
52 if(latch.compareAndSet(false, true)) {
55 } catch (Throwable t) {
56 Logger.defaultLogError("AsyncMultiProcedure.exception failed for " + procedure, t);
61 Logger.defaultLogError("Finished or exception was called many times (this time is finished)");
66 public void exception(AsyncReadGraph graph, Throwable t) {
67 if(latch.compareAndSet(false, true)) {
70 procedure.exception(t);
71 } catch (Throwable throwable) {
72 Logger.defaultLogError("AsyncMultiProcedure.exception failed for " + procedure, throwable);
77 Logger.defaultLogError("Finished or exception was called many times (this time is exception)");
81 public ArrayList<Result> getResult() {
85 public Throwable getException() {