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