1+ /*
2+ * Copyright 2025 Google LLC
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ package com .example .datastore ;
18+
19+ // [START datastore_configure_connection_pool]
20+
21+ import com .google .api .gax .grpc .ChannelPoolSettings ;
22+ import com .google .api .gax .grpc .InstantiatingGrpcChannelProvider ;
23+ import com .google .cloud .datastore .DatastoreOptions ;
24+ import com .google .cloud .datastore .v1 .DatastoreSettings ;
25+ import com .google .cloud .grpc .GrpcTransportOptions ;
26+
27+
28+ public class ConfigureConnectionPool {
29+
30+ public static void main (String ... args ) throws Exception {
31+ InstantiatingGrpcChannelProvider channelProvider =
32+ DatastoreSettings .defaultGrpcTransportProviderBuilder ()
33+ .setChannelPoolSettings (
34+ ChannelPoolSettings .builder ()
35+ .setInitialChannelCount (10 )
36+ .setMinChannelCount (5 )
37+ .setMaxChannelCount (200 )
38+ .build ())
39+ .build ();
40+
41+ DatastoreOptions datastoreOptions = DatastoreOptions .newBuilder ()
42+ .setProjectId ("my-project" )
43+ .setChannelProvider (channelProvider )
44+ .setTransportOptions (GrpcTransportOptions .newBuilder ().build ())
45+ .build ();
46+
47+ ChannelPoolSettings channelPoolSettings =
48+ ((InstantiatingGrpcChannelProvider ) datastoreOptions .getTransportChannelProvider ())
49+ .getChannelPoolSettings ();
50+
51+ System .out .printf (String .format (
52+ "Connected with pool with InitialChannelCount: %d, MinChannelCount: %d, MaxChannelCount: %d" ,
53+ channelPoolSettings .getInitialChannelCount (), channelPoolSettings .getMinChannelCount (),
54+ channelPoolSettings .getMaxChannelCount ()
55+ ));
56+ }
57+ }
58+
59+ // [END datastore_configure_connection_pool]
0 commit comments