BatchPolicy
Stay organized with collections
Save and categorize content based on your preferences.
Policy for flushing batched requests.
The trigger for uploading a batch of requests is by either the number of requests or the
timeout, whichever comes first. For example, if the batch delay time has expired without the
batch size being reached, or if the batch size number of documents is reached before the delay
time expires, then the batch upload is triggered.
Public Method Summary
static
BatchPolicy
|
|
int
|
|
int
|
|
int
|
getMaxActiveBatches()
Gets maximum number of allowed active batch requests under processing at a given instance.
|
int
|
|
TimeUnit
|
|
int
|
getMaxBatchSize()
Gets maximum number of requests allowed in single batch request.
|
int
|
getQueueLength()
Gets total number of requests allowed to be batched before blocking batching of additional
requests.
|
boolean
|
isFlushOnShutdown()
Gets flag indicating if already enqueued requests would be executed once shutdown is initiated
or already enqueued requests would be marked as cancelled.
|
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()
|
Public Methods
public
static
BatchPolicy
fromConfiguration
()
Creates a batch policy from configuration file parameters.
The configuration file should have parameters in the format of:
- batch.flushOnShutdown = true to flush batched request during service shutdown
- batch.batchSize = 10 number of requests to batch together
- batch.maxBatchDelaySeconds = 5 number of seconds to wait before batched requests are
flushed automatically
- batch.maxQueueLength = 1000 maximum number of requests in batch queue for execution
- batch.maxActiveBatches = 20 number of allowable concurrently executing batches
- batch.readTimeoutSeconds = 120 read timeout in seconds for batch request
- batch.connectTimeoutSeconds = 120 connect timeout in seconds for batch request
public
int
getBatchConnectTimeoutSeconds
()
public
int
getBatchReadTimeoutSeconds
()
public
int
getMaxActiveBatches
()
Gets maximum number of allowed active batch requests under processing at a given instance.
Returns
- Maximum number of allowed active batch requests under processing at a given instance.
public
int
getMaxBatchDelay
()
Gets maximum batch auto flush delay.
Returns
- maximum duration to wait before auto flushing batch.
public
TimeUnit
getMaxBatchDelayUnit
()
Gets TimeUnit
for batch auto flush delay.
public
int
getMaxBatchSize
()
Gets maximum number of requests allowed in single batch request.
Returns
- maximum number of requests allowed in single batch request
public
int
getQueueLength
()
Gets total number of requests allowed to be batched before blocking batching of additional
requests.
Returns
- Total number of requests allowed to be batched before blocking batching of additional
requests.
public
boolean
isFlushOnShutdown
()
Gets flag indicating if already enqueued requests would be executed once shutdown is initiated
or already enqueued requests would be marked as cancelled.
Returns
- true implies already enqueued requests would be executed once shutdown is initiated,
false implies already enqueued requests would be marked as cancelled.
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,["# BatchPolicy\n\npublic class **BatchPolicy** extends Object \nPolicy for flushing batched requests.\n\nThe trigger for uploading a batch of requests is by either the number of requests or the\ntimeout, whichever comes first. For example, if the batch delay time has expired without the\nbatch size being reached, or if the batch size number of documents is reached before the delay\ntime expires, then the batch upload is triggered. \n\n### Nested Class Summary\n\n|-------|---|---|------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| class | [BatchPolicy.Builder](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/BatchPolicy.Builder) || Builder object for creating an instance of [BatchRequest](/workspace/cloud-search/docs/reference/sdk/com/google/api/client/googleapis/batch/BatchRequest). |\n\n### Public Method Summary\n\n|--------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| static [BatchPolicy](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/BatchPolicy) | [fromConfiguration](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/BatchPolicy#fromConfiguration())() Creates a batch policy from configuration file parameters. |\n| int | [getBatchConnectTimeoutSeconds](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/BatchPolicy#getBatchConnectTimeoutSeconds())() Gets connect timeout in seconds for [BatchRequest](/workspace/cloud-search/docs/reference/sdk/com/google/api/client/googleapis/batch/BatchRequest) execution. |\n| int | [getBatchReadTimeoutSeconds](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/BatchPolicy#getBatchReadTimeoutSeconds())() Gets read timeout in seconds for [BatchRequest](/workspace/cloud-search/docs/reference/sdk/com/google/api/client/googleapis/batch/BatchRequest) execution. |\n| int | [getMaxActiveBatches](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/BatchPolicy#getMaxActiveBatches())() Gets maximum number of allowed active batch requests under processing at a given instance. |\n| int | [getMaxBatchDelay](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/BatchPolicy#getMaxBatchDelay())() Gets maximum batch auto flush delay. |\n| TimeUnit | [getMaxBatchDelayUnit](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/BatchPolicy#getMaxBatchDelayUnit())() Gets [TimeUnit](/workspace/cloud-search/docs/reference/sdk/java/util/concurrent/TimeUnit) for batch auto flush delay. |\n| int | [getMaxBatchSize](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/BatchPolicy#getMaxBatchSize())() Gets maximum number of requests allowed in single batch request. |\n| int | [getQueueLength](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/BatchPolicy#getQueueLength())() Gets total number of requests allowed to be batched before blocking batching of additional requests. |\n| boolean | [isFlushOnShutdown](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/BatchPolicy#isFlushOnShutdown())() Gets flag indicating if already enqueued requests would be executed once shutdown is initiated or already enqueued requests would be marked as cancelled. |\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\nPublic Methods\n--------------\n\n#### public static [BatchPolicy](/workspace/cloud-search/docs/reference/sdk/com/google/enterprise/cloudsearch/sdk/BatchPolicy)\n**fromConfiguration**\n()\n\nCreates a batch policy from configuration file parameters.\n\nThe configuration file should have parameters in the format of:\n\n- batch.flushOnShutdown = true to flush batched request during service shutdown\n- batch.batchSize = 10 number of requests to batch together\n- batch.maxBatchDelaySeconds = 5 number of seconds to wait before batched requests are flushed automatically\n- batch.maxQueueLength = 1000 maximum number of requests in batch queue for execution\n- batch.maxActiveBatches = 20 number of allowable concurrently executing batches\n- batch.readTimeoutSeconds = 120 read timeout in seconds for batch request\n- batch.connectTimeoutSeconds = 120 connect timeout in seconds for batch request\n\n\u003cbr /\u003e\n\n#### public int\n**getBatchConnectTimeoutSeconds**\n()\n\nGets connect timeout in seconds for [BatchRequest](/workspace/cloud-search/docs/reference/sdk/com/google/api/client/googleapis/batch/BatchRequest) execution. \n\n##### Returns\n\n- connect timeout in seconds for [BatchRequest](/workspace/cloud-search/docs/reference/sdk/com/google/api/client/googleapis/batch/BatchRequest) execution. \n\n#### public int\n**getBatchReadTimeoutSeconds**\n()\n\nGets read timeout in seconds for [BatchRequest](/workspace/cloud-search/docs/reference/sdk/com/google/api/client/googleapis/batch/BatchRequest) execution. \n\n##### Returns\n\n- read timeout in seconds for [BatchRequest](/workspace/cloud-search/docs/reference/sdk/com/google/api/client/googleapis/batch/BatchRequest) execution. \n\n#### public int\n**getMaxActiveBatches**\n()\n\nGets maximum number of allowed active batch requests under processing at a given instance. \n\n##### Returns\n\n- Maximum number of allowed active batch requests under processing at a given instance. \n\n#### public int\n**getMaxBatchDelay**\n()\n\nGets maximum batch auto flush delay. \n\n##### Returns\n\n- maximum duration to wait before auto flushing batch. \n\n#### public TimeUnit\n**getMaxBatchDelayUnit**\n()\n\nGets [TimeUnit](/workspace/cloud-search/docs/reference/sdk/java/util/concurrent/TimeUnit) for batch auto flush delay. \n\n##### Returns\n\n- [TimeUnit](/workspace/cloud-search/docs/reference/sdk/java/util/concurrent/TimeUnit) for batch auto flush delay \n\n#### public int\n**getMaxBatchSize**\n()\n\nGets maximum number of requests allowed in single batch request. \n\n##### Returns\n\n- maximum number of requests allowed in single batch request \n\n#### public int\n**getQueueLength**\n()\n\nGets total number of requests allowed to be batched before blocking batching of additional\nrequests. \n\n##### Returns\n\n- Total number of requests allowed to be batched before blocking batching of additional requests. \n\n#### public boolean\n**isFlushOnShutdown**\n()\n\nGets flag indicating if already enqueued requests would be executed once shutdown is initiated\nor already enqueued requests would be marked as cancelled. \n\n##### Returns\n\n- true implies already enqueued requests would be executed once shutdown is initiated, false implies already enqueued requests would be marked as cancelled."]]