View Javadoc

1   /*
2    * $Id: ServerStartupSplashScreen.java 22008 2011-05-27 16:07:45Z aperepel $
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.util;
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  
18  import java.net.InetAddress;
19  import java.net.UnknownHostException;
20  import java.util.Collection;
21  import java.util.jar.Attributes;
22  import java.util.jar.Manifest;
23  
24  public class ServerStartupSplashScreen extends SplashScreen
25  {
26      @Override
27      protected void doHeader(MuleContext context)
28      {
29          String notset = CoreMessages.notSet().getMessage();
30  
31          // Mule Version, Timestamp, and Server ID
32          Manifest mf = MuleManifest.getManifest();
33          Attributes att = mf.getMainAttributes();
34          if (att.values().size() > 0)
35          {
36              header.add(StringUtils.defaultString(MuleManifest.getProductDescription(), notset));
37              header.add(CoreMessages.version().getMessage() + " Build: "
38                      + StringUtils.defaultString(MuleManifest.getBuildNumber(), notset));
39  
40              header.add(StringUtils.defaultString(MuleManifest.getVendorName(), notset));
41              header.add(StringUtils.defaultString(MuleManifest.getProductMoreInfo(), notset));
42          }
43          else
44          {
45              header.add(CoreMessages.versionNotSet().getMessage());
46          }
47          header.add(" ");
48          if (context.getStartDate() > 0)
49          {
50              header.add(CoreMessages.serverStartedAt(context.getStartDate()).getMessage());
51          }
52          header.add("Server ID: " + context.getConfiguration().getId());
53  
54          // JDK, Encoding, OS, and Host
55          header.add("JDK: " + System.getProperty("java.version") + " ("
56              + System.getProperty("java.vm.info") + ")");
57          header.add("OS encoding: " + System.getProperty("file.encoding")
58                  + ", Mule encoding: " + context.getConfiguration().getDefaultEncoding());
59          String patch = System.getProperty("sun.os.patch.level", null);
60          header.add("OS: " + System.getProperty("os.name")
61                  + (patch != null && !"unknown".equalsIgnoreCase(patch) ? " - " + patch : "") + " ("
62                  + System.getProperty("os.version") + ", " + System.getProperty("os.arch") + ")");
63          try
64          {
65              InetAddress host = InetAddress.getLocalHost();
66              header.add("Host: " + host.getHostName() + " (" + host.getHostAddress() + ")");
67          }
68          catch (UnknownHostException e)
69          {
70              // ignore
71          }
72  
73          // Dev/Production mode
74          // TODO for now now used, potentially a 'production' mode can disable direcotry (non-api) hot-deployment for tight app control
75          //final boolean productionMode = StartupContext.get().getStartupOptions().containsKey("production");
76          //header.add("Mode: " + (productionMode ? "Production" : "Development"));
77  
78          header.add(" ");
79      }
80  
81      @Override
82      protected void doFooter(MuleContext context)
83      {
84          // Mule Agents
85          if (!body.isEmpty())
86          {
87              footer.add(" ");
88          }
89          //List agents
90          Collection<Agent> agents = context.getRegistry().lookupObjects(Agent.class);
91          if (agents.size() == 0)
92          {
93              footer.add(CoreMessages.agentsRunning().getMessage() + " "
94                      + CoreMessages.none().getMessage());
95          }
96          else
97          {
98              footer.add(CoreMessages.agentsRunning().getMessage());
99              for (Agent agent : agents)
100             {
101                 footer.add("  " + agent.getDescription());
102             }
103         }
104     }
105 }