001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }