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.kernel.cluster.messaging;
016    
017    import com.liferay.portal.kernel.cluster.Address;
018    import com.liferay.portal.kernel.cluster.ClusterLinkUtil;
019    import com.liferay.portal.kernel.cluster.Priority;
020    import com.liferay.portal.kernel.log.Log;
021    import com.liferay.portal.kernel.log.LogFactoryUtil;
022    import com.liferay.portal.kernel.messaging.Message;
023    import com.liferay.portal.kernel.messaging.MessageListener;
024    
025    /**
026     * @author Shuyang Zhou
027     */
028    public class ClusterBridgeMessageListener implements MessageListener {
029    
030            public void receive(Message message) {
031                    if (!_active) {
032                            return;
033                    }
034    
035                    if (ClusterLinkUtil.isForwardMessage(message)) {
036                            return;
037                    }
038    
039                    Address address = ClusterLinkUtil.getAddress(message);
040    
041                    if (address == null) {
042                            if (_log.isInfoEnabled()) {
043                                    _log.info("Bridging cluster link multicast message " + message);
044                            }
045    
046                            ClusterLinkUtil.sendMulticastMessage(message, _priority);
047                    }
048                    else {
049                            if (_log.isInfoEnabled()) {
050                                    _log.info(
051                                            "Bridging cluster link unicast message " + message +
052                                                    " to " + address);
053                            }
054    
055                            ClusterLinkUtil.sendUnicastMessage(address, message, _priority);
056                    }
057            }
058    
059            public void setActive(boolean active) {
060                    _active = active;
061            }
062    
063            public void setPriority(Priority priority) {
064                    _priority = priority;
065            }
066    
067            private static Log _log = LogFactoryUtil.getLog(
068                    ClusterBridgeMessageListener.class);
069    
070            private boolean _active = true;
071            private Priority _priority;
072    
073    }