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-2009 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 part of the replication protocol.
023 * This message is sent by a server to one or several other servers after the
024 * last entry sent in the context of a total update and signals to the server
025 * that receives it that the export is now finished.
026 */
027public class DoneMsg extends RoutableMsg
028{
029  /**
030   * Creates a message.
031   *
032   * @param serverID The sender server of this message.
033   * @param i The server or servers targeted by this message.
034   */
035  public DoneMsg(int serverID, int i)
036  {
037    super(serverID, i);
038  }
039
040  /**
041   * Creates a new message by decoding the provided byte array.
042   * @param in A byte array containing the encoded information for the message,
043   * @throws DataFormatException If the in does not contain a properly,
044   *                             encoded message.
045   */
046  DoneMsg(byte[] in) throws DataFormatException
047  {
048    final ByteArrayScanner scanner = new ByteArrayScanner(in);
049    final byte msgType = scanner.nextByte();
050    if (msgType != MSG_TYPE_DONE)
051    {
052      throw new DataFormatException("input is not a valid DoneMessage");
053    }
054    this.senderID = scanner.nextIntUTF8();
055    this.destination = scanner.nextIntUTF8();
056  }
057
058  /** {@inheritDoc} */
059  @Override
060  public byte[] getBytes(short protocolVersion)
061  {
062    final ByteArrayBuilder builder = new ByteArrayBuilder();
063    builder.appendByte(MSG_TYPE_DONE);
064    builder.appendIntUTF8(senderID);
065    builder.appendIntUTF8(destination);
066    return builder.toByteArray();
067  }
068}