001    /*
002     * Copyright 2013-2015 UnboundID Corp.
003     * All Rights Reserved.
004     */
005    /*
006     * Copyright (C) 2015 UnboundID Corp.
007     *
008     * This program is free software; you can redistribute it and/or modify
009     * it under the terms of the GNU General Public License (GPLv2 only)
010     * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011     * as published by the Free Software Foundation.
012     *
013     * This program is distributed in the hope that it will be useful,
014     * but WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016     * GNU General Public License for more details.
017     *
018     * You should have received a copy of the GNU General Public License
019     * along with this program; if not, see <http://www.gnu.org/licenses>.
020     */
021    package com.unboundid.ldap.sdk.unboundidds.controls;
022    
023    
024    
025    import com.unboundid.util.ThreadSafety;
026    import com.unboundid.util.ThreadSafetyLevel;
027    
028    
029    
030    /**
031     * <BLOCKQUOTE>
032     *   <B>NOTE:</B>  This class is part of the Commercial Edition of the UnboundID
033     *   LDAP SDK for Java.  It is not available for use in applications that
034     *   include only the Standard Edition of the LDAP SDK, and is not supported for
035     *   use in conjunction with non-UnboundID products.
036     * </BLOCKQUOTE>
037     * This enum defines an assurance level that may be used for servers in the
038     * same location as the server receiving the change.
039     */
040    @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
041    public enum AssuredReplicationLocalLevel
042    {
043      /**
044       * Indicates that no local assurance is desired for the associated operation.
045       */
046      NONE(0),
047    
048    
049    
050      /**
051       * Indicates that the operation result should not be returned to the client
052       * until the change has been received by at least one other replication server
053       * in same location.  Note that this level does not require the change to have
054       * already been processed by any other directory server, but merely requires
055       * that it exist in at least one other replication server for the sake of
056       * redundancy.  If the client interacts with another local directory server
057       * immediately after receiving a result with this level of assurance, there is
058       * no guarantee that the associated change will be visible on that server.
059       */
060      RECEIVED_ANY_SERVER(1),
061    
062    
063    
064      /**
065       * Indicates that the operation result should not be returned to the client
066       * until the change has been processed by all available directory servers in
067       * the same location as the original server.
068       */
069      PROCESSED_ALL_SERVERS(2);
070    
071    
072    
073      // The integer value for this local assurance level.
074      private final int intValue;
075    
076    
077    
078      /**
079       * Creates a new local assurance level with the provided integer value.
080       *
081       * @param  intValue  The integer value for this local assurance level.
082       */
083      AssuredReplicationLocalLevel(final int intValue)
084      {
085        this.intValue = intValue;
086      }
087    
088    
089    
090      /**
091       * Retrieves integer value for this local assurance level.
092       *
093       * @return  The integer value for this local assurance level.
094       */
095      public int intValue()
096      {
097        return intValue;
098      }
099    
100    
101    
102      /**
103       * Retrieves the local assurance level with the specified integer value.
104       *
105       * @param  intValue  The integer value for the local assurance level to
106       *                   retrieve.
107       *
108       * @return  The requested local assurance level, or {@code null} if there is
109       *          no local assurance level with the specified integer value.
110       */
111      public static AssuredReplicationLocalLevel valueOf(final int intValue)
112      {
113        for (final AssuredReplicationLocalLevel l : values())
114        {
115          if (l.intValue == intValue)
116          {
117            return l;
118          }
119        }
120    
121        return null;
122      }
123    
124    
125    
126      /**
127       * Retrieves the less strict of the two provided assured replication local
128       * level values.  If the two provided values are the same, then that value
129       * will be returned.
130       *
131       * @param  l1  The first value to compare.
132       * @param  l2  The second value to compare.
133       *
134       * @return  The less strict of the two provided assured replication local
135       *          level values.
136       */
137      public static AssuredReplicationLocalLevel getLessStrict(
138                         final AssuredReplicationLocalLevel l1,
139                         final AssuredReplicationLocalLevel l2)
140      {
141        // At present, the integer values can be used to make the comparison.  If
142        // any more enum values are added, this may need to be changed.
143        if (l1.intValue <= l2.intValue)
144        {
145          return l1;
146        }
147        else
148        {
149          return l2;
150        }
151      }
152    
153    
154    
155      /**
156       * Retrieves the more strict of the two provided assured replication local
157       * level values.  If the two provided values are the same, then that value
158       * will be returned.
159       *
160       * @param  l1  The first value to compare.
161       * @param  l2  The second value to compare.
162       *
163       * @return  The more strict of the two provided assured replication local
164       *          level values.
165       */
166      public static AssuredReplicationLocalLevel getMoreStrict(
167                         final AssuredReplicationLocalLevel l1,
168                         final AssuredReplicationLocalLevel l2)
169      {
170        // At present, the integer values can be used to make the comparison.  If
171        // any more enum values are added, this may need to be changed.
172        if (l1.intValue >= l2.intValue)
173        {
174          return l1;
175        }
176        else
177        {
178          return l2;
179        }
180      }
181    }