1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
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  }