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