X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.impl%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fimpl%2Fquery%2FExternalReadEntry.java;h=18d91dc0618643e092aa4d242f6a50545cbf6c6e;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=a411fa7730be1c5ed874719c00093d2c331971c9;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ExternalReadEntry.java b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ExternalReadEntry.java index a411fa773..18d91dc06 100644 --- a/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ExternalReadEntry.java +++ b/bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ExternalReadEntry.java @@ -1,183 +1,183 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 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 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.db.impl.query; - -import java.util.ArrayList; -import java.util.LinkedList; - -import org.simantics.db.impl.graph.ReadGraphImpl; -import org.simantics.db.procedure.Procedure; -import org.simantics.db.request.ExternalRead; -import org.simantics.db.request.RequestFlags; - -final public class ExternalReadEntry extends CacheEntryBase { - - final LinkedList items = new LinkedList(); - -// public ArrayList> procs; - - protected ExternalRead request; - - @Override - int makeHash() { - return request.hashCode(); - } - - @Override - public Object getOriginalRequest() { - return request; - } - - @Override - public void clearResult(QuerySupport support) { - } - - @Override - public void discard() { - request.unregistered(); - request = null; - super.discard(); - } - - public ExternalReadEntry(ExternalRead request) { - assert request != null; - this.request = request; - } - - final public void queue(T item) { - synchronized(items) { - items.addLast(item); - // TODO: implement flags/logic in ExternalRead to state that all but the latest request result can be evaporated - // In some cases where data is produced really fast this might be necessary but currently this queueing will do. - } - } - - final public void addOrSet(QueryProcessor processor, Object item) { - - try { - - assert(isPending()); - - ArrayList> p = null; - - synchronized(this) { - - setResult(item); - setReady(); -// p = procs; -// procs = null; - - } - -// if(p != null) -// for(Procedure proc : p) { -// proc.execute((T)item); -// } - - } catch (Throwable t) { - t.printStackTrace(); - } - - } - - @Override - final public Query getQuery() { - - return new Query() { - - @Override - public void recompute(ReadGraphImpl graph, Object provider, CacheEntry entry) { - - final QueryProcessor qp = (QueryProcessor)provider; - synchronized(items) { - - if(entry.isExcepted()) { - - // Exception persists - - } else { - - // Update - if(!items.isEmpty()) { - setResult(items.removeFirst()); - } - // Reschedule - if(!items.isEmpty()) { - qp.updatePrimitive(request); - } - - setReady(); - - } - - } - - } - - @Override - public void removeEntry(QueryProcessor processor) { - processor.externalReadMap.remove(request); - } - - @Override - public int type() { - return RequestFlags.IMMEDIATE_UPDATE; - } - - @Override - public String toString() { - if(request == null) return "DISCARDED ExternalRead"; - else return request.toString(); - } - - }; - - } - - public void performFromCache(Object procedure) { - - Procedure proc = (Procedure)procedure; - - if(isExcepted()) { - - proc.exception((Throwable)getResult()); - - } else { - - proc.execute((T)getResult()); - - } - - } - - @Override - public String toString() { - if(request == null) return "DISCARDED ExternalRead " + System.identityHashCode(this); - else return request.toString() + " " + + System.identityHashCode(this); - } - - @Override - public void performFromCache(ReadGraphImpl graph, Object provider, Object procedure) { - performFromCache(procedure); - } - - @Override - public void setReady() { - super.setReady(); - } - - @Override - void prepareRecompute(QuerySupport querySupport) { - // Do nothing - the state is already set and cannot be recomputed on demand - } - -} +/******************************************************************************* + * Copyright (c) 2007, 2010 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 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.impl.query; + +import java.util.ArrayList; +import java.util.LinkedList; + +import org.simantics.db.impl.graph.ReadGraphImpl; +import org.simantics.db.procedure.Procedure; +import org.simantics.db.request.ExternalRead; +import org.simantics.db.request.RequestFlags; + +final public class ExternalReadEntry extends CacheEntryBase { + + final LinkedList items = new LinkedList(); + +// public ArrayList> procs; + + protected ExternalRead request; + + @Override + int makeHash() { + return request.hashCode(); + } + + @Override + public Object getOriginalRequest() { + return request; + } + + @Override + public void clearResult(QuerySupport support) { + } + + @Override + public void discard() { + request.unregistered(); + request = null; + super.discard(); + } + + public ExternalReadEntry(ExternalRead request) { + assert request != null; + this.request = request; + } + + final public void queue(T item) { + synchronized(items) { + items.addLast(item); + // TODO: implement flags/logic in ExternalRead to state that all but the latest request result can be evaporated + // In some cases where data is produced really fast this might be necessary but currently this queueing will do. + } + } + + final public void addOrSet(QueryProcessor processor, Object item) { + + try { + + assert(isPending()); + + ArrayList> p = null; + + synchronized(this) { + + setResult(item); + setReady(); +// p = procs; +// procs = null; + + } + +// if(p != null) +// for(Procedure proc : p) { +// proc.execute((T)item); +// } + + } catch (Throwable t) { + t.printStackTrace(); + } + + } + + @Override + final public Query getQuery() { + + return new Query() { + + @Override + public void recompute(ReadGraphImpl graph, Object provider, CacheEntry entry) { + + final QueryProcessor qp = (QueryProcessor)provider; + synchronized(items) { + + if(entry.isExcepted()) { + + // Exception persists + + } else { + + // Update + if(!items.isEmpty()) { + setResult(items.removeFirst()); + } + // Reschedule + if(!items.isEmpty()) { + qp.updatePrimitive(request); + } + + setReady(); + + } + + } + + } + + @Override + public void removeEntry(QueryProcessor processor) { + processor.externalReadMap.remove(request); + } + + @Override + public int type() { + return RequestFlags.IMMEDIATE_UPDATE; + } + + @Override + public String toString() { + if(request == null) return "DISCARDED ExternalRead"; + else return request.toString(); + } + + }; + + } + + public void performFromCache(Object procedure) { + + Procedure proc = (Procedure)procedure; + + if(isExcepted()) { + + proc.exception((Throwable)getResult()); + + } else { + + proc.execute((T)getResult()); + + } + + } + + @Override + public String toString() { + if(request == null) return "DISCARDED ExternalRead " + System.identityHashCode(this); + else return request.toString() + " " + + System.identityHashCode(this); + } + + @Override + public void performFromCache(ReadGraphImpl graph, Object provider, Object procedure) { + performFromCache(procedure); + } + + @Override + public void setReady() { + super.setReady(); + } + + @Override + void prepareRecompute(QuerySupport querySupport) { + // Do nothing - the state is already set and cannot be recomputed on demand + } + +}