001/*
002 * Copyright 2008-2018 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2015-2018 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 * This extended request has an OID of 1.3.6.1.4.1.30221.1.6.2.  It does not
060 * have a value.
061 * <BR>
062 * <H2>Example</H2>
063 * The following example demonstrates the process for using the get connection
064 * ID extended operation:
065 * <PRE>
066 * GetConnectionIDExtendedResult result =
067 *      (GetConnectionIDExtendedResult) connection.processExtendedOperation(
068 *           new GetConnectionIDExtendedRequest());
069 *
070 * // NOTE:  The processExtendedOperation method will generally only throw an
071 * // exception if a problem occurs while trying to send the request or read
072 * // the response.  It will not throw an exception because of a non-success
073 * // response.
074 *
075 * if (result.getResultCode() == ResultCode.SUCCESS)
076 * {
077 *   long connectionID = result.getConnectionID();
078 * }
079 * </PRE>
080 */
081@NotMutable()
082@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
083public final class GetConnectionIDExtendedRequest
084       extends ExtendedRequest
085{
086  /**
087   * The OID (1.3.6.1.4.1.30221.1.6.2) for the get connection ID extended
088   * request.
089   */
090  public static final String GET_CONNECTION_ID_REQUEST_OID =
091       "1.3.6.1.4.1.30221.1.6.2";
092
093
094
095  /**
096   * The serial version UID for this serializable class.
097   */
098  private static final long serialVersionUID = 4787797927715098127L;
099
100
101
102  // This is an ugly hack to prevent checkstyle from complaining about the
103  // import for the IntermediateClientRequestControl class.  It is used by the
104  // @link element in the javadoc, but checkstyle apparently doesn't recognize
105  // that so we just need to use it in some way in this class to placate
106  // checkstyle.
107  static
108  {
109    final IntermediateClientRequestControl c = null;
110  }
111
112
113
114  /**
115   * Creates a new get connection ID extended request with no controls.
116   */
117  public GetConnectionIDExtendedRequest()
118  {
119    this((Control[]) null);
120  }
121
122
123
124  /**
125   * Creates a new get connection ID extended request with the provided set of
126   * controls.
127   *
128   * @param  controls  The set of controls to include in the request.
129   */
130  public GetConnectionIDExtendedRequest(final Control[] controls)
131  {
132    super(GET_CONNECTION_ID_REQUEST_OID, null, controls);
133  }
134
135
136
137  /**
138   * Creates a new get connection ID extended request from the provided generic
139   * extended request.
140   *
141   * @param  extendedRequest  The generic extended request to use to create this
142   *                          get connection ID extended request.
143   *
144   * @throws  LDAPException  If a problem occurs while decoding the request.
145   */
146  public GetConnectionIDExtendedRequest(final ExtendedRequest extendedRequest)
147         throws LDAPException
148  {
149    super(extendedRequest);
150
151    if (extendedRequest.hasValue())
152    {
153      throw new LDAPException(ResultCode.DECODING_ERROR,
154                              ERR_GET_CONN_ID_REQUEST_HAS_VALUE.get());
155    }
156  }
157
158
159
160  /**
161   * {@inheritDoc}
162   */
163  @Override()
164  public GetConnectionIDExtendedResult process(final LDAPConnection connection,
165                                               final int depth)
166         throws LDAPException
167  {
168    final ExtendedResult extendedResponse = super.process(connection, depth);
169    return new GetConnectionIDExtendedResult(extendedResponse);
170  }
171
172
173
174  /**
175   * {@inheritDoc}
176   */
177  @Override()
178  public GetConnectionIDExtendedRequest duplicate()
179  {
180    return duplicate(getControls());
181  }
182
183
184
185  /**
186   * {@inheritDoc}
187   */
188  @Override()
189  public GetConnectionIDExtendedRequest duplicate(final Control[] controls)
190  {
191    final GetConnectionIDExtendedRequest r =
192         new GetConnectionIDExtendedRequest(controls);
193    r.setResponseTimeoutMillis(getResponseTimeoutMillis(null));
194    return r;
195  }
196
197
198
199  /**
200   * {@inheritDoc}
201   */
202  @Override()
203  public String getExtendedRequestName()
204  {
205    return INFO_EXTENDED_REQUEST_NAME_GET_CONNECTION_ID.get();
206  }
207
208
209
210  /**
211   * {@inheritDoc}
212   */
213  @Override()
214  public void toString(final StringBuilder buffer)
215  {
216    buffer.append("GetConnectionIDExtendedRequest(");
217
218    final Control[] controls = getControls();
219    if (controls.length > 0)
220    {
221      buffer.append("controls={");
222      for (int i=0; i < controls.length; i++)
223      {
224        if (i > 0)
225        {
226          buffer.append(", ");
227        }
228
229        buffer.append(controls[i]);
230      }
231      buffer.append('}');
232    }
233
234    buffer.append(')');
235  }
236}