001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2009 Sun Microsystems, Inc. 015 * Portions Copyright 2015 ForgeRock AS. 016 */ 017package org.opends.guitools.controlpanel.ui; 018 019import static org.opends.messages.AdminToolMessages.*; 020 021import java.awt.Component; 022import java.awt.GridBagConstraints; 023import java.util.ArrayList; 024import java.util.List; 025 026import javax.swing.Box; 027import javax.swing.JLabel; 028 029import org.opends.guitools.controlpanel.datamodel.CustomSearchResult; 030import org.opends.guitools.controlpanel.datamodel.BasicMonitoringAttributes; 031import org.opends.guitools.controlpanel.datamodel.MonitoringAttributes; 032import org.opends.guitools.controlpanel.datamodel.ServerDescriptor; 033import org.opends.guitools.controlpanel.util.Utilities; 034 035/** 036 * The panel displaying the work queue monitor panel. 037 */ 038public class WorkQueueMonitoringPanel extends GeneralMonitoringPanel 039{ 040 private static final long serialVersionUID = 9031734563700069830L; 041 static List<MonitoringAttributes> attributes = new ArrayList<>(); 042 { 043 attributes.add(BasicMonitoringAttributes.AVERAGE_REQUEST_BACKLOG); 044 attributes.add(BasicMonitoringAttributes.MAX_REQUEST_BACKLOG); 045 attributes.add(BasicMonitoringAttributes.CURRENT_REQUEST_BACKLOG); 046 attributes.add(BasicMonitoringAttributes.REQUESTS_SUBMITTED); 047 attributes.add(BasicMonitoringAttributes.REQUESTS_REJECTED); 048 } 049 private ArrayList<JLabel> monitoringLabels = new ArrayList<>(); 050 { 051 for (int i=0; i<attributes.size(); i++) 052 { 053 monitoringLabels.add(Utilities.createDefaultLabel()); 054 } 055 } 056 057 /** 058 * Default constructor. 059 */ 060 public WorkQueueMonitoringPanel() 061 { 062 super(); 063 createLayout(); 064 } 065 066 /** {@inheritDoc} */ 067 public Component getPreferredFocusComponent() 068 { 069 return monitoringLabels.get(0); 070 } 071 072 /** 073 * Creates the layout of the panel (but the contents are not populated here). 074 */ 075 private void createLayout() 076 { 077 GridBagConstraints gbc = new GridBagConstraints(); 078 JLabel lTitle = Utilities.createTitleLabel( 079 INFO_CTRL_PANEL_WORK_QUEUE.get()); 080 gbc.fill = GridBagConstraints.NONE; 081 gbc.anchor = GridBagConstraints.WEST; 082 gbc.gridwidth = 2; 083 gbc.gridx = 0; 084 gbc.gridy = 0; 085 gbc.insets.top = 5; 086 gbc.insets.bottom = 7; 087 add(lTitle, gbc); 088 089 gbc.insets.bottom = 0; 090 gbc.insets.top = 10; 091 gbc.gridy ++; 092 gbc.anchor = GridBagConstraints.WEST; 093 gbc.gridwidth = 1; 094 for (int i=0; i<attributes.size(); i++) 095 { 096 JLabel l = Utilities.createPrimaryLabel(getLabel(attributes.get(i))); 097 gbc.gridy ++; 098 gbc.insets.left = 0; 099 gbc.gridx = 0; 100 gbc.weightx = 0.0; 101 gbc.gridwidth = 1; 102 add(l, gbc); 103 gbc.insets.left = 10; 104 gbc.gridx = 1; 105 gbc.gridwidth = 2; 106 add(monitoringLabels.get(i), gbc); 107 } 108 109 gbc.gridx = 0; 110 gbc.gridy ++; 111 gbc.fill = GridBagConstraints.BOTH; 112 gbc.weightx = 1.0; 113 gbc.weighty = 1.0; 114 gbc.gridwidth = 3; 115 add(Box.createGlue(), gbc); 116 117 setBorder(PANEL_BORDER); 118 } 119 120 /** 121 * Updates the contents of the panel. 122 * 123 */ 124 public void updateContents() 125 { 126 ServerDescriptor server = null; 127 if (getInfo() != null) 128 { 129 server = getInfo().getServerDescriptor(); 130 } 131 CustomSearchResult csr = null; 132 if (server != null) 133 { 134 csr = server.getWorkQueueMonitor(); 135 } 136 if (csr != null) 137 { 138 updateMonitoringInfo(attributes, monitoringLabels, csr); 139 } 140 else 141 { 142 for (JLabel l : monitoringLabels) 143 { 144 l.setText(NO_VALUE_SET.toString()); 145 } 146 } 147 } 148}