QuotaServer
Stay organized with collections
Save and categorize content based on your preferences.
Utility object to enforce quota requirements.
Create an instance to enforce individual quota maximums on a set of operations defined by an
enumeration. Before executing a quota restricted operation, call the acquire(T)
method to restrict the rate at which the operation is allowed to execute. Internally, quota is
enforced using a RateLimiter
object. The calling thread is blocked if the token cannot be
granted immediately.
Public Method Summary
double
|
acquire(T operation)
Acquires a token before allowing an operation to execute.
|
static
<T extends Enum<T>>
QuotaServer<T>
|
|
double
|
getRate(T operation)
Returns current QPS rate limit for the specified enumeration operation.
|
Inherited Method Summary
From class
java.lang.Object
boolean
|
equals(Object arg0)
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
Constants
public
static
final
double
DEFAULT_QPS
Public Methods
public
double
acquire
(T operation)
Acquires a token before allowing an operation to execute.
Note: The calling thread is blocked if the token cannot be granted immediately.
Parameters
operation |
the enumeration operation to rate limit base on its quota |
Returns
- time spent sleeping to enforce quota in seconds (0.0 if not rate limited)
public
static
QuotaServer<T>
createFromConfiguration
(String quotaPrefix, Class<T> enumClass)
Creates a QuotaServer
instance using parameter values from the configuration file.
The configuration file should have QPS value parameters in the format of:
- quotaServer.[quotaPrefix].defaultQps = 10
- quotaServer.[quotaPrefix].ENUM_OPERATION1 = 2;
- quotaServer.[quotaPrefix].ENUM_OPERATION2 = 5;
- quotaServer.[quotaPrefix].ENUM_OPERATION3 = 20;
Where quotaPrefix
is defined by the connector and the ENUM_*
values are
operation types defined in an enumeration. Any unspecified ENUM_*
values take the QPS
value from the defaultQps
parameter.
Parameters
quotaPrefix |
prefix for configuration keys related to quota server parameters |
enumClass |
class for enumerations representing operations |
public
double
getRate
(T operation)
Returns current QPS rate limit for the specified enumeration operation.
Parameters
operation |
for rate limit lookup |
Returns
- current configured rate limit for the operation
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-03-18 UTC.
[null,null,["Last updated 2025-03-18 UTC."],[],[],null,["# QuotaServer\n\npublic class **QuotaServer** extends Object \nUtility object to enforce quota requirements.\n\nCreate an instance to enforce individual quota maximums on a set of operations defined by an\nenumeration. Before executing a quota restricted operation, call the [acquire(T)](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/QuotaServer#acquire(T))\nmethod to restrict the rate at which the operation is allowed to execute. Internally, quota is\nenforced using a [RateLimiter](/workspace/cloud-search/docs/reference/sdk/com/google/common/util/concurrent/RateLimiter) object. The calling thread is blocked if the token cannot be\ngranted immediately. \n\n### Nested Class Summary\n\n|-------|---|---|------------------------------------------------------------------------------------------------------------------------------------|\n| class | [QuotaServer.Builder](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/QuotaServer.Builder)\\\u003cT extends Enum\\\u003cT\\\u003e, K extends [QuotaServer](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/QuotaServer)\\\u003cT\\\u003e\\\u003e || Builder for [QuotaServer](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/QuotaServer) instances. |\n\n### Constant Summary\n\n|--------|-------------------------------------------------------------------------------------------------------------------------|---|\n| double | [DEFAULT_QPS](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/QuotaServer#DEFAULT_QPS) | |\n\n### Public Method Summary\n\n|-------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| double | [acquire](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/QuotaServer#acquire(T))(T operation) Acquires a token before allowing an operation to execute. |\n| static \\\u003cT extends Enum\\\u003cT\\\u003e\\\u003e [QuotaServer](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/QuotaServer)\\\u003cT\\\u003e | [createFromConfiguration](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/QuotaServer#createFromConfiguration(java.lang.String, java.lang.Class\u003cT\u003e))(String quotaPrefix, Class\\\u003cT\\\u003e enumClass) Creates a [QuotaServer](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/QuotaServer) instance using parameter values from the configuration file. |\n| double | [getRate](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/QuotaServer#getRate(T))(T operation) Returns current QPS rate limit for the specified enumeration operation. |\n\n### Inherited Method Summary\n\nFrom class java.lang.Object \n\n|------------------|---------------------------|\n| boolean | equals(Object arg0) |\n| final Class\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| String | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nConstants\n---------\n\n#### public static final double\n**DEFAULT_QPS**\n\n\u003cbr /\u003e\n\nConstant Value: 10.0\n\nPublic Methods\n--------------\n\n#### public double\n**acquire**\n(T operation)\n\nAcquires a token before allowing an operation to execute.\n\nNote: The calling thread is blocked if the token cannot be granted immediately. \n\n##### Parameters\n\n| operation | the enumeration operation to rate limit base on its quota |\n|-----------|-----------------------------------------------------------|\n\n##### Returns\n\n- time spent sleeping to enforce quota in seconds (0.0 if not rate limited) \n\n#### public static [QuotaServer](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/QuotaServer)\\\u003cT\\\u003e\n**createFromConfiguration**\n(String quotaPrefix, Class\\\u003cT\\\u003e enumClass)\n\nCreates a [QuotaServer](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/QuotaServer) instance using parameter values from the configuration file.\n\nThe configuration file should have QPS value parameters in the format of:\n\n- quotaServer.\\[quotaPrefix\\].defaultQps = 10\n- quotaServer.\\[quotaPrefix\\].ENUM_OPERATION1 = 2;\n- quotaServer.\\[quotaPrefix\\].ENUM_OPERATION2 = 5;\n- quotaServer.\\[quotaPrefix\\].ENUM_OPERATION3 = 20;\n\nWhere `quotaPrefix` is defined by the connector and the `ENUM_*` values are\noperation types defined in an enumeration. Any unspecified `ENUM_*` values take the QPS\nvalue from the `defaultQps` parameter. \n\n##### Parameters\n\n| quotaPrefix | prefix for configuration keys related to quota server parameters |\n| enumClass | class for enumerations representing operations |\n|-------------|------------------------------------------------------------------|\n\n##### Returns\n\n- a [QuotaServer](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/QuotaServer) instance \n\n#### public double\n**getRate**\n(T operation)\n\nReturns current QPS rate limit for the specified enumeration operation. \n\n##### Parameters\n\n| operation | for rate limit lookup |\n|-----------|-----------------------|\n\n##### Returns\n\n- current configured rate limit for the operation"]]