001
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.PACLConstants;
019 import com.liferay.portal.kernel.security.pacl.permission.PortalRuntimePermission;
020 import com.liferay.registry.Registry;
021 import com.liferay.registry.RegistryUtil;
022 import com.liferay.registry.ServiceTracker;
023
024
027 public class PortalExecutorManagerUtil {
028
029 public static ThreadPoolExecutor getPortalExecutor(String name) {
030 PortalRuntimePermission.checkThreadPoolExecutor(name);
031
032 return getPortalExecutorManager().getPortalExecutor(name);
033 }
034
035 public static ThreadPoolExecutor getPortalExecutor(
036 String name, boolean createIfAbsent) {
037
038 PortalRuntimePermission.checkThreadPoolExecutor(name);
039
040 return getPortalExecutorManager().getPortalExecutor(
041 name, createIfAbsent);
042 }
043
044 public static PortalExecutorManager getPortalExecutorManager() {
045 PortalRuntimePermission.checkGetBeanProperty(
046 PortalExecutorManagerUtil.class);
047
048 try {
049 while (_instance._serviceTracker.getService() == null) {
050 Thread.sleep(500);
051 }
052 }
053 catch (InterruptedException e) {
054 }
055
056 return _instance._serviceTracker.getService();
057 }
058
059 public static ThreadPoolExecutor registerPortalExecutor(
060 String name, ThreadPoolExecutor threadPoolExecutor) {
061
062 PortalRuntimePermission.checkThreadPoolExecutor(name);
063
064 return getPortalExecutorManager().registerPortalExecutor(
065 name, threadPoolExecutor);
066 }
067
068 public static void shutdown() {
069 PortalRuntimePermission.checkThreadPoolExecutor(
070 PACLConstants.PORTAL_RUNTIME_PERMISSION_THREAD_POOL_ALL_EXECUTORS);
071
072 getPortalExecutorManager().shutdown();
073 }
074
075 public static void shutdown(boolean interrupt) {
076 PortalRuntimePermission.checkThreadPoolExecutor(
077 PACLConstants.PORTAL_RUNTIME_PERMISSION_THREAD_POOL_ALL_EXECUTORS);
078
079 getPortalExecutorManager().shutdown(interrupt);
080 }
081
082 private PortalExecutorManagerUtil() {
083 Registry registry = RegistryUtil.getRegistry();
084
085 _serviceTracker = registry.trackServices(PortalExecutorManager.class);
086
087 _serviceTracker.open();
088 }
089
090 private static final PortalExecutorManagerUtil _instance =
091 new PortalExecutorManagerUtil();
092
093 private final ServiceTracker<PortalExecutorManager, PortalExecutorManager>
094 _serviceTracker;
095
096 }