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