1 // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. 2 // This source code is licensed under both the GPLv2 (found in the 3 // COPYING file in the root directory) and Apache 2.0 License 4 // (found in the LICENSE.Apache file in the root directory). 5 6 package org.rocksdb; 7 8 /** 9 * Mode for {@link RateLimiter#RateLimiter(long, long, int, RateLimiterMode)}. 10 */ 11 public enum RateLimiterMode { 12 READS_ONLY((byte)0x0), 13 WRITES_ONLY((byte)0x1), 14 ALL_IO((byte)0x2); 15 16 private final byte value; 17 RateLimiterMode(final byte value)18 RateLimiterMode(final byte value) { 19 this.value = value; 20 } 21 22 /** 23 * <p>Returns the byte value of the enumerations value.</p> 24 * 25 * @return byte representation 26 */ getValue()27 public byte getValue() { 28 return value; 29 } 30 31 /** 32 * <p>Get the RateLimiterMode enumeration value by 33 * passing the byte identifier to this method.</p> 34 * 35 * @param byteIdentifier of RateLimiterMode. 36 * 37 * @return AccessHint instance. 38 * 39 * @throws IllegalArgumentException if the access hint for the byteIdentifier 40 * cannot be found 41 */ getRateLimiterMode(final byte byteIdentifier)42 public static RateLimiterMode getRateLimiterMode(final byte byteIdentifier) { 43 for (final RateLimiterMode rateLimiterMode : RateLimiterMode.values()) { 44 if (rateLimiterMode.getValue() == byteIdentifier) { 45 return rateLimiterMode; 46 } 47 } 48 49 throw new IllegalArgumentException( 50 "Illegal value provided for RateLimiterMode."); 51 } 52 } 53