/******************************************************************************* * 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 * 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; import java.util.Collection; import java.util.function.Consumer; import org.simantics.db.exception.DatabaseException; import org.simantics.db.procedure.AsyncListener; import org.simantics.db.procedure.AsyncMultiListener; import org.simantics.db.procedure.AsyncMultiProcedure; import org.simantics.db.procedure.AsyncProcedure; import org.simantics.db.procedure.Listener; import org.simantics.db.procedure.MultiListener; import org.simantics.db.procedure.MultiProcedure; import org.simantics.db.procedure.Procedure; import org.simantics.db.procedure.SyncListener; import org.simantics.db.procedure.SyncMultiListener; import org.simantics.db.procedure.SyncMultiProcedure; import org.simantics.db.procedure.SyncProcedure; import org.simantics.db.request.AsyncMultiRead; import org.simantics.db.request.AsyncRead; import org.simantics.db.request.DelayedWrite; import org.simantics.db.request.DelayedWriteResult; import org.simantics.db.request.ExternalRead; import org.simantics.db.request.MultiRead; import org.simantics.db.request.Read; import org.simantics.db.request.Write; import org.simantics.db.request.WriteOnly; import org.simantics.db.request.WriteOnlyResult; import org.simantics.db.request.WriteResult; /** * * For initiating requests in synchronous manner. The possible requests are * *

* The standard RequestProcessors are *

* * Database services (see e.g. {@link Session}) are available from implemented * {@link ServiceLocator}. For an asynchronous counterpart with the same * functionality as RequestProcessor see {@link AsyncRequestProcessor} * *

* IMPORTANT:A client invoking any of the syncRequest * -methods in this interface must not assume that the request is performed * within the same thread that performed the syncRequest * invocation. This is an implementation-specific matter. * * @version 0.7 * @author Antti Villberg * @see Read * @see AsyncRead * @see MultiRead * @see AsyncMultiRead * @see Write * @see WriteOnly * @see ReadGraph * @see Session * @see MergingGraphRequestProcessor * @see AsyncRequestProcessor */ public interface RequestProcessorSpecific { /** * Synchronously determines and returns the result of the given {@link Read} * and registers the given {@link Read} as a dependency of the ongoing * request if any. This is usually invoked for the side-effects of the given * {@link Read} but can also be used for e.g. dependency registering or * cache priming. * * @param request an instance of {@link Read} * @return the result of the given {@link Read} * @throws DatabaseException from {@link Read#perform(ReadGraph)} or from * request processing system */ T syncRequest(Read request) throws DatabaseException; /** * Synchronously registers the given {@link AsyncListener} (as identified * by {@link Object#equals(Object)}) to track changes in the result * determined from the given {@link Read}. Registers the given {@link Read} * as a dependency of the ongoing request if any. Exceptions due to the * determination of the result of the given {@link Read} will be transferred * to the given {@link AsyncListener}. * * @param request an instance of {@link Read}. * @param procedure an instance of {@link AsyncListener}. */ // T syncRequest(Read request, AsyncListener procedure) throws DatabaseException; /** * Synchronously registers the given {@link SyncListener} (as identified by * {@link Object#equals(Object)}) to track changes in the result determined * from the given {@link Read}. Registers the given {@link Read} as a * dependency of the ongoing request if any. Exceptions due to the * determination of the result of the given {@link Read} will be transferred * to the given {@link SyncListener} * * @param request an instance of {@link Read}. * @param procedure an instance of {@link SyncListener}. */ T syncRequest(Read request, SyncListener procedure) throws DatabaseException; /** * Synchronously registers the given {@link Listener} (as identified by * {@link Object#equals(Object)}) to track changes in the result determined * from the given {@link Read}. Registers the given {@link Read} as a * dependency of the ongoing request if any. Exceptions due to the * determination of the result of the given {@link Read} will be transferred * to the given {@link Listener} * * @param request an instance of {@link Read}. * @param procedure an instance of {@link Listener}. */ T syncRequest(Read request, Listener procedure) throws DatabaseException; /** * Synchronously supplies the result determined from the given {@link Read} * to the given {@link AsyncProcedure}. Registers the given {@link Read} as * a dependency of the ongoing request if any. Exceptions due to the * determination of the result of the given {@link Read} will be transferred * to the given {@link AsyncProcedure} * * @param request an instance of {@link Read}. * @param procedure an instance of {@link AsyncProcedure}. */ T syncRequest(Read request, AsyncProcedure procedure) throws DatabaseException; /** * Synchronously supplies the result determined from the given {@link Read} * to the given {@link SyncProcedure}. Registers the given {@link Read} as a * dependency of the ongoing request if any. Exceptions due to the * determination of the result of the given {@link Read} will be transferred * to the given {@link SyncProcedure} * * @param request an instance of {@link Read}. * @param procedure an instance of {@link SyncProcedure}. */ T syncRequest(Read request, SyncProcedure procedure) throws DatabaseException; /** * Synchronously supplies the result determined from the given {@link Read} * to the given {@link Procedure}. Registers the given {@link Read} as a * dependency of the ongoing request if any. Exceptions due to the * determination of the result of the given {@link Read} will be transferred * to the given {@link Procedure} * * @param request an instance of {@link Read}. * @param procedure an instance of {@link Procedure}. */ T syncRequest(Read request, Procedure procedure) throws DatabaseException; /** * Synchronously determines the result of the given {@link AsyncRead} and * registers the given {@link AsyncRead} as a dependency of the ongoing * request if any. This is usually invoked for the side-effects of the given * {@link AsyncRead} but can also be used for e.g. dependency registering or * cache priming. * * @param request an instance of {@link AsyncRead}. * @return the result of the given {@link AsyncRead} * @throws DatabaseException from {@link AsyncRead#perform(AsyncReadGraph)} or from * request processing system */ T syncRequest(AsyncRead request) throws DatabaseException; /** * Synchronously registers the given {@link AsyncListener} (as identified * by {@link Object#equals(Object)}) to track changes in the result * determined from the given {@link AsyncRead}. Registers the given * {@link AsyncRead} as a dependency of the ongoing request if any. * Exceptions due to the determination of the result of the given * {@link AsyncRead} will be transferred to the given {@link AsyncListener}. * * @param request an instance of {@link AsyncRead}. * @param procedure an instance of {@link AsyncListener}. */ T syncRequest(AsyncRead request, AsyncListener procedure) throws DatabaseException; /** * Synchronously registers the given {@link SyncListener} (as identified by * {@link Object#equals(Object)}) to track changes in the result determined * from the given {@link AsyncRead}. Registers the given {@link AsyncRead} * as a dependency of the ongoing request if any. Exceptions due to the * determination of the result of the given {@link AsyncRead} will be * transferred to the given {@link SyncListener} * * @param request an instance of {@link AsyncRead}. * @param procedure an instance of {@link SyncListener}. */ T syncRequest(AsyncRead request, SyncListener procedure) throws DatabaseException; /** * Synchronously registers the given {@link Listener} (as identified by * {@link Object#equals(Object)}) to track changes in the result determined * from the given {@link AsyncRead}. Registers the given {@link AsyncRead} * as a dependency of the ongoing request if any. Exceptions due to the * determination of the result of the given {@link AsyncRead} will be * transferred to the given {@link Listener} * * @param request an instance of {@link AsyncRead}. * @param procedure an instance of {@link Listener}. */ T syncRequest(AsyncRead request, Listener procedure) throws DatabaseException; /** * Synchronously supplies the result determined from the given * {@link AsyncRead} to the given {@link AsyncProcedure}. Registers the * given {@link AsyncRead} as a dependency of the ongoing request if any. * Exceptions due to the determination of the result of the given * {@link AsyncRead} will be transferred to the given {@link AsyncProcedure} * * @param request an instance of {@link AsyncRead}. * @param procedure an instance of {@link AsyncProcedure}. */ T syncRequest(AsyncRead request, AsyncProcedure procedure) throws DatabaseException; /** * Synchronously supplies the result determined from the given * {@link AsyncRead} to the given {@link SyncProcedure}. Registers the given * {@link AsyncRead} as a dependency of the ongoing request if any. * Exceptions due to the determination of the result of the given * {@link AsyncRead} will be transferred to the given {@link SyncProcedure} * * @param request an instance of {@link AsyncRead}. * @param procedure an instance of {@link SyncProcedure}. */ T syncRequest(AsyncRead request, SyncProcedure procedure) throws DatabaseException; /** * Synchronously supplies the result determined from the given * {@link AsyncRead} to the given {@link Procedure}. Registers the given * {@link AsyncRead} as a dependency of the ongoing request if any. * Exceptions due to the determination of the result of the given * {@link AsyncRead} will be transferred to the given {@link Procedure} * * @param request an instance of {@link AsyncRead}. * @param procedure an instance of {@link Procedure}. */ T syncRequest(AsyncRead request, Procedure procedure) throws DatabaseException; /** * Synchronously determines the result of the given {@link MultiRead} and * registers the given {@link MultiRead} as a dependency of the ongoing * request if any. This is usually invoked for the side-effects of the given * {@link MultiRead} but can also be used for e.g. dependency registering or * cache priming. All exceptions from request processing will be lost. * * @param request an instance of {@link MultiRead}. * @return the result of the given {@link MultiRead} * @throws DatabaseException from {@link MultiRead#perform(ReadGraph)} or from * request processing system */ Collection syncRequest(MultiRead request) throws DatabaseException; /** * Synchronously registers the given {@link AsyncMultiListener} (as * identified by {@link Object#equals(Object)}) to track changes in the * result determined from the given {@link MultiRead}. Registers the given * {@link MultiRead} as a dependency of the ongoing request if any. * Exceptions due to the determination of the result of the given * {@link MultiRead} will be transferred to the given * {@link AsyncMultiListener}. * * @param request an instance of {@link MultiRead}. * @param procedure an instance of {@link AsyncMultiListener}. */ // Collection syncRequest(MultiRead request, AsyncMultiListener procedure) throws DatabaseException; /** * Synchronously registers the given {@link SyncMultiListener} (as * identified by {@link Object#equals(Object)}) to track changes in the * result determined from the given {@link MultiRead}. Registers the given * {@link MultiRead} as a dependency of the ongoing request if any. * Exceptions due to the determination of the result of the given * {@link MultiRead} will be transferred to the given * {@link SyncMultiListener} * * @param request an instance of {@link MultiRead}. * @param procedure an instance of {@link SyncMultiListener}. */ Collection syncRequest(MultiRead request, SyncMultiListener procedure) throws DatabaseException; /** * Synchronously registers the given {@link MultiListener} (as identified * by {@link Object#equals(Object)}) to track changes in the result * determined from the given {@link MultiRead}. Registers the given * {@link MultiRead} as a dependency of the ongoing request if any. * Exceptions due to the determination of the result of the given * {@link MultiRead} will be transferred to the given {@link MultiListener} * * @param request an instance of {@link MultiRead}. * @param procedure an instance of {@link MultiListener}. */ Collection syncRequest(MultiRead request, MultiListener procedure) throws DatabaseException; /** * Synchronously supplies the result determined from the given * {@link MultiRead} to the given {@link AsyncMultiProcedure}. Registers the * given {@link MultiRead} as a dependency of the ongoing request if any. * Exceptions due to the determination of the result of the given * {@link MultiRead} will be transferred to the given * {@link AsyncMultiProcedure} * * @param request an instance of {@link MultiRead}. * @param procedure an instance of {@link AsyncMultiProcedure}. */ // Collection syncRequest(MultiRead request, AsyncMultiProcedure procedure) throws DatabaseException; /** * Synchronously supplies the result determined from the given * {@link MultiRead} to the given {@link SyncMultiProcedure}. Registers the * given {@link MultiRead} as a dependency of the ongoing request if any. * Exceptions due to the determination of the result of the given * {@link MultiRead} will be transferred to the given * {@link SyncMultiProcedure} * * @param request an instance of {@link MultiRead}. * @param procedure an instance of {@link SyncMultiProcedure}. */ Collection syncRequest(MultiRead request, SyncMultiProcedure procedure) throws DatabaseException; /** * Synchronously supplies the result determined from the given * {@link MultiRead} to the given {@link MultiProcedure}. Registers the * given {@link MultiRead} as a dependency of the ongoing request if any. * Exceptions due to the determination of the result of the given * {@link MultiRead} will be transferred to the given {@link MultiProcedure} * * @param request an instance of {@link MultiRead}. * @param procedure an instance of {@link MultiProcedure}. */ Collection syncRequest(MultiRead request, MultiProcedure procedure) throws DatabaseException; /** * Synchronously determines the result of the given {@link AsyncMultiRead} * and registers the given {@link AsyncMultiRead} as a dependency of the * ongoing request if any. This is usually invoked for the side-effects of * the given {@link AsyncMultiRead} but can also be used for e.g. dependency * registering or cache priming. All exceptions from request processing will * be lost. * * @param request an instance of {@link AsyncMultiRead}. * @throws DatabaseException from {@link AsyncMultiRead#perform(AsyncReadGraph)} or from * request processing system */ Collection syncRequest(AsyncMultiRead request) throws DatabaseException; /** * Synchronously registers the given {@link AsyncMultiListener} (as * identified by {@link Object#equals(Object)}) to track changes in the * result determined from the given {@link AsyncMultiRead}. Registers the * given {@link AsyncMultiRead} as a dependency of the ongoing request if * any. Exceptions due to the determination of the result of the given * {@link AsyncMultiRead} will be transferred to the given * {@link AsyncMultiListener}. * * @param request an instance of {@link AsyncMultiRead}. * @param procedure an instance of {@link AsyncMultiListener}. */ Collection syncRequest(AsyncMultiRead request, AsyncMultiListener procedure) throws DatabaseException; /** * Synchronously registers the given {@link SyncMultiListener} (as * identified by {@link Object#equals(Object)}) to track changes in the * result determined from the given {@link AsyncMultiRead}. Registers the * given {@link AsyncMultiRead} as a dependency of the ongoing request if * any. Exceptions due to the determination of the result of the given * {@link AsyncMultiRead} will be transferred to the given * {@link SyncMultiListener} * * @param request an instance of {@link AsyncMultiRead}. * @param procedure an instance of {@link SyncMultiListener}. */ Collection syncRequest(AsyncMultiRead request, SyncMultiListener procedure) throws DatabaseException; /** * Synchronously registers the given {@link MultiListener} (as identified * by {@link Object#equals(Object)}) to track changes in the result * determined from the given {@link AsyncMultiRead}. Registers the given * {@link AsyncMultiRead} as a dependency of the ongoing request if any. * Exceptions due to the determination of the result of the given * {@link AsyncMultiRead} will be transferred to the given * {@link MultiListener} * * @param request an instance of {@link AsyncMultiRead}. * @param procedure an instance of {@link MultiListener}. */ Collection syncRequest(AsyncMultiRead request, MultiListener procedure) throws DatabaseException; /** * Synchronously supplies the result determined from the given * {@link AsyncMultiRead} to the given {@link AsyncMultiProcedure}. * Registers the given {@link AsyncMultiRead} as a dependency of the ongoing * request if any. Exceptions due to the determination of the result of the * given {@link AsyncMultiRead} will be transferred to the given * {@link AsyncMultiProcedure} * * @param request an instance of {@link AsyncMultiRead}. * @param procedure an instance of {@link AsyncMultiProcedure}. */ Collection syncRequest(AsyncMultiRead request, AsyncMultiProcedure procedure) throws DatabaseException; /** * Synchronously supplies the result determined from the given * {@link AsyncMultiRead} to the given {@link SyncMultiProcedure}. Registers * the given {@link AsyncMultiRead} as a dependency of the ongoing request * if any. Exceptions due to the determination of the result of the given * {@link AsyncMultiRead} will be transferred to the given * {@link SyncMultiProcedure} * * @param request an instance of {@link AsyncMultiRead}. * @param procedure an instance of {@link SyncMultiProcedure}. */ Collection syncRequest(AsyncMultiRead request, SyncMultiProcedure procedure) throws DatabaseException; /** * Synchronously supplies the result determined from the given * {@link AsyncMultiRead} to the given {@link MultiProcedure}. Registers the * given {@link AsyncMultiRead} as a dependency of the ongoing request if * any. Exceptions due to the determination of the result of the given * {@link AsyncMultiRead} will be transferred to the given * {@link MultiProcedure} * * @param request an instance of {@link AsyncMultiRead}. * @param procedure an instance of {@link MultiProcedure}. */ Collection syncRequest(AsyncMultiRead request, MultiProcedure procedure) throws DatabaseException; T syncRequest(ExternalRead request) throws DatabaseException; T syncRequest(ExternalRead request, Listener procedure) throws DatabaseException; T syncRequest(ExternalRead request, Procedure procedure) throws DatabaseException; /** * Synchronously performs the given {@link Write}. * * @param request an instance of {@link Write}. */ void syncRequest(Write request) throws DatabaseException; /** * Synchronously performs the given {@link DelayedWrite}. * * @param request an instance of {@link DelayedWrite}. */ void syncRequest(DelayedWrite request) throws DatabaseException; /** * Synchronously performs the given {@link WriteOnly}. * * @param request an instance of {@link Write}. */ void syncRequest(WriteOnly r) throws DatabaseException; /** * Synchronously performs the given {@link Write}. * * @param request an instance of {@link Write}. */ T syncRequest(WriteResult request) throws DatabaseException; /** * Synchronously performs the given {@link DelayedWrite}. * * @param request an instance of {@link DelayedWrite}. */ T syncRequest(DelayedWriteResult request) throws DatabaseException; /** * Synchronously performs the given {@link WriteOnly}. * * @param request an instance of {@link Write}. */ T syncRequest(WriteOnlyResult r) throws DatabaseException; /** * Asynchronously performs the given {@link Write}. The outcome of the * request will be lost. * * @param request an instance of {@link Write}. */ void asyncRequest(Write request); /** * Asynchronously performs the given {@link Write}. The outcome of the * request will be reported to given {@link Consumer} in the form of a * DatabaseException raised during request processing or null upon success. * * @param request an instance of {@link Write}. * @param request an instance of {@link Consumer}. */ void asyncRequest(Write request, Consumer callback); void asyncRequest(WriteResult r, Procedure procedure); /** * Asynchronously performs the given {@link WriteOnly}. The outcome of the * request will be lost. * * @param request an instance of {@link Write}. */ void asyncRequest(DelayedWrite request); /** * Asynchronously performs the given {@link WriteOnly}. The outcome of the * request will be reported to given {@link Consumer} in the form of a * DatabaseException raised during request processing or null upon success. * * @param request an instance of {@link WriteOnly}. * @param request an instance of {@link Consumer}. */ void asyncRequest(DelayedWrite request, Consumer callback); void asyncRequest(DelayedWriteResult r, Procedure procedure); /** * Asynchronously performs the given {@link WriteOnly}. The outcome of the * request will be lost. * * @param request an instance of {@link Write}. */ void asyncRequest(WriteOnly r); /** * Asynchronously performs the given {@link WriteOnly}. The outcome of the * request will be reported to given {@link Consumer} in the form of a * DatabaseException raised during request processing or null upon success. * * @param request an instance of {@link WriteOnly}. * @param request an instance of {@link Consumer}. */ void asyncRequest(WriteOnly r, Consumer callback); void asyncRequest(WriteOnlyResult r, Procedure procedure); }