1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.cluster;
16  
17  import com.liferay.portal.kernel.cluster.ClusterEvent;
18  import com.liferay.portal.kernel.cluster.ClusterEventListener;
19  import com.liferay.portal.kernel.cluster.ClusterEventType;
20  import com.liferay.portal.kernel.cluster.ClusterNode;
21  import com.liferay.portal.kernel.log.Log;
22  import com.liferay.portal.kernel.log.LogFactoryUtil;
23  import com.liferay.portal.kernel.util.StringBundler;
24  import com.liferay.portal.kernel.util.StringPool;
25  
26  import java.util.List;
27  
28  /**
29   * <a href="DebuggingClusterEventListenerImpl.java.html"><b><i>View Source</i>
30   * </b></a>
31   *
32   * @author Tina Tian
33   */
34  public class DebuggingClusterEventListenerImpl implements ClusterEventListener {
35  
36      public void processClusterEvent(ClusterEvent clusterEvent) {
37          if (!_log.isInfoEnabled()) {
38              return;
39          }
40  
41          ClusterEventType clusterEventType = clusterEvent.getClusterEventType();
42  
43          List<ClusterNode> clusterNodes = clusterEvent.getClusterNodes();
44  
45          StringBundler sb = new StringBundler(clusterNodes.size() * 3 + 3);
46  
47          sb.append("Cluster event ");
48          sb.append(clusterEventType);
49          sb.append(StringPool.NEW_LINE);
50  
51          for (ClusterNode clusterNode : clusterNodes) {
52              sb.append("Cluster node ");
53              sb.append(clusterNode);
54              sb.append(StringPool.NEW_LINE);
55          }
56  
57          sb.setIndex(sb.index() - 1);
58  
59          _log.info(sb.toString());
60      }
61  
62      private static final Log _log = LogFactoryUtil.getLog(
63          DebuggingClusterEventListenerImpl.class);
64  
65  }