001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2008 Sun Microsystems, Inc.
025 *      Portions Copyright 2015 ForgeRock AS
026 */
027package org.opends.server.replication.protocol;
028
029/**
030 * This exception should be raised by the un-serialization code of a PDU
031 * (typically the constructor code with a byte[] parameter), when the detected
032 * PDU type (deduced from the first received byte of the message) is a PDU used
033 * in an older version of the replication protocol than the current one, and we
034 * do not support translation from this old version PDU to his matching PDU in
035 * the current protocol version (if it exists). Thus, the code catching this
036 * exception may decide special treatment, depending on the situation. For
037 * instance it may decide to trash the PDU and keep the connection opened, or to
038 * trash the PDU and close the connection...
039 */
040public class NotSupportedOldVersionPDUException extends Exception
041{
042  /** Suppress compile warning. */
043  static final long serialVersionUID = 1739875L;
044  /** Explicit message. */
045  private String msg;
046  /** Protocol version of the pdu. */
047  private short protocolVersion = -1;
048  /** Type of the pdu. */
049  private byte pduType = -1;
050
051  /**
052   * Exception constructor.
053   * @param pduStr PDU description.
054   * @param protocolVersion PDU protocol version.
055   * @param pduType PDU number.
056   */
057  public NotSupportedOldVersionPDUException(String pduStr,
058    short protocolVersion, byte pduType)
059  {
060    super();
061    msg = "Received unsupported " + pduStr + " PDU (" + pduType +
062      ") from protocol version " + protocolVersion;
063    this.protocolVersion = protocolVersion;
064    this.pduType = pduType;
065  }
066
067  /**
068   * Get the PDU message.
069   * @return The PDU message.
070   */
071  public String getMessage()
072  {
073    return msg;
074  }
075
076  /** {@inheritDoc} */
077  @Override
078  public String getLocalizedMessage()
079  {
080    return getMessage();
081  }
082
083  /** {@inheritDoc} */
084  @Override
085  public String toString()
086  {
087    return getMessage();
088  }
089
090  /**
091   * Get the PDU protocol version.
092   * @return The PDU protocol version.
093   */
094  public short getProtocolVersion()
095  {
096    return protocolVersion;
097  }
098
099  /**
100   * Get the PDU type.
101   * @return The PDU type.
102   */
103  public byte getPduType()
104  {
105    return pduType;
106  }
107}