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.agent.selectors;
016    
017    import com.liferay.portal.kernel.process.ProcessCallable;
018    import com.liferay.portal.kernel.util.StringPool;
019    
020    import java.util.Map;
021    
022    /**
023     * @author Shuyang Zhou
024     */
025    public class ProcessCallableAssignmentFabricAgentSelector
026            extends SystemPropertiesFilterFabricAgentSelector {
027    
028            public static final String PROCESS_CALLABLE_ASSIGNMENT_EXPRESSION_KEY =
029                    ProcessCallableAssignmentFabricAgentSelector.class.getName() +
030                            StringPool.POUND + "processCallableAssignmentExpressionKey";
031    
032            @Override
033            protected boolean accept(
034                    Map<String, String> systemProperties,
035                    ProcessCallable<?> processCallable) {
036    
037                    String processCallableAssignmentExpressionValue = systemProperties.get(
038                            PROCESS_CALLABLE_ASSIGNMENT_EXPRESSION_KEY);
039    
040                    if (processCallableAssignmentExpressionValue == null) {
041                            return false;
042                    }
043    
044                    Class<?> clazz = processCallable.getClass();
045    
046                    String className = clazz.getName();
047    
048                    return className.matches(processCallableAssignmentExpressionValue);
049            }
050    
051    }