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    import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
019    
020    import java.util.concurrent.Callable;
021    import java.util.concurrent.ExecutionException;
022    import java.util.concurrent.Future;
023    import java.util.concurrent.TimeUnit;
024    import java.util.concurrent.TimeoutException;
025    
026    /**
027     * @author Shuyang Zhou
028     */
029    public class PortalExecutorManagerUtil {
030    
031            public static <T> Future<T> execute(String name, Callable<T> callable) {
032                    return getPortalExecutorManager().execute(name, callable);
033            }
034    
035            public static <T> T execute(
036                            String name, Callable<T> callable, long timeout, TimeUnit timeUnit)
037                    throws ExecutionException, InterruptedException, TimeoutException {
038    
039                    return getPortalExecutorManager().execute(
040                            name, callable, timeout, timeUnit);
041            }
042    
043            public static ThreadPoolExecutor getPortalExecutor(String name) {
044                    return getPortalExecutorManager().getPortalExecutor(name);
045            }
046    
047            public static ThreadPoolExecutor getPortalExecutor(
048                    String name, boolean createIfAbsent) {
049    
050                    return getPortalExecutorManager().getPortalExecutor(
051                            name, createIfAbsent);
052            }
053    
054            public static PortalExecutorManager getPortalExecutorManager() {
055                    PortalRuntimePermission.checkGetBeanProperty(
056                            PortalExecutorManagerUtil.class);
057    
058                    return _portalExecutorManager;
059            }
060    
061            public static ThreadPoolExecutor registerPortalExecutor(
062                    String name, ThreadPoolExecutor threadPoolExecutor) {
063    
064                    return getPortalExecutorManager().registerPortalExecutor(
065                            name, threadPoolExecutor);
066            }
067    
068            public static void shutdown() {
069                    getPortalExecutorManager().shutdown();
070            }
071    
072            public static void shutdown(boolean interrupt) {
073                    getPortalExecutorManager().shutdown(interrupt);
074            }
075    
076            public static void shutdown(String name) {
077                    getPortalExecutorManager().shutdown(name);
078            }
079    
080            public static void shutdown(String name, boolean interrupt) {
081                    getPortalExecutorManager().shutdown(name, interrupt);
082            }
083    
084            public void setPortalExecutorManager(
085                    PortalExecutorManager portalExecutorManager) {
086    
087                    PortalRuntimePermission.checkSetBeanProperty(getClass());
088    
089                    _portalExecutorManager = portalExecutorManager;
090            }
091    
092            private static PortalExecutorManager _portalExecutorManager;
093    
094    }