001/*
002 * Copyright 2008-2017 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2015-2017 Ping Identity Corporation
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 */
021package com.unboundid.ldap.sdk.unboundidds.extensions;
022
023
024
025import com.unboundid.ldap.sdk.Control;
026import com.unboundid.ldap.sdk.ExtendedRequest;
027import com.unboundid.ldap.sdk.ExtendedResult;
028import com.unboundid.ldap.sdk.LDAPConnection;
029import com.unboundid.ldap.sdk.LDAPException;
030import com.unboundid.ldap.sdk.ResultCode;
031import com.unboundid.ldap.sdk.unboundidds.controls.
032            IntermediateClientRequestControl;
033import com.unboundid.util.NotMutable;
034import com.unboundid.util.ThreadSafety;
035import com.unboundid.util.ThreadSafetyLevel;
036
037import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*;
038
039
040
041/**
042 * This class provides an implementation of the get connection ID extended
043 * operation as used in the Ping Identity, UnboundID, and Alcatel-Lucent 8661
044 * Directory Server.  It may be used to obtain the connection ID associated with
045 * the current connection.  This is primarily useful for debugging purposes, and
046 * the {@link IntermediateClientRequestControl} may also be used to obtain this
047 * (along with other information).
048 * <BR>
049 * <BLOCKQUOTE>
050 *   <B>NOTE:</B>  This class, and other classes within the
051 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
052 *   supported for use against Ping Identity, UnboundID, and Alcatel-Lucent 8661
053 *   server products.  These classes provide support for proprietary
054 *   functionality or for external specifications that are not considered stable
055 *   or mature enough to be guaranteed to work in an interoperable way with
056 *   other types of LDAP servers.
057 * </BLOCKQUOTE>
058 * <BR>
059 * <H2>Example</H2>
060 * The following example demonstrates the process for using the get connection
061 * ID extended operation:
062 * <PRE>
063 * GetConnectionIDExtendedResult result =
064 *      (GetConnectionIDExtendedResult) connection.processExtendedOperation(
065 *           new GetConnectionIDExtendedRequest());
066 *
067 * // NOTE:  The processExtendedOperation method will generally only throw an
068 * // exception if a problem occurs while trying to send the request or read
069 * // the response.  It will not throw an exception because of a non-success
070 * // response.
071 *
072 * if (result.getResultCode() == ResultCode.SUCCESS)
073 * {
074 *   long connectionID = result.getConnectionID();
075 * }
076 * </PRE>
077 */
078@NotMutable()
079@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
080public final class GetConnectionIDExtendedRequest
081       extends ExtendedRequest
082{
083  /**
084   * The OID (1.3.6.1.4.1.30221.1.6.2) for the get connection ID extended
085   * request.
086   */
087  public static final String GET_CONNECTION_ID_REQUEST_OID =
088       "1.3.6.1.4.1.30221.1.6.2";
089
090
091
092  /**
093   * The serial version UID for this serializable class.
094   */
095  private static final long serialVersionUID = 4787797927715098127L;
096
097
098
099  // This is an ugly hack to prevent checkstyle from complaining about the
100  // import for the IntermediateClientRequestControl class.  It is used by the
101  // @link element in the javadoc, but checkstyle apparently doesn't recognize
102  // that so we just need to use it in some way in this class to placate
103  // checkstyle.
104  static
105  {
106    final IntermediateClientRequestControl c = null;
107  }
108
109
110
111  /**
112   * Creates a new get connection ID extended request with no controls.
113   */
114  public GetConnectionIDExtendedRequest()
115  {
116    this((Control[]) null);
117  }
118
119
120
121  /**
122   * Creates a new get connection ID extended request with the provided set of
123   * controls.
124   *
125   * @param  controls  The set of controls to include in the request.
126   */
127  public GetConnectionIDExtendedRequest(final Control[] controls)
128  {
129    super(GET_CONNECTION_ID_REQUEST_OID, null, controls);
130  }
131
132
133
134  /**
135   * Creates a new get connection ID extended request from the provided generic
136   * extended request.
137   *
138   * @param  extendedRequest  The generic extended request to use to create this
139   *                          get connection ID extended request.
140   *
141   * @throws  LDAPException  If a problem occurs while decoding the request.
142   */
143  public GetConnectionIDExtendedRequest(final ExtendedRequest extendedRequest)
144         throws LDAPException
145  {
146    super(extendedRequest);
147
148    if (extendedRequest.hasValue())
149    {
150      throw new LDAPException(ResultCode.DECODING_ERROR,
151                              ERR_GET_CONN_ID_REQUEST_HAS_VALUE.get());
152    }
153  }
154
155
156
157  /**
158   * {@inheritDoc}
159   */
160  @Override()
161  public GetConnectionIDExtendedResult process(final LDAPConnection connection,
162                                               final int depth)
163         throws LDAPException
164  {
165    final ExtendedResult extendedResponse = super.process(connection, depth);
166    return new GetConnectionIDExtendedResult(extendedResponse);
167  }
168
169
170
171  /**
172   * {@inheritDoc}
173   */
174  @Override()
175  public GetConnectionIDExtendedRequest duplicate()
176  {
177    return duplicate(getControls());
178  }
179
180
181
182  /**
183   * {@inheritDoc}
184   */
185  @Override()
186  public GetConnectionIDExtendedRequest duplicate(final Control[] controls)
187  {
188    final GetConnectionIDExtendedRequest r =
189         new GetConnectionIDExtendedRequest(controls);
190    r.setResponseTimeoutMillis(getResponseTimeoutMillis(null));
191    return r;
192  }
193
194
195
196  /**
197   * {@inheritDoc}
198   */
199  @Override()
200  public String getExtendedRequestName()
201  {
202    return INFO_EXTENDED_REQUEST_NAME_GET_CONNECTION_ID.get();
203  }
204
205
206
207  /**
208   * {@inheritDoc}
209   */
210  @Override()
211  public void toString(final StringBuilder buffer)
212  {
213    buffer.append("GetConnectionIDExtendedRequest(");
214
215    final Control[] controls = getControls();
216    if (controls.length > 0)
217    {
218      buffer.append("controls={");
219      for (int i=0; i < controls.length; i++)
220      {
221        if (i > 0)
222        {
223          buffer.append(", ");
224        }
225
226        buffer.append(controls[i]);
227      }
228      buffer.append('}');
229    }
230
231    buffer.append(')');
232  }
233}