001/*
002 * Copyright 2009-2017 UnboundID Corp.
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2009-2017 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 */
021package com.unboundid.ldap.protocol;
022
023
024
025import com.unboundid.asn1.ASN1Buffer;
026import com.unboundid.asn1.ASN1Element;
027import com.unboundid.asn1.ASN1Integer;
028import com.unboundid.asn1.ASN1StreamReader;
029import com.unboundid.ldap.sdk.LDAPException;
030import com.unboundid.ldap.sdk.ResultCode;
031import com.unboundid.util.NotMutable;
032import com.unboundid.util.InternalUseOnly;
033import com.unboundid.util.ThreadSafety;
034import com.unboundid.util.ThreadSafetyLevel;
035
036import static com.unboundid.ldap.protocol.ProtocolMessages.*;
037import static com.unboundid.util.Debug.*;
038import static com.unboundid.util.StaticUtils.*;
039
040
041
042/**
043 * This class provides an implementation of an LDAP abandon request protocol op.
044 */
045@InternalUseOnly()
046@NotMutable()
047@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
048public final class AbandonRequestProtocolOp
049       implements ProtocolOp
050{
051  /**
052   * The serial version UID for this serializable class.
053   */
054  private static final long serialVersionUID = -7824390696388231825L;
055
056
057
058  // The message ID of the operation to abandon.
059  private final int idToAbandon;
060
061
062
063  /**
064   * Creates a new abandon request protocol op with the provided information.
065   *
066   * @param  idToAbandon  The message ID of the operation to abandon.
067   */
068  public AbandonRequestProtocolOp(final int idToAbandon)
069  {
070    this.idToAbandon = idToAbandon;
071  }
072
073
074
075  /**
076   * Creates a new abandon request protocol op read from the provided ASN.1
077   * stream reader.
078   *
079   * @param  reader  The ASN.1 stream reader from which to read the abandon
080   *                 request protocol op.
081   *
082   * @throws  LDAPException  If a problem occurs while reading or parsing the
083   *                         abandon request.
084   */
085  AbandonRequestProtocolOp(final ASN1StreamReader reader)
086       throws LDAPException
087  {
088    try
089    {
090      idToAbandon = reader.readInteger();
091    }
092    catch (Exception e)
093    {
094      debugException(e);
095
096      throw new LDAPException(ResultCode.DECODING_ERROR,
097           ERR_ABANDON_REQUEST_CANNOT_DECODE.get(getExceptionMessage(e)), e);
098    }
099  }
100
101
102
103  /**
104   * Retrieves the message ID of the operation to abandon.
105   *
106   * @return  The message ID of the operation to abandon.
107   */
108  public int getIDToAbandon()
109  {
110    return idToAbandon;
111  }
112
113
114
115  /**
116   * {@inheritDoc}
117   */
118  public byte getProtocolOpType()
119  {
120    return LDAPMessage.PROTOCOL_OP_TYPE_ABANDON_REQUEST;
121  }
122
123
124
125  /**
126   * {@inheritDoc}
127   */
128  public ASN1Element encodeProtocolOp()
129  {
130    return new ASN1Integer(LDAPMessage.PROTOCOL_OP_TYPE_ABANDON_REQUEST,
131         idToAbandon);
132  }
133
134
135
136  /**
137   * Decodes the provided ASN.1 element as an abandon request protocol op.
138   *
139   * @param  element  The ASN.1 element to be decoded.
140   *
141   * @return  The decoded abandon request protocol op.
142   *
143   * @throws  LDAPException  If the provided ASN.1 element cannot be decoded as
144   *                         an abandon request protocol op.
145   */
146  public static AbandonRequestProtocolOp decodeProtocolOp(
147                                              final ASN1Element element)
148         throws LDAPException
149  {
150    try
151    {
152      return new AbandonRequestProtocolOp(
153           ASN1Integer.decodeAsInteger(element).intValue());
154    }
155    catch (final Exception e)
156    {
157      debugException(e);
158      throw new LDAPException(ResultCode.DECODING_ERROR,
159           ERR_ABANDON_REQUEST_CANNOT_DECODE.get(getExceptionMessage(e)),
160           e);
161    }
162  }
163
164
165
166  /**
167   * {@inheritDoc}
168   */
169  public void writeTo(final ASN1Buffer buffer)
170  {
171    buffer.addInteger(LDAPMessage.PROTOCOL_OP_TYPE_ABANDON_REQUEST,
172                      idToAbandon);
173  }
174
175
176
177  /**
178   * Retrieves a string representation of this protocol op.
179   *
180   * @return  A string representation of this protocol op.
181   */
182  @Override()
183  public String toString()
184  {
185    final StringBuilder buffer = new StringBuilder();
186    toString(buffer);
187    return buffer.toString();
188  }
189
190
191
192  /**
193   * {@inheritDoc}
194   */
195  public void toString(final StringBuilder buffer)
196  {
197    buffer.append("AbandonRequestProtocolOp(idToAbandon=");
198    buffer.append(idToAbandon);
199    buffer.append(')');
200  }
201}