View Javadoc

1   /*
2    * $Id: MuleContainerStartupSplashScreen.java 19191 2010-08-25 21:05:23Z tcarlson $
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 org.mule.api.MuleContext;
14  import org.mule.api.agent.Agent;
15  import org.mule.config.MuleManifest;
16  import org.mule.config.i18n.CoreMessages;
17  import org.mule.util.SplashScreen;
18  import org.mule.util.StringUtils;
19  
20  import java.net.InetAddress;
21  import java.net.UnknownHostException;
22  import java.util.Collection;
23  import java.util.Iterator;
24  import java.util.Map;
25  import java.util.jar.Manifest;
26  
27  public class MuleContainerStartupSplashScreen extends SplashScreen
28  {
29      public void doBody()
30      {
31          String notset = CoreMessages.notSet().getMessage();
32  
33          // Mule Version, Timestamp, and Server ID
34          Manifest mf = MuleManifest.getManifest();
35          Map att = mf.getMainAttributes();
36          if (att.values().size() > 0)
37          {
38              doBody(StringUtils.defaultString(MuleManifest.getProductDescription(), notset));
39              doBody(String.format("%s Build: %s",
40                                   CoreMessages.version().getMessage(),
41                                   StringUtils.defaultString(MuleManifest.getBuildNumber(), notset)));
42  
43              doBody(StringUtils.defaultString(MuleManifest.getVendorName(), notset));
44              doBody(StringUtils.defaultString(MuleManifest.getProductMoreInfo(), notset));
45          }
46          else
47          {
48              doBody(CoreMessages.versionNotSet().getMessage());
49          }
50          doBody(" ");
51  
52          // TODO maybe be more precise and count from container bootstrap time?
53          doBody(CoreMessages.serverStartedAt(System.currentTimeMillis()).getMessage());
54  
55          doBody(String.format("JDK: %s (%s)",
56                               System.getProperty("java.version"),
57                               System.getProperty("java.vm.info")));
58  
59          String patch = System.getProperty("sun.os.patch.level", null);
60  
61          doBody(String.format("OS: %s%s (%s, %s)",
62                               System.getProperty("os.name"),
63                               (patch != null && !"unknown".equalsIgnoreCase(patch) ? " - " + patch : ""),
64                               System.getProperty("os.version"),
65                               System.getProperty("os.arch")));
66          try
67          {
68              InetAddress host = InetAddress.getLocalHost();
69              doBody(String.format("Host: %s (%s)", host.getHostName(), host.getHostAddress()));
70          }
71          catch (UnknownHostException e)
72          {
73              // ignore
74          }
75      }
76  
77      protected void doFooter(MuleContext context)
78      {
79          // Mule Agents
80          if (!body.isEmpty())
81          {
82              footer.add(" ");
83          }
84          //List agents
85          Collection agents = context.getRegistry().lookupObjects(Agent.class);
86          if (agents.size() == 0)
87          {
88              footer.add(CoreMessages.agentsRunning().getMessage() + " "
89                      + CoreMessages.none().getMessage());
90          }
91          else
92          {
93              footer.add(CoreMessages.agentsRunning().getMessage());
94              Agent agent;
95              for (Iterator iterator = agents.iterator(); iterator.hasNext();)
96              {
97                  agent = (Agent) iterator.next();
98                  footer.add("  " + agent.getDescription());
99              }
100         }
101     }    
102 }