001 /* 002 * Copyright 2008-2015 UnboundID Corp. 003 * All Rights Reserved. 004 */ 005 /* 006 * Copyright (C) 2015 UnboundID Corp. 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU General Public License (GPLv2 only) 010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 011 * as published by the Free Software Foundation. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Public License for more details. 017 * 018 * You should have received a copy of the GNU General Public License 019 * along with this program; if not, see <http://www.gnu.org/licenses>. 020 */ 021 package com.unboundid.ldap.sdk.unboundidds.extensions; 022 023 024 025 import com.unboundid.ldap.sdk.Control; 026 import com.unboundid.ldap.sdk.ExtendedRequest; 027 import com.unboundid.ldap.sdk.ExtendedResult; 028 import com.unboundid.ldap.sdk.LDAPConnection; 029 import com.unboundid.ldap.sdk.LDAPException; 030 import com.unboundid.ldap.sdk.ResultCode; 031 import com.unboundid.ldap.sdk.unboundidds.controls. 032 IntermediateClientRequestControl; 033 import com.unboundid.util.NotMutable; 034 import com.unboundid.util.ThreadSafety; 035 import com.unboundid.util.ThreadSafetyLevel; 036 037 import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*; 038 039 040 041 /** 042 * <BLOCKQUOTE> 043 * <B>NOTE:</B> This class is part of the Commercial Edition of the UnboundID 044 * LDAP SDK for Java. It is not available for use in applications that 045 * include only the Standard Edition of the LDAP SDK, and is not supported for 046 * use in conjunction with non-UnboundID products. 047 * </BLOCKQUOTE> 048 * This class provides an implementation of the get connection ID extended 049 * operation as used in the UnboundID Directory Server. It may be used to 050 * obtain the connection ID associated with the current connection. This is 051 * primarily useful for debugging purposes, and the 052 * {@link IntermediateClientRequestControl} may also be used to obtain this 053 * (along with other information). 054 * <BR><BR> 055 * <H2>Example</H2> 056 * The following example demonstrates the process for using the get connection 057 * ID extended operation: 058 * <PRE> 059 * GetConnectionIDExtendedResult result = 060 * (GetConnectionIDExtendedResult) connection.processExtendedOperation( 061 * new GetConnectionIDExtendedRequest()); 062 * 063 * // NOTE: The processExtendedOperation method will generally only throw an 064 * // exception if a problem occurs while trying to send the request or read 065 * // the response. It will not throw an exception because of a non-success 066 * // response. 067 * 068 * if (result.getResultCode() == ResultCode.SUCCESS) 069 * { 070 * long connectionID = result.getConnectionID(); 071 * } 072 * </PRE> 073 */ 074 @NotMutable() 075 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 076 public final class GetConnectionIDExtendedRequest 077 extends ExtendedRequest 078 { 079 /** 080 * The OID (1.3.6.1.4.1.30221.1.6.2) for the get connection ID extended 081 * request. 082 */ 083 public static final String GET_CONNECTION_ID_REQUEST_OID = 084 "1.3.6.1.4.1.30221.1.6.2"; 085 086 087 088 /** 089 * The serial version UID for this serializable class. 090 */ 091 private static final long serialVersionUID = 4787797927715098127L; 092 093 094 095 // This is an ugly hack to prevent checkstyle from complaining about the 096 // import for the IntermediateClientRequestControl class. It is used by the 097 // @link element in the javadoc, but checkstyle apparently doesn't recognize 098 // that so we just need to use it in some way in this class to placate 099 // checkstyle. 100 static 101 { 102 final IntermediateClientRequestControl c = null; 103 } 104 105 106 107 /** 108 * Creates a new get connection ID extended request with no controls. 109 */ 110 public GetConnectionIDExtendedRequest() 111 { 112 this((Control[]) null); 113 } 114 115 116 117 /** 118 * Creates a new get connection ID extended request with the provided set of 119 * controls. 120 * 121 * @param controls The set of controls to include in the request. 122 */ 123 public GetConnectionIDExtendedRequest(final Control[] controls) 124 { 125 super(GET_CONNECTION_ID_REQUEST_OID, null, controls); 126 } 127 128 129 130 /** 131 * Creates a new get connection ID extended request from the provided generic 132 * extended request. 133 * 134 * @param extendedRequest The generic extended request to use to create this 135 * get connection ID extended request. 136 * 137 * @throws LDAPException If a problem occurs while decoding the request. 138 */ 139 public GetConnectionIDExtendedRequest(final ExtendedRequest extendedRequest) 140 throws LDAPException 141 { 142 super(extendedRequest); 143 144 if (extendedRequest.hasValue()) 145 { 146 throw new LDAPException(ResultCode.DECODING_ERROR, 147 ERR_GET_CONN_ID_REQUEST_HAS_VALUE.get()); 148 } 149 } 150 151 152 153 /** 154 * {@inheritDoc} 155 */ 156 @Override() 157 public GetConnectionIDExtendedResult process(final LDAPConnection connection, 158 final int depth) 159 throws LDAPException 160 { 161 final ExtendedResult extendedResponse = super.process(connection, depth); 162 return new GetConnectionIDExtendedResult(extendedResponse); 163 } 164 165 166 167 /** 168 * {@inheritDoc} 169 */ 170 @Override() 171 public GetConnectionIDExtendedRequest duplicate() 172 { 173 return duplicate(getControls()); 174 } 175 176 177 178 /** 179 * {@inheritDoc} 180 */ 181 @Override() 182 public GetConnectionIDExtendedRequest duplicate(final Control[] controls) 183 { 184 final GetConnectionIDExtendedRequest r = 185 new GetConnectionIDExtendedRequest(controls); 186 r.setResponseTimeoutMillis(getResponseTimeoutMillis(null)); 187 return r; 188 } 189 190 191 192 /** 193 * {@inheritDoc} 194 */ 195 @Override() 196 public String getExtendedRequestName() 197 { 198 return INFO_EXTENDED_REQUEST_NAME_GET_CONNECTION_ID.get(); 199 } 200 201 202 203 /** 204 * {@inheritDoc} 205 */ 206 @Override() 207 public void toString(final StringBuilder buffer) 208 { 209 buffer.append("GetConnectionIDExtendedRequest("); 210 211 final Control[] controls = getControls(); 212 if (controls.length > 0) 213 { 214 buffer.append("controls={"); 215 for (int i=0; i < controls.length; i++) 216 { 217 if (i > 0) 218 { 219 buffer.append(", "); 220 } 221 222 buffer.append(controls[i]); 223 } 224 buffer.append('}'); 225 } 226 227 buffer.append(')'); 228 } 229 }