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