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 2011-2015 ForgeRock AS 026 */ 027package org.opends.server.replication.common; 028 029import java.util.*; 030 031/** 032 * This class holds information about a DS connected to the topology. This 033 * information is to be exchanged through the replication protocol in topology 034 * messages, to keep every member (RS or DS) of the topology aware of the DS 035 * topology. 036 * <p> 037 * @Immutable 038 */ 039public final class DSInfo 040{ 041 /** DS server id. */ 042 private final int dsId; 043 /** DS server url. */ 044 private final String dsUrl; 045 /** Server id of the RS that the DS is connected to. */ 046 private final int rsId; 047 /** DS Generation Id. */ 048 private final long generationId; 049 /** DS Status. */ 050 private final ServerStatus status; 051 /** Assured replication enabled on DS or not. */ 052 private final boolean assuredFlag; 053 /** DS assured mode (relevant if assured replication enabled). */ 054 private final AssuredMode assuredMode; 055 /** DS safe data level (relevant if assured mode is safe data). */ 056 private final byte safeDataLevel; 057 /** List of referrals URLs exported by the DS. */ 058 private final List<String> refUrls; 059 /** Group id. */ 060 private final byte groupId; 061 /** Protocol version. */ 062 private final short protocolVersion; 063 064 private final Set<String> eclIncludes; 065 private final Set<String> eclIncludesForDeletes; 066 067 068 /** 069 * Creates a new instance of DSInfo with every given info. 070 * 071 * @param dsId 072 * The DS id 073 * @param dsUrl Url of the DS 074 * @param rsId 075 * The RS id the DS is connected to 076 * @param generationId 077 * The generation id the DS is using 078 * @param status 079 * The DS status 080 * @param assuredFlag 081 * DS assured replication enabled or not 082 * @param assuredMode 083 * DS assured mode 084 * @param safeDataLevel 085 * DS safe data level 086 * @param groupId 087 * DS group id 088 * @param refUrls 089 * DS exported referrals URLs 090 * @param eclIncludes 091 * The list of entry attributes to include in the ECL. 092 * @param eclIncludesForDeletes 093 * The list of entry attributes to include in the ECL for deletes. 094 * @param protocolVersion 095 * Protocol version supported by this server. 096 */ 097 public DSInfo(int dsId, String dsUrl, int rsId, long generationId, 098 ServerStatus status, boolean assuredFlag, 099 AssuredMode assuredMode, byte safeDataLevel, byte groupId, 100 Collection<String> refUrls, Collection<String> eclIncludes, 101 Collection<String> eclIncludesForDeletes, short protocolVersion) 102 { 103 this.dsId = dsId; 104 this.dsUrl = dsUrl; 105 this.rsId = rsId; 106 this.generationId = generationId; 107 this.status = status; 108 this.assuredFlag = assuredFlag; 109 this.assuredMode = assuredMode; 110 this.safeDataLevel = safeDataLevel; 111 this.groupId = groupId; 112 this.refUrls = Collections.unmodifiableList(new ArrayList<String>(refUrls)); 113 this.eclIncludes = 114 Collections.unmodifiableSet(new HashSet<String>(eclIncludes)); 115 this.eclIncludesForDeletes = 116 Collections.unmodifiableSet(new HashSet<String>(eclIncludesForDeletes)); 117 this.protocolVersion = protocolVersion; 118 } 119 120 /** 121 * Get the DS id. 122 * @return the DS id 123 */ 124 public int getDsId() 125 { 126 return dsId; 127 } 128 129 /** 130 * Get the DS URL. 131 * @return the DS URL 132 */ 133 public String getDsUrl() 134 { 135 return dsUrl; 136 } 137 138 /** 139 * Get the RS id the DS is connected to. 140 * @return the RS id the DS is connected to 141 */ 142 public int getRsId() 143 { 144 return rsId; 145 } 146 147 /** 148 * Get the generation id DS is using. 149 * @return the generation id DS is using. 150 */ 151 public long getGenerationId() 152 { 153 return generationId; 154 } 155 156 /** 157 * Get the DS status. 158 * @return the DS status 159 */ 160 public ServerStatus getStatus() 161 { 162 return status; 163 } 164 165 /** 166 * Tells if the DS has assured replication enabled. 167 * @return True if the DS has assured replication enabled 168 */ 169 public boolean isAssured() 170 { 171 return assuredFlag; 172 } 173 174 /** 175 * Get the DS assured mode (relevant if DS has assured replication enabled). 176 * @return The DS assured mode 177 */ 178 public AssuredMode getAssuredMode() 179 { 180 return assuredMode; 181 } 182 183 /** 184 * Get the DS safe data level (relevant if assured mode is safe data). 185 * @return The DS safe data level 186 */ 187 public byte getSafeDataLevel() 188 { 189 return safeDataLevel; 190 } 191 192 /** 193 * Get the DS group id. 194 * @return The DS group id 195 */ 196 public byte getGroupId() 197 { 198 return groupId; 199 } 200 201 /** 202 * Get the DS exported URLs for referrals. 203 * @return The DS exported URLs for referrals 204 */ 205 public List<String> getRefUrls() 206 { 207 return refUrls; 208 } 209 210 /** 211 * Get the entry attributes to be included in the ECL. 212 * @return The entry attributes to be included in the ECL. 213 */ 214 public Set<String> getEclIncludes() 215 { 216 return eclIncludes; 217 } 218 219 /** 220 * Get the entry attributes to be included in the ECL for delete operations. 221 * @return The entry attributes to be included in the ECL. 222 */ 223 public Set<String> getEclIncludesForDeletes() 224 { 225 return eclIncludesForDeletes; 226 } 227 228 /** 229 * Get the protocol version supported by this server. 230 * Returns -1 when the protocol version is not known (too old version). 231 * @return The protocol version. 232 */ 233 public short getProtocolVersion() 234 { 235 return protocolVersion; 236 } 237 238 /** 239 * Returns a new instance of {@link DSInfo} with the specified replication 240 * server Id. 241 * 242 * @param rsId 243 * the replication server Id to set on the new DSInfo object. 244 * @return a new instance of {@link DSInfo} with the specified replication 245 * server Id. 246 */ 247 public DSInfo cloneWithReplicationServerId(int rsId) 248 { 249 return new DSInfo(dsId, dsUrl, rsId, generationId, status, assuredFlag, 250 assuredMode, safeDataLevel, groupId, refUrls, eclIncludes, 251 eclIncludesForDeletes, protocolVersion); 252 } 253 254 /** 255 * Test if the passed object is equal to this one. 256 * @param obj The object to test 257 * @return True if both objects are equal 258 */ 259 @Override 260 public boolean equals(Object obj) 261 { 262 if (obj == null) 263 { 264 return false; 265 } 266 if (obj.getClass() != getClass()) 267 { 268 return false; 269 } 270 final DSInfo dsInfo = (DSInfo) obj; 271 return dsId == dsInfo.getDsId() 272 && rsId == dsInfo.getRsId() 273 && generationId == dsInfo.getGenerationId() 274 && status == dsInfo.getStatus() 275 && assuredFlag == dsInfo.isAssured() 276 && assuredMode == dsInfo.getAssuredMode() 277 && safeDataLevel == dsInfo.getSafeDataLevel() 278 && groupId == dsInfo.getGroupId() 279 && protocolVersion == dsInfo.getProtocolVersion() 280 && refUrls.equals(dsInfo.getRefUrls()) 281 && Objects.equals(eclIncludes, dsInfo.getEclIncludes()) 282 && Objects.equals(eclIncludesForDeletes, dsInfo.getEclIncludesForDeletes()); 283 } 284 285 /** 286 * Computes hash code for this object instance. 287 * @return Hash code for this object instance. 288 */ 289 @Override 290 public int hashCode() 291 { 292 int hash = 7; 293 hash = 73 * hash + this.dsId; 294 hash = 73 * hash + this.rsId; 295 hash = 73 * hash + (int) (this.generationId ^ (this.generationId >>> 32)); 296 hash = 73 * hash + (this.status != null ? this.status.hashCode() : 0); 297 hash = 73 * hash + (this.assuredFlag ? 1 : 0); 298 hash = 299 73 * hash + (this.assuredMode != null ? this.assuredMode.hashCode() : 0); 300 hash = 73 * hash + this.safeDataLevel; 301 hash = 73 * hash + (this.refUrls != null ? this.refUrls.hashCode() : 0); 302 hash = 73 * hash + (this.eclIncludes != null ? eclIncludes.hashCode() : 0); 303 hash = 73 * hash + (this.eclIncludesForDeletes != null ? 304 eclIncludesForDeletes.hashCode() : 0); 305 hash = 73 * hash + this.groupId; 306 hash = 73 * hash + this.protocolVersion; 307 return hash; 308 } 309 310 /** 311 * Returns a string representation of the DS info. 312 * @return A string representation of the DS info 313 */ 314 @Override 315 public String toString() 316 { 317 final StringBuilder sb = new StringBuilder(); 318 sb.append("DS id: ").append(dsId); 319 sb.append(" ; DS url: ").append(dsUrl); 320 sb.append(" ; RS id: ").append(rsId); 321 sb.append(" ; Generation id: ").append(generationId); 322 sb.append(" ; Status: ").append(status); 323 sb.append(" ; Assured replication: ").append(assuredFlag); 324 if (assuredFlag) 325 { 326 sb.append(" ; Assured mode: ").append(assuredMode); 327 sb.append(" ; Safe data level: ").append(safeDataLevel); 328 } 329 sb.append(" ; Group id: ").append(groupId); 330 sb.append(" ; Protocol version: ").append(protocolVersion); 331 sb.append(" ; Referral URLs: ").append(refUrls); 332 sb.append(" ; ECL Include: ").append(eclIncludes); 333 sb.append(" ; ECL Include for Deletes: ").append(eclIncludesForDeletes); 334 return sb.toString(); 335 } 336 337}