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
010     * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011     * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012     * See the License for the specific language governing permissions
013     * and limitations under the License.
014     *
015     * When distributing Covered Code, include this CDDL HEADER in each
016     * file and include the License file at
017     * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
018     * add the following below this CDDL HEADER, with the fields enclosed
019     * by brackets "[]" replaced with your own identifying information:
020     *      Portions Copyright [yyyy] [name of copyright owner]
021     *
022     * CDDL HEADER END
023     *
024     *
025     *      Copyright 2006-2008 Sun Microsystems, Inc.
026     */
027    package org.opends.server.replication.protocol;
028    
029    import java.io.Serializable;
030    
031    /**
032     * This is an abstract class of messages of the replication protocol
033     * for message that needs to contain information about the server that
034     * send them and the destination servers to whitch they should be sent.
035     */
036    public abstract class RoutableMessage extends ReplicationMessage implements
037        Serializable
038    {
039    
040      /**
041       *  Special values for the server ids fields contained in the routable
042       *  messages.
043       **/
044    
045      /**
046       *  Specifies that no server is identified.
047       */
048      public static final short UNKNOWN_SERVER      = -1;
049      /**
050       * Specifies all servers in the replication domain.
051       */
052      public static final short ALL_SERVERS         = -2;
053      /**
054       * Inside a topology of servers in the same domain, it specifies
055       * the server that is the "closest" to the sender.
056       */
057      public static final short THE_CLOSEST_SERVER  = -3;
058    
059      /**
060       * The destination server or servers of this message.
061       */
062      protected short destination = UNKNOWN_SERVER;
063      /**
064       * The serverID of the server that sends this message.
065       */
066      protected short senderID = UNKNOWN_SERVER;
067    
068      /**
069       * Creates a routable message.
070       * @param senderID replication server id
071       * @param destination replication server id
072       */
073      public RoutableMessage(short senderID, short destination)
074      {
075        this.senderID = senderID;
076        this.destination = destination;
077      }
078    
079      /**
080       * Creates a routable message.
081       */
082      public RoutableMessage()
083      {
084      }
085    
086      /**
087       * Get the destination.
088       * @return the destination
089       */
090      public short getDestination()
091      {
092        return this.destination;
093      }
094    
095      /**
096       * Get the server ID of the server that sent this message.
097       * @return the server id
098       */
099      public short getsenderID()
100      {
101        return this.senderID;
102      }
103    
104      /**
105       * Returns a string representation of the message.
106       *
107       * @return the string representation of this message.
108       */
109      public String toString()
110      {
111        return "["+
112          this.getClass().getCanonicalName() +
113          " sender=" + this.senderID +
114          " destination=" + this.destination + "]";
115      }
116    }