001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }