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.controls;
022
023
024
025import com.unboundid.ldap.sdk.Control;
026import com.unboundid.ldap.sdk.LDAPException;
027import com.unboundid.ldap.sdk.ResultCode;
028import com.unboundid.util.NotMutable;
029import com.unboundid.util.ThreadSafety;
030import com.unboundid.util.ThreadSafetyLevel;
031
032import static com.unboundid.ldap.sdk.unboundidds.controls.ControlMessages.*;
033
034
035
036/**
037 * This class provides a request control which may be used to request the server
038 * ID of the server that actually processed the associated request.  It may be
039 * used for requests sent directly to a Directory Server, but it is more useful
040 * when the request will pass through a Directory Proxy Server instance because
041 * the corresponding {@link GetServerIDResponseControl} will provide the server
042 * ID of the backend server used to process the request.  This server ID may be
043 * used in a {@link RouteToServerRequestControl} instance to request that
044 * subsequent operations be processed by the same server.  See the documentation
045 * for the {@code RouteToServerRequestControl} for an example that demonstrates
046 * this.
047 * <BR>
048 * <BLOCKQUOTE>
049 *   <B>NOTE:</B>  This class, and other classes within the
050 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
051 *   supported for use against Ping Identity, UnboundID, and
052 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
053 *   for proprietary functionality or for external specifications that are not
054 *   considered stable or mature enough to be guaranteed to work in an
055 *   interoperable way with other types of LDAP servers.
056 * </BLOCKQUOTE>
057 * <BR>
058 * This control does not have a value.  The criticality may be either
059 * {@code true} or {@code false}.
060 */
061@NotMutable()
062@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
063public final class GetServerIDRequestControl
064       extends Control
065{
066  /**
067   * The OID (1.3.6.1.4.1.30221.2.5.14) for the get server ID request control.
068   */
069  public static final String GET_SERVER_ID_REQUEST_OID =
070       "1.3.6.1.4.1.30221.2.5.14";
071
072
073  /**
074   * The serial version UID for this serializable class.
075   */
076  private static final long serialVersionUID = -6015835755174298354L;
077
078
079
080  /**
081   * Creates a new get server ID request control.  It will not be marked
082   * critical.
083   */
084  public GetServerIDRequestControl()
085  {
086    this(false);
087  }
088
089
090
091  /**
092   * Creates a new get server ID request control with the specified
093   * criticality.
094   *
095   * @param  isCritical  Indicates whether this control should be marked
096   *                     critical.
097   */
098  public GetServerIDRequestControl(final boolean isCritical)
099  {
100    super(GET_SERVER_ID_REQUEST_OID, isCritical,  null);
101  }
102
103
104
105  /**
106   * Creates a new get server ID request control which is decoded from the
107   * provided generic control.
108   *
109   * @param  control  The generic control to be decoded as a get server ID
110   *                  request control.
111   *
112   * @throws  LDAPException  If the provided control cannot be decoded as a get
113   *                         server ID request control.
114   */
115  public GetServerIDRequestControl(final Control control)
116         throws LDAPException
117  {
118    super(control);
119
120    if (control.hasValue())
121    {
122      throw new LDAPException(ResultCode.DECODING_ERROR,
123                              ERR_GET_SERVER_ID_REQUEST_HAS_VALUE.get());
124    }
125  }
126
127
128
129  /**
130   * {@inheritDoc}
131   */
132  @Override()
133  public String getControlName()
134  {
135    return INFO_CONTROL_NAME_GET_SERVER_ID_REQUEST.get();
136  }
137
138
139
140  /**
141   * {@inheritDoc}
142   */
143  @Override()
144  public void toString(final StringBuilder buffer)
145  {
146    buffer.append("GetServerIDRequestControl(isCritical=");
147    buffer.append(isCritical());
148    buffer.append(')');
149  }
150}