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