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