001    /**
002     * Copyright (c) 2000-2012 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(String name, Callable<T> callable) {
031                    return getPortalExecutorManager().execute(name, callable);
032            }
033    
034            public static <T> T execute(
035                            String name, Callable<T> callable, long timeout, TimeUnit timeUnit)
036                    throws ExecutionException, InterruptedException, TimeoutException {
037    
038                    return getPortalExecutorManager().execute(
039                            name, callable, timeout, timeUnit);
040            }
041    
042            public static ThreadPoolExecutor getPortalExecutor(String name) {
043                    return getPortalExecutorManager().getPortalExecutor(name);
044            }
045    
046            public static ThreadPoolExecutor getPortalExecutor(
047                    String name, boolean createIfAbsent) {
048    
049                    return getPortalExecutorManager().getPortalExecutor(
050                            name, createIfAbsent);
051            }
052    
053            public static PortalExecutorManager getPortalExecutorManager() {
054                    return _portalExecutorManager;
055            }
056    
057            public static void shutdown() {
058                    getPortalExecutorManager().shutdown();
059            }
060    
061            public static void shutdown(boolean interrupt) {
062                    getPortalExecutorManager().shutdown(interrupt);
063            }
064    
065            public static void shutdown(String name) {
066                    getPortalExecutorManager().shutdown(name);
067            }
068    
069            public static void shutdown(String name, boolean interrupt) {
070                    getPortalExecutorManager().shutdown(name, interrupt);
071            }
072    
073            public void setPortalExecutorManager(
074                    PortalExecutorManager portalExecutorManager) {
075    
076                    _portalExecutorManager = portalExecutorManager;
077            }
078    
079            private static PortalExecutorManager _portalExecutorManager;
080    
081    }