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 2013-2014 ForgeRock AS.
016 */
017package org.opends.server.replication.protocol;
018
019import java.util.zip.DataFormatException;
020
021/**
022 * This message is used by an LDAP server to communicate to the topology
023 * that the generation must be reset for the domain.
024 */
025public class ResetGenerationIdMsg extends ReplicationMsg
026{
027  private final long generationId;
028
029  /**
030   * Creates a new message.
031   * @param generationId The new reference value of the generationID.
032   */
033  public ResetGenerationIdMsg(long generationId)
034  {
035    this.generationId = generationId;
036  }
037
038  /**
039   * Creates a new GenerationIdMessage from its encoded form.
040   *
041   * @param in The byte array containing the encoded form of the
042   *           WindowMessage.
043   * @throws DataFormatException If the byte array does not contain a valid
044   *                             encoded form of the WindowMessage.
045   */
046  ResetGenerationIdMsg(byte[] in) throws DataFormatException
047  {
048    final ByteArrayScanner scanner = new ByteArrayScanner(in);
049    if (scanner.nextByte() != MSG_TYPE_RESET_GENERATION_ID)
050    {
051      throw new DataFormatException(
052          "input is not a valid GenerationId Message");
053    }
054    generationId = scanner.nextLongUTF8();
055  }
056
057  /** {@inheritDoc} */
058  @Override
059  public byte[] getBytes(short protocolVersion)
060  {
061    final ByteArrayBuilder builder = new ByteArrayBuilder();
062    builder.appendByte(MSG_TYPE_RESET_GENERATION_ID);
063    builder.appendLongUTF8(generationId);
064    return builder.toByteArray();
065  }
066
067  /**
068   * Returns the generation Id set in this message.
069   * @return the value of the generation ID.
070   *
071   */
072  public long getGenerationId()
073  {
074    return this.generationId;
075  }
076
077  /** {@inheritDoc} */
078  @Override
079  public String toString()
080  {
081    return "ResetGenerationIdMsg content: " +
082      "\ngenerationId: " + generationId;
083  }
084}