]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/wrapper/SyncToAsyncMultiListener.java
Add logging by default to adapters exception-methods
[simantics/platform.git] / bundles / org.simantics.db.common / src / org / simantics / db / common / procedure / wrapper / SyncToAsyncMultiListener.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.common.procedure.wrapper;
13
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.exception.DatabaseException;
18 import org.simantics.db.procedure.AsyncMultiListener;
19 import org.simantics.db.procedure.SyncMultiListener;
20
21 final public class SyncToAsyncMultiListener<T> implements AsyncMultiListener<T> {
22
23         final private SyncMultiListener<T> procedure;
24
25         public SyncToAsyncMultiListener(SyncMultiListener<T> procedure) {
26                 this.procedure = procedure;
27         }
28         
29         @Override
30         final public void execute(AsyncReadGraph graph, final T result) {
31                 graph.asyncRequest(new ReadRequest() {
32
33                         @Override
34                         public void run(ReadGraph graph) throws DatabaseException {
35                                 procedure.execute(graph, result);
36                         }
37                         
38                 });
39         }
40
41         @Override
42         final public void finished(AsyncReadGraph graph) {
43                 graph.asyncRequest(new ReadRequest() {
44
45                         @Override
46                         public void run(ReadGraph graph) throws DatabaseException {
47                                 procedure.finished(graph);
48                         }
49                         
50                 });
51         }
52
53         @Override
54         final public void exception(AsyncReadGraph graph, final Throwable t) {
55         graph.asyncRequest(new ReadRequest() {
56
57             @Override
58             public void run(ReadGraph graph) throws DatabaseException {
59                 procedure.exception(graph, t);
60             }
61             
62         });
63         }
64
65     @Override
66     public boolean isDisposed() {
67         return procedure.isDisposed();
68     }
69
70     @Override
71     public String toString() {
72         return "SyncToAsyncMultiListener -> " + procedure;
73    }
74     
75 }