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-2008 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 used by an LDAP server to communicate to the topology 033 * that the generation must be reset for the domain. 034 */ 035public class ResetGenerationIdMsg extends ReplicationMsg 036{ 037 private final long generationId; 038 039 /** 040 * Creates a new message. 041 * @param generationId The new reference value of the generationID. 042 */ 043 public ResetGenerationIdMsg(long generationId) 044 { 045 this.generationId = generationId; 046 } 047 048 /** 049 * Creates a new GenerationIdMessage from its encoded form. 050 * 051 * @param in The byte array containing the encoded form of the 052 * WindowMessage. 053 * @throws DataFormatException If the byte array does not contain a valid 054 * encoded form of the WindowMessage. 055 */ 056 ResetGenerationIdMsg(byte[] in) throws DataFormatException 057 { 058 final ByteArrayScanner scanner = new ByteArrayScanner(in); 059 if (scanner.nextByte() != MSG_TYPE_RESET_GENERATION_ID) 060 { 061 throw new DataFormatException( 062 "input is not a valid GenerationId Message"); 063 } 064 generationId = scanner.nextLongUTF8(); 065 } 066 067 /** {@inheritDoc} */ 068 @Override 069 public byte[] getBytes(short protocolVersion) 070 { 071 final ByteArrayBuilder builder = new ByteArrayBuilder(); 072 builder.appendByte(MSG_TYPE_RESET_GENERATION_ID); 073 builder.appendLongUTF8(generationId); 074 return builder.toByteArray(); 075 } 076 077 /** 078 * Returns the generation Id set in this message. 079 * @return the value of the generation ID. 080 * 081 */ 082 public long getGenerationId() 083 { 084 return this.generationId; 085 } 086 087 /** {@inheritDoc} */ 088 @Override 089 public String toString() 090 { 091 return "ResetGenerationIdMsg content: " + 092 "\ngenerationId: " + generationId; 093 } 094}