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.wrapper;
\r
14 import org.simantics.db.AsyncReadGraph;
\r
15 import org.simantics.db.ReadGraph;
\r
16 import org.simantics.db.common.request.ReadRequest;
\r
17 import org.simantics.db.common.utils.Logger;
\r
18 import org.simantics.db.exception.DatabaseException;
\r
19 import org.simantics.db.procedure.AsyncListener;
\r
20 import org.simantics.db.procedure.Procedure;
\r
21 import org.simantics.db.procedure.SyncListener;
\r
23 final public class SyncToAsyncListener<T> implements AsyncListener<T> {
\r
25 final private SyncListener<T> procedure;
\r
27 public SyncToAsyncListener(SyncListener<T> procedure) {
\r
28 this.procedure = procedure;
\r
32 final public void execute(AsyncReadGraph graph, final T result) {
\r
33 // System.out.println("SyncToAsyncListener for " + procedure + " - execute " + result);
\r
34 graph.asyncRequest(new ReadRequest() {
\r
37 public void run(ReadGraph graph) throws DatabaseException {
\r
38 // System.out.println("SyncToAsyncListener for " + procedure + " - execute " + result);
\r
39 procedure.execute(graph, result);
\r
43 public String toString() {
\r
44 return "execute for " + SyncToAsyncListener.this.toString();
\r
47 }, new Procedure<Object>() {
\r
50 public void exception(Throwable t) {
\r
51 Logger.defaultLogError(t);
\r
55 public void execute(Object result) {
\r
62 final public void exception(AsyncReadGraph graph, final Throwable t) {
\r
63 graph.asyncRequest(new ReadRequest() {
\r
66 public void run(ReadGraph graph) throws DatabaseException {
\r
67 procedure.exception(graph, t);
\r
74 public boolean isDisposed() {
\r
75 return procedure.isDisposed();
\r
79 public String toString() {
\r
80 return "SyncToAsyncListener -> " + procedure;
\r