001    /**
002     * Copyright (c) 2000-present 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.fabric;
016    
017    import com.liferay.portal.fabric.agent.FabricAgentRegistry;
018    import com.liferay.portal.fabric.agent.PortalClassPathWarmupFabricAgentListener;
019    import com.liferay.portal.fabric.agent.selectors.FabricAgentSelector;
020    import com.liferay.portal.kernel.process.ProcessExecutor;
021    import com.liferay.portal.util.PropsValues;
022    
023    /**
024     * @author Shuyang Zhou
025     */
026    public class FabricProcessExecutorFactory {
027    
028            public static ProcessExecutor createFabricProcessExecutor(
029                            FabricAgentRegistry fabricAgentRegistry,
030                            ProcessExecutor processExecutor)
031                    throws Exception {
032    
033                    if (!PropsValues.PORTAL_FABRIC_ENABLED) {
034                            return processExecutor;
035                    }
036    
037                    if (PropsValues.PORTAL_FABRIC_SERVER_WARMUP_AGENT_ON_REGISTER) {
038                            fabricAgentRegistry.registerFabricAgentListener(
039                                    new PortalClassPathWarmupFabricAgentListener());
040                    }
041    
042                    Thread currentThread = Thread.currentThread();
043    
044                    ClassLoader classLoader = currentThread.getContextClassLoader();
045    
046                    Class<? extends FabricAgentSelector> fabricAgentSelectorClass =
047                            (Class<? extends FabricAgentSelector>)classLoader.loadClass(
048                                    PropsValues.PORTAL_FABRIC_AGENT_SELECTOR_CLASS);
049    
050                    return new FabricProcessExecutor(
051                            fabricAgentRegistry, fabricAgentSelectorClass.newInstance());
052            }
053    
054    }