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.kernel.cluster.messaging;
16  
17  import com.liferay.portal.kernel.cluster.ClusterLinkUtil;
18  import com.liferay.portal.kernel.log.Log;
19  import com.liferay.portal.kernel.log.LogFactoryUtil;
20  import com.liferay.portal.kernel.messaging.Message;
21  import com.liferay.portal.kernel.messaging.MessageBusUtil;
22  import com.liferay.portal.kernel.util.Validator;
23  
24  /**
25   * <a href="ClusterForwardMessageListener.java.html"><b><i>View Source</i></b>
26   * </a>
27   *
28   * @author Shuyang Zhou
29   */
30  public class ClusterForwardMessageListener implements ClusterMessageListener {
31  
32      public void receive(Message message) {
33          String destinationName = message.getDestinationName();
34  
35          if (Validator.isNotNull(destinationName)) {
36              if (_log.isInfoEnabled()) {
37                  _log.info(
38                      "Forwarding cluster link message " + message + " to " +
39                          destinationName);
40              }
41  
42              ClusterLinkUtil.setForwardMessage(message);
43  
44              MessageBusUtil.sendMessage(destinationName, message);
45          }
46          else {
47              if (_log.isErrorEnabled()) {
48                  _log.error(
49                      "Forwarded cluster link message has no destination " +
50                          message);
51              }
52          }
53      }
54  
55      private static Log _log = LogFactoryUtil.getLog(
56          ClusterForwardMessageListener.class);
57  
58  }