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 2008-2009 Sun Microsystems, Inc. 025 * Portions Copyright 2013-2015 ForgeRock AS 026 */ 027package org.opends.guitools.controlpanel.datamodel; 028 029import static org.opends.messages.AdminToolMessages.*; 030 031import java.net.InetAddress; 032import java.util.Collection; 033import java.util.Collections; 034import java.util.Set; 035import java.util.SortedSet; 036import java.util.TreeSet; 037 038import org.forgerock.i18n.LocalizableMessage; 039import org.opends.server.admin.std.meta.AdministrationConnectorCfgDefn; 040 041/** 042 * This class is used to represent a Listener and is aimed to be used by the 043 * classes in the ListenersTableModel class. 044 */ 045public class ConnectionHandlerDescriptor 046{ 047 private Set<CustomSearchResult> monitoringEntries = Collections.emptySet(); 048 049 /** Enumeration used to represent the state of the listener. */ 050 public enum State 051 { 052 /** The listener is enabled. */ 053 ENABLED, 054 /** The listener is disabled. */ 055 DISABLED, 056 /** The state of the listener is unknown. */ 057 UNKNOWN 058 } 059 060 /** Enumeration used to represent the Protocol of the listener. */ 061 public enum Protocol 062 { 063 /** LDAP protocol. */ 064 LDAP(INFO_CTRL_PANEL_CONN_HANDLER_LDAP.get()), 065 /** LDAP accepting Start TLS protocol. */ 066 LDAP_STARTTLS(INFO_CTRL_PANEL_CONN_HANDLER_LDAP_STARTTLS.get()), 067 /** LDAP secure protocol. */ 068 LDAPS(INFO_CTRL_PANEL_CONN_HANDLER_LDAPS.get()), 069 /** HTTP protocol. */ 070 HTTP(INFO_CTRL_PANEL_CONN_HANDLER_HTTP.get()), 071 /** HTTP secure protocol. */ 072 HTTPS(INFO_CTRL_PANEL_CONN_HANDLER_HTTPS.get()), 073 /** JMX protocol. */ 074 JMX(INFO_CTRL_PANEL_CONN_HANDLER_JMX.get()), 075 /** JMX secure protocol. */ 076 JMXS(INFO_CTRL_PANEL_CONN_HANDLER_JMXS.get()), 077 /** LDIF protocol. */ 078 LDIF(INFO_CTRL_PANEL_CONN_HANDLER_LDIF.get()), 079 /** SNMP protocol. */ 080 SNMP(INFO_CTRL_PANEL_CONN_HANDLER_SNMP.get()), 081 /** 082 * Replication protocol. Even if in the configuration is not considered 083 * as a listener, we display it on the table. 084 */ 085 REPLICATION(INFO_CTRL_PANEL_CONN_HANDLER_REPLICATION.get()), 086 /** Secure replication protocol. */ 087 REPLICATION_SECURE(INFO_CTRL_PANEL_CONN_HANDLER_REPLICATION_SECURE.get()), 088 /** Admin connector protocol. */ 089 ADMINISTRATION_CONNECTOR(INFO_CTRL_PANEL_CONN_HANDLER_ADMINISTRATION.get()), 090 /** Other protocol. */ 091 OTHER(INFO_CTRL_PANEL_CONN_HANDLER_OTHER.get()); 092 093 private LocalizableMessage displayMessage; 094 095 private Protocol(LocalizableMessage displayMessage) 096 { 097 this.displayMessage = displayMessage; 098 } 099 100 /** 101 * Returns the display LocalizableMessage to be used for the protocol. 102 * @return the display LocalizableMessage to be used for the protocol. 103 */ 104 public LocalizableMessage getDisplayMessage() 105 { 106 return displayMessage; 107 } 108 } 109 110 private State state; 111 private SortedSet<InetAddress> addresses = new TreeSet<>( 112 AdministrationConnectorCfgDefn.getInstance(). 113 getListenAddressPropertyDefinition()); 114 private int port; 115 private Protocol protocol; 116 private String toString; 117 private String name; 118 119 private int hashCode; 120 121 /** 122 * Constructor for the connection handler.. 123 * @param addresses the list of InetAdresses of the listener. 124 * @param port the port of the connection handler. 125 * @param protocol the protocol of the listener. 126 * @param state the state of the connection handler (enabled, disabled, etc.). 127 * @param name the name of the listener. 128 * @param monitoringEntries the LDAP entries containing the monitoring 129 * information. 130 */ 131 public ConnectionHandlerDescriptor(Collection<InetAddress> addresses, 132 int port, Protocol protocol, State state, String name, 133 Set<CustomSearchResult> monitoringEntries) 134 { 135 this.addresses.addAll(addresses); 136 this.port = port; 137 this.protocol = protocol; 138 this.state = state; 139 this.name = name; 140 this.monitoringEntries = Collections.unmodifiableSet(monitoringEntries); 141 142 StringBuilder builder = new StringBuilder(); 143 builder.append(getProtocol()).append(" ").append(getState()).append(" "); 144 for (InetAddress address : addresses) 145 { 146 builder.append(address); 147 } 148 builder.append(" Port: ").append(port); 149 toString = builder.toString(); 150 hashCode = toString.hashCode(); 151 } 152 153 /** 154 * Returns the address port representation of the listener. 155 * @return the address port representation of the listener. 156 */ 157 public SortedSet<InetAddress> getAddresses() 158 { 159 return addresses; 160 } 161 162 /** 163 * Returns the protocol of the listener. 164 * @return the protocol of the listener. 165 */ 166 public Protocol getProtocol() 167 { 168 return protocol; 169 } 170 171 /** 172 * Returns the state of the listener. 173 * @return the state of the listener. 174 */ 175 public State getState() 176 { 177 return state; 178 } 179 180 /** 181 * Returns the monitoring entries. 182 * @return the monitoring entries. 183 */ 184 public Set<CustomSearchResult> getMonitoringEntries() 185 { 186 return monitoringEntries; 187 } 188 189 /** 190 * Sets the monitoring entries. 191 * @param monitoringEntries the monitoring entries. 192 */ 193 public void setMonitoringEntries(Set<CustomSearchResult> monitoringEntries) 194 { 195 this.monitoringEntries = Collections.unmodifiableSet(monitoringEntries); 196 } 197 198 /** {@inheritDoc} */ 199 @Override 200 public int hashCode() 201 { 202 return hashCode; 203 } 204 205 /** {@inheritDoc} */ 206 @Override 207 public String toString() 208 { 209 return toString; 210 } 211 212 /** {@inheritDoc} */ 213 @Override 214 public boolean equals(Object o) 215 { 216 if (o == this) 217 { 218 return true; 219 } 220 if (o instanceof ConnectionHandlerDescriptor) 221 { 222 ConnectionHandlerDescriptor ch = (ConnectionHandlerDescriptor) o; 223 return toString.equals(o.toString()) 224 && getMonitoringEntries().equals(ch.getMonitoringEntries()); 225 } 226 return false; 227 } 228 229 /** 230 * Returns the port of the connection handler. 231 * @return the port of the connection handler. 232 */ 233 public int getPort() 234 { 235 return port; 236 } 237 238 /** 239 * Returns the name of the connection handler. 240 * @return the name of the connection handler. 241 */ 242 public String getName() 243 { 244 return name; 245 } 246}