001    /**
002     * Copyright (c) 2000-2011 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.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    }