Class BigtableDataClientFactory (2.28.0)

public final class BigtableDataClientFactory implements AutoCloseable

A factory to create multiple BigtableDataClient instances that all share the same channel pool.

This allows multiple client instances to share the same gRPC channel pool, which makes client creation very cheap. The intended use case is for applications that need to access multiple Bigtable Instances from the same process.

Example Usage:


 BigtableDataSettings defaultSettings = BigtableDataSettings.newBuilder()
   .setProject("my-default-project")
   .setInstance("my-default-instance")
   .build();

 BigtableDataClientFactory clientFactory = BigtableDataClientFactory.create(defaultSettings);

 // Create a new client for "my-default-instance" in "my-default-project";
 BigtableDataClient defaultInstanceClient = clientFactory.createDefault();

 // Create a new client for a different application profile
 BigtableDataClient otherAppProfileClient = clientFactory.createForAppProfile("other-app-profile");

 // Create a new client for a completely different instance and application profile.
 BigtableDataClient otherInstanceClient = clientFactory
   .createForInstance("my-other-project", "my-other-instance", "my-other-app-profile");

 // Clean up: make sure close the clients AND the factory.
 defaultInstanceClient.close();
 otherAppProfileClient.close();
 otherInstanceClient.close();

 clientFactory.close();

 

Please note that this is an experimental feature and might be changed or removed in future.

Inheritance

java.lang.Object > BigtableDataClientFactory

Implements

AutoCloseable

Static Methods

create(BigtableDataSettings defaultSettings)

public static BigtableDataClientFactory create(BigtableDataSettings defaultSettings)

Create a instance of this factory.

The factory will be used to create clients using the provided settings as the base. Make sure to call #close() on the factory after closing all clients.

Parameter
NameDescription
defaultSettingsBigtableDataSettings
Returns
TypeDescription
BigtableDataClientFactory
Exceptions
TypeDescription
IOException

Methods

close()

public void close()

Release all of the resources associated with this factory.

This will close the underlying channel pooling, disconnecting all create clients.

Exceptions
TypeDescription
Exception

createDefault()

public BigtableDataClient createDefault()

Create a lightweight client using the default settings in this factory. This will use the factory default project, instance and application profile ids. The client will also share resources like the channel pool with other clients created using this factory.

The client should be closed when it is no longer needed. Closing the client will release client specific resources, but will leave shared resources like the channel pool open. To release all resources, first close all of the created clients and then this factory instance.

Returns
TypeDescription
BigtableDataClient

createForAppProfile(String appProfileId)

public BigtableDataClient createForAppProfile(String appProfileId)

Create a lightweight client with an overriden application profile and the factory default project and instance ids. The client will also share resources like the channel pool with other clients created using this factory.

The client should be closed when it is no longer needed. Closing the client will release client specific resources, but will leave shared resources like the channel pool open. To release all resources, first close all of the created clients and then this factory instance.

Parameter
NameDescription
appProfileIdString
Returns
TypeDescription
BigtableDataClient
Exceptions
TypeDescription
IOException

createForInstance(String projectId, String instanceId)

public BigtableDataClient createForInstance(String projectId, String instanceId)

Create a lightweight client with the specified project and instance id. The resulting client will use the server default application profile. The client will also share resources like the channel pool with other clients created using this factory.

The client should be closed when it is no longer needed. Closing the client will release client specific resources, but will leave shared resources like the channel pool open. To release all resources, first close all of the created clients and then this factory instance.

Parameters
NameDescription
projectIdString
instanceIdString
Returns
TypeDescription
BigtableDataClient
Exceptions
TypeDescription
IOException

createForInstance(String projectId, String instanceId, String appProfileId)

public BigtableDataClient createForInstance(String projectId, String instanceId, String appProfileId)

Create a lightweight client to the specified project, instance and application profile id. The client will share resources like the channel pool with other clients created using this factory.

The client should be closed when it is no longer needed. Closing the client will release client specific resources, but will leave shared resources like the channel pool open. To release all resources, first close all of the created clients and then this factory instance.

Parameters
NameDescription
projectIdString
instanceIdString
appProfileIdString
Returns
TypeDescription
BigtableDataClient
Exceptions
TypeDescription
IOException