opendj3-server-dev/src/guitools/org/opends/guitools/controlpanel/datamodel/ConnectionHandlersMonitoringTableModel.java
@@ -26,21 +26,20 @@ */ package org.opends.guitools.controlpanel.datamodel; import static org.opends.messages.AdminToolMessages.*; import java.net.InetAddress; import java.util.ArrayList; import java.util.HashSet; import java.util.Set; import org.opends.guitools.controlpanel.datamodel.ConnectionHandlerDescriptor. Protocol; import org.forgerock.i18n.LocalizableMessage; import org.opends.guitools.controlpanel.datamodel.ConnectionHandlerDescriptor.Protocol; import static org.opends.guitools.controlpanel.util.Utilities.*; import static org.opends.messages.AdminToolMessages.*; /** * The table model used to display the monitoring information of connection * handlers. * */ public class ConnectionHandlersMonitoringTableModel extends MonitoringTableModel<ConnectionHandlerDescriptor, @@ -48,9 +47,8 @@ { private static final long serialVersionUID = -8891998773191495L; /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override protected Set<AddressConnectionHandlerDescriptor> convertToInternalData( Set<ConnectionHandlerDescriptor> newData) { @@ -75,22 +73,18 @@ return newAddresses; } /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public int compare(AddressConnectionHandlerDescriptor desc1, AddressConnectionHandlerDescriptor desc2) { int result; ArrayList<Integer> possibleResults = new ArrayList<Integer>(); possibleResults.add(compareNames(desc1, desc2)); possibleResults.addAll(getMonitoringPossibleResults( desc1.getMonitoringEntry(), desc2.getMonitoringEntry())); result = possibleResults.get(getSortColumn()); int result = possibleResults.get(getSortColumn()); if (result == 0) { for (int i : possibleResults) @@ -112,58 +106,56 @@ private int compareNames(AddressConnectionHandlerDescriptor ach1, AddressConnectionHandlerDescriptor ach2) { int compare = 0; boolean addressEqual = false; if (ach1.getAddress() == null) if (equal(ach1.getAddress(), ach2.getAddress())) { if (ach2.getAddress() == null) { addressEqual = true; } Integer port1 = Integer.valueOf(ach1.getConnectionHandler().getPort()); Integer port2 = Integer.valueOf(ach2.getConnectionHandler().getPort()); return port1.compareTo(port2); } else if (ach2.getAddress() != null) { addressEqual = ach1.getAddress().equals(ach2.getAddress()); } if (addressEqual) { Integer port1 = new Integer(ach1.getConnectionHandler().getPort()); Integer port2 = new Integer(ach2.getConnectionHandler().getPort()); compare = port1.compareTo(port2); } else { compare = getName(ach1).compareTo(getName(ach2)); } return compare; return getName(ach1).compareTo(getName(ach2)); } /** * {@inheritDoc} * Returns whether two addresses are equal. * * @param address1 * the first address * @param address2 * the second address * @return true if both are equal, false otherwise */ static boolean equal(InetAddress address1, InetAddress address2) { if (address1 != null) { return address1.equals(address2); } return address2 == null; } /** {@inheritDoc} */ @Override protected CustomSearchResult getMonitoringEntry( AddressConnectionHandlerDescriptor ach) { return ach.getMonitoringEntry(); } /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override protected String getName(AddressConnectionHandlerDescriptor ach) { StringBuilder sb = new StringBuilder(); ConnectionHandlerDescriptor ch = ach.getConnectionHandler(); if (ch.getProtocol() == Protocol.ADMINISTRATION_CONNECTOR) { sb.append(INFO_CTRL_PANEL_ADMINISTRATION_CONNECTOR_NAME.get( ch.getPort())); sb.append(INFO_CTRL_PANEL_ADMINISTRATION_CONNECTOR_NAME.get(ch.getPort())); } else { if (ach.getAddress() != null) { sb.append(ach.getAddress().getHostAddress()+":"+ch.getPort()); sb.append(ach.getAddress().getHostAddress()).append(":").append(ch.getPort()); } else { @@ -186,35 +178,26 @@ private CustomSearchResult getMonitoringEntry(InetAddress address, ConnectionHandlerDescriptor cch) { CustomSearchResult monitoringEntry = null; for (CustomSearchResult sr : cch.getMonitoringEntries()) { String cn = (String)getFirstMonitoringValue(sr, "cn"); String cn = getFirstValueAsString(sr, "cn"); if (cn != null) { if (address == null) { monitoringEntry = sr; break; return sr; } else if (cn.endsWith(" " + address.getHostAddress() + " port " + cch.getPort() + " Statistics")) { if (cn.endsWith( " "+address.getHostAddress()+" port "+cch.getPort()+ " Statistics")) { monitoringEntry = sr; break; } return sr; } } } return monitoringEntry; return null; } /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override protected LocalizableMessage getNameHeader() { return INFO_CTRL_PANEL_CONNECTION_HANDLER_HEADER.get(); @@ -285,48 +268,27 @@ return monitoringEntry; } /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public int hashCode() { return hashCode; } /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public boolean equals(Object o) { boolean equals = false; if (o != this) { if (o instanceof AddressConnectionHandlerDescriptor) { AddressConnectionHandlerDescriptor ach = (AddressConnectionHandlerDescriptor)o; if (ach.getAddress() == null) { equals = getAddress() == null; } else if (getAddress() == null) { equals = false; } else { equals = ach.getAddress().equals(getAddress()); } if (equals) { equals = ach.getConnectionHandler().equals(getConnectionHandler()); } } return true; } else if (!(o instanceof AddressConnectionHandlerDescriptor)) { equals = true; return false; } return equals; AddressConnectionHandlerDescriptor ach = (AddressConnectionHandlerDescriptor) o; return ConnectionHandlersMonitoringTableModel.equal(getAddress(), ach.getAddress()) && ach.getConnectionHandler().equals(getConnectionHandler()); } } opendj3-server-dev/src/guitools/org/opends/guitools/controlpanel/datamodel/ControlPanelInfo.java
@@ -69,6 +69,7 @@ import static com.forgerock.opendj.util.OperatingSystem.*; import static org.opends.admin.ads.util.ConnectionUtils.*; import static org.opends.guitools.controlpanel.util.Utilities.*; /** * This is the classes that is shared among all the different places in the @@ -343,16 +344,7 @@ { if (userDataCtx != null) { if (connectionPool.isConnectionRegistered(userDataCtx)) { try { connectionPool.unregisterConnection(userDataCtx); } catch (Throwable t) { } } unregisterConnection(connectionPool, ctx); } this.userDataCtx = ctx; if (ctx != null) @@ -500,22 +492,7 @@ } ConfigReader reader; ServerDescriptor.ServerStatus status = null; for (Task task : getTasks()) { if ((task.getType() == Task.Type.START_SERVER) && (task.getState() == Task.State.RUNNING) && isRunningOnServer(desc, task)) { status = ServerDescriptor.ServerStatus.STARTING; } else if ((task.getType() == Task.Type.STOP_SERVER) && (task.getState() == Task.State.RUNNING) && isRunningOnServer(desc, task)) { status = ServerDescriptor.ServerStatus.STOPPING; } } ServerDescriptor.ServerStatus status = getStatus(desc); if (status != null) { desc.setStatus(status); @@ -525,16 +502,7 @@ this.ctx = null; if (userDataCtx != null) { if (connectionPool.isConnectionRegistered(userDataCtx)) { try { connectionPool.unregisterConnection(userDataCtx); } catch (Throwable t) { } } unregisterConnection(connectionPool, ctx); StaticUtils.close(userDataCtx); userDataCtx = null; } @@ -616,35 +584,13 @@ } else { desc.setStatus( ServerDescriptor.ServerStatus.NOT_CONNECTED_TO_REMOTE); desc.setStatus(ServerDescriptor.ServerStatus.NOT_CONNECTED_TO_REMOTE); reader = null; } try { ctx.close(); } catch (Throwable t) { } StaticUtils.close(ctx); this.ctx = null; if (connectionPool.isConnectionRegistered(userDataCtx)) { try { connectionPool.unregisterConnection(userDataCtx); } catch (Throwable t) { } } try { userDataCtx.close(); } catch (Throwable t) { } unregisterConnection(connectionPool, ctx); StaticUtils.close(userDataCtx); userDataCtx = null; } } @@ -663,16 +609,13 @@ desc.setJvmMemoryUsageMonitor(rCtx.getJvmMemoryUsage()); desc.setSystemInformationMonitor(rCtx.getSystemInformation()); desc.setWorkQueueMonitor(rCtx.getWorkQueue()); desc.setOpenDSVersion((String)Utilities.getFirstMonitoringValue( rCtx.getVersionMonitor(), "fullVersion")); String installPath = (String)Utilities.getFirstMonitoringValue( rCtx.getSystemInformation(), "installPath"); desc.setOpenDSVersion(getFirstValueAsString(rCtx.getVersionMonitor(), "fullVersion")); String installPath = getFirstValueAsString(rCtx.getSystemInformation(), "installPath"); if (installPath != null) { desc.setInstallPath(installPath); } String instancePath = (String)Utilities.getFirstMonitoringValue( rCtx.getSystemInformation(), "instancePath"); String instancePath = getFirstValueAsString(rCtx.getSystemInformation(), "instancePath"); if (instancePath != null) { desc.setInstancePath(instancePath); @@ -712,6 +655,41 @@ } } private ServerDescriptor.ServerStatus getStatus(ServerDescriptor desc) { ServerDescriptor.ServerStatus status = null; for (Task task : getTasks()) { if ((task.getType() == Task.Type.START_SERVER) && (task.getState() == Task.State.RUNNING) && isRunningOnServer(desc, task)) { status = ServerDescriptor.ServerStatus.STARTING; } else if ((task.getType() == Task.Type.STOP_SERVER) && (task.getState() == Task.State.RUNNING) && isRunningOnServer(desc, task)) { status = ServerDescriptor.ServerStatus.STOPPING; } } return status; } private void unregisterConnection(LDAPConnectionPool connectionPool, InitialLdapContext userDataCtx) { if (connectionPool.isConnectionRegistered(userDataCtx)) { try { connectionPool.unregisterConnection(userDataCtx); } catch (Throwable t) { } } } /** * Adds a configuration change listener. * @param listener the listener. opendj3-server-dev/src/guitools/org/opends/guitools/controlpanel/datamodel/DBEnvironmentMonitoringTableModel.java
@@ -26,8 +26,6 @@ */ package org.opends.guitools.controlpanel.datamodel; import static org.opends.messages.AdminToolMessages.*; import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; @@ -36,9 +34,11 @@ import java.util.Set; import java.util.TreeSet; import org.opends.guitools.controlpanel.util.Utilities; import org.forgerock.i18n.LocalizableMessage; import static org.opends.guitools.controlpanel.util.Utilities.*; import static org.opends.messages.AdminToolMessages.*; /** * The abstract table model used to display all the network groups. */ @@ -48,25 +48,17 @@ private static final long serialVersionUID = 548035716525600536L; private Set<BackendDescriptor> data = new HashSet<BackendDescriptor>(); private ArrayList<String[]> dataArray = new ArrayList<String[]>(); private ArrayList<BackendDescriptor> dataSourceArray = new ArrayList<BackendDescriptor>(); private ArrayList<BackendDescriptor> dataSourceArray = new ArrayList<BackendDescriptor>(); private String[] columnNames = {}; private LocalizableMessage NO_VALUE_SET = INFO_CTRL_PANEL_NO_MONITORING_VALUE.get(); private LocalizableMessage NOT_IMPLEMENTED = INFO_CTRL_PANEL_NOT_IMPLEMENTED.get(); /** * The operations to be displayed. */ /** The operations to be displayed. */ private LinkedHashSet<String> attributes = new LinkedHashSet<String>(); /** * The sort column of the table. */ private int sortColumn = 0; /** * Whether the sorting is ascending or descending. */ /** The sort column of the table. */ private int sortColumn; /** Whether the sorting is ascending or descending. */ private boolean sortAscending = true; /** @@ -88,6 +80,7 @@ * Updates the table model contents and sorts its contents depending on the * sort options set by the user. */ @Override public void forceResort() { updateDataArray(); @@ -105,154 +98,45 @@ fireTableDataChanged(); } /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public int getColumnCount() { return columnNames.length; } /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public int getRowCount() { return dataArray.size(); } /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public Object getValueAt(int row, int col) { return dataArray.get(row)[col]; } /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public String getColumnName(int col) { return columnNames[col]; } /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public int compare(BackendDescriptor desc1, BackendDescriptor desc2) { int result; CustomSearchResult monitor1 = desc1.getMonitoringEntry(); CustomSearchResult monitor2 = desc2.getMonitoringEntry(); ArrayList<Integer> possibleResults = new ArrayList<Integer>(); possibleResults.add(getName(desc1).compareTo(getName(desc2))); for (String attrName : attributes) { int possibleResult; if (desc1.getMonitoringEntry() == null) { if (desc2.getMonitoringEntry() == null) { possibleResult = 0; } else { possibleResult = -1; } } else if (desc2.getMonitoringEntry() == null) { possibleResult = 1; } else { Object v1 = null; Object v2 = null; computeMonitoringPossibleResults(monitor1, monitor2, possibleResults, attributes); for (String attr : desc1.getMonitoringEntry().getAttributeNames()) { if (attr.equalsIgnoreCase(attrName)) { v1 = getFirstMonitoringValue(desc1.getMonitoringEntry(), attrName); break; } } for (String attr : desc2.getMonitoringEntry().getAttributeNames()) { if (attr.equalsIgnoreCase(attrName)) { v2 = getFirstMonitoringValue(desc2.getMonitoringEntry(), attrName); break; } } if (v1 == null) { if (v2 == null) { possibleResult = 0; } else { possibleResult = -1; } } else if (v2 == null) { possibleResult = 1; } else { if (v1 instanceof Number) { if ((v1 instanceof Double) || (v2 instanceof Double)) { double n1 = ((Number)v1).doubleValue(); double n2 = ((Number)v2).doubleValue(); if (n1 > n2) { possibleResult = 1; } else if (n1 < n2) { possibleResult = -1; } else { possibleResult = 0; } } else { long n1 = ((Number)v1).longValue(); long n2 = ((Number)v2).longValue(); if (n1 > n2) { possibleResult = 1; } else if (n1 < n2) { possibleResult = -1; } else { possibleResult = 0; } } } else if (v2 instanceof Number) { possibleResult = -1; } else { possibleResult = v1.toString().compareTo(v2.toString()); } } } possibleResults.add(possibleResult); } result = possibleResults.get(getSortColumn()); int result = possibleResults.get(getSortColumn()); if (result == 0) { for (int i : possibleResults) @@ -276,6 +160,7 @@ * @return <CODE>true</CODE> if the sort is ascending and <CODE>false</CODE> * otherwise. */ @Override public boolean isSortAscending() { return sortAscending; @@ -285,6 +170,7 @@ * Sets whether to sort ascending of descending. * @param sortAscending whether to sort ascending or descending. */ @Override public void setSortAscending(boolean sortAscending) { this.sortAscending = sortAscending; @@ -294,6 +180,7 @@ * Returns the column index used to sort. * @return the column index used to sort. */ @Override public int getSortColumn() { return sortColumn; @@ -303,6 +190,7 @@ * Sets the column index used to sort. * @param sortColumn column index used to sort.. */ @Override public void setSortColumn(int sortColumn) { this.sortColumn = sortColumn; @@ -401,14 +289,6 @@ } /** * {@inheritDoc} */ protected String[] getColumnNames() { return columnNames; } /** * Returns the label to be used for the provided backend. * @param backend the backend. * @return the label to be used for the provided backend. @@ -424,8 +304,7 @@ * @return the monitoring entry associated with the provided backend. Returns * <CODE>null</CODE> if there is no monitoring entry associated. */ protected CustomSearchResult getMonitoringEntry( BackendDescriptor backend) protected CustomSearchResult getMonitoringEntry(BackendDescriptor backend) { return backend.getMonitoringEntry(); } @@ -438,29 +317,18 @@ CustomSearchResult monitoringEntry = getMonitoringEntry(backend); for (String attr : attributes) { Object o = getFirstMonitoringValue(monitoringEntry, attr); if (o == null) String o = getFirstValueAsString(monitoringEntry, attr); if (o != null) { line[i] = NO_VALUE_SET.toString(); line[i] = o; } else { line[i] = o.toString(); line[i] = NO_VALUE_SET.toString(); } i++; } return line; } /** * Returns the first value for a given attribute in the provided entry. * @param sr the entry. * @param attrName the attribute name. * @return the first value for a given attribute in the provided entry. */ protected Object getFirstMonitoringValue(CustomSearchResult sr, String attrName) { return Utilities.getFirstMonitoringValue(sr, attrName); } } opendj3-server-dev/src/guitools/org/opends/guitools/controlpanel/datamodel/MonitoringTableModel.java
@@ -26,65 +26,47 @@ */ package org.opends.guitools.controlpanel.datamodel; import static org.opends.messages.AdminToolMessages.*; import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import java.util.TreeSet; import org.opends.guitools.controlpanel.util.Utilities; import org.forgerock.i18n.LocalizableMessage; import org.opends.guitools.controlpanel.util.Utilities; import static org.opends.guitools.controlpanel.util.Utilities.*; import static org.opends.messages.AdminToolMessages.*; /** * The abstract table model used to display all the network groups. * @param <T> the type of the objects passed externally to the table model. * @param <P> the type of the objects used internally by the table model. */ public abstract class MonitoringTableModel<T, P> extends SortableTableModel implements Comparator<P> abstract class MonitoringTableModel<T, P> extends SortableTableModel implements Comparator<P> { private static final long serialVersionUID = -3974562860632179025L; private Set<P> data = new HashSet<P>(); private ArrayList<String[]> dataArray = new ArrayList<String[]>(); private ArrayList<P> dataSourceArray = new ArrayList<P>(); private final Set<P> data = new HashSet<P>(); private final ArrayList<String[]> dataArray = new ArrayList<String[]>(); private final ArrayList<P> dataSourceArray = new ArrayList<P>(); private boolean showAverages; private long runningTime; private String[] columnNames = {}; private LocalizableMessage NO_VALUE_SET = INFO_CTRL_PANEL_NO_MONITORING_VALUE.get(); private LocalizableMessage NOT_IMPLEMENTED = INFO_CTRL_PANEL_NOT_IMPLEMENTED.get(); private final LocalizableMessage NO_VALUE_SET = INFO_CTRL_PANEL_NO_MONITORING_VALUE.get(); private final LocalizableMessage NOT_IMPLEMENTED = INFO_CTRL_PANEL_NOT_IMPLEMENTED.get(); /** * The attributes to be displayed. */ private LinkedHashSet<MonitoringAttributes> attributes = new LinkedHashSet<MonitoringAttributes>(); /** * The sort column of the table. */ private int sortColumn = 0; /** * Whether the sorting is ascending or descending. */ /** The attributes to be displayed. */ private final LinkedHashSet<MonitoringAttributes> attributes = new LinkedHashSet<MonitoringAttributes>(); /** The sort column of the table. */ private int sortColumn; /** Whether the sorting is ascending or descending. */ private boolean sortAscending = true; /** * Indicates whether a total row must be added or not. The default behavior * is to add it. * @return <CODE>true</CODE> if a total row must be added and * <CODE>false</CODE> otherwise. */ protected boolean addTotalRow() { return true; } /** * Sets the data for this table model. * @param newData the data for this table model. * @param runningTime the running time of the server in miliseconds. @@ -109,6 +91,7 @@ * Updates the table model contents and sorts its contents depending on the * sort options set by the user. */ @Override public void forceResort() { updateDataArray(); @@ -126,33 +109,29 @@ fireTableDataChanged(); } /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public int getColumnCount() { return columnNames.length; } /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public int getRowCount() { return dataArray.size(); } /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public Object getValueAt(int row, int col) { return dataArray.get(row)[col]; } /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public String getColumnName(int col) { return columnNames[col]; } @@ -162,6 +141,7 @@ * @return <CODE>true</CODE> if the sort is ascending and <CODE>false</CODE> * otherwise. */ @Override public boolean isSortAscending() { return sortAscending; @@ -171,6 +151,7 @@ * Sets whether to sort ascending of descending. * @param sortAscending whether to sort ascending or descending. */ @Override public void setSortAscending(boolean sortAscending) { this.sortAscending = sortAscending; @@ -180,6 +161,7 @@ * Returns the column index used to sort. * @return the column index used to sort. */ @Override public int getSortColumn() { return sortColumn; @@ -189,6 +171,7 @@ * Sets the column index used to sort. * @param sortColumn column index used to sort.. */ @Override public void setSortColumn(int sortColumn) { this.sortColumn = sortColumn; @@ -264,53 +247,42 @@ } // Add the total: always at the end if (addTotalRow()) String[] line = new String[columnNames.length]; line[0] = "<html><b>" + INFO_CTRL_PANEL_TOTAL_LABEL.get() + "</b>"; for (int i = 1; i < line.length; i++) { String[] line = new String[columnNames.length]; line[0] = "<html><b>" + INFO_CTRL_PANEL_TOTAL_LABEL.get() + "</b>"; for (int i=1; i<line.length; i++) boolean valueSet = false; boolean notImplemented = false; long totalValue = 0; for (int j = 0; j < dataArray.size(); j++) { boolean valueSet = false; boolean notImplemented = false; long totalValue = 0; for (int j=0; j<dataArray.size(); j++) String[] l = dataArray.get(j); String value = l[i]; try { String[] l = dataArray.get(j); String value = l[i]; try { long v = Long.parseLong(value); totalValue += v; valueSet = true; } catch (Throwable t) { notImplemented = NOT_IMPLEMENTED.toString().equals(value); } long v = Long.parseLong(value); totalValue += v; valueSet = true; } if (notImplemented) catch (Throwable t) { line[i] = NOT_IMPLEMENTED.toString(); } else if (valueSet) { line[i] = String.valueOf(totalValue); } else { line[i] = NO_VALUE_SET.toString(); notImplemented = NOT_IMPLEMENTED.toString().equals(value); } } dataArray.add(line); if (notImplemented) { line[i] = NOT_IMPLEMENTED.toString(); } else if (valueSet) { line[i] = String.valueOf(totalValue); } else { line[i] = NO_VALUE_SET.toString(); } } } /** * {@inheritDoc} */ protected String[] getColumnNames() { return columnNames; dataArray.add(line); } /** @@ -358,7 +330,7 @@ String s = String.valueOf(average); int index = s.indexOf("."); // Show a maximum of two decimals. if ((index != -1) && ((index + 3) < s.length())) if (index != -1 && index + 3 < s.length()) { s = s.substring(0, index + 3); } @@ -392,18 +364,6 @@ } /** * Returns the first value for a given attribute in the provided entry. * @param sr the entry. * @param attrName the attribute name. * @return the first value for a given attribute in the provided entry. */ protected Object getFirstMonitoringValue(CustomSearchResult sr, String attrName) { return Utilities.getFirstMonitoringValue(sr, attrName); } /** * Returns a list of integer with all the values of two monitoring entries * compared. * @param monitor1 the first monitoring entry. @@ -414,120 +374,13 @@ protected ArrayList<Integer> getMonitoringPossibleResults( CustomSearchResult monitor1, CustomSearchResult monitor2) { ArrayList<Integer> possibleResults = new ArrayList<Integer>(); final List<String> attrs = new ArrayList<String>(); for (MonitoringAttributes operation : getAttributes()) { int possibleResult; if (monitor1 == null) { if (monitor2 == null) { possibleResult = 0; } else { possibleResult = -1; } } else if (monitor2 == null) { possibleResult = 1; } else { Object v1 = null; Object v2 = null; for (String attrName : monitor1.getAttributeNames()) { if (operation.getAttributeName().equalsIgnoreCase(attrName)) { v1 = getFirstMonitoringValue(monitor1, attrName); break; } } for (String attrName : monitor2.getAttributeNames()) { if (operation.getAttributeName().equalsIgnoreCase(attrName)) { v2 = getFirstMonitoringValue(monitor2, attrName); break; } } if (v1 == null) { if (v2 == null) { possibleResult = 0; } else { possibleResult = -1; } } else if (v2 == null) { possibleResult = 1; } else { if (v1 instanceof Number) { if (v2 instanceof Number) { if ((v1 instanceof Double) || (v2 instanceof Double)) { double n1 = ((Number)v1).doubleValue(); double n2 = ((Number)v2).doubleValue(); if (n1 > n2) { possibleResult = 1; } else if (n1 < n2) { possibleResult = -1; } else { possibleResult = 0; } } else { long n1 = ((Number)v1).longValue(); long n2 = ((Number)v2).longValue(); if (n1 > n2) { possibleResult = 1; } else if (n1 < n2) { possibleResult = -1; } else { possibleResult = 0; } } } else { possibleResult = 1; } } else if (v2 instanceof Number) { possibleResult = -1; } else { possibleResult = v1.toString().compareTo(v2.toString()); } } } possibleResults.add(possibleResult); attrs.add(operation.getAttributeName()); } final ArrayList<Integer> possibleResults = new ArrayList<Integer>(); computeMonitoringPossibleResults(monitor1, monitor2, possibleResults, attrs); return possibleResults; } } opendj3-server-dev/src/guitools/org/opends/guitools/controlpanel/datamodel/ServerDescriptor.java
@@ -527,7 +527,7 @@ { return false; } String os = (String) getFirstMonitoringValue(sr, "operatingSystem"); String os = getFirstValueAsString(sr, "operatingSystem"); if (os != null) { return OperatingSystem.WINDOWS == OperatingSystem.forName(os); @@ -729,8 +729,8 @@ { try { String start = (String) getFirstMonitoringValue(rootMonitor, START_DATE.getAttributeName()); String current = (String) getFirstMonitoringValue(rootMonitor, CURRENT_DATE.getAttributeName()); String start = getFirstValueAsString(rootMonitor, START_DATE.getAttributeName()); String current = getFirstValueAsString(rootMonitor, CURRENT_DATE.getAttributeName()); Date startTime = ConfigFromDirContext.utcParser.parse(start); Date currentTime = ConfigFromDirContext.utcParser.parse(current); return currentTime.getTime() - startTime.getTime(); opendj3-server-dev/src/guitools/org/opends/guitools/controlpanel/ui/EntryCachesMonitoringPanel.java
@@ -22,43 +22,38 @@ * * * Copyright 2009 Sun Microsystems, Inc. * Portions Copyright 2014 ForgeRock AS */ package org.opends.guitools.controlpanel.ui; import static org.opends.messages.AdminToolMessages.*; import java.awt.Component; import java.awt.GridBagConstraints; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import javax.swing.Box; import javax.swing.JLabel; import org.opends.guitools.controlpanel.datamodel.CustomSearchResult; import org.opends.guitools.controlpanel.datamodel.BasicMonitoringAttributes; import org.opends.guitools.controlpanel.datamodel.MonitoringAttributes; import org.opends.guitools.controlpanel.datamodel.ServerDescriptor; import org.opends.guitools.controlpanel.util.Utilities; import static org.opends.guitools.controlpanel.datamodel.BasicMonitoringAttributes.*; import static org.opends.guitools.controlpanel.util.Utilities.*; import static org.opends.messages.AdminToolMessages.*; /** * The panel displaying the entry caches monitor panel. */ public class EntryCachesMonitoringPanel extends GeneralMonitoringPanel { private static final long serialVersionUID = 9031734563700069830L; static List<MonitoringAttributes> ngOperations = new ArrayList<MonitoringAttributes>(); { ngOperations.add(BasicMonitoringAttributes.ENTRY_CACHE_TRIES); ngOperations.add(BasicMonitoringAttributes.ENTRY_CACHE_HITS); ngOperations.add(BasicMonitoringAttributes.ENTRY_CACHE_HIT_RATIO); ngOperations.add(BasicMonitoringAttributes.CURRENT_ENTRY_CACHE_SIZE); ngOperations.add(BasicMonitoringAttributes.MAX_ENTRY_CACHE_SIZE); ngOperations.add(BasicMonitoringAttributes.CURRENT_ENTRY_CACHE_COUNT); ngOperations.add(BasicMonitoringAttributes.MAX_ENTRY_CACHE_COUNT); } private ArrayList<JLabel> monitoringLabels = new ArrayList<JLabel>(); private static List<MonitoringAttributes> ngOperations = new ArrayList<MonitoringAttributes>(Arrays.asList( ENTRY_CACHE_TRIES, ENTRY_CACHE_HITS, ENTRY_CACHE_HIT_RATIO, CURRENT_ENTRY_CACHE_SIZE, MAX_ENTRY_CACHE_SIZE, CURRENT_ENTRY_CACHE_COUNT, MAX_ENTRY_CACHE_COUNT)); private ArrayList<JLabel> monitoringLabels = new ArrayList<JLabel>(); { for (int i=0; i<ngOperations.size(); i++) { @@ -85,6 +80,7 @@ /** * {@inheritDoc} */ @Override public Component getPreferredFocusComponent() { return monitoringLabels.get(0); @@ -159,8 +155,7 @@ int index = 0; for (MonitoringAttributes attr : ngOperations) { if (Utilities.getFirstMonitoringValue(csr, attr.getAttributeName()) == null) if (getFirstValueAsString(csr, attr.getAttributeName()) == null) { monitoringLabels.get(index).setVisible(false); labels.get(index).setVisible(false); opendj3-server-dev/src/guitools/org/opends/guitools/controlpanel/ui/JavaInformationMonitoringPanel.java
@@ -22,11 +22,10 @@ * * * Copyright 2009 Sun Microsystems, Inc. * Portions Copyright 2014 ForgeRock AS */ package org.opends.guitools.controlpanel.ui; import static org.opends.messages.AdminToolMessages.*; import java.awt.Component; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; @@ -46,12 +45,15 @@ import javax.swing.event.ChangeListener; import javax.swing.text.JTextComponent; import org.opends.guitools.controlpanel.datamodel.CustomSearchResult; import org.opends.guitools.controlpanel.datamodel.BasicMonitoringAttributes; import org.opends.guitools.controlpanel.datamodel.CustomSearchResult; import org.opends.guitools.controlpanel.datamodel.ServerDescriptor; import org.opends.guitools.controlpanel.ui.components.BasicExpander; import org.opends.guitools.controlpanel.util.Utilities; import org.opends.server.util.ServerConstants; import static org.opends.guitools.controlpanel.util.Utilities.*; import static org.opends.messages.AdminToolMessages.*; import static org.opends.server.util.ServerConstants.*; /** * The panel displaying the java monitoring information. @@ -82,8 +84,8 @@ { for (int i=0; i<generalAttributes.size(); i++) { if ((generalAttributes.get(i) == BasicMonitoringAttributes.CLASS_PATH) || (generalAttributes.get(i) == BasicMonitoringAttributes.JVM_ARGUMENTS)) if (generalAttributes.get(i) == BasicMonitoringAttributes.CLASS_PATH || generalAttributes.get(i) == BasicMonitoringAttributes.JVM_ARGUMENTS) { JEditorPane pane = new JEditorPane(); pane.setEditable(false); @@ -112,9 +114,8 @@ createLayout(); } /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public Component getPreferredFocusComponent() { return generalMonitoringComps.get(0); @@ -175,14 +176,13 @@ gbc.insets.right = 10; gbc.weightx = 1.0; gbc.fill = GridBagConstraints.BOTH; add(generalMonitoringComps.get(i), gbc); } else { gbc.weightx = 0.0; gbc.fill = GridBagConstraints.HORIZONTAL; add(generalMonitoringComps.get(i), gbc); } add(generalMonitoringComps.get(i), gbc); } final BasicExpander extraExpander = new BasicExpander( @@ -249,22 +249,20 @@ gbc1.insets.right = 10; gbc1.weightx = 1.0; gbc1.fill = GridBagConstraints.BOTH; extraGeneralPanel.add(generalMonitoringComps.get(index), gbc1); } else { gbc1.weightx = 1.0; gbc1.fill = GridBagConstraints.HORIZONTAL; extraGeneralPanel.add(generalMonitoringComps.get(index), gbc1); } extraGeneralPanel.add(generalMonitoringComps.get(index), gbc1); gbc1.insets.top = 10; gbc1.gridy ++; } ChangeListener changeListener = new ChangeListener() { /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public void stateChanged(ChangeEvent e) { extraGeneralPanel.setVisible(extraExpander.isSelected()); @@ -274,9 +272,8 @@ changeListener = new ChangeListener() { /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public void stateChanged(ChangeEvent e) { memoryPanel.setVisible(memoryExpander.isSelected()); @@ -360,9 +357,8 @@ SortedSet<String> sortedNames = new TreeSet<String>(); for (String attrName : allNames) { if (!attrName.equalsIgnoreCase( ServerConstants.OBJECTCLASS_ATTRIBUTE_TYPE_NAME) && !attrName.equalsIgnoreCase(ServerConstants.ATTR_COMMON_NAME)) if (!OBJECTCLASS_ATTRIBUTE_TYPE_NAME.equalsIgnoreCase(attrName) && !ATTR_COMMON_NAME.equalsIgnoreCase(attrName)) { sortedNames.add(attrName); } @@ -399,12 +395,10 @@ for (int i=0; i<memoryAttributes.size() ; i++) { Object value = Utilities.getFirstMonitoringValue( csrMemory, memoryAttributes.get(i)); String value = getFirstValueAsString(csrMemory, memoryAttributes.get(i)); if (value != null) { memoryLabels.get(i).setText(value.toString()); memoryLabels.get(i).setText(value); } else { opendj3-server-dev/src/guitools/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java
@@ -80,14 +80,18 @@ import static com.forgerock.opendj.cli.Utils.*; import static org.opends.admin.ads.util.ConnectionUtils.*; import static org.opends.guitools.controlpanel.util.Utilities.*; import static org.opends.messages.AdminToolMessages.*; import static org.opends.messages.QuickSetupMessages.*; import static org.opends.server.monitors.VersionMonitorProvider.*; /** * The panel that appears when the user is asked to provide authentication. */ public class LocalOrRemotePanel extends StatusGenericPanel { private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); private static final long serialVersionUID = 5051556513294844797L; private JComboBox combo; @@ -101,19 +105,11 @@ private String usedUrl; private JLabel localInstallLabel; private JEditorPane localInstall; private JLabel localNotRunning; private boolean isLocalServerRunning; private boolean callOKWhenVisible; private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); /** * Default constructor. * */ /** Default constructor. */ public LocalOrRemotePanel() { super(); @@ -431,13 +427,7 @@ @Override public Void processBackgroundTask() throws Throwable { try { Thread.sleep(200); } catch (Throwable t) { } StaticUtils.sleep(200); File instancePath = Installation.getLocal().getInstanceDirectory(); isLocalServerRunning = Utilities.isServerRunning(instancePath); return null; @@ -583,7 +573,7 @@ else { usedUrl = ConnectionUtils.getLDAPUrl(hostName.getText().trim(), new Integer(port.getText().trim()), true); Integer.valueOf(port.getText().trim()), true); ctx = createLdapsContext(usedUrl, dn.getText(), String.valueOf(pwd.getPassword()), getInfo().getConnectTimeout(), null, @@ -591,20 +581,13 @@ checkVersion(ctx); } try { Thread.sleep(500); } catch (Throwable t) { } StaticUtils.sleep(500); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { displayMessage( INFO_CTRL_PANEL_READING_CONFIGURATION_SUMMARY.get()); displayMessage(INFO_CTRL_PANEL_READING_CONFIGURATION_SUMMARY.get()); } }); closeInfoConnections(); @@ -715,7 +698,7 @@ { String hostPort = ServerDescriptor.getServerRepresentation( hostName.getText().trim(), new Integer(port.getText().trim())); Integer.valueOf(port.getText().trim())); NamingException ne = (NamingException)throwable; errors.add(getMessageForException(ne, hostPort)); setPrimaryInvalid(portLabel); @@ -907,13 +890,7 @@ @Override public void run() { try { Thread.sleep(getInfo().getPoolingPeriod()); } catch (Throwable t) { } StaticUtils.sleep(getInfo().getPoolingPeriod()); getInfo().startPooling(); } }); @@ -925,9 +902,7 @@ LocalizableMessage msg = null; try { /* * Search for the version on the remote server. */ // Search for the version on the remote server. SearchControls searchControls = new SearchControls(); searchControls.setSearchScope( SearchControls.OBJECT_SCOPE); @@ -939,8 +914,7 @@ VersionMonitorProvider.ATTR_MINOR_VERSION }); NamingEnumeration<SearchResult> en = ctx.search("cn=Version,cn=monitor", "objectclass=*", searchControls); ctx.search("cn=Version,cn=monitor", "objectclass=*", searchControls); SearchResult sr = null; try { @@ -953,21 +927,16 @@ { en.close(); } CustomSearchResult csr = new CustomSearchResult(sr, "cn=Version,cn=monitor"); CustomSearchResult csr = new CustomSearchResult(sr, "cn=Version,cn=monitor"); String hostName = ConnectionUtils.getHostName(ctx); String productName = String.valueOf(Utilities.getFirstMonitoringValue(csr, VersionMonitorProvider.ATTR_PRODUCT_NAME)); String major = String.valueOf(Utilities.getFirstMonitoringValue(csr, VersionMonitorProvider.ATTR_MAJOR_VERSION)); String point = String.valueOf(Utilities.getFirstMonitoringValue(csr, VersionMonitorProvider.ATTR_POINT_VERSION)); String minor = String.valueOf(Utilities.getFirstMonitoringValue(csr, VersionMonitorProvider.ATTR_MINOR_VERSION)); // Be strict, control panel is only compatible with exactly the same // version. String productName = String.valueOf(getFirstValueAsString(csr, ATTR_PRODUCT_NAME)); String major = String.valueOf(getFirstValueAsString(csr, ATTR_MAJOR_VERSION)); String point = String.valueOf(getFirstValueAsString(csr, ATTR_POINT_VERSION)); String minor = String.valueOf(getFirstValueAsString(csr, ATTR_MINOR_VERSION)); // Be strict, control panel is only compatible with exactly the same version if (!productName.equalsIgnoreCase(DynamicConstants.PRODUCT_NAME)) { msg = ERR_NOT_SAME_PRODUCT_IN_REMOTE_SERVER_NOT_FOUND.get(hostName, @@ -994,7 +963,6 @@ private boolean isVersionException(Throwable t) { boolean isVersionException = false; if (t instanceof OpenDsException) { OpenDsException oe = (OpenDsException)t; @@ -1005,34 +973,15 @@ StaticUtils.hasDescriptor(msg, ERR_VERSION_IN_REMOTE_SERVER_NOT_FOUND) || StaticUtils.hasDescriptor(msg, ERR_NOT_SAME_PRODUCT_IN_REMOTE_SERVER_NOT_FOUND)) { isVersionException = true; return true; } } } return isVersionException; return false; } private void closeInfoConnections() { if (getInfo().getDirContext() != null) { try { getInfo().getDirContext().close(); } catch (Throwable t) { } } if (getInfo().getUserDataDirContext() != null) { try { getInfo().getUserDataDirContext().close(); } catch (Throwable t) { } } StaticUtils.close(getInfo().getDirContext(), getInfo().getUserDataDirContext()); } } opendj3-server-dev/src/guitools/org/opends/guitools/controlpanel/ui/StatusGenericPanel.java
@@ -26,8 +26,6 @@ */ package org.opends.guitools.controlpanel.ui; import static org.opends.messages.AdminToolMessages.*; import java.awt.CardLayout; import java.awt.Color; import java.awt.Component; @@ -56,9 +54,6 @@ import java.util.SortedSet; import java.util.TreeSet; import org.forgerock.i18n.LocalizableMessage; import org.forgerock.i18n.slf4j.LocalizedLogger; import javax.naming.NamingEnumeration; import javax.naming.directory.SearchControls; import javax.naming.directory.SearchResult; @@ -73,6 +68,11 @@ import javax.swing.SwingUtilities; import javax.swing.border.Border; import org.forgerock.i18n.LocalizableMessage; import org.forgerock.i18n.LocalizableMessageBuilder; import org.forgerock.i18n.LocalizableMessageDescriptor; import org.forgerock.i18n.slf4j.LocalizedLogger; import org.forgerock.opendj.ldap.schema.ObjectClassType; import org.opends.admin.ads.util.ConnectionUtils; import org.opends.guitools.controlpanel.browser.BrowserController; import org.opends.guitools.controlpanel.browser.IconPool; @@ -85,7 +85,10 @@ import org.opends.guitools.controlpanel.datamodel.MonitoringAttributes; import org.opends.guitools.controlpanel.datamodel.ScheduleType; import org.opends.guitools.controlpanel.datamodel.ServerDescriptor; import org.opends.guitools.controlpanel.event.*; import org.opends.guitools.controlpanel.datamodel.SortableListModel; import org.opends.guitools.controlpanel.event.ConfigChangeListener; import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent; import org.opends.guitools.controlpanel.event.ConfigurationElementCreatedListener; import org.opends.guitools.controlpanel.task.RebuildIndexTask; import org.opends.guitools.controlpanel.task.RestartServerTask; import org.opends.guitools.controlpanel.task.StartServerTask; @@ -95,14 +98,15 @@ import org.opends.guitools.controlpanel.util.BackgroundTask; import org.opends.guitools.controlpanel.util.LowerCaseComparator; import org.opends.guitools.controlpanel.util.Utilities; import org.forgerock.i18n.LocalizableMessageBuilder; import org.forgerock.i18n.LocalizableMessageDescriptor; import org.opends.quicksetup.ui.CustomHTMLEditorKit; import org.opends.server.schema.SchemaConstants; import org.opends.server.types.ObjectClass; import org.forgerock.opendj.ldap.schema.ObjectClassType; import org.opends.server.types.OpenDsException; import org.opends.server.util.ServerConstants; import org.opends.server.util.StaticUtils; import static org.opends.guitools.controlpanel.ui.ControlCenterMainPane.*; import static org.opends.messages.AdminToolMessages.*; /** * An abstract class that contains a number of methods that are shared by all @@ -124,49 +128,44 @@ /** * The not applicable message. */ protected final static LocalizableMessage NOT_APPLICABLE = protected static final LocalizableMessage NOT_APPLICABLE = INFO_NOT_APPLICABLE_LABEL.get(); private LocalizableMessage AUTHENTICATE = INFO_AUTHENTICATE_BUTTON_LABEL.get(); private LocalizableMessage START = INFO_START_BUTTON_LABEL.get(); private final LocalizableMessage AUTHENTICATE = INFO_AUTHENTICATE_BUTTON_LABEL.get(); private final LocalizableMessage START = INFO_START_BUTTON_LABEL.get(); private ControlPanelInfo info; private boolean enableClose = true; private final boolean enableClose = true; private boolean enableCancel = true; private boolean enableOK = true; private boolean disposeOnClose = false; private boolean disposeOnClose; private JPanel cardPanel; private JPanel mainPanel; private JEditorPane message; private final JPanel cardPanel; private final JPanel mainPanel; private final JEditorPane message; private CardLayout cardLayout; private final CardLayout cardLayout; private static final String MAIN_PANEL = "mainPanel"; private static final String MESSAGE_PANEL = "messagePanel"; private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); /** * The error pane. */ /** The error pane. */ protected JEditorPane errorPane; /** * The last displayed message in the error pane. */ protected String lastDisplayedError = null; /** The last displayed message in the error pane. */ private String lastDisplayedError; private ArrayList<ConfigurationElementCreatedListener> confListeners = private final ArrayList<ConfigurationElementCreatedListener> confListeners = new ArrayList<ConfigurationElementCreatedListener>(); private boolean sizeSet = false; private boolean focusSet = false; private boolean sizeSet; private boolean focusSet; private static DateFormat taskDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); private static final DateFormat taskDateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); /** * Returns the title that will be used as title of the dialog. @@ -291,6 +290,7 @@ * @param comp the Component to be added. * @param constraints the constraints. */ @Override public void add(Component comp, Object constraints) { mainPanel.add(comp, constraints); @@ -378,6 +378,7 @@ CustomHTMLEditorKit htmlEditor = new CustomHTMLEditorKit(); htmlEditor.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { if (AUTHENTICATE.toString().equals(ev.getActionCommand())) @@ -535,7 +536,7 @@ * of doing whatever is required (close the dialog, launch a task, etc.). * */ abstract public void okClicked(); public abstract void okClicked(); /** * Adds a configuration element created listener. @@ -558,21 +559,6 @@ } /** * Notifies the configuration element created listener that a new object has * been created. * @param configObject the created object. */ protected void notifyConfigurationElementCreated(Object configObject) { for (ConfigurationElementCreatedListener listener : getConfigurationElementCreatedListeners()) { listener.elementCreated( new ConfigurationElementCreatedEvent(this, configObject)); } } /** * Returns the list of configuration listeners. * @return the list of configuration listeners. */ @@ -668,41 +654,34 @@ progressDialog.setTaskIsOver(false); boolean rebuildIndexes; String backendName = index.getBackend().getBackendID(); LocalizableMessage summary = INFO_CTRL_PANEL_INDEX_REBUILD_REQUIRED_SUMMARY.get(); if (!isServerRunning()) { rebuildIndexes = Utilities.displayConfirmationDialog(progressDialog, INFO_CTRL_PANEL_INDEX_REBUILD_REQUIRED_SUMMARY.get(), rebuildIndexes = Utilities.displayConfirmationDialog(progressDialog, summary, INFO_CTRL_PANEL_INDEX_REBUILD_REQUIRED_OFFLINE_DETAILS.get( index.getName(), backendName)); } else if (isLocal()) { rebuildIndexes = Utilities.displayConfirmationDialog(progressDialog, summary, INFO_CTRL_PANEL_INDEX_REBUILD_REQUIRED_ONLINE_DETAILS.get( index.getName(), backendName, backendName)); } else { if (isLocal()) { rebuildIndexes = Utilities.displayConfirmationDialog(progressDialog, INFO_CTRL_PANEL_INDEX_REBUILD_REQUIRED_SUMMARY.get(), INFO_CTRL_PANEL_INDEX_REBUILD_REQUIRED_ONLINE_DETAILS.get( index.getName(), backendName, backendName)); } else { Utilities.displayWarningDialog(progressDialog, INFO_CTRL_PANEL_INDEX_REBUILD_REQUIRED_SUMMARY.get(), INFO_CTRL_PANEL_INDEX_REBUILD_REQUIRED_REMOTE_DETAILS.get( index.getName(), backendName)); rebuildIndexes = false; } Utilities.displayWarningDialog(progressDialog, summary, INFO_CTRL_PANEL_INDEX_REBUILD_REQUIRED_REMOTE_DETAILS.get( index.getName(), backendName)); rebuildIndexes = false; } if (rebuildIndexes) { SortedSet<AbstractIndexDescriptor> indexes = new TreeSet<AbstractIndexDescriptor>(); SortedSet<AbstractIndexDescriptor> indexes = new TreeSet<AbstractIndexDescriptor>(); indexes.add(index); SortedSet<String> baseDNs = new TreeSet<String>(); for (BaseDNDescriptor b : index.getBackend().getBaseDns()) { String baseDN = Utilities.unescapeUtf8(b.getDn().toString()); baseDNs.add(baseDN); baseDNs.add(Utilities.unescapeUtf8(b.getDn().toString())); } RebuildIndexTask newTask = new RebuildIndexTask(getInfo(), @@ -760,7 +739,7 @@ protected class IgnoreItemListener implements ItemListener { private Object selectedItem; private JComboBox combo; private final JComboBox combo; /** * Constructor. @@ -776,9 +755,8 @@ } } /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public void itemStateChanged(ItemEvent ev) { Object o = combo.getSelectedItem(); @@ -790,13 +768,10 @@ for (int i=0; i<combo.getModel().getSize(); i++) { Object item = combo.getModel().getElementAt(i); if (item instanceof CategorizedComboBoxElement) if (item instanceof CategorizedComboBoxElement && !isCategory(item)) { if (!isCategory(item)) { selectedItem = item; break; } selectedItem = item; break; } } } @@ -848,15 +823,14 @@ { LocalizableMessageBuilder mb = new LocalizableMessageBuilder(); mb.append(details); mb.append("<br><br>"+getAuthenticateHTML()); mb.append("<br><br>").append(getAuthenticateHTML()); LocalizableMessage title = INFO_CTRL_PANEL_AUTHENTICATION_REQUIRED_SUMMARY.get(); updateErrorPane(errorPane, title, ColorAndFontConstants.errorTitleFont, mb.toMessage(), ColorAndFontConstants.defaultFont); SwingUtilities.invokeLater(new Runnable() { /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public void run() { errorPane.setVisible(true); @@ -869,9 +843,8 @@ { SwingUtilities.invokeLater(new Runnable() { /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public void run() { errorPane.setVisible(false); @@ -890,19 +863,9 @@ */ protected boolean authenticationRequired(ServerDescriptor desc) { boolean returnValue; ServerDescriptor.ServerStatus status = desc.getStatus(); if (((status == ServerDescriptor.ServerStatus.STARTED) && !desc.isAuthenticated()) || (status == ServerDescriptor.ServerStatus.NOT_CONNECTED_TO_REMOTE)) { returnValue = true; } else { returnValue = false; } return returnValue; return (status == ServerDescriptor.ServerStatus.STARTED && !desc.isAuthenticated()) || status == ServerDescriptor.ServerStatus.NOT_CONNECTED_TO_REMOTE; } /** @@ -919,14 +882,13 @@ LocalizableMessage title = INFO_CTRL_PANEL_AUTHENTICATION_REQUIRED_SUMMARY.get(); LocalizableMessageBuilder mb = new LocalizableMessageBuilder(); mb.append(details); mb.append("<br><br>"+getAuthenticateHTML()); mb.append("<br><br>").append(getAuthenticateHTML()); updateErrorPane(errorPane, title, ColorAndFontConstants.errorTitleFont, mb.toMessage(), ColorAndFontConstants.defaultFont); SwingUtilities.invokeLater(new Runnable() { /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public void run() { errorPane.setVisible(true); @@ -938,9 +900,8 @@ { SwingUtilities.invokeLater(new Runnable() { /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public void run() { errorPane.setVisible(false); @@ -965,21 +926,20 @@ LocalizableMessage authRequired) { ServerDescriptor.ServerStatus status = desc.getStatus(); if ((status != ServerDescriptor.ServerStatus.STARTED) && (status != ServerDescriptor.ServerStatus.NOT_CONNECTED_TO_REMOTE)) if (status != ServerDescriptor.ServerStatus.STARTED && status != ServerDescriptor.ServerStatus.NOT_CONNECTED_TO_REMOTE) { LocalizableMessage title = INFO_CTRL_PANEL_SERVER_NOT_RUNNING_SUMMARY.get(); LocalizableMessageBuilder mb = new LocalizableMessageBuilder(); mb.append(detailsServerNotRunning); mb.append("<br><br>"+getStartServerHTML()); mb.append("<br><br>").append(getStartServerHTML()); updateErrorPane(errorPane, title, ColorAndFontConstants.errorTitleFont, mb.toMessage(), ColorAndFontConstants.defaultFont); SwingUtilities.invokeLater(new Runnable() { /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public void run() { errorPane.setVisible(true); @@ -992,14 +952,13 @@ LocalizableMessage title = INFO_CTRL_PANEL_AUTHENTICATION_REQUIRED_SUMMARY.get(); LocalizableMessageBuilder mb = new LocalizableMessageBuilder(); mb.append(authRequired); mb.append("<br><br>"+getAuthenticateHTML()); mb.append("<br><br>").append(getAuthenticateHTML()); updateErrorPane(errorPane, title, ColorAndFontConstants.errorTitleFont, mb.toMessage(), ColorAndFontConstants.defaultFont); SwingUtilities.invokeLater(new Runnable() { /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public void run() { errorPane.setVisible(true); @@ -1011,9 +970,8 @@ { SwingUtilities.invokeLater(new Runnable() { /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public void run() { errorPane.setVisible(false); @@ -1041,13 +999,12 @@ */ protected boolean isCategory(Object o) { boolean isCategory = false; if (o instanceof CategorizedComboBoxElement) { CategorizedComboBoxElement desc = (CategorizedComboBoxElement)o; isCategory = desc.getType() == CategorizedComboBoxElement.Type.CATEGORY; return desc.getType() == CategorizedComboBoxElement.Type.CATEGORY; } return isCategory; return false; } /** @@ -1086,15 +1043,10 @@ // Do it outside the event thread if the panel requires it. BackgroundTask<Void> worker = new BackgroundTask<Void>() { @Override public Void processBackgroundTask() throws Throwable { try { Thread.sleep(1000); } catch (Throwable t) { } StaticUtils.sleep(1000); configurationChanged(new ConfigurationChangeEvent( StatusGenericPanel.this.info, StatusGenericPanel.this.info.getServerDescriptor())); @@ -1102,6 +1054,7 @@ } @Override public void backgroundTaskCompleted(Void returnValue, Throwable t) { @@ -1129,25 +1082,13 @@ } } /** * Displays the main panel. * */ /** Displays the main panel. */ protected void displayMainPanel() { cardLayout.show(cardPanel, MAIN_PANEL); } /** * Returns whether the main panel is visible or not. * @return whether the main panel is visible or not. */ protected boolean isMainPanelVisible() { return mainPanel.isVisible(); } /** * Displays a message and hides the main panel. * @param msg the message to be displayed. */ @@ -1173,15 +1114,6 @@ } /** * Returns whether the message is visible or not. * @return whether the message is visible or not. */ protected boolean isMessageVisible() { return message.isVisible(); } /** * Updates the contents of an editor pane using the error format. * @param pane the editor pane to be updated. * @param title the title. @@ -1196,20 +1128,6 @@ } /** * Updates the contents of an editor pane using the warning format. * @param pane the editor pane to be updated. * @param title the title. * @param titleFont the font to be used for the title. * @param details the details message. * @param detailsFont the font to be used for the details. */ protected void updateWarningPane(JEditorPane pane, LocalizableMessage title, Font titleFont, LocalizableMessage details, Font detailsFont) { updatePane(pane, title, titleFont, details, detailsFont, PanelType.WARNING); } /** * Updates the contents of an editor pane using the confirmation format. * @param pane the editor pane to be updated. * @param title the title. @@ -1220,33 +1138,21 @@ protected void updateConfirmationPane(JEditorPane pane, LocalizableMessage title, Font titleFont, LocalizableMessage details, Font detailsFont) { updatePane(pane, title, titleFont, details, detailsFont, PanelType.CONFIRMATION); updatePane(pane, title, titleFont, details, detailsFont, PanelType.CONFIRMATION); } /** * The different types of error panels that are handled. * */ protected enum PanelType /** The different types of error panels that are handled. */ private enum PanelType { /** * The message in the panel is an error. */ /** The message in the panel is an error. */ ERROR, /** * The message in the panel is a confirmation. */ /** The message in the panel is a confirmation. */ CONFIRMATION, /** * The message in the panel is an information message. */ /** The message in the panel is an information message. */ INFORMATION, /** * The message in the panel is a warning message. */ /** The message in the panel is a warning message. */ WARNING }; } /** * Updates the contents of an editor pane using the provided format. @@ -1312,9 +1218,8 @@ { SwingUtilities.invokeLater(new Runnable() { /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public void run() { pane.invalidate(); @@ -1350,6 +1255,7 @@ updateComboBoxModel(newElements, model); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { combo.setVisible(newElements.size() > 0); @@ -1380,8 +1286,7 @@ { LinkedHashSet<CategorizedComboBoxElement> newElements = new LinkedHashSet<CategorizedComboBoxElement>(); SortedSet<String> backendIDs = new TreeSet<String>(new LowerCaseComparator()); SortedSet<String> backendIDs = new TreeSet<String>(new LowerCaseComparator()); HashMap<String, SortedSet<String>> hmBaseDNs = new HashMap<String, SortedSet<String>>(); @@ -1391,8 +1296,7 @@ { String backendID = backend.getBackendID(); backendIDs.add(backendID); SortedSet<String> baseDNs = new TreeSet<String>(new LowerCaseComparator()); SortedSet<String> baseDNs = new TreeSet<String>(new LowerCaseComparator()); for (BaseDNDescriptor baseDN : backend.getBaseDns()) { try @@ -1441,12 +1345,13 @@ * @param comparator the object that will be used to compare the objects in * the model. If <CODE>null</CODE>, the equals method will be used. */ protected void updateComboBoxModel(final Collection<?> newElements, private void updateComboBoxModel(final Collection<?> newElements, final DefaultComboBoxModel model, final Comparator<Object> comparator) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Utilities.updateComboBoxModel(newElements, model, comparator); @@ -1483,8 +1388,7 @@ } dns.add(dn); SortedSet<AbstractIndexDescriptor> indexes = new TreeSet<AbstractIndexDescriptor>(); indexes.addAll(backend.getIndexes()); new TreeSet<AbstractIndexDescriptor>(backend.getIndexes()); indexes.addAll(backend.getVLVIndexes()); SortedSet<AbstractIndexDescriptor> currentIndexes = hmIndexes.get(dn); @@ -1542,10 +1446,10 @@ { boolean availableChanged = false; boolean selectedChanged = false; SortedSet<AbstractIndexDescriptor> availableIndexes = addRemove.getAvailableListModel().getData(); SortedSet<AbstractIndexDescriptor> selectedIndexes = addRemove.getSelectedListModel().getData(); SortableListModel<AbstractIndexDescriptor> availableListModel = addRemove.getAvailableListModel(); SortableListModel<AbstractIndexDescriptor> selectedListModel = addRemove.getSelectedListModel(); SortedSet<AbstractIndexDescriptor> availableIndexes = availableListModel.getData(); SortedSet<AbstractIndexDescriptor> selectedIndexes = selectedListModel.getData(); availableChanged = availableIndexes.retainAll(indexes); selectedChanged = selectedIndexes.retainAll(indexes); @@ -1560,19 +1464,19 @@ } if (availableChanged) { addRemove.getAvailableListModel().clear(); addRemove.getAvailableListModel().addAll(availableIndexes); addRemove.getAvailableListModel().fireContentsChanged( addRemove.getAvailableListModel(), 0, addRemove.getAvailableListModel().getSize()); availableListModel.clear(); availableListModel.addAll(availableIndexes); availableListModel.fireContentsChanged( availableListModel, 0, availableListModel.getSize()); } if (selectedChanged) { addRemove.getSelectedListModel().clear(); addRemove.getSelectedListModel().addAll(selectedIndexes); addRemove.getSelectedListModel().fireContentsChanged( addRemove.getSelectedListModel(), 0, addRemove.getSelectedListModel().getSize()); selectedListModel.clear(); selectedListModel.addAll(selectedIndexes); selectedListModel.fireContentsChanged( selectedListModel, 0, selectedListModel.getSize()); } } } @@ -1686,7 +1590,7 @@ * @param resetLogs whether the contents of the progress dialog should be * reset or not. */ protected void launchOperation(final Task task, LocalizableMessage initialSummary, private void launchOperation(final Task task, LocalizableMessage initialSummary, final LocalizableMessage successSummary, final LocalizableMessage successDetail, final LocalizableMessage errorSummary, final LocalizableMessage errorDetail, @@ -1730,8 +1634,7 @@ { dialog.setTaskIsOver(false); dialog.getProgressBar().setIndeterminate(true); dialog.addPrintStreamListeners(task.getOutPrintStream(), task.getErrorPrintStream()); dialog.addPrintStreamListeners(task.getOutPrintStream(), task.getErrorPrintStream()); if (resetLogs) { dialog.resetProgressLogs(); @@ -1751,9 +1654,8 @@ dialog.getProgressBar().setVisible(true); BackgroundTask<Task> worker = new BackgroundTask<Task>() { /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public Task processBackgroundTask() throws Throwable { task.runTask(); @@ -1764,9 +1666,8 @@ return task; } /** * {@inheritDoc} */ /** {@inheritDoc} */ @Override public void backgroundTaskCompleted(Task returnValue, Throwable t) { String summaryMsg; @@ -1786,29 +1687,24 @@ if (t != null) { logger.warn(LocalizableMessage.raw("Error occurred running task: "+t, t)); if ((task.getReturnCode() != null) && (errorDetailCode != null)) if (task.getReturnCode() != null && errorDetailCode != null) { String sThrowable; if (t instanceof OpenDsException) { sThrowable = ((OpenDsException)t).getMessageObject().toString(); } else if (t.getMessage() != null) { sThrowable = t.getMessage(); } else { if (t.getMessage() != null) { sThrowable = t.getMessage(); } else { sThrowable = t.toString(); } sThrowable = t.toString(); } LocalizableMessageBuilder mb = new LocalizableMessageBuilder(); mb.append(errorDetailCode.get(task.getReturnCode())); mb.append( " "+INFO_CTRL_PANEL_DETAILS_THROWABLE.get(sThrowable)); mb.append(" ").append(INFO_CTRL_PANEL_DETAILS_THROWABLE.get(sThrowable)); summaryMsg = Utilities.getFormattedError(errorSummary, ColorAndFontConstants.errorTitleFont, mb.toMessage(), ColorAndFontConstants.defaultFont); @@ -1827,8 +1723,7 @@ summaryMsg = null; } } else if ((task.getReturnCode() != null) && (errorDetailCode != null)) else if (task.getReturnCode() != null && errorDetailCode != null) { summaryMsg = Utilities.getFormattedError(errorSummary, ColorAndFontConstants.errorTitleFont, @@ -1879,7 +1774,7 @@ try { int n = Integer.parseInt(stringValue); if ((n > maxValue) || (n < minValue)) if (n > maxValue || n < minValue) { throw new RuntimeException("Invalid value"); } @@ -1894,7 +1789,6 @@ * Starts the server. This method will launch a task and open a progress * dialog that will start the server. This method must be called from the * event thread. * */ protected void startServer() { @@ -1951,7 +1845,7 @@ INFO_CTRL_PANEL_CONFIRMATION_REQUIRED_SUMMARY.get(), INFO_CTRL_PANEL_CONFIRM_STOP_SERVER_DETAILS.get()); } if ((errors.size() == 0) && confirmed) if (errors.size() == 0 && confirmed) { launchOperation(newTask, INFO_CTRL_PANEL_STOPPING_SERVER_SUMMARY.get(), @@ -1982,8 +1876,7 @@ Utilities.createFrame(), Utilities.getParentDialog(this), INFO_CTRL_PANEL_RESTART_SERVER_PROGRESS_DLG_TITLE.get(), getInfo()); RestartServerTask newTask = new RestartServerTask(getInfo(), progressDialog); RestartServerTask newTask = new RestartServerTask(getInfo(), progressDialog); for (Task task : getInfo().getTasks()) { task.canLaunch(newTask, errors); @@ -1995,7 +1888,7 @@ INFO_CTRL_PANEL_CONFIRMATION_REQUIRED_SUMMARY.get(), INFO_CTRL_PANEL_CONFIRM_RESTART_SERVER_DETAILS.get()); } if ((errors.size() == 0) && confirmed) if (errors.size() == 0 && confirmed) { launchOperation(newTask, INFO_CTRL_PANEL_STOPPING_SERVER_SUMMARY.get(), @@ -2016,9 +1909,8 @@ /** * Displays a dialog asking for authentication. This method must be called * from the event thread. * */ protected void authenticate() private void authenticate() { if (!getLoginDialog().isVisible()) { @@ -2035,22 +1927,12 @@ */ protected GenericDialog getLoginDialog() { if (isLocal()) { GenericDialog loginDialog = ControlCenterMainPane.getLocalServerLoginDialog(getInfo()); Utilities.centerGoldenMean(loginDialog, Utilities.getFrame(this)); loginDialog.setModal(true); return loginDialog; } else { GenericDialog localOrRemoteDialog = ControlCenterMainPane.getLocalOrRemoteDialog(getInfo()); Utilities.centerGoldenMean(localOrRemoteDialog, Utilities.getFrame(this)); localOrRemoteDialog.setModal(true); return localOrRemoteDialog; } GenericDialog dialog = isLocal() ? getLocalServerLoginDialog(getInfo()) : getLocalOrRemoteDialog(getInfo()); Utilities.centerGoldenMean(dialog, Utilities.getFrame(this)); dialog.setModal(true); return dialog; } /** @@ -2194,18 +2076,6 @@ } /** * Returns the first value for a given attribute in the provided entry. * @param sr the entry. It may be <CODE>null</CODE>. * @param attrName the attribute name. * @return the first value for a given attribute in the provided entry. */ protected Object getFirstMonitoringValue(CustomSearchResult sr, String attrName) { return Utilities.getFirstMonitoringValue(sr, attrName); } /** * Returns the label to be used in panels (with ':') based on the definition * of the monitoring attribute. * @param attr the monitoring attribute. opendj3-server-dev/src/guitools/org/opends/guitools/controlpanel/util/ConfigReader.java
@@ -24,11 +24,8 @@ * Copyright 2008-2009 Sun Microsystems, Inc. * Portions Copyright 2014 ForgeRock AS */ package org.opends.guitools.controlpanel.util; import static org.opends.messages.AdminToolMessages.*; import java.io.File; import java.net.InetAddress; import java.util.ArrayList; @@ -39,13 +36,12 @@ import org.forgerock.i18n.LocalizableMessage; import org.forgerock.i18n.slf4j.LocalizedLogger; import org.forgerock.opendj.config.server.ConfigException; import org.opends.guitools.controlpanel.datamodel.BackendDescriptor; import org.opends.guitools.controlpanel.datamodel.ConnectionHandlerDescriptor; import org.opends.guitools.controlpanel.datamodel.VLVSortOrder; import org.opends.guitools.controlpanel.task.OfflineUpdateException; import org.opends.server.admin.std.meta.AdministrationConnectorCfgDefn; import org.forgerock.opendj.config.server.ConfigException; import org.opends.server.core.DirectoryServer; import org.opends.server.tools.tasks.TaskEntry; import org.opends.server.types.DN; @@ -55,10 +51,11 @@ import org.opends.server.types.OpenDsException; import org.opends.server.types.Schema; import static org.opends.messages.AdminToolMessages.*; /** * An abstract class providing some common interface for the class that read * the configuration (and if the server is running, the monitoring information). * */ public abstract class ConfigReader { @@ -322,19 +319,19 @@ if (s != null) { String[] attrNames = s.split(" "); for (int i=0; i<attrNames.length; i++) for (String attrName : attrNames) { if (attrNames[i].startsWith("+")) if (attrName.startsWith("+")) { sortOrder.add(new VLVSortOrder(attrNames[i].substring(1), true)); sortOrder.add(new VLVSortOrder(attrName.substring(1), true)); } else if (attrNames[i].startsWith("-")) else if (attrName.startsWith("-")) { sortOrder.add(new VLVSortOrder(attrNames[i].substring(1), false)); sortOrder.add(new VLVSortOrder(attrName.substring(1), false)); } else { sortOrder.add(new VLVSortOrder(attrNames[i], true)); sortOrder.add(new VLVSortOrder(attrName, true)); } } } opendj3-server-dev/src/guitools/org/opends/guitools/controlpanel/util/Utilities.java
@@ -93,6 +93,7 @@ import org.forgerock.i18n.LocalizableMessage; import org.forgerock.opendj.config.server.ConfigException; import org.forgerock.opendj.ldap.ByteString; import org.forgerock.opendj.ldap.schema.MatchingRule; import org.opends.guitools.controlpanel.ControlPanel; import org.opends.guitools.controlpanel.browser.IconPool; import org.opends.guitools.controlpanel.datamodel.CategorizedComboBoxElement; @@ -114,12 +115,17 @@ import org.opends.quicksetup.util.Utils; import org.opends.server.api.AttributeSyntax; import org.opends.server.api.ConfigHandler; import org.forgerock.opendj.ldap.schema.MatchingRule; import org.opends.server.config.ConfigEntry; import org.opends.server.core.DirectoryServer; import org.opends.server.core.LockFileManager; import org.opends.server.schema.SchemaConstants; import org.opends.server.types.*; import org.opends.server.types.AttributeType; import org.opends.server.types.CommonSchemaElements; import org.opends.server.types.DN; import org.opends.server.types.OpenDsException; import org.opends.server.types.RDN; import org.opends.server.types.Schema; import org.opends.server.types.SchemaFileElement; import org.opends.server.util.ServerConstants; import org.opends.server.util.StaticUtils; @@ -2480,16 +2486,7 @@ } } /** * Returns the first value for a given attribute in the provided entry. * @param sr the entry. It may be <CODE>null</CODE>. * @param attrName the attribute name. * @return the first value for a given attribute in the provided entry. */ public static Object getFirstMonitoringValue(CustomSearchResult sr, String attrName) private static Object getFirstMonitoringValue(CustomSearchResult sr, String attrName) { if (sr != null) { @@ -2519,6 +2516,34 @@ } /** * Returns the first value as a String for a given attribute in the provided * entry. * * @param sr * the entry. It may be <CODE>null</CODE>. * @param attrName * the attribute name. * @return the first value as a String for a given attribute in the provided * entry. */ public static String getFirstValueAsString(CustomSearchResult sr, String attrName) { if (sr != null) { final List<Object> values = sr.getAttributeValues(attrName); if (values != null && !values.isEmpty()) { final Object o = values.get(0); if (o != null) { return String.valueOf(o); } } } return null; } /** * Returns the monitoring value in a String form to be displayed to the user. * @param attr the attribute to analyze. * @param monitoringEntry the monitoring entry. @@ -2527,9 +2552,7 @@ public static String getMonitoringValue(MonitoringAttributes attr, CustomSearchResult monitoringEntry) { Object monitoringValue = Utilities.getFirstMonitoringValue(monitoringEntry, attr.getAttributeName()); String monitoringValue = getFirstValueAsString(monitoringEntry, attr.getAttributeName()); if (monitoringValue == null) { return NO_VALUE_SET.toString(); @@ -2540,46 +2563,42 @@ } else if (attr.isNumericDate()) { if("0".equals(monitoringValue.toString())) if ("0".equals(monitoringValue)) { return NO_VALUE_SET.toString(); } else { Long l = Long.parseLong(monitoringValue.toString()); Date date = new Date(l); return ConfigFromDirContext.formatter.format(date); } Long l = Long.parseLong(monitoringValue); Date date = new Date(l); return ConfigFromDirContext.formatter.format(date); } else if (attr.isTime()) { if("-1".equals(monitoringValue.toString())) if ("-1".equals(monitoringValue)) { return NO_VALUE_SET.toString(); } return monitoringValue.toString(); return monitoringValue; } else if (attr.isGMTDate()) { try { Date date = ConfigFromDirContext.utcParser.parse( monitoringValue.toString()); Date date = ConfigFromDirContext.utcParser.parse(monitoringValue); return ConfigFromDirContext.formatter.format(date); } catch (Throwable t) { return monitoringValue.toString(); return monitoringValue; } } else if (attr.isValueInBytes()) { Long l = Long.parseLong(monitoringValue.toString()); Long l = Long.parseLong(monitoringValue); long mb = l / (1024 * 1024); long kbs = (l - mb * 1024 * 1024) / 1024; return INFO_CTRL_PANEL_MEMORY_VALUE.get(mb, kbs).toString(); } return monitoringValue.toString(); return monitoringValue; } /** @@ -2593,13 +2612,12 @@ public static boolean isNotImplemented(MonitoringAttributes attr, CustomSearchResult monitoringEntry) { Object monitoringValue = Utilities.getFirstMonitoringValue( monitoringEntry, attr.getAttributeName()); String monitoringValue = getFirstValueAsString(monitoringEntry, attr.getAttributeName()); if (attr.isNumeric() && monitoringValue != null) { try { Long.parseLong(String.valueOf(monitoringValue)); Long.parseLong(monitoringValue); return false; } catch (Throwable t) @@ -2750,4 +2768,125 @@ return false; } /** * Computes the possible comparison results for monitoring information. * * @param monitor1 * the first monitor to compare * @param monitor2 * the second monitor to compare * @param possibleResults * where possible results are output * @param attrNames * the names for which to compute possible comparison results */ public static void computeMonitoringPossibleResults(CustomSearchResult monitor1, CustomSearchResult monitor2, ArrayList<Integer> possibleResults, Collection<String> attrNames) { for (String attrName : attrNames) { int possibleResult; if (monitor1 == null) { if (monitor2 == null) { possibleResult = 0; } else { possibleResult = -1; } } else if (monitor2 == null) { possibleResult = 1; } else { Object v1 = getFirstValue(monitor1, attrName); Object v2 = getFirstValue(monitor2, attrName); if (v1 == null) { if (v2 == null) { possibleResult = 0; } else { possibleResult = -1; } } else if (v2 == null) { possibleResult = 1; } else if (v1 instanceof Number) { if (v2 instanceof Number) { if ((v1 instanceof Double) || (v2 instanceof Double)) { double n1 = ((Number) v1).doubleValue(); double n2 = ((Number) v2).doubleValue(); if (n1 > n2) { possibleResult = 1; } else if (n1 < n2) { possibleResult = -1; } else { possibleResult = 0; } } else { long n1 = ((Number) v1).longValue(); long n2 = ((Number) v2).longValue(); if (n1 > n2) { possibleResult = 1; } else if (n1 < n2) { possibleResult = -1; } else { possibleResult = 0; } } } else { possibleResult = 1; } } else if (v2 instanceof Number) { possibleResult = -1; } else { possibleResult = v1.toString().compareTo(v2.toString()); } } possibleResults.add(possibleResult); } } private static Object getFirstValue(CustomSearchResult monitor, String attrName) { for (String attr : monitor.getAttributeNames()) { if (attr.equalsIgnoreCase(attrName)) { return getFirstMonitoringValue(monitor, attrName); } } return null; } }