001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.cluster;
016    
017    import com.liferay.portal.kernel.cluster.messaging.ClusterForwardMessageListener;
018    import com.liferay.portal.kernel.log.Log;
019    import com.liferay.portal.kernel.log.LogFactoryUtil;
020    
021    import java.util.List;
022    
023    import org.jgroups.Address;
024    import org.jgroups.Message;
025    import org.jgroups.View;
026    
027    /**
028     * @author Shuyang Zhou
029     */
030    public class ClusterForwardReceiver extends BaseReceiver {
031    
032            public ClusterForwardReceiver(
033                    List<Address> localTransportAddresses,
034                    ClusterForwardMessageListener clusterForwardMessageListener) {
035    
036                    _localTransportAddresses = localTransportAddresses;
037                    _clusterForwardMessageListener = clusterForwardMessageListener;
038            }
039    
040            public void receive(Message message) {
041                    if ((!_localTransportAddresses.contains(message.getSrc())) ||
042                            (message.getDest() != null)) {
043    
044                            _clusterForwardMessageListener.receive(
045                                    (com.liferay.portal.kernel.messaging.Message)
046                                            message.getObject());
047                    }
048                    else {
049                            if (_log.isDebugEnabled()) {
050                                    _log.debug("Block received message " + message);
051                            }
052                    }
053            }
054    
055            public void viewAccepted(View view) {
056                    if (_log.isDebugEnabled()) {
057                            _log.debug("Accepted view " + view);
058                    }
059            }
060    
061            private static Log _log = LogFactoryUtil.getLog(
062                    ClusterForwardReceiver.class);
063    
064            private List<org.jgroups.Address> _localTransportAddresses;
065            private ClusterForwardMessageListener _clusterForwardMessageListener;
066    
067    }