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