001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.executor;
016    
017    import com.liferay.portal.kernel.concurrent.ThreadPoolExecutor;
018    
019    import java.util.concurrent.Callable;
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     * @author Shuyang Zhou
027     */
028    public class PortalExecutorManagerUtil {
029    
030            public static <T> Future<T> execute(
031                    String name, Callable<T> callable) {
032    
033                    return getPortalExecutorManager().execute(name, callable);
034            }
035    
036            public static <T> T execute(
037                            String name, Callable<T> callable, long timeout, TimeUnit timeUnit)
038                    throws ExecutionException, InterruptedException, TimeoutException {
039    
040                    return getPortalExecutorManager().execute(
041                            name, callable, timeout, timeUnit);
042            }
043    
044            public static ThreadPoolExecutor getPortalExecutor(String name) {
045                    return getPortalExecutorManager().getPortalExecutor(name);
046            }
047    
048            public static ThreadPoolExecutor getPortalExecutor(
049                    String name, boolean createIfAbsent) {
050    
051                    return getPortalExecutorManager().getPortalExecutor(
052                            name, createIfAbsent);
053            }
054    
055            public static PortalExecutorManager getPortalExecutorManager() {
056                    return _portalExecutorManager;
057            }
058    
059            public static void shutdown() {
060                    getPortalExecutorManager().shutdown();
061            }
062    
063            public static void shutdown(boolean interrupt) {
064                    getPortalExecutorManager().shutdown(interrupt);
065            }
066    
067            public static void shutdown(String name) {
068                    getPortalExecutorManager().shutdown(name);
069            }
070    
071            public static void shutdown(String name, boolean interrupt) {
072                    getPortalExecutorManager().shutdown(name, interrupt);
073            }
074    
075            public void setPortalExecutorManager(
076                    PortalExecutorManager portalExecutorManager) {
077    
078                    _portalExecutorManager = portalExecutorManager;
079            }
080    
081            private static PortalExecutorManager _portalExecutorManager;
082    
083    }