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
038     * different locations from the server receiving the change.
039     */
040    @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
041    public enum AssuredReplicationRemoteLevel
042    {
043      /**
044       * Indicates that no remote 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 replication server in a
053       * different location.  Note that this level does not require the change to
054       * have already been processed by any other directory server, but merely
055       * requires that it exist in at least one remote replication server for the
056       * sake of redundancy.  If the client interacts with another remote directory
057       * server immediately after receiving a result with this level of assurance,
058       * there is no guarantee that the associated change will be visible on that
059       * server.
060       */
061      RECEIVED_ANY_REMOTE_LOCATION(1),
062    
063    
064    
065      /**
066       * Indicates that the operation result should not be returned to the client
067       * until the change has been received by at least one replication server in
068       * each of the remote locations.  Note that this level does not require the
069       * change to have already been processed by any other directory server, but
070       * merely requires that it exist in at least one remote replication server in
071       * each remote location for the sake of redundancy.  If the client interacts
072       * with another remote directory server immediately after receiving a result
073       * with this level of assurance, there is no guarantee that the associated
074       * change will be visible on that server.
075       */
076      RECEIVED_ALL_REMOTE_LOCATIONS(2),
077    
078    
079    
080      /**
081       * Indicates that the operation result should not be returned to the client
082       * until the change has been processed by all available servers in all remote
083       * locations.
084       */
085      PROCESSED_ALL_REMOTE_SERVERS(3);
086    
087    
088    
089      // The integer value for this remote assurance level.
090      private final int intValue;
091    
092    
093    
094      /**
095       * Creates a new remote assurance level with the provided integer value.
096       *
097       * @param  intValue  The integer value for this remote assurance level.
098       */
099      AssuredReplicationRemoteLevel(final int intValue)
100      {
101        this.intValue = intValue;
102      }
103    
104    
105    
106      /**
107       * Retrieves integer value for this remote assurance level.
108       *
109       * @return  The integer value for this remote assurance level.
110       */
111      public int intValue()
112      {
113        return intValue;
114      }
115    
116    
117    
118      /**
119       * Retrieves the remote assurance level with the specified integer value.
120       *
121       * @param  intValue  The integer value for the remote assurance level to
122       *                   retrieve.
123       *
124       * @return  The requested remote assurance level, or {@code null} if there is
125       *          no remote assurance level with the specified integer value.
126       */
127      public static AssuredReplicationRemoteLevel valueOf(final int intValue)
128      {
129        for (final AssuredReplicationRemoteLevel l : values())
130        {
131          if (l.intValue == intValue)
132          {
133            return l;
134          }
135        }
136    
137        return null;
138      }
139    
140    
141    
142      /**
143       * Retrieves the less strict of the two provided assured replication remote
144       * level values.  If the two provided values are the same, then that value
145       * will be returned.
146       *
147       * @param  l1  The first value to compare.
148       * @param  l2  The second value to compare.
149       *
150       * @return  The less strict of the two provided assured replication remote
151       *          level values.
152       */
153      public static AssuredReplicationRemoteLevel getLessStrict(
154                         final AssuredReplicationRemoteLevel l1,
155                         final AssuredReplicationRemoteLevel l2)
156      {
157        // At present, the integer values can be used to make the comparison.  If
158        // any more enum values are added, this may need to be changed.
159        if (l1.intValue <= l2.intValue)
160        {
161          return l1;
162        }
163        else
164        {
165          return l2;
166        }
167      }
168    
169    
170    
171      /**
172       * Retrieves the more strict of the two provided assured replication remote
173       * level values.  If the two provided values are the same, then that value
174       * will be returned.
175       *
176       * @param  l1  The first value to compare.
177       * @param  l2  The second value to compare.
178       *
179       * @return  The more strict of the two provided assured replication remote
180       *          level values.
181       */
182      public static AssuredReplicationRemoteLevel getMoreStrict(
183                         final AssuredReplicationRemoteLevel l1,
184                         final AssuredReplicationRemoteLevel l2)
185      {
186        // At present, the integer values can be used to make the comparison.  If
187        // any more enum values are added, this may need to be changed.
188        if (l1.intValue >= l2.intValue)
189        {
190          return l1;
191        }
192        else
193        {
194          return l2;
195        }
196      }
197    }