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-2010 Sun Microsystems, Inc. 015 * Portions copyright 2014-2016 ForgeRock AS. 016 */ 017package org.opends.server.replication.protocol; 018 019/** 020 * This is an abstract class of messages of the replication protocol for message 021 * that needs to contain information about the server that send them and the 022 * destination servers to which they should be sent. 023 * <p> 024 * Routable messages are used when initializing a new replica from an existing 025 * replica: the total update messages are sent across the topology from the 026 * source replica to the target replica, possibly traversing one or two 027 * replication servers in the process (e.g. DS1 -> RS1 -> RS2 -> DS2). 028 */ 029public abstract class RoutableMsg extends ReplicationMsg 030{ 031 /* Special values for the server ids fields contained in the routable messages. */ 032 033 /** Specifies that no server is identified. */ 034 public static final int UNKNOWN_SERVER = -1; 035 /** Specifies all servers in the replication domain. */ 036 public static final int ALL_SERVERS = -2; 037 /** 038 * Inside a topology of servers in the same domain, it specifies 039 * the server that is the "closest" to the sender. 040 */ 041 public static final int THE_CLOSEST_SERVER = -3; 042 043 /** The destination server or servers of this message. */ 044 protected int destination = UNKNOWN_SERVER; 045 /** The serverID of the server that sends this message. */ 046 protected int senderID = UNKNOWN_SERVER; 047 048 /** 049 * Creates a routable message. 050 * @param serverID replication server id 051 * @param destination replication server id 052 */ 053 public RoutableMsg(int serverID, int destination) 054 { 055 this.senderID = serverID; 056 this.destination = destination; 057 } 058 059 /** Creates a routable message. */ 060 public RoutableMsg() 061 { 062 } 063 064 /** 065 * Get the destination. The value is a serverId, or ALL_SERVERS dedicated 066 * value. 067 * @return the destination 068 */ 069 public int getDestination() 070 { 071 return this.destination; 072 } 073 074 /** 075 * Get the server ID of the server that sent this message. 076 * @return the server id 077 */ 078 public int getSenderID() 079 { 080 return this.senderID; 081 } 082 083 /** 084 * Returns a string representation of the message. 085 * 086 * @return the string representation of this message. 087 */ 088 @Override 089 public String toString() 090 { 091 return "[" + getClass().getCanonicalName() + 092 " sender=" + this.senderID + 093 " destination=" + this.destination + "]"; 094 } 095}