001    /**
002     * Copyright (c) 2000-2013 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.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    }