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-2015 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  public byte getType()
076  {
077    return OP_TYPE_ABANDON_REQUEST;
078  }
079
080
081
082  /**
083   * Retrieves the name for this protocol op type.
084   *
085   * @return  The name for this protocol op type.
086   */
087  public String getProtocolOpName()
088  {
089    return "Abandon Request";
090  }
091
092  /**
093   * Writes this protocol op to an ASN.1 output stream.
094   *
095   * @param stream The ASN.1 output stream to write to.
096   * @throws IOException If a problem occurs while writing to the stream.
097   */
098  public void write(ASN1Writer stream) throws IOException
099  {
100    stream.writeInteger(OP_TYPE_ABANDON_REQUEST, idToAbandon);
101  }
102
103
104  /**
105   * Appends a string representation of this LDAP protocol op to the provided
106   * buffer.
107   *
108   * @param  buffer  The buffer to which the string should be appended.
109   */
110  public void toString(StringBuilder buffer)
111  {
112    buffer.append("AbandonRequest(idToAbandon=");
113    buffer.append(idToAbandon);
114    buffer.append(")");
115  }
116
117
118
119  /**
120   * Appends a multi-line string representation of this LDAP protocol op to the
121   * provided buffer.
122   *
123   * @param  buffer  The buffer to which the information should be appended.
124   * @param  indent  The number of spaces from the margin that the lines should
125   *                 be indented.
126   */
127  public void toString(StringBuilder buffer, int indent)
128  {
129    StringBuilder indentBuf = new StringBuilder(indent);
130    for (int i=0 ; i < indent; i++)
131    {
132      indentBuf.append(' ');
133    }
134
135    buffer.append(indentBuf);
136    buffer.append("Abandon Request");
137    buffer.append(EOL);
138
139    buffer.append(indentBuf);
140    buffer.append("  ID to Abandon:  ");
141    buffer.append(idToAbandon);
142    buffer.append(EOL);
143  }
144}
145