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