@BetaApi @Generated(value="by gapic-generator-java") public class ChunkServiceClient extends Object implements com.google.api.gax.core.BackgroundResource
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ChunkServiceClient chunkServiceClient = ChunkServiceClient.create()) {
ChunkName name =
ChunkName.ofProjectLocationDataStoreBranchDocumentChunkName(
"[PROJECT]", "[LOCATION]", "[DATA_STORE]", "[BRANCH]", "[DOCUMENT]", "[CHUNK]");
Chunk response = chunkServiceClient.getChunk(name);
}
Note: close() needs to be called on the ChunkServiceClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
| Method | Description | Method Variants |
|---|---|---|
GetChunk |
Gets a [Document][google.cloud.discoveryengine.v1alpha.Document]. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
ListChunks |
Gets a list of [Chunk][google.cloud.discoveryengine.v1alpha.Chunk]s. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of ChunkServiceSettings to create(). For example:
To customize credentials:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
ChunkServiceSettings chunkServiceSettings =
ChunkServiceSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
ChunkServiceClient chunkServiceClient = ChunkServiceClient.create(chunkServiceSettings);
To customize the endpoint:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
ChunkServiceSettings chunkServiceSettings =
ChunkServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
ChunkServiceClient chunkServiceClient = ChunkServiceClient.create(chunkServiceSettings);
To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
ChunkServiceSettings chunkServiceSettings = ChunkServiceSettings.newHttpJsonBuilder().build();
ChunkServiceClient chunkServiceClient = ChunkServiceClient.create(chunkServiceSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
| Modifier and Type | Class and Description |
|---|---|
static class |
ChunkServiceClient.ListChunksFixedSizeCollection |
static class |
ChunkServiceClient.ListChunksPage |
static class |
ChunkServiceClient.ListChunksPagedResponse |
| Modifier | Constructor and Description |
|---|---|
protected |
ChunkServiceClient(ChunkServiceSettings settings)
Constructs an instance of ChunkServiceClient, using the given settings.
|
protected |
ChunkServiceClient(ChunkServiceStub stub) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
awaitTermination(long duration,
TimeUnit unit) |
void |
close() |
static ChunkServiceClient |
create()
Constructs an instance of ChunkServiceClient with default settings.
|
static ChunkServiceClient |
create(ChunkServiceSettings settings)
Constructs an instance of ChunkServiceClient, using the given settings.
|
static ChunkServiceClient |
create(ChunkServiceStub stub)
Constructs an instance of ChunkServiceClient, using the given stub for making calls.
|
Chunk |
getChunk(ChunkName name)
Gets a [Document][google.cloud.discoveryengine.v1alpha.Document].
|
Chunk |
getChunk(GetChunkRequest request)
Gets a [Document][google.cloud.discoveryengine.v1alpha.Document].
|
Chunk |
getChunk(String name)
Gets a [Document][google.cloud.discoveryengine.v1alpha.Document].
|
com.google.api.gax.rpc.UnaryCallable<GetChunkRequest,Chunk> |
getChunkCallable()
Gets a [Document][google.cloud.discoveryengine.v1alpha.Document].
|
ChunkServiceSettings |
getSettings() |
ChunkServiceStub |
getStub() |
boolean |
isShutdown() |
boolean |
isTerminated() |
ChunkServiceClient.ListChunksPagedResponse |
listChunks(DocumentName parent)
Gets a list of [Chunk][google.cloud.discoveryengine.v1alpha.Chunk]s.
|
ChunkServiceClient.ListChunksPagedResponse |
listChunks(ListChunksRequest request)
Gets a list of [Chunk][google.cloud.discoveryengine.v1alpha.Chunk]s.
|
ChunkServiceClient.ListChunksPagedResponse |
listChunks(String parent)
Gets a list of [Chunk][google.cloud.discoveryengine.v1alpha.Chunk]s.
|
com.google.api.gax.rpc.UnaryCallable<ListChunksRequest,ListChunksResponse> |
listChunksCallable()
Gets a list of [Chunk][google.cloud.discoveryengine.v1alpha.Chunk]s.
|
com.google.api.gax.rpc.UnaryCallable<ListChunksRequest,ChunkServiceClient.ListChunksPagedResponse> |
listChunksPagedCallable()
Gets a list of [Chunk][google.cloud.discoveryengine.v1alpha.Chunk]s.
|
void |
shutdown() |
void |
shutdownNow() |
protected ChunkServiceClient(ChunkServiceSettings settings) throws IOException
IOExceptionprotected ChunkServiceClient(ChunkServiceStub stub)
public static final ChunkServiceClient create() throws IOException
IOExceptionpublic static final ChunkServiceClient create(ChunkServiceSettings settings) throws IOException
IOExceptionpublic static final ChunkServiceClient create(ChunkServiceStub stub)
public final ChunkServiceSettings getSettings()
public ChunkServiceStub getStub()
public final Chunk getChunk(ChunkName name)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ChunkServiceClient chunkServiceClient = ChunkServiceClient.create()) {
ChunkName name =
ChunkName.ofProjectLocationDataStoreBranchDocumentChunkName(
"[PROJECT]", "[LOCATION]", "[DATA_STORE]", "[BRANCH]", "[DOCUMENT]", "[CHUNK]");
Chunk response = chunkServiceClient.getChunk(name);
}
name - Required. Full resource name of
[Chunk][google.cloud.discoveryengine.v1alpha.Chunk], such as
`projects/{project}/locations/{location}/collections/{collection}/dataStores/{data_store}/branches/{branch}/documents/{document}/chunks/{chunk}`.
If the caller does not have permission to access the [Chunk][google.cloud.discoveryengine.v1alpha.Chunk], regardless of whether or not it exists, a `PERMISSION_DENIED` error is returned.
If the requested [Chunk][google.cloud.discoveryengine.v1alpha.Chunk] does not exist, a `NOT_FOUND` error is returned.
com.google.api.gax.rpc.ApiException - if the remote call failspublic final Chunk getChunk(String name)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ChunkServiceClient chunkServiceClient = ChunkServiceClient.create()) {
String name =
ChunkName.ofProjectLocationDataStoreBranchDocumentChunkName(
"[PROJECT]", "[LOCATION]", "[DATA_STORE]", "[BRANCH]", "[DOCUMENT]", "[CHUNK]")
.toString();
Chunk response = chunkServiceClient.getChunk(name);
}
name - Required. Full resource name of
[Chunk][google.cloud.discoveryengine.v1alpha.Chunk], such as
`projects/{project}/locations/{location}/collections/{collection}/dataStores/{data_store}/branches/{branch}/documents/{document}/chunks/{chunk}`.
If the caller does not have permission to access the [Chunk][google.cloud.discoveryengine.v1alpha.Chunk], regardless of whether or not it exists, a `PERMISSION_DENIED` error is returned.
If the requested [Chunk][google.cloud.discoveryengine.v1alpha.Chunk] does not exist, a `NOT_FOUND` error is returned.
com.google.api.gax.rpc.ApiException - if the remote call failspublic final Chunk getChunk(GetChunkRequest request)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ChunkServiceClient chunkServiceClient = ChunkServiceClient.create()) {
GetChunkRequest request =
GetChunkRequest.newBuilder()
.setName(
ChunkName.ofProjectLocationDataStoreBranchDocumentChunkName(
"[PROJECT]",
"[LOCATION]",
"[DATA_STORE]",
"[BRANCH]",
"[DOCUMENT]",
"[CHUNK]")
.toString())
.build();
Chunk response = chunkServiceClient.getChunk(request);
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<GetChunkRequest,Chunk> getChunkCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ChunkServiceClient chunkServiceClient = ChunkServiceClient.create()) {
GetChunkRequest request =
GetChunkRequest.newBuilder()
.setName(
ChunkName.ofProjectLocationDataStoreBranchDocumentChunkName(
"[PROJECT]",
"[LOCATION]",
"[DATA_STORE]",
"[BRANCH]",
"[DOCUMENT]",
"[CHUNK]")
.toString())
.build();
ApiFuture<Chunk> future = chunkServiceClient.getChunkCallable().futureCall(request);
// Do something.
Chunk response = future.get();
}
public final ChunkServiceClient.ListChunksPagedResponse listChunks(DocumentName parent)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ChunkServiceClient chunkServiceClient = ChunkServiceClient.create()) {
DocumentName parent =
DocumentName.ofProjectLocationDataStoreBranchDocumentName(
"[PROJECT]", "[LOCATION]", "[DATA_STORE]", "[BRANCH]", "[DOCUMENT]");
for (Chunk element : chunkServiceClient.listChunks(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent - Required. The parent document resource name, such as
`projects/{project}/locations/{location}/collections/{collection}/dataStores/{data_store}/branches/{branch}/documents/{document}`.
If the caller does not have permission to list [Chunk][google.cloud.discoveryengine.v1alpha.Chunk]s under this document, regardless of whether or not this document exists, a `PERMISSION_DENIED` error is returned.
com.google.api.gax.rpc.ApiException - if the remote call failspublic final ChunkServiceClient.ListChunksPagedResponse listChunks(String parent)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ChunkServiceClient chunkServiceClient = ChunkServiceClient.create()) {
String parent =
DocumentName.ofProjectLocationDataStoreBranchDocumentName(
"[PROJECT]", "[LOCATION]", "[DATA_STORE]", "[BRANCH]", "[DOCUMENT]")
.toString();
for (Chunk element : chunkServiceClient.listChunks(parent).iterateAll()) {
// doThingsWith(element);
}
}
parent - Required. The parent document resource name, such as
`projects/{project}/locations/{location}/collections/{collection}/dataStores/{data_store}/branches/{branch}/documents/{document}`.
If the caller does not have permission to list [Chunk][google.cloud.discoveryengine.v1alpha.Chunk]s under this document, regardless of whether or not this document exists, a `PERMISSION_DENIED` error is returned.
com.google.api.gax.rpc.ApiException - if the remote call failspublic final ChunkServiceClient.ListChunksPagedResponse listChunks(ListChunksRequest request)
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ChunkServiceClient chunkServiceClient = ChunkServiceClient.create()) {
ListChunksRequest request =
ListChunksRequest.newBuilder()
.setParent(
DocumentName.ofProjectLocationDataStoreBranchDocumentName(
"[PROJECT]", "[LOCATION]", "[DATA_STORE]", "[BRANCH]", "[DOCUMENT]")
.toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
for (Chunk element : chunkServiceClient.listChunks(request).iterateAll()) {
// doThingsWith(element);
}
}
request - The request object containing all of the parameters for the API call.com.google.api.gax.rpc.ApiException - if the remote call failspublic final com.google.api.gax.rpc.UnaryCallable<ListChunksRequest,ChunkServiceClient.ListChunksPagedResponse> listChunksPagedCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ChunkServiceClient chunkServiceClient = ChunkServiceClient.create()) {
ListChunksRequest request =
ListChunksRequest.newBuilder()
.setParent(
DocumentName.ofProjectLocationDataStoreBranchDocumentName(
"[PROJECT]", "[LOCATION]", "[DATA_STORE]", "[BRANCH]", "[DOCUMENT]")
.toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
ApiFuture<Chunk> future = chunkServiceClient.listChunksPagedCallable().futureCall(request);
// Do something.
for (Chunk element : future.get().iterateAll()) {
// doThingsWith(element);
}
}
public final com.google.api.gax.rpc.UnaryCallable<ListChunksRequest,ListChunksResponse> listChunksCallable()
Sample code:
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ChunkServiceClient chunkServiceClient = ChunkServiceClient.create()) {
ListChunksRequest request =
ListChunksRequest.newBuilder()
.setParent(
DocumentName.ofProjectLocationDataStoreBranchDocumentName(
"[PROJECT]", "[LOCATION]", "[DATA_STORE]", "[BRANCH]", "[DOCUMENT]")
.toString())
.setPageSize(883849137)
.setPageToken("pageToken873572522")
.build();
while (true) {
ListChunksResponse response = chunkServiceClient.listChunksCallable().call(request);
for (Chunk element : response.getChunksList()) {
// doThingsWith(element);
}
String nextPageToken = response.getNextPageToken();
if (!Strings.isNullOrEmpty(nextPageToken)) {
request = request.toBuilder().setPageToken(nextPageToken).build();
} else {
break;
}
}
}
public final void close()
close in interface AutoCloseablepublic void shutdown()
shutdown in interface com.google.api.gax.core.BackgroundResourcepublic boolean isShutdown()
isShutdown in interface com.google.api.gax.core.BackgroundResourcepublic boolean isTerminated()
isTerminated in interface com.google.api.gax.core.BackgroundResourcepublic void shutdownNow()
shutdownNow in interface com.google.api.gax.core.BackgroundResourcepublic boolean awaitTermination(long duration,
TimeUnit unit)
throws InterruptedException
awaitTermination in interface com.google.api.gax.core.BackgroundResourceInterruptedExceptionCopyright © 2025 Google LLC. All rights reserved.