001    /**
002     * Copyright (c) 2000-2013 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            @Override
034            public void processClusterEvent(ClusterEvent clusterEvent) {
035                    if (!_log.isInfoEnabled()) {
036                            return;
037                    }
038    
039                    ClusterEventType clusterEventType = clusterEvent.getClusterEventType();
040    
041                    List<ClusterNode> clusterNodes = clusterEvent.getClusterNodes();
042    
043                    StringBundler sb = new StringBundler(clusterNodes.size() * 3 + 3);
044    
045                    sb.append("Cluster event ");
046                    sb.append(clusterEventType);
047                    sb.append(StringPool.NEW_LINE);
048    
049                    for (ClusterNode clusterNode : clusterNodes) {
050                            sb.append("Cluster node ");
051                            sb.append(clusterNode);
052                            sb.append(StringPool.NEW_LINE);
053                    }
054    
055                    sb.setIndex(sb.index() - 1);
056    
057                    _log.info(sb.toString());
058            }
059    
060            private static Log _log = LogFactoryUtil.getLog(
061                    DebuggingClusterEventListenerImpl.class);
062    
063    }