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 Sun Microsystems, Inc. 025 * Portions Copyright 2015 ForgeRock AS 026 */ 027package org.opends.admin.ads; 028 029import java.util.HashSet; 030import java.util.Set; 031 032/** 033 * The object of this class represent a topology of replicas across servers that 034 * have the same suffix DN. If there is more than one replica on the suffix, the 035 * contents of the replicas are replicated. 036 */ 037public class SuffixDescriptor 038{ 039 private String suffixDN; 040 private final Set<ReplicaDescriptor> replicas = new HashSet<>(); 041 042 /** 043 * Returns the DN associated with this suffix descriptor. 044 * 045 * @return the DN associated with this suffix descriptor. 046 */ 047 public String getDN() 048 { 049 return suffixDN; 050 } 051 052 /** 053 * Sets the DN associated with this suffix descriptor. 054 * 055 * @param suffixDN 056 * the DN associated with this suffix descriptor. 057 */ 058 public void setDN(String suffixDN) 059 { 060 this.suffixDN = suffixDN; 061 } 062 063 /** 064 * Returns the replicas associated with this SuffixDescriptor. 065 * 066 * @return a Set containing the replicas associated with this 067 * SuffixDescriptor. 068 */ 069 public Set<ReplicaDescriptor> getReplicas() 070 { 071 return new HashSet<>(replicas); 072 } 073 074 /** 075 * Sets the replicas associated with this SuffixDescriptor. 076 * 077 * @param replicas 078 * a Set containing the replicas associated with this 079 * SuffixDescriptor. 080 */ 081 public void setReplicas(Set<ReplicaDescriptor> replicas) 082 { 083 this.replicas.clear(); 084 this.replicas.addAll(replicas); 085 } 086 087 /** 088 * Returns the Set of Replication servers for the whole suffix topology. The 089 * servers are provided in their String representation. 090 * 091 * @return the Set of Replication servers for the whole suffix topology. 092 */ 093 public Set<String> getReplicationServers() 094 { 095 Set<String> replicationServers = new HashSet<>(); 096 for (ReplicaDescriptor replica : getReplicas()) 097 { 098 replicationServers.addAll(replica.getReplicationServers()); 099 } 100 return replicationServers; 101 } 102 103 @Override 104 public int hashCode() 105 { 106 return getId().hashCode(); 107 } 108 109 /** 110 * Returns an Id that is unique for this suffix. 111 * 112 * @return an Id that is unique for this suffix. 113 */ 114 public String getId() 115 { 116 StringBuilder buf = new StringBuilder(); 117 buf.append(getDN()); 118 for (ReplicaDescriptor replica : getReplicas()) 119 { 120 buf.append("-").append(replica.getServer().getId()); 121 } 122 123 return buf.toString(); 124 } 125}