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    
015    package org.apache.tapestry5.ioc.internal.services;
016    
017    import org.apache.tapestry5.ioc.Invokable;
018    import org.apache.tapestry5.ioc.services.ParallelExecutor;
019    
020    import java.util.concurrent.ExecutionException;
021    import java.util.concurrent.Future;
022    import java.util.concurrent.TimeUnit;
023    import 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     */
031    public class NonParallelExecutor implements ParallelExecutor
032    {
033        public <T> Future<T> invoke(Invokable<T> invocable)
034        {
035            final T result = invocable.invoke();
036    
037            return new Future<T>()
038            {
039                public boolean cancel(boolean mayInterruptIfRunning)
040                {
041                    return false;
042                }
043    
044                public boolean isCancelled()
045                {
046                    return false;
047                }
048    
049                public boolean isDone()
050                {
051                    return true;
052                }
053    
054                public T get() throws InterruptedException, ExecutionException
055                {
056                    return result;
057                }
058    
059                public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
060                {
061                    return result;
062                }
063            };
064        }
065    
066        public <T> T invoke(Class<T> proxyType, Invokable<T> invocable)
067        {
068            return invocable.invoke();
069        }
070    }