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.common.procedure.single.wrapper;
\r
14 import org.simantics.db.AsyncReadGraph;
\r
15 import org.simantics.db.common.utils.Logger;
\r
16 import org.simantics.db.procedure.AsyncProcedure;
\r
18 final public class NullSingleOrNullProcedure<Result> {
\r
20 private Result result = null;
\r
21 final AsyncProcedure<Result> procedure;
\r
23 boolean done = false;
\r
24 boolean found = false;
\r
27 // final AtomicBoolean done = new AtomicBoolean(false);
\r
28 // final AtomicBoolean found = new AtomicBoolean(false);
\r
29 // final AtomicInteger ready = new AtomicInteger(1);
\r
31 public NullSingleOrNullProcedure(AsyncProcedure<Result> procedure) {
\r
33 this.procedure = procedure;
\r
39 // ready.incrementAndGet();
\r
42 public void dec(AsyncReadGraph graph) {
\r
44 if((--ready) == 0) {
\r
45 // Shall fire exactly once!
\r
49 procedure.execute(graph, result);
\r
50 } catch (Throwable t) {
\r
51 Logger.defaultLogError(t);
\r
58 public void offer(AsyncReadGraph graph, Result result) {
\r
62 this.result = result;
\r
64 // Shall fire exactly once!
\r
68 procedure.execute(graph, null);
\r
69 } catch (Throwable t) {
\r
70 Logger.defaultLogError(t);
\r
77 public void exception(AsyncReadGraph graph, Throwable t) {
\r
78 // Shall fire exactly once!
\r
82 procedure.exception(graph, t);
\r
83 } catch (Throwable t2) {
\r
84 Logger.defaultLogError(t2);
\r