4141N/A/*
4141N/A * CDDL HEADER START
4141N/A *
4141N/A * The contents of this file are subject to the terms of the
4141N/A * Common Development and Distribution License, Version 1.0 only
4141N/A * (the "License"). You may not use this file except in compliance
4141N/A * with the License.
4141N/A *
4141N/A * You can obtain a copy of the license at
4141N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
4141N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
4141N/A * See the License for the specific language governing permissions
4141N/A * and limitations under the License.
4141N/A *
4141N/A * When distributing Covered Code, include this CDDL HEADER in each
4141N/A * file and include the License file at
4141N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
4141N/A * add the following below this CDDL HEADER, with the fields enclosed
4141N/A * by brackets "[]" replaced with your own identifying information:
4141N/A * Portions Copyright [yyyy] [name of copyright owner]
4141N/A *
4141N/A * CDDL HEADER END
4141N/A *
4141N/A *
4141N/A * Copyright 2009 Sun Microsystems, Inc.
4141N/A */
4141N/Apackage org.opends.guitools.controlpanel.ui;
4141N/A
4141N/Aimport static org.opends.messages.AdminToolMessages.*;
4141N/Aimport static org.opends.messages.BackendMessages.INFO_MONITOR_UPTIME;
4141N/A
4141N/Aimport java.awt.Component;
4141N/Aimport java.awt.GridBagConstraints;
4141N/Aimport java.util.Date;
4141N/A
4141N/Aimport javax.swing.Box;
4141N/Aimport javax.swing.JLabel;
4141N/A
4141N/Aimport org.opends.guitools.controlpanel.datamodel.CustomSearchResult;
4141N/Aimport org.opends.guitools.controlpanel.datamodel.BasicMonitoringAttributes;
4141N/Aimport org.opends.guitools.controlpanel.datamodel.ServerDescriptor;
4141N/Aimport org.opends.guitools.controlpanel.util.ConfigFromDirContext;
4141N/Aimport org.opends.guitools.controlpanel.util.Utilities;
4141N/Aimport org.opends.messages.Message;
4141N/A
4141N/A/**
4141N/A * The panel displaying the root monitor panel.
4141N/A */
4141N/Apublic class RootMonitoringPanel extends GeneralMonitoringPanel
4141N/A{
4141N/A private static final long serialVersionUID = 9031734563746269830L;
4141N/A
4141N/A private JLabel openConnections = Utilities.createDefaultLabel();
4141N/A private JLabel maxConnections = Utilities.createDefaultLabel();
4141N/A private JLabel totalConnections = Utilities.createDefaultLabel();
4141N/A private JLabel startTime = Utilities.createDefaultLabel();
4141N/A private JLabel upTime = Utilities.createDefaultLabel();
4141N/A private JLabel version = Utilities.createDefaultLabel();
4141N/A
4141N/A /**
4141N/A * Default constructor.
4141N/A */
4141N/A public RootMonitoringPanel()
4141N/A {
4141N/A super();
4141N/A createLayout();
4141N/A }
4141N/A
4141N/A /**
4141N/A * {@inheritDoc}
4141N/A */
4141N/A public Component getPreferredFocusComponent()
4141N/A {
4141N/A return openConnections;
4141N/A }
4141N/A
4141N/A /**
4141N/A * Creates the layout of the panel (but the contents are not populated here).
4141N/A */
4141N/A private void createLayout()
4141N/A {
4141N/A GridBagConstraints gbc = new GridBagConstraints();
4141N/A gbc.gridy ++;
4141N/A JLabel lTitle = Utilities.createTitleLabel(
4141N/A INFO_CTRL_PANEL_GENERAL_MONITORING_ROOT.get());
4141N/A gbc.fill = GridBagConstraints.NONE;
4141N/A gbc.anchor = GridBagConstraints.WEST;
4141N/A gbc.gridwidth = 2;
4141N/A gbc.gridy = 0;
4141N/A gbc.insets.top = 5;
4141N/A gbc.insets.bottom = 7;
4141N/A add(lTitle, gbc);
4141N/A
4141N/A gbc.insets.bottom = 0;
4141N/A gbc.insets.top = 10;
4141N/A Message[] labels = {
4141N/A INFO_CTRL_PANEL_OPEN_CONNECTIONS_LABEL.get(),
4141N/A INFO_CTRL_PANEL_MAX_CONNECTIONS_LABEL.get(),
4141N/A INFO_CTRL_PANEL_TOTAL_CONNECTIONS_LABEL.get(),
4141N/A INFO_CTRL_PANEL_START_TIME_LABEL.get(),
4141N/A INFO_CTRL_PANEL_UP_TIME_LABEL.get(),
4141N/A INFO_CTRL_PANEL_OPENDS_VERSION_LABEL.get()
4141N/A };
4141N/A JLabel[] values = {
4141N/A openConnections,
4141N/A maxConnections,
4141N/A totalConnections,
4141N/A startTime,
4141N/A upTime,
4141N/A version
4141N/A };
4141N/A gbc.gridy ++;
4141N/A gbc.anchor = GridBagConstraints.WEST;
4141N/A gbc.gridwidth = 1;
4141N/A for (int i=0; i < labels.length; i++)
4141N/A {
4141N/A gbc.insets.left = 0;
4141N/A gbc.gridx = 0;
4141N/A JLabel l = Utilities.createPrimaryLabel(labels[i]);
4141N/A add(l, gbc);
4141N/A gbc.insets.left = 10;
4141N/A gbc.gridx = 1;
4141N/A add(values[i], gbc);
4141N/A gbc.gridy ++;
4141N/A }
4141N/A
4141N/A gbc.gridwidth = 2;
4141N/A gbc.gridx = 0;
4141N/A gbc.gridy ++;
4141N/A gbc.fill = GridBagConstraints.BOTH;
4141N/A gbc.weightx = 1.0;
4141N/A gbc.weighty = 1.0;
4141N/A add(Box.createGlue(), gbc);
4141N/A
4141N/A setBorder(PANEL_BORDER);
4141N/A }
4141N/A
4141N/A /**
4141N/A * Updates the contents of the panel.
4141N/A *
4141N/A */
4141N/A public void updateContents()
4141N/A {
4141N/A ServerDescriptor server = null;
4141N/A if (getInfo() != null)
4141N/A {
4141N/A server = getInfo().getServerDescriptor();
4141N/A }
4141N/A CustomSearchResult csr = null;
4141N/A if (server != null)
4141N/A {
4141N/A csr = server.getRootMonitor();
4141N/A }
4141N/A if (csr != null)
4141N/A {
4141N/A JLabel[] ls =
4141N/A {
4141N/A openConnections,
4141N/A maxConnections,
4141N/A totalConnections,
4141N/A startTime
4141N/A };
4141N/A BasicMonitoringAttributes[] attrs =
4141N/A {
4141N/A BasicMonitoringAttributes.CURRENT_CONNECTIONS,
4141N/A BasicMonitoringAttributes.MAX_CONNECTIONS,
4141N/A BasicMonitoringAttributes.TOTAL_CONNECTIONS,
4141N/A BasicMonitoringAttributes.START_DATE
4141N/A };
4141N/A for (int i=0; i<ls.length; i++)
4141N/A {
4141N/A ls[i].setText(getMonitoringValue(attrs[i], csr));
4141N/A }
4141N/A version.setText(server.getOpenDSVersion());
4141N/A try
4141N/A {
4141N/A String start = (String)getFirstMonitoringValue(csr,
4141N/A BasicMonitoringAttributes.START_DATE.getAttributeName());
4141N/A String current = (String)getFirstMonitoringValue(csr,
4141N/A BasicMonitoringAttributes.CURRENT_DATE.getAttributeName());
4141N/A Date startTime = ConfigFromDirContext.utcParser.parse(start);
4141N/A Date currentTime = ConfigFromDirContext.utcParser.parse(current);
4141N/A
4141N/A long upSeconds = (currentTime.getTime() - startTime.getTime()) / 1000;
4141N/A long upDays = (upSeconds / 86400);
4141N/A upSeconds %= 86400;
4141N/A long upHours = (upSeconds / 3600);
4141N/A upSeconds %= 3600;
4141N/A long upMinutes = (upSeconds / 60);
4141N/A upSeconds %= 60;
4141N/A Message upTimeStr =
4141N/A INFO_MONITOR_UPTIME.get(upDays, upHours, upMinutes, upSeconds);
4141N/A
4141N/A upTime.setText(upTimeStr.toString());
4141N/A }
4141N/A catch (Throwable t)
4141N/A {
4141N/A upTime.setText(NO_VALUE_SET.toString());
4141N/A }
4141N/A }
4141N/A else
4141N/A {
4141N/A openConnections.setText(NO_VALUE_SET.toString());
4141N/A maxConnections.setText(NO_VALUE_SET.toString());
4141N/A totalConnections.setText(NO_VALUE_SET.toString());
4141N/A startTime.setText(NO_VALUE_SET.toString());
4141N/A upTime.setText(NO_VALUE_SET.toString());
4141N/A version.setText(NO_VALUE_SET.toString());
4141N/A }
4141N/A }
4141N/A}