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