resinstatusservlet.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 848 行 · 第 1/2 页

JAVA
848
字号
          boolean canConnect = client.ping();          if (canConnect)            out.print("<td bgcolor='#80ff80'>");          else            out.print("<td>");          out.print(host + ":" + port);          if (canConnect)            out.println(" (up)");          else            out.println(" (down)");          out.println("<td>" + client.getConnectionActiveCount());        }        out.println("</table>");      }    } catch (Exception e) {      throw new ServletException(e);    }  }  public void printConnectionPools(PrintWriter out, String context)    throws Exception  {    ObjectName pattern = new ObjectName("resin:*,type=ConnectionPool" + context);    Set<ObjectName> poolNames;    poolNames = _mbeanServer.queryNames(pattern, null);    if (poolNames.size() == 0)      return;    out.println("<h3>Connection Pools</h3>");    out.println("<table border='2'>");    out.println("<tr><th>&nbsp;<th colspan='3'>Connections<th colspan='2'>Config");    out.println("<tr><th>Name<th>Active<th>Idle<th>Total");    out.println("    <th>max-connections<th>idle-time");    Iterator<ObjectName> iter = poolNames.iterator();    while (iter.hasNext()) {      ObjectName name = iter.next();      ConnectionPoolMXBean pool = (ConnectionPoolMXBean) Jmx.findGlobal(name);      if (pool != null) {        out.println("<tr><td>" + pool.getName());        out.println("    <td>" + pool.getConnectionActiveCount());        out.println("    <td>" + pool.getConnectionIdleCount());        out.println("    <td>" + pool.getConnectionCount());        out.println("    <td>" + pool.getMaxConnections());        out.println("    <td>" + periodToString(pool.getMaxIdleTime()));      }    }    out.println("</table>");  }  private String periodToString(long time)  {    if (time == 0)      return "0s";    else if (time % DAY == 0)      return (time / DAY) + "d";    else if (time % HOUR == 0)      return (time / HOUR) + "h";    else if (time % MINUTE == 0)      return (time / MINUTE) + "min";    else if (time % SECOND == 0)      return (time / SECOND) + "s";    else      return time + "ms";  }  /*  public void printSrun(PrintWriter out)    throws IOException, ServletException  {    DistributionServer []srunList = _server.getDistributionServerList();    if (srunList == null || srunList.length == 0)      return;    out.println("<h3>Srun Servers</h3>");    out.println("<table border=2>");    out.println("<tr><th>Host</th><th>Active Count</th><th>live-time</th><th>dead-time</th><th>request-timeout</th>");    for (int i = 0; i < srunList.length; i++) {      DistributionServer srun = srunList[i];      out.print("<tr>");      boolean isLive = false;      try {        ReadWritePair pair = srun.open();        if (pair != null) {          isLive = true;          srun.free(pair);        }      } catch (Throwable e) {        dbg.log(e);      }      if (isLive) {        out.println("<td bgcolor=\"#66ff66\">" +                    (srun.getIndex() + 1) + ". " +                    srun.getHost() + ":" + srun.getPort() +                    (srun.isBackup() ? "*" : "") +                    " (ok)");      }      else {        out.println("<td bgcolor=\"#ff6666\">" +                    (srun.getIndex() + 1) + ". " +                    srun.getHost() + ":" + srun.getPort() +                    (srun.isBackup() ? "*" : "") +                    " (down)");      }      out.println("<td>" + srun.getActiveCount());      out.println("<td>" + srun.getLiveTime() / 1000);      out.println("<td>" + srun.getDeadTime() / 1000);      out.println("<td>" + srun.getTimeout() / 1000);    }    out.println("</table>");  }  public void printJNDI(PrintWriter out, Context ic)    throws IOException, ServletException  {    printDatabasePools(out, ic);    printEJBLocalHomes(out, ic);    printEJBRemoteHomes(out, ic);  }  public void printEJBLocalHomes(PrintWriter out, Context ic)    throws IOException, ServletException  {    try {      Context cmpCxt = (Context) ic.lookup("java:comp/env/cmp");      if (cmpCxt == null)        return;      NamingEnumeration list = cmpCxt.list("");      ArrayList cmpNames = new ArrayList();      while (list.hasMoreElements()) {        NameClassPair pair = (NameClassPair) list.nextElement();        cmpNames.add(pair.getName());      }      if (cmpNames.size() == 0)        return;      out.println("<h3>EJB Local Home</h3>");      out.println("<table border=\"2\">");      out.println("<tr><th>Name<th>Home Stub Class");      Collections.sort(cmpNames);      for (int i = 0; i < cmpNames.size(); i++) {        String name = (String) cmpNames.get(i);        Object value = cmpCxt.lookup(name);        if (! (value instanceof EJBLocalHome))          continue;        EJBLocalHome home = (EJBLocalHome) value;        out.print("<tr><td>cmp/" + name);        Class homeStub = home.getClass();        Class []interfaces = home.getClass().getInterfaces();        for (int j = 0; j < interfaces.length; j++) {          if (EJBLocalHome.class.isAssignableFrom(interfaces[j])) {            homeStub = interfaces[j];            break;          }        }        out.print("<td>" + homeStub.getName());      }      out.println("</table>");    } catch (Exception e) {      dbg.log(e);    }  }  public void printEJBRemoteHomes(PrintWriter out, Context ic)    throws IOException, ServletException  {    try {      Context ejbCxt = (Context) ic.lookup("java:comp/env/ejb");      if (ejbCxt == null)        return;      NamingEnumeration list = ejbCxt.list("");      ArrayList ejbNames = new ArrayList();      while (list.hasMoreElements()) {        NameClassPair pair = (NameClassPair) list.nextElement();        ejbNames.add(pair.getName());      }      if (ejbNames.size() == 0)        return;      out.println("<h3>EJB Home</h3>");      out.println("<table border=\"2\">");      out.println("<tr><th>Name<th>Home Stub Class");      Collections.sort(ejbNames);      for (int i = 0; i < ejbNames.size(); i++) {        String name = (String) ejbNames.get(i);        Object value = ejbCxt.lookup(name);        if (! (value instanceof EJBHome))          continue;        EJBHome home = (EJBHome) value;        out.print("<tr><td>ejb/" + name);        Class homeStub = home.getClass();        Class []interfaces = home.getClass().getInterfaces();        for (int j = 0; j < interfaces.length; j++) {          if (EJBHome.class.isAssignableFrom(interfaces[j])) {            homeStub = interfaces[j];            break;          }        }        out.print("<td>" + homeStub.getName());      }      out.println("</table>");    } catch (Exception e) {      dbg.log(e);    }  }  public void printJMXServlets(PrintWriter out, MXBeanServer server)    throws IOException, ServletException  {    try {      ObjectName queryName = new ObjectName("*:j2eeType=Servlet,*");      Set servlets = server.queryNames(queryName, null);      if (servlets.size() == 0)        return;      out.println("<h3>Servlets</h3>");      Iterator iter = servlets.iterator();      while (iter.hasNext()) {        ObjectName servletName = (ObjectName) iter.next();        String name = servletName.getKeyProperty("name");        MXBeanInfo mbeanInfo = server.getMXBeanInfo(servletName);        MXBeanAttributeInfo []attrs = mbeanInfo.getAttributes();        out.println("<table border=\"2\">");        out.print("<tr><th>Name</th>");        for (int i = 0; i < attrs.length; i++)          out.print("<th>" + attrs[i].getName() + "</th>");        out.println("</tr>");        out.print("<tr><td>" + name + "</td>");        for (int i = 0; i < attrs.length; i++) {          Object value = server.getAttribute(servletName, attrs[i].getName());          out.print("<td>" + value + "</td>");        }        out.println("</table>");      }    } catch (Exception e) {      dbg.log(e);    }  }  */  public void printApplicationSummary(PrintWriter out, String pwd)    throws Exception  {    out.println("<h3>Hosts and Applications</h3>");    out.println("<table border=\"2\">");    out.println("<tr><th>Host<th>Web-App<th>State<th>Sessions");    ObjectName hostPattern = new ObjectName("resin:*,type=Host");    Set<ObjectName> names = _mbeanServer.queryNames(hostPattern, null);    Iterator<ObjectName> iter = names.iterator();    ArrayList<HostMXBean> hosts = new ArrayList<HostMXBean>();    while (iter.hasNext()) {      ObjectName name = iter.next();      // the Host with name=current is a duplicate      if ("current".equals(name.getKeyProperty("name")))        continue;      HostMXBean host = (HostMXBean) Jmx.findGlobal(name);      if (host != null) {        hosts.add(host);      }    }    Collections.sort(hosts, new HostCompare());    for (int i = 0; i < hosts.size(); i++) {      HostMXBean host = hosts.get(i);      out.println("<tr><td><b>" + host.getURL() + "</b>");      // thread.setContextClassLoader(hostLoader);      String hostName = host.getHostName();      if (hostName.equals(""))        hostName = "default";      ObjectName appPattern = new ObjectName("resin:*,Host=" + hostName + ",type=WebApp");      names = _mbeanServer.queryNames(appPattern, null);      iter = names.iterator();      ArrayList<WebAppMXBean> apps = new ArrayList<WebAppMXBean>();      while (iter.hasNext()) {        ObjectName name = iter.next();        try {          WebAppMXBean app = (WebAppMXBean) Jmx.findGlobal(name);          if (app != null)            apps.add(app);        } catch (Exception e) {          log.log(Level.WARNING, e.toString());          out.println("<tr><td>" + name + "<td>" + e.toString());        }      }      Collections.sort(apps, new AppCompare());      for (int j = 0; j < apps.size(); j++) {        WebAppMXBean app = apps.get(j);	SessionManagerMXBean session = app.getSessionManager();        String contextPath = app.getContextPath();        if (contextPath.equals(""))          contextPath = "/";        out.print("<tr><td><td>");        out.print("<a href=\"" + pwd + "?host=" + host.getHostName() +                  "&app=" + app.getContextPath() + "\">");        out.print(contextPath);        out.print("</a>");        String state = app.getState();        if (state.equals("active"))          out.print("<td bgcolor='#80ff80'>" + app.getState());        else          out.print("<td>" + app.getState());        out.print("<td>" + session.getSessionActiveCount());      }    }    out.println("</table>");  }  public void printVirtualHosts(PrintWriter out)    throws IOException, ServletException  {  }  /**   * Prints footer information.   */  public void printFooter(PrintWriter out)    throws IOException, ServletException  {    /*    if (_server.isTesting())      out.println("<br><em>Resin test</em>");    else    */      out.println("<br><em>" + com.caucho.Version.FULL_VERSION + "</em>");  }  static class HostCompare implements Comparator<HostMXBean> {    public int compare(HostMXBean a, HostMXBean b)    {      String urlA = a.getURL();      String urlB = b.getURL();      if (urlA == urlB)        return 0;      else if (urlA == null)        return -1;      else if (urlB == null)        return 1;      else        return urlA.compareTo(urlB);    }  }  static class AppCompare implements Comparator<WebAppMXBean> {    public int compare(WebAppMXBean a, WebAppMXBean b)    {      String cpA = a.getContextPath();      String cpB = b.getContextPath();      return cpA.compareTo(cpB);    }  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?