001    /**
002     * Copyright (c) 2000-2013 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            @Override
030            public void receive(Message message) {
031                    String destinationName = message.getDestinationName();
032    
033                    if (Validator.isNotNull(destinationName)) {
034                            if (_log.isInfoEnabled()) {
035                                    _log.info(
036                                            "Forwarding cluster link message " + message + " to " +
037                                                    destinationName);
038                            }
039    
040                            ClusterLinkUtil.setForwardMessage(message);
041    
042                            MessageBusUtil.sendMessage(destinationName, message);
043                    }
044                    else {
045                            if (_log.isErrorEnabled()) {
046                                    _log.error(
047                                            "Forwarded cluster link message has no destination " +
048                                                    message);
049                            }
050                    }
051            }
052    
053            private static Log _log = LogFactoryUtil.getLog(
054                    ClusterForwardMessageListener.class);
055    
056    }