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-2010 Sun Microsystems, Inc.
025 *      Portions Copyright 2012-2014 ForgeRock AS
026 */
027package org.opends.server.replication.common;
028
029/**
030 * This class holds information about a RS connected to the topology. This
031 * information is to be exchanged through the replication protocol in topology
032 * messages, to keep every member DS of the topology aware of the RS topology.
033 * <p>
034 * This class is immutable.
035 */
036public final class RSInfo
037{
038  /** Server id of the RS. */
039  private final int rsServerId;
040  /** Generation Id of the RS. */
041  private final long generationId;
042  /** Group id of the RS. */
043  private final byte groupId;
044  /**
045   * The weight of the RS.
046   * <p>
047   * It is important to keep the default value to 1 so that it is used as
048   * default value for a RS using protocol V3: this default value will be used
049   * in algorithms that use weight.
050   */
051  private final int weight;
052  /** The server URL of the RS. */
053  private final String rsServerURL;
054
055  /**
056   * Creates a new instance of RSInfo with every given info.
057   *
058   * @param rsServerId The RS id
059   * @param rsServerURL Url of the RS
060   * @param generationId The generation id the RS is using
061   * @param groupId RS group id
062   * @param weight RS weight
063   */
064  public RSInfo(int rsServerId, String rsServerURL,
065    long generationId, byte groupId, int weight)
066  {
067    this.rsServerId = rsServerId;
068    this.rsServerURL = rsServerURL;
069    this.generationId = generationId;
070    this.groupId = groupId;
071    this.weight = weight;
072  }
073
074  /**
075   * Get the RS id.
076   * @return the RS id
077   */
078  public int getId()
079  {
080    return rsServerId;
081  }
082
083  /**
084   * Get the generation id RS is using.
085   * @return the generation id RS is using.
086   */
087  public long getGenerationId()
088  {
089    return generationId;
090  }
091
092  /**
093   * Get the RS group id.
094   * @return The RS group id
095   */
096  public byte getGroupId()
097  {
098    return groupId;
099  }
100
101  /**
102   * Get the RS weight.
103   * @return The RS weight
104   */
105  public int getWeight()
106  {
107    return weight;
108  }
109
110
111  /**
112   * Test if the passed object is equal to this one.
113   * @param obj The object to test
114   * @return True if both objects are equal
115   */
116  @Override
117  public boolean equals(Object obj)
118  {
119    if (obj == null)
120    {
121      return false;
122    }
123    if (obj.getClass() != getClass())
124    {
125      return false;
126    }
127    final RSInfo rsInfo = (RSInfo) obj;
128    return rsServerId == rsInfo.getId()
129        && generationId == rsInfo.getGenerationId()
130        && groupId == rsInfo.getGroupId()
131        && weight == rsInfo.getWeight();
132  }
133
134  /**
135   * Computes hash code for this object instance.
136   * @return Hash code for this object instance.
137   */
138  @Override
139  public int hashCode()
140  {
141    int hash = 7;
142    hash = 17 * hash + this.rsServerId;
143    hash = 17 * hash + (int) (this.generationId ^ (this.generationId >>> 32));
144    hash = 17 * hash + this.groupId;
145    hash = 17 * hash + this.weight;
146    return hash;
147  }
148
149  /**
150   * Gets the server URL.
151   * @return the serverUrl
152   */
153  public String getServerUrl()
154  {
155    return rsServerURL;
156  }
157
158  /**
159   * Returns a string representation of the DS info.
160   * @return A string representation of the DS info
161   */
162  @Override
163  public String toString()
164  {
165    return "RS id: " + rsServerId
166        + " ; RS URL: " + rsServerURL
167        + " ; Generation id: " + generationId
168        + " ; Group id: " + groupId
169        + " ; Weight: " + weight;
170  }
171}