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.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  }