001    /**
002     * Copyright (c) 2000-2012 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.deploy.hot;
016    
017    import com.liferay.portal.kernel.deploy.hot.BaseHotDeployListener;
018    import com.liferay.portal.kernel.deploy.hot.HotDeployEvent;
019    import com.liferay.portal.kernel.deploy.hot.HotDeployException;
020    import com.liferay.portal.kernel.messaging.DestinationNames;
021    import com.liferay.portal.kernel.messaging.Message;
022    import com.liferay.portal.kernel.messaging.MessageBusUtil;
023    
024    import javax.servlet.ServletContext;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class MessagingHotDeployListener extends BaseHotDeployListener {
030    
031            public void invokeDeploy(HotDeployEvent hotDeployEvent)
032                    throws HotDeployException {
033    
034                    try {
035                            doInvokeDeploy(hotDeployEvent);
036                    }
037                    catch (Throwable t) {
038                            throwHotDeployException(
039                                    hotDeployEvent, "Error sending deploy message for ", t);
040                    }
041            }
042    
043            public void invokeUndeploy(HotDeployEvent hotDeployEvent)
044                    throws HotDeployException {
045    
046                    try {
047                            doInvokeUndeploy(hotDeployEvent);
048                    }
049                    catch (Throwable t) {
050                            throwHotDeployException(
051                                    hotDeployEvent, "Error sending undeploy message for ", t);
052                    }
053            }
054    
055            protected void doInvokeDeploy(HotDeployEvent hotDeployEvent)
056                    throws Exception {
057    
058                    ServletContext servletContext = hotDeployEvent.getServletContext();
059    
060                    String servletContextName = servletContext.getServletContextName();
061    
062                    Message message = new Message();
063    
064                    message.put("command", "deploy");
065                    message.put("servletContextName", servletContextName);
066    
067                    MessageBusUtil.sendMessage(DestinationNames.HOT_DEPLOY, message);
068            }
069    
070            protected void doInvokeUndeploy(HotDeployEvent hotDeployEvent)
071                    throws Exception {
072    
073                    ServletContext servletContext = hotDeployEvent.getServletContext();
074    
075                    String servletContextName = servletContext.getServletContextName();
076    
077                    Message message = new Message();
078    
079                    message.put("command", "undeploy");
080                    message.put("servletContextName", servletContextName);
081    
082                    MessageBusUtil.sendMessage(DestinationNames.HOT_DEPLOY, message);
083            }
084    
085    }