001    /**
002     * Copyright (c) 2000-2010 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 event) throws HotDeployException {
032                    try {
033                            doInvokeDeploy(event);
034                    }
035                    catch (Throwable t) {
036                            throwHotDeployException(
037                                    event, "Error sending deploy message for ", t);
038                    }
039            }
040    
041            public void invokeUndeploy(HotDeployEvent event) throws HotDeployException {
042                    try {
043                            doInvokeUndeploy(event);
044                    }
045                    catch (Throwable t) {
046                            throwHotDeployException(
047                                    event, "Error sending undeploy message for ", t);
048                    }
049            }
050    
051            protected void doInvokeDeploy(HotDeployEvent event) throws Exception {
052                    ServletContext servletContext = event.getServletContext();
053    
054                    String servletContextName = servletContext.getServletContextName();
055    
056                    Message message = new Message();
057    
058                    message.put("command", "deploy");
059                    message.put("servletContextName", servletContextName);
060    
061                    MessageBusUtil.sendMessage(DestinationNames.HOT_DEPLOY, message);
062            }
063    
064            protected void doInvokeUndeploy(HotDeployEvent event) throws Exception {
065                    ServletContext servletContext = event.getServletContext();
066    
067                    String servletContextName = servletContext.getServletContextName();
068    
069                    Message message = new Message();
070    
071                    message.put("command", "undeploy");
072                    message.put("servletContextName", servletContextName);
073    
074                    MessageBusUtil.sendMessage(DestinationNames.HOT_DEPLOY, message);
075            }
076    
077    }