001// Copyright 2009 The Apache Software Foundation
002//
003// Licensed under the Apache License, Version 2.0 (the "License");
004// you may not use this file except in compliance with the License.
005// You may obtain a copy of the License at
006//
007//     http://www.apache.org/licenses/LICENSE-2.0
008//
009// Unless required by applicable law or agreed to in writing, software
010// distributed under the License is distributed on an "AS IS" BASIS,
011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012// See the License for the specific language governing permissions and
013// limitations under the License.
014
015package org.apache.tapestry5.ioc.services;
016
017import org.apache.tapestry5.ioc.Invokable;
018
019import java.util.concurrent.Future;
020
021/**
022 * A service that allows work to occur in parallel using a thread pool. The thread pool is started lazily, and is
023 * shutdown when the Registry is shutdown.
024 *
025 * @see org.apache.tapestry5.ioc.IOCSymbols
026 * @since 5.1.0.1
027 */
028public interface ParallelExecutor
029{
030    /**
031     * Submits the invocable object to be executed in a pooled thread. Returns a Future object representing the eventual
032     * result of the invocable's operation.  The actual operation will be wrapped such that {@link
033     * PerthreadManager#cleanup()} is invoked after the operation completes.
034     *
035     * @param invocable to execute in a thread
036     * @param <T>
037     * @return Future result of that invocation
038     */
039    <T> Future<T> invoke(Invokable<T> invocable);
040
041    /**
042     * As with {@link #invoke(org.apache.tapestry5.ioc.Invokable)}, but the result is wrapped inside a {@linkplain
043     * org.apache.tapestry5.ioc.services.ThunkCreator thunk}. Invoking methods on the thunk will block until the value
044     * is available.
045     *
046     * @param proxyType return type, used to create the thunk
047     * @param invocable object that will eventually execute and return a value
048     * @param <T>
049     * @return the thunk
050     */
051    <T> T invoke(Class<T> proxyType, Invokable<T> invocable);
052}