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.cluster;
16  
17  import com.liferay.portal.kernel.cluster.messaging.ClusterForwardMessageListener;
18  import com.liferay.portal.kernel.log.Log;
19  import com.liferay.portal.kernel.log.LogFactoryUtil;
20  
21  import java.util.List;
22  
23  import org.jgroups.Address;
24  import org.jgroups.Message;
25  import org.jgroups.View;
26  
27  /**
28   * <a href="ClusterForwardReceiver.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Shuyang Zhou
31   */
32  public class ClusterForwardReceiver extends BaseReceiver {
33  
34      public ClusterForwardReceiver(
35          List<Address> localTransportAddresses,
36          ClusterForwardMessageListener clusterForwardMessageListener) {
37  
38          _localTransportAddresses = localTransportAddresses;
39          _clusterForwardMessageListener = clusterForwardMessageListener;
40      }
41  
42      public void receive(Message message) {
43          if ((!_localTransportAddresses.contains(message.getSrc())) ||
44              (message.getDest() != null)) {
45  
46              _clusterForwardMessageListener.receive(
47                  (com.liferay.portal.kernel.messaging.Message)
48                      message.getObject());
49          }
50          else {
51              if (_log.isDebugEnabled()) {
52                  _log.debug("Block received message " + message);
53              }
54          }
55      }
56  
57      public void viewAccepted(View view) {
58          if (_log.isDebugEnabled()) {
59              _log.debug("Accepted view " + view);
60          }
61      }
62  
63      private static Log _log = LogFactoryUtil.getLog(
64          ClusterForwardReceiver.class);
65  
66      private List<org.jgroups.Address> _localTransportAddresses;
67      private ClusterForwardMessageListener _clusterForwardMessageListener;
68  
69  }