X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.db.common%2Fsrc%2Forg%2Fsimantics%2Fdb%2Fcommon%2Fprocedure%2Fguarded%2FGuardedAsyncMultiProcedure.java;h=2759c3e9ef3b40bdf8aca95f7e9da05cb3c3109f;hb=dc199d26ff816dbd7e9021941334052adf7184f7;hp=f9bee02517d81a04811c794d78ba57043bbc7570;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/guarded/GuardedAsyncMultiProcedure.java b/bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/guarded/GuardedAsyncMultiProcedure.java index f9bee0251..2759c3e9e 100644 --- a/bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/guarded/GuardedAsyncMultiProcedure.java +++ b/bundles/org.simantics.db.common/src/org/simantics/db/common/procedure/guarded/GuardedAsyncMultiProcedure.java @@ -1,66 +1,66 @@ -/******************************************************************************* - * 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.common.procedure.guarded; - -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - -import org.simantics.db.AsyncReadGraph; -import org.simantics.db.common.procedure.adapter.AsyncProcedureSupport; -import org.simantics.db.procedure.AsyncMultiProcedure; - -abstract public class GuardedAsyncMultiProcedure implements AsyncMultiProcedure, AsyncProcedureSupport { - - private final AsyncMultiProcedure procedure; - private final AtomicBoolean onceGuard = new AtomicBoolean(false); - private final AtomicInteger resultCounter; - - public GuardedAsyncMultiProcedure(AsyncMultiProcedure procedure) { - this.procedure = procedure; - this.resultCounter = new AtomicInteger(1); - } - - @Override - final public void exception(AsyncReadGraph graph, Throwable t) { - except(graph, t); - } - - protected void except(AsyncReadGraph graph, Throwable t) { - if (onceGuard.compareAndSet(false, true)) { - procedure.exception(graph, t); - } - } - - protected void offer(AsyncReadGraph graph, T item) { - if (!onceGuard.get()) { - procedure.execute(graph, item); - } - } - - protected void dec(AsyncReadGraph graph) { - if (resultCounter.decrementAndGet() <= 0) { - if (onceGuard.compareAndSet(false, true)) { - procedure.finished(graph); - } - } - } - - protected void inc() { - resultCounter.incrementAndGet(); - } - - @Override - final public void finished(AsyncReadGraph graph) { - dec(graph); - } - -} +/******************************************************************************* + * 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.common.procedure.guarded; + +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + +import org.simantics.db.AsyncReadGraph; +import org.simantics.db.common.procedure.adapter.AsyncProcedureSupport; +import org.simantics.db.procedure.AsyncMultiProcedure; + +abstract public class GuardedAsyncMultiProcedure implements AsyncMultiProcedure, AsyncProcedureSupport { + + private final AsyncMultiProcedure procedure; + private final AtomicBoolean onceGuard = new AtomicBoolean(false); + private final AtomicInteger resultCounter; + + public GuardedAsyncMultiProcedure(AsyncMultiProcedure procedure) { + this.procedure = procedure; + this.resultCounter = new AtomicInteger(1); + } + + @Override + final public void exception(AsyncReadGraph graph, Throwable t) { + except(graph, t); + } + + protected void except(AsyncReadGraph graph, Throwable t) { + if (onceGuard.compareAndSet(false, true)) { + procedure.exception(graph, t); + } + } + + protected void offer(AsyncReadGraph graph, T item) { + if (!onceGuard.get()) { + procedure.execute(graph, item); + } + } + + protected void dec(AsyncReadGraph graph) { + if (resultCounter.decrementAndGet() <= 0) { + if (onceGuard.compareAndSet(false, true)) { + procedure.finished(graph); + } + } + } + + protected void inc() { + resultCounter.incrementAndGet(); + } + + @Override + final public void finished(AsyncReadGraph graph) { + dec(graph); + } + +}