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