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-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. RS1 sends a 033 * MonitorRequestMsg to RS2 to request its monitoring information. When RS2 034 * receives a MonitorRequestMsg from RS1, RS2 responds with a MonitorMessage. 035 */ 036public class MonitorRequestMsg extends ReplicationMsg 037{ 038 /** 039 * The destination server or servers of this message. 040 */ 041 private final int destination; 042 043 /** 044 * The serverID of the server that sends this message. 045 */ 046 private final int senderID; 047 048 /** 049 * Creates a message. 050 * 051 * @param serverID 052 * The sender server of this message. 053 * @param destination 054 * The server or servers targeted by this message. 055 */ 056 public MonitorRequestMsg(int serverID, int destination) 057 { 058 this.senderID = serverID; 059 this.destination = destination; 060 } 061 062 063 064 /** 065 * Creates a new message by decoding the provided byte array. 066 * 067 * @param in 068 * A byte array containing the encoded information for the message, 069 * @throws DataFormatException 070 * If the in does not contain a properly, encoded message. 071 */ 072 MonitorRequestMsg(byte[] in) throws DataFormatException 073 { 074 final ByteArrayScanner scanner = new ByteArrayScanner(in); 075 final byte msgType = scanner.nextByte(); 076 if (msgType != MSG_TYPE_REPL_SERVER_MONITOR_REQUEST) 077 { 078 throw new DataFormatException("input is not a valid " 079 + getClass().getCanonicalName()); 080 } 081 this.senderID = scanner.nextIntUTF8(); 082 this.destination = scanner.nextIntUTF8(); 083 } 084 085 /** {@inheritDoc} */ 086 @Override 087 public byte[] getBytes(short protocolVersion) 088 { 089 final ByteArrayBuilder builder = new ByteArrayBuilder(); 090 builder.appendByte(MSG_TYPE_REPL_SERVER_MONITOR_REQUEST); 091 builder.appendIntUTF8(senderID); 092 builder.appendIntUTF8(destination); 093 return builder.toByteArray(); 094 } 095 096 /** 097 * Get the destination. 098 * 099 * @return the destination 100 */ 101 public int getDestination() 102 { 103 return destination; 104 } 105 106 /** 107 * Get the server ID of the server that sent this message. 108 * 109 * @return the server id 110 */ 111 public int getSenderID() 112 { 113 return senderID; 114 } 115 116 /** 117 * Returns a string representation of the message. 118 * 119 * @return the string representation of this message. 120 */ 121 @Override 122 public String toString() 123 { 124 return "[" + getClass().getCanonicalName() + " sender=" + senderID 125 + " destination=" + destination + "]"; 126 } 127}