001    /**
002     * Copyright (c) 2000-2012 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    
026    /**
027     * @author Shuyang Zhou
028     */
029    public class ClusterForwardReceiver extends BaseReceiver {
030    
031            public ClusterForwardReceiver(
032                    List<Address> localTransportAddresses,
033                    ClusterForwardMessageListener clusterForwardMessageListener) {
034    
035                    _localTransportAddresses = localTransportAddresses;
036                    _clusterForwardMessageListener = clusterForwardMessageListener;
037            }
038    
039            @Override
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            private static Log _log = LogFactoryUtil.getLog(
056                    ClusterForwardReceiver.class);
057    
058            private ClusterForwardMessageListener _clusterForwardMessageListener;
059            private List<org.jgroups.Address> _localTransportAddresses;
060    
061    }