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.ClusterLinkUtil;
018    import com.liferay.portal.kernel.log.Log;
019    import com.liferay.portal.kernel.log.LogFactoryUtil;
020    import com.liferay.portal.kernel.messaging.Message;
021    import com.liferay.portal.kernel.messaging.MessageBusUtil;
022    import com.liferay.portal.kernel.util.Validator;
023    
024    /**
025     * @author Shuyang Zhou
026     */
027    public class ClusterForwardMessageListener implements ClusterMessageListener {
028    
029            public void receive(Message message) {
030                    String destinationName = message.getDestinationName();
031    
032                    if (Validator.isNotNull(destinationName)) {
033                            if (_log.isInfoEnabled()) {
034                                    _log.info(
035                                            "Forwarding cluster link message " + message + " to " +
036                                                    destinationName);
037                            }
038    
039                            ClusterLinkUtil.setForwardMessage(message);
040    
041                            MessageBusUtil.sendMessage(destinationName, message);
042                    }
043                    else {
044                            if (_log.isErrorEnabled()) {
045                                    _log.error(
046                                            "Forwarded cluster link message has no destination " +
047                                                    message);
048                            }
049                    }
050            }
051    
052            private static Log _log = LogFactoryUtil.getLog(
053                    ClusterForwardMessageListener.class);
054    
055    }