View Javadoc

1   /*
2    * $Id: StartupSummaryDeploymentListener.java 21857 2011-05-09 11:45:34Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.module.launcher;
12  
13  import java.util.Map;
14  
15  import org.apache.commons.logging.Log;
16  import org.apache.commons.logging.LogFactory;
17  
18  /**
19   * Prints application status summary table on Mule startup.
20   */
21  public class StartupSummaryDeploymentListener implements DeploymentService.StartupListener
22  {
23      protected transient final Log logger = LogFactory.getLog(getClass());
24  
25      protected DeploymentStatusTracker tracker;
26  
27      public StartupSummaryDeploymentListener(DeploymentStatusTracker tracker)
28      {
29          this.tracker = tracker;
30      }
31  
32      public void onAfterStartup()
33      {
34          if (!logger.isInfoEnabled())
35          {
36              return;
37          }
38  
39          Map<String, DeploymentStatusTracker.DeploymentState> applicationStates = tracker.getDeploymentStates();
40  
41          if (applicationStates.isEmpty())
42          {
43              return;
44          }
45  
46          SimpleLoggingTable applicationTable = new SimpleLoggingTable();
47          applicationTable.addColumn("APPLICATION", 45);
48          applicationTable.addColumn("STATUS", 18);
49  
50          for (String app : applicationStates.keySet())
51          {
52              String[] data = new String[] {app, applicationStates.get(app).toString()};
53              applicationTable.addDataRow(data);
54          }
55  
56          String message = String.format("%n%n%s", applicationTable);
57  
58          logger.info(message);
59      }
60  }