001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2006-2008 Sun Microsystems, Inc.
015 * Portions Copyright 2014-2016 ForgeRock AS.
016 */
017package org.opends.server.protocols.ldap;
018
019
020
021import org.forgerock.opendj.io.ASN1Writer;
022
023import org.forgerock.i18n.slf4j.LocalizedLogger;
024import static org.opends.server.protocols.ldap.LDAPConstants.*;
025import static org.opends.server.util.ServerConstants.*;
026
027import java.io.IOException;
028
029
030/**
031 * This class defines the structures and methods for an LDAP abandon request
032 * protocol op, which is used to indicate that the server should stop processing
033 * a previously requested operation.
034 */
035public class AbandonRequestProtocolOp
036       extends ProtocolOp
037{
038  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
039
040  /** The message ID of the operation to abandon. */
041  private int idToAbandon;
042
043
044
045  /**
046   * Creates a new abandon request protocol op to abandon the specified
047   * operation.
048   *
049   * @param  idToAbandon  The message ID of the operation to abandon.
050   */
051  public AbandonRequestProtocolOp(int idToAbandon)
052  {
053    this.idToAbandon = idToAbandon;
054  }
055
056
057
058  /**
059   * Retrieves the message ID of the operation to abandon.
060   *
061   * @return  The message ID of the operation to abandon.
062   */
063  public int getIDToAbandon()
064  {
065    return idToAbandon;
066  }
067
068
069
070  /**
071   * Retrieves the BER type for this protocol op.
072   *
073   * @return  The BER type for this protocol op.
074   */
075  @Override
076  public byte getType()
077  {
078    return OP_TYPE_ABANDON_REQUEST;
079  }
080
081
082
083  /**
084   * Retrieves the name for this protocol op type.
085   *
086   * @return  The name for this protocol op type.
087   */
088  @Override
089  public String getProtocolOpName()
090  {
091    return "Abandon Request";
092  }
093
094  /**
095   * Writes this protocol op to an ASN.1 output stream.
096   *
097   * @param stream The ASN.1 output stream to write to.
098   * @throws IOException If a problem occurs while writing to the stream.
099   */
100  @Override
101  public void write(ASN1Writer stream) throws IOException
102  {
103    stream.writeInteger(OP_TYPE_ABANDON_REQUEST, idToAbandon);
104  }
105
106
107  /**
108   * Appends a string representation of this LDAP protocol op to the provided
109   * buffer.
110   *
111   * @param  buffer  The buffer to which the string should be appended.
112   */
113  @Override
114  public void toString(StringBuilder buffer)
115  {
116    buffer.append("AbandonRequest(idToAbandon=");
117    buffer.append(idToAbandon);
118    buffer.append(")");
119  }
120
121
122
123  /**
124   * Appends a multi-line string representation of this LDAP protocol op to the
125   * provided buffer.
126   *
127   * @param  buffer  The buffer to which the information should be appended.
128   * @param  indent  The number of spaces from the margin that the lines should
129   *                 be indented.
130   */
131  @Override
132  public void toString(StringBuilder buffer, int indent)
133  {
134    StringBuilder indentBuf = new StringBuilder(indent);
135    for (int i=0 ; i < indent; i++)
136    {
137      indentBuf.append(' ');
138    }
139
140    buffer.append(indentBuf);
141    buffer.append("Abandon Request");
142    buffer.append(EOL);
143
144    buffer.append(indentBuf);
145    buffer.append("  ID to Abandon:  ");
146    buffer.append(idToAbandon);
147    buffer.append(EOL);
148  }
149}
150