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 2006-2009 Sun Microsystems, Inc. 025 * Portions Copyright 2014-2015 ForgeRock AS 026 */ 027package org.opends.server.protocols.internal; 028import org.forgerock.i18n.LocalizableMessage; 029 030 031 032 033import java.util.Collection; 034import java.util.LinkedList; 035 036import org.opends.server.admin.std.server.*; 037import org.opends.server.api.ClientConnection; 038import org.opends.server.api.ConnectionHandler; 039import org.opends.server.core.ServerContext; 040import org.forgerock.opendj.config.server.ConfigException; 041import org.opends.server.types.DN; 042import org.opends.server.types.InitializationException; 043import org.opends.server.types.HostPort; 044 045 046 047/** 048 * This class defines a Directory Server connection handler that will 049 * handle internal "connections". 050 */ 051@org.opends.server.types.PublicAPI( 052 stability=org.opends.server.types.StabilityLevel.PRIVATE, 053 mayInstantiate=false, 054 mayExtend=false, 055 mayInvoke=false) 056public final class InternalConnectionHandler 057 extends ConnectionHandler 058{ 059 /** The singleton instance of this internal connection handler. */ 060 private static InternalConnectionHandler handlerInstance = 061 new InternalConnectionHandler(); 062 063 /** The list of "connections" associated with this connection handler. */ 064 private LinkedList<ClientConnection> connectionList; 065 066 /** The list of listeners associated with this connection handler. */ 067 private LinkedList<HostPort> listeners; 068 069 /** The name of the protocol for this connection handler. */ 070 private String protocol; 071 072 /** Configuration object of the connection handler. */ 073 private ConnectionHandlerCfg configuration; 074 075 076 /** 077 * Creates a new instance of this connection handler. All 078 * initialization should be done in the 079 * <CODE>initializeConnectionHandler</CODE> method. 080 */ 081 private InternalConnectionHandler() 082 { 083 super("Internal Connection Handler Thread"); 084 085 086 // Since we can't guarantee that the initializeConnectionHandler 087 // method will always be called for this method, we'll do the 088 // necessary "initialization" here. 089 protocol = "internal"; 090 connectionList = new LinkedList<>(); 091 listeners = new LinkedList<>(); 092 } 093 094 095 096 /** 097 * Retrieves the static instance of this internal connection 098 * handler. 099 * 100 * @return The static instance of this internal connection handler. 101 */ 102 public static InternalConnectionHandler getInstance() 103 { 104 return handlerInstance; 105 } 106 107 108 109 /** 110 * Initializes this connection handler provider based on the 111 * information in the provided connection handler configuration. 112 * 113 * @param serverContext The server context. 114 * @param configuration The connection handler configuration that 115 * contains the information to use to 116 * initialize this connection handler. 117 * 118 * @throws ConfigException If an unrecoverable problem arises in 119 * the process of performing the 120 * initialization as a result of the 121 * server configuration. 122 * 123 * @throws InitializationException If a problem occurs during 124 * initialization that is not 125 * related to the server 126 * configuration. 127 */ 128 @Override 129 public void initializeConnectionHandler(ServerContext serverContext, ConnectionHandlerCfg configuration) 130 throws ConfigException, InitializationException 131 { 132 this.configuration = configuration; 133 } 134 135 136 137 /** {@inheritDoc} */ 138 @Override 139 public void finalizeConnectionHandler(LocalizableMessage finalizeReason) 140 { 141 // No implementation is required. 142 } 143 144 145 146 /** 147 * Retrieves a name that may be used to refer to this connection 148 * handler. Every connection handler instance (even handlers of the 149 * same type) must have a unique name. 150 * 151 * @return A unique name that may be used to refer to this 152 * connection handler. 153 */ 154 @Override 155 public String getConnectionHandlerName() 156 { 157 return "Internal Connection Handler"; 158 } 159 160 161 162 /** 163 * Retrieves the name of the protocol used to communicate with 164 * clients. It should take into account any special naming that may 165 * be needed to express any security mechanisms or other constraints 166 * in place (e.g., "LDAPS" for LDAP over SSL). 167 * 168 * @return The name of the protocol used to communicate with 169 * clients. 170 */ 171 @Override 172 public String getProtocol() 173 { 174 return protocol; 175 } 176 177 178 179 /** 180 * Retrieves information about the listener(s) that will be used to 181 * accept client connections. 182 * 183 * @return Information about the listener(s) that will be used to 184 * accept client connections, or an empty list if this 185 * connection handler does not accept connections from 186 * network clients. 187 */ 188 @Override 189 public Collection<HostPort> getListeners() 190 { 191 return listeners; 192 } 193 194 195 196 /** 197 * Retrieves the set of active client connections that have been 198 * established through this connection handler. 199 * 200 * @return The set of active client connections that have been 201 * established through this connection handler. 202 */ 203 @Override 204 public Collection<ClientConnection> getClientConnections() 205 { 206 return connectionList; 207 } 208 209 210 211 /** 212 * Operates in a loop, accepting new connections and ensuring that 213 * requests on those connections are handled properly. 214 */ 215 @Override 216 public void run() 217 { 218 // No implementation is required since this connection handler 219 // won't actually accept connections. 220 return; 221 } 222 223 224 225 /** 226 * Retrieves a string representation of this connection handler. 227 * 228 * @return A string representation of this connection handler. 229 */ 230 @Override 231 public String toString() 232 { 233 return "Internal Connection Handler"; 234 } 235 236 237 238 /** 239 * Appends a string representation of this connection handler to the 240 * provided buffer. 241 * 242 * @param buffer The buffer to which the information should be 243 * appended. 244 */ 245 @Override 246 public void toString(StringBuilder buffer) 247 { 248 buffer.append("Internal Connection Handler"); 249 } 250 251 /** 252 * Called near the end of server shutdown. This ensures that a new 253 * InternalClientConnection is created if the server is immediately 254 * restarted as part of an in-core restart. 255 */ 256 public static void clearRootClientConnectionAtShutdown() 257 { 258 InternalClientConnection.clearRootClientConnectionAtShutdown(); 259 } 260 261 /** 262 * Return the configuration dn of the object. 263 * @return DN of the entry. 264 */ 265 @Override 266 public DN getComponentEntryDN() { 267 return this.configuration.dn(); 268 } 269 270} 271