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