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