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.cluster;
016    
017    import com.liferay.portal.kernel.cluster.ClusterEvent;
018    import com.liferay.portal.kernel.cluster.ClusterEventListener;
019    import com.liferay.portal.kernel.cluster.ClusterEventType;
020    import com.liferay.portal.kernel.cluster.ClusterNode;
021    import com.liferay.portal.kernel.log.Log;
022    import com.liferay.portal.kernel.log.LogFactoryUtil;
023    import com.liferay.portal.kernel.util.StringBundler;
024    import com.liferay.portal.kernel.util.StringPool;
025    
026    import java.util.List;
027    
028    /**
029     * @author Tina Tian
030     */
031    public class DebuggingClusterEventListenerImpl implements ClusterEventListener {
032    
033            public void processClusterEvent(ClusterEvent clusterEvent) {
034                    if (!_log.isInfoEnabled()) {
035                            return;
036                    }
037    
038                    ClusterEventType clusterEventType = clusterEvent.getClusterEventType();
039    
040                    List<ClusterNode> clusterNodes = clusterEvent.getClusterNodes();
041    
042                    StringBundler sb = new StringBundler(clusterNodes.size() * 3 + 3);
043    
044                    sb.append("Cluster event ");
045                    sb.append(clusterEventType);
046                    sb.append(StringPool.NEW_LINE);
047    
048                    for (ClusterNode clusterNode : clusterNodes) {
049                            sb.append("Cluster node ");
050                            sb.append(clusterNode);
051                            sb.append(StringPool.NEW_LINE);
052                    }
053    
054                    sb.setIndex(sb.index() - 1);
055    
056                    _log.info(sb.toString());
057            }
058    
059            private static final Log _log = LogFactoryUtil.getLog(
060                    DebuggingClusterEventListenerImpl.class);
061    
062    }