1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.deploy.hot;
16  
17  import com.liferay.portal.kernel.deploy.hot.BaseHotDeployListener;
18  import com.liferay.portal.kernel.deploy.hot.HotDeployEvent;
19  import com.liferay.portal.kernel.deploy.hot.HotDeployException;
20  import com.liferay.portal.kernel.messaging.DestinationNames;
21  import com.liferay.portal.kernel.messaging.Message;
22  import com.liferay.portal.kernel.messaging.MessageBusUtil;
23  
24  import javax.servlet.ServletContext;
25  
26  /**
27   * <a href="MessagingHotDeployListener.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Brian Wing Shun Chan
30   */
31  public class MessagingHotDeployListener extends BaseHotDeployListener {
32  
33      public void invokeDeploy(HotDeployEvent event) throws HotDeployException {
34          try {
35              doInvokeDeploy(event);
36          }
37          catch (Throwable t) {
38              throwHotDeployException(
39                  event, "Error sending deploy message for ", t);
40          }
41      }
42  
43      public void invokeUndeploy(HotDeployEvent event) throws HotDeployException {
44          try {
45              doInvokeUndeploy(event);
46          }
47          catch (Throwable t) {
48              throwHotDeployException(
49                  event, "Error sending undeploy message for ", t);
50          }
51      }
52  
53      protected void doInvokeDeploy(HotDeployEvent event) throws Exception {
54          ServletContext servletContext = event.getServletContext();
55  
56          String servletContextName = servletContext.getServletContextName();
57  
58          Message message = new Message();
59  
60          message.put("command", "deploy");
61          message.put("servletContextName", servletContextName);
62  
63          MessageBusUtil.sendMessage(DestinationNames.HOT_DEPLOY, message);
64      }
65  
66      protected void doInvokeUndeploy(HotDeployEvent event) throws Exception {
67          ServletContext servletContext = event.getServletContext();
68  
69          String servletContextName = servletContext.getServletContextName();
70  
71          Message message = new Message();
72  
73          message.put("command", "undeploy");
74          message.put("servletContextName", servletContextName);
75  
76          MessageBusUtil.sendMessage(DestinationNames.HOT_DEPLOY, message);
77      }
78  
79  }