001    /**
002     * Copyright (c) 2000-2013 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    
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            protected void doReceive(Message message) {
041                    Object object = retrievePayload(message);
042    
043                    if (object == null) {
044                            return;
045                    }
046    
047                    if (!_localTransportAddresses.contains(message.getSrc()) ||
048                            (message.getDest() != null)) {
049    
050                            _clusterForwardMessageListener.receive(
051                                    (com.liferay.portal.kernel.messaging.Message)object);
052                    }
053                    else {
054                            if (_log.isDebugEnabled()) {
055                                    _log.debug("Block received message " + message);
056                            }
057                    }
058            }
059    
060            private static Log _log = LogFactoryUtil.getLog(
061                    ClusterForwardReceiver.class);
062    
063            private ClusterForwardMessageListener _clusterForwardMessageListener;
064            private List<org.jgroups.Address> _localTransportAddresses;
065    
066    }