001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.messaging;
016    
017    import com.liferay.portal.kernel.util.GetterUtil;
018    import com.liferay.portal.kernel.util.SetUtil;
019    
020    import java.util.Collections;
021    import java.util.Set;
022    
023    /**
024     * @author Brian Wing Shun Chan
025     */
026    public class HotDeployMessageListener extends BaseMessageListener {
027    
028            public HotDeployMessageListener() {
029                    this((String[])null);
030            }
031    
032            public HotDeployMessageListener(String... servletContextNames) {
033                    if (servletContextNames == null) {
034                            _servletContextNames = Collections.emptySet();
035                    }
036                    else {
037                            _servletContextNames = SetUtil.fromArray(servletContextNames);
038                    }
039            }
040    
041            @Override
042            protected void doReceive(Message message) throws Exception {
043                    String servletContextName = GetterUtil.getString(
044                            message.getString("servletContextName"));
045    
046                    if (!_servletContextNames.isEmpty() &&
047                            !_servletContextNames.contains(servletContextName)) {
048    
049                            return;
050                    }
051    
052                    String command = GetterUtil.getString(message.getString("command"));
053    
054                    if (command.equals("deploy")) {
055                            onDeploy(message);
056                    }
057                    else if (command.equals("undeploy")) {
058                            onUndeploy(message);
059                    }
060            }
061    
062            protected void onDeploy(Message message) throws Exception {
063            }
064    
065            protected void onUndeploy(Message message) throws Exception {
066            }
067    
068            private Set<String> _servletContextNames;
069    
070    }