X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.db.common%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fcommon%2Fprocessor%2FMergingGraphRequestProcessor.java;h=e9523c0c899628ee03fb29a4130067131044708a;hp=acd2aad02c909e40a66eb22c406923aad39c0471;hb=0d9b90834ce56b292c00b1a39850ed842c3e4d42;hpb=0ae2b770234dfc3cbb18bd38f324125cf0faca07 diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/processor/MergingGraphRequestProcessor.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/processor/MergingGraphRequestProcessor.java index acd2aad02..e9523c0c8 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/processor/MergingGraphRequestProcessor.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/processor/MergingGraphRequestProcessor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * Copyright (c) 2007, 2018 Association for Decentralized Information Management * in Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -19,17 +19,17 @@ import java.util.LinkedList; import java.util.Set; import java.util.UUID; import java.util.concurrent.Semaphore; +import java.util.function.Consumer; import org.simantics.db.AsyncReadGraph; import org.simantics.db.AsyncRequestProcessor; import org.simantics.db.ReadGraph; -import org.simantics.db.RequestProcessor; import org.simantics.db.Resource; import org.simantics.db.Session; -import org.simantics.db.VirtualGraph; import org.simantics.db.WriteGraph; import org.simantics.db.common.procedure.adapter.AsyncMultiProcedureAdapter; import org.simantics.db.common.procedure.adapter.ProcedureAdapter; +import org.simantics.db.common.procedure.adapter.SyncMultiProcedureAdapter; import org.simantics.db.common.procedure.wrapper.NoneToAsyncProcedure; import org.simantics.db.common.request.ReadRequest; import org.simantics.db.common.request.WriteRequest; @@ -56,17 +56,15 @@ import org.simantics.db.request.ExternalRead; import org.simantics.db.request.MultiRead; import org.simantics.db.request.Read; import org.simantics.db.request.ReadInterface; -import org.simantics.db.request.UndoTraits; import org.simantics.db.request.Write; import org.simantics.db.request.WriteInterface; import org.simantics.db.request.WriteOnly; import org.simantics.db.request.WriteOnlyResult; import org.simantics.db.request.WriteResult; import org.simantics.utils.DataContainer; -import org.simantics.utils.datastructures.Callback; import org.simantics.utils.datastructures.Pair; -public class MergingGraphRequestProcessor implements RequestProcessor { +public class MergingGraphRequestProcessor implements AsyncRequestProcessor { private static class SyncWriteRequestAdapter implements Write { @@ -126,15 +124,6 @@ public class MergingGraphRequestProcessor implements RequestProcessor { throw new RuntimeException("See cause for the real exception.", exception); } - @Override - public VirtualGraph getProvider() { - return null; - } - -// @Override -// public void fillMetadata(Map metadata) { -// } - public void acquire() { try { semaphore.acquire(); @@ -147,11 +136,6 @@ public class MergingGraphRequestProcessor implements RequestProcessor { semaphore.release(); } - @Override - public UndoTraits getUndoTraits() { - return null; - } - @Override public String toString() { return "SyncWriteRequestAdapter " + request; @@ -280,11 +264,11 @@ public class MergingGraphRequestProcessor implements RequestProcessor { Logger.defaultLogError(t); - if(currentRequest.second instanceof AsyncProcedure) { - ((AsyncProcedure)currentRequest.second).exception(graph, t); - } else { - ((AsyncMultiProcedure)currentRequest.second).exception(graph, t); - } +// if(currentRequest.second instanceof AsyncProcedure) { +// ((AsyncProcedure)currentRequest.second).exception(graph, t); +// } else { +// ((AsyncMultiProcedure)currentRequest.second).exception(graph, t); +// } } @@ -302,25 +286,25 @@ public class MergingGraphRequestProcessor implements RequestProcessor { if(currentRequest.second instanceof AsyncProcedure) { if(currentRequest.first instanceof AsyncRead) { AsyncRead req = (AsyncRead)currentRequest.first; - graph.asyncRequest(req, (AsyncProcedure)currentRequest.second); + graph.syncRequest(req, (AsyncProcedure)currentRequest.second); } else { Read req = (Read)currentRequest.first; - graph.asyncRequest(req, (AsyncProcedure)currentRequest.second); + graph.syncRequest(req, (AsyncProcedure)currentRequest.second); } } else { AsyncMultiRead req = (AsyncMultiRead)currentRequest.first; - graph.asyncRequest(req, (AsyncMultiProcedure)currentRequest.second); + graph.syncRequest(req, (AsyncMultiProcedure)currentRequest.second); } } catch(Throwable t) { Logger.defaultLogError(t); - if(currentRequest.second instanceof AsyncProcedure) { - ((AsyncProcedure)currentRequest.second).exception(graph, t); - } else { - ((AsyncMultiProcedure)currentRequest.second).exception(graph, t); - } +// if(currentRequest.second instanceof AsyncProcedure) { +// ((AsyncProcedure)currentRequest.second).exception(graph, t); +// } else { +// ((AsyncMultiProcedure)currentRequest.second).exception(graph, t); +// } } } @@ -390,7 +374,7 @@ public class MergingGraphRequestProcessor implements RequestProcessor { } @SuppressWarnings("unchecked") - Callback callback = (Callback)currentRequest.second; + Consumer callback = (Consumer)currentRequest.second; if (currentRequest.first.getClass().equals(SyncWriteRequestAdapter.class)) { @@ -399,10 +383,10 @@ public class MergingGraphRequestProcessor implements RequestProcessor { try { // System.out.println("merg.sync " + adapter); graph.syncRequest(adapter); - if(callback != null) callback.run(null); + if(callback != null) callback.accept(null); } catch(Throwable t) { Logger.defaultLogError(t); - if(callback != null) callback.run(t); + if(callback != null) callback.accept(t); } adapter.release(); @@ -413,10 +397,10 @@ public class MergingGraphRequestProcessor implements RequestProcessor { try { if(currentRequest.first instanceof Write) graph.syncRequest((Write)currentRequest.first); else if(currentRequest.first instanceof DelayedWrite) graph.syncRequest((DelayedWrite)currentRequest.first); - if(callback != null) callback.run(null); + if(callback != null) callback.accept(null); } catch(Throwable t) { Logger.defaultLogError(t); - if(callback != null) callback.run(t); + if(callback != null) callback.accept(t); } } @@ -459,10 +443,10 @@ public class MergingGraphRequestProcessor implements RequestProcessor { // System.out.println(this + " asyncRequest(ReadGraphRequest> request, QueryProcedure4 procedure)"); - if (requestSet.contains(request)) + Pair pair = Pair.make(request, procedure); + if (requestSet.contains(pair)) return; - Pair pair = new Pair(request, procedure); requestQueue.add(pair); requestSet.add(pair); @@ -480,10 +464,10 @@ public class MergingGraphRequestProcessor implements RequestProcessor { // System.out.println(this + " asyncRequest(ReadGraphRequest> request, SingleQueryProcedure4 procedure) " + this); - if (requestSet.contains(request)) + Pair pair = Pair.make(request, procedure); + if (requestSet.contains(pair)) return; - Pair pair = new Pair(request, procedure); requestQueue.add(pair); requestSet.add(pair); @@ -498,14 +482,14 @@ public class MergingGraphRequestProcessor implements RequestProcessor { } @Override - public synchronized void asyncRequest(Write request, Callback callback) { + public synchronized void asyncRequest(Write request, Consumer callback) { // System.out.println(this + " asyncRequest(WriteGraphRequest request)"); - if (requestSet.contains(request)) + Pair pair = Pair.make(request, callback); + if (requestSet.contains(pair)) return; - Pair pair = new Pair(request, callback); requestQueue.add(pair); requestSet.add(pair); @@ -521,14 +505,14 @@ public class MergingGraphRequestProcessor implements RequestProcessor { } @Override - public synchronized void asyncRequest(DelayedWrite request, Callback callback) { + public synchronized void asyncRequest(DelayedWrite request, Consumer callback) { // System.out.println(this + " asyncRequest(WriteGraphRequest request)"); - if (requestSet.contains(request)) + Pair pair = Pair.make(request, callback); + if (requestSet.contains(pair)) return; - Pair pair = new Pair(request, callback); requestQueue.add(pair); requestSet.add(pair); @@ -544,14 +528,14 @@ public class MergingGraphRequestProcessor implements RequestProcessor { } @Override - public synchronized void asyncRequest(WriteOnly request, Callback callback) { + public synchronized void asyncRequest(WriteOnly request, Consumer callback) { // System.out.println(this + " asyncRequest(WriteGraphRequest request)"); - if (requestSet.contains(request)) + Pair pair = Pair.make(request, callback); + if (requestSet.contains(pair)) return; - Pair pair = new Pair(request, callback); requestQueue.add(pair); requestSet.add(pair); @@ -905,10 +889,10 @@ public class MergingGraphRequestProcessor implements RequestProcessor { public synchronized void asyncRequest(Read request, AsyncProcedure procedure) { - if (requestSet.contains(request)) + Pair pair = Pair.make(request, procedure); + if (requestSet.contains(pair)) return; - Pair pair = new Pair(request, procedure); requestQueue.add(pair); requestSet.add(pair); @@ -933,17 +917,17 @@ public class MergingGraphRequestProcessor implements RequestProcessor { final ArrayList result = new ArrayList(); final DataContainer exception = new DataContainer(); - syncRequest(request, new AsyncMultiProcedureAdapter() { + syncRequest(request, new SyncMultiProcedureAdapter() { @Override - public void execute(AsyncReadGraph graph, T t) { + public void execute(ReadGraph graph, T t) { synchronized(result) { result.add(t); } } @Override - public void exception(AsyncReadGraph graph, Throwable t) { + public void exception(ReadGraph graph, Throwable t) { exception.set(t); } @@ -963,11 +947,6 @@ public class MergingGraphRequestProcessor implements RequestProcessor { return result; } - @Override - public Collection syncRequest(MultiRead request, AsyncMultiProcedure procedure) { - throw new UnsupportedOperationException("Not implemented"); - } - @Override public Collection syncRequest(MultiRead request, MultiProcedure procedure) { throw new UnsupportedOperationException("Not implemented"); @@ -983,11 +962,6 @@ public class MergingGraphRequestProcessor implements RequestProcessor { throw new UnsupportedOperationException("Not implemented"); } - @Override - public void asyncRequest(MultiRead request, AsyncMultiProcedure procedure) { - throw new UnsupportedOperationException("Not implemented"); - } - @Override public void asyncRequest(MultiRead request, MultiProcedure procedure) { throw new UnsupportedOperationException("Not implemented"); @@ -1119,12 +1093,6 @@ public class MergingGraphRequestProcessor implements RequestProcessor { } - @Override - public Collection syncRequest(MultiRead arg0, AsyncMultiListener arg1) { - throw new UnsupportedOperationException("Not implemented."); - - } - @Override public Collection syncRequest(MultiRead arg0, SyncMultiListener arg1) { throw new UnsupportedOperationException("Not implemented."); @@ -1169,12 +1137,6 @@ public class MergingGraphRequestProcessor implements RequestProcessor { } - @Override - public void asyncRequest(MultiRead arg0, AsyncMultiListener arg1) { - throw new UnsupportedOperationException("Not implemented."); - - } - @Override public void asyncRequest(MultiRead arg0, SyncMultiListener arg1) { throw new UnsupportedOperationException("Not implemented.");