    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.internal.services;
    016
    017import org.apache.tapestry5.ioc.Invokable;
    018import org.apache.tapestry5.ioc.services.ParallelExecutor;
    019
    020import java.util.concurrent.ExecutionException;
    021import java.util.concurrent.Future;
    022import java.util.concurrent.TimeUnit;
    023import java.util.concurrent.TimeoutException;
    024
    025/**
    026 * Implementation of {@link ParallelExecutor} used when {@linkplain org.apache.tapestry5.ioc.IOCSymbols#THREAD_POOL_ENABLED
    027 * the thread pool is disabled}.
    028 *
    029 * @since 5.1.0.3
    030 */
    031public class NonParallelExecutor implements ParallelExecutor
    032{
    033    @Override
    034    public <T> Future<T> invoke(Invokable<T> invocable)
    035    {
    036        final T result = invocable.invoke();
    037
    038        return new Future<T>()
    039        {
    040            @Override
    041            public boolean cancel(boolean mayInterruptIfRunning)
    042            {
    043                return false;
    044            }
    045
    046            @Override
    047            public boolean isCancelled()
    048            {
    049                return false;
    050            }
    051
    052            @Override
    053            public boolean isDone()
    054            {
    055                return true;
    056            }
    057
    058            @Override
    059            public T get() throws InterruptedException, ExecutionException
    060            {
    061                return result;
    062            }
    063
    064            @Override
    065            public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
    066            {
    067                return result;
    068            }
    069        };
    070    }
    071
    072    @Override
    073    public <T> T invoke(Class<T> proxyType, Invokable<T> invocable)
    074    {
    075        return invocable.invoke();
    076    }
    077}