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 2006-2008 Sun Microsystems, Inc.
026 */
027 package org.opends.server.replication.server;
028
029 import java.util.LinkedList;
030
031 import org.opends.server.replication.common.ChangeNumber;
032
033 /**
034 * This class is used to store the list of acks received for
035 * a Given Update Messages.
036 *
037 * The acks are kept only for the update that are marked, hopefully this
038 * should be a limited number of updates and in all cases, LDAP servers
039 * operations are going to be blocked waiting for these acks so they
040 * won't be able to generate a huge number of such messages.
041 *
042 * Therefore, the amount of memory used keeping those changes is not a problem,
043 */
044 public class AckMessageList
045 {
046 // The ChangeNumber of the updates that was acked
047 // or that is waiting acks
048 private ChangeNumber changeNumber;
049
050 // The list of serverIdentifiers for which acks have been received so far
051 // can be empty when no acks have been received
052 private LinkedList<Short> acks;
053
054 private int numExpectedAcks;
055
056 /**
057 * Creates a new AckMessageList for a given ChangeNumber.
058 *
059 * @param changeNumber The ChangeNumber for which the ack list is created.
060 * @param numExpectedAcks The number of acks waited before acking the
061 * original change.
062 */
063 public AckMessageList(ChangeNumber changeNumber, int numExpectedAcks)
064 {
065 acks = new LinkedList<Short>();
066 this.changeNumber = changeNumber;
067 this.numExpectedAcks = numExpectedAcks;
068 }
069
070 /**
071 * Get the ChangeNumber of this Ack Message List.
072 * @return Returns the changeNumber.
073 */
074 public ChangeNumber getChangeNumber()
075 {
076 return changeNumber;
077 }
078
079 /**
080 * Add an ack from a given LDAP server to the ack list.
081 *
082 * @param serverId the identifier of the LDAP server.
083 */
084 public synchronized void addAck(short serverId)
085 {
086 acks.add(serverId);
087 }
088
089 /**
090 * This method can be used to check if all acks have been received for the
091 * ChangeNumber managed by this list.
092 * @return A boolean indicating if all acks have been received for the
093 * ChangeNumber managed by this list.
094 */
095 public boolean completed()
096 {
097 return (acks.size() >= numExpectedAcks);
098 }
099 }