Use listener as listener in TimeoutingRequest 33/1333/1
authorAntti Villberg <antti.villberg@semantum.fi>
Thu, 21 Dec 2017 11:35:35 +0000 (13:35 +0200)
committerJussi Koskela <jussi.koskela@semantum.fi>
Thu, 21 Dec 2017 11:35:35 +0000 (13:35 +0200)
refs #7692

Change-Id: I94aafae16131f3d7a9c688d3861db5b3f56dea1b

bundles/org.simantics.db.common/src/org/simantics/db/common/utils/RequestUtil.java

index 3ab4d2644f567ae5e054c7fa02d600e821398706..d1256444ba7f2ce52c51680320b556bb27bb94b3 100644 (file)
@@ -8,6 +8,7 @@ import org.simantics.db.ReadGraph;
 import org.simantics.db.Session;
 
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.procedure.Listener;
 import org.simantics.db.procedure.Procedure;
 import org.simantics.db.request.Read;
 
@@ -95,9 +96,15 @@ public final class RequestUtil {
                public R perform(ReadGraph graph) throws DatabaseException {
                        if (state.compareAndSet(0, 1)) {
                                release();
-                               return wrappedProcedure != null
-                                               ? graph.syncRequest(wrappedRequest, wrappedProcedure)
-                                               : graph.syncRequest(wrappedRequest);
+                               if(wrappedProcedure != null) {
+                                       if(wrappedProcedure instanceof Listener<?>) {
+                                               return graph.syncRequest(wrappedRequest, (Listener<R>)wrappedProcedure);
+                                       } else {
+                                               return graph.syncRequest(wrappedRequest, wrappedProcedure);
+                                       }
+                               } else {
+                                       return graph.syncRequest(wrappedRequest);
+                               }
                        } else {
                                if (TRACE_TIMEOUT)
                                        System.out.println("[" + System.currentTimeMillis() + "] canceling execution of request " + wrappedRequest + ", startup timed out");