2525import static com .google .cloud .logging .Logging .WriteOption .OptionType .LOG_NAME ;
2626import static com .google .cloud .logging .Logging .WriteOption .OptionType .RESOURCE ;
2727
28+ import com .google .api .gax .core .ApiFuture ;
29+ import com .google .api .gax .core .ApiFutures ;
2830import com .google .cloud .AsyncPage ;
2931import com .google .cloud .AsyncPageImpl ;
3032import com .google .cloud .BaseService ;
3941import com .google .common .collect .Iterables ;
4042import com .google .common .collect .Lists ;
4143import com .google .common .collect .Maps ;
42- import com .google .common .util .concurrent .Futures ;
4344import com .google .common .util .concurrent .Uninterruptibles ;
4445import com .google .logging .v2 .CreateLogMetricRequest ;
4546import com .google .logging .v2 .CreateSinkRequest ;
6566import com .google .logging .v2 .WriteLogEntriesRequest ;
6667import com .google .logging .v2 .WriteLogEntriesResponse ;
6768import com .google .protobuf .Empty ;
68-
6969import java .util .List ;
7070import java .util .Map ;
7171import java .util .concurrent .ExecutionException ;
72- import java .util .concurrent .Future ;
7372
7473class LoggingImpl extends BaseService <LoggingOptions > implements Logging {
7574
@@ -96,17 +95,22 @@ public Void apply(WriteLogEntriesResponse input) {
9695 rpc = options .getRpc ();
9796 }
9897
99- private static <V > V get (Future <V > future ) {
98+ private static <V > V get (ApiFuture <V > future ) {
10099 try {
101100 return Uninterruptibles .getUninterruptibly (future );
102101 } catch (ExecutionException ex ) {
103102 throw Throwables .propagate (ex .getCause ());
104103 }
105104 }
106105
107- private static <I , O > Future <O > transform (Future <I > future ,
108- Function <? super I , ? extends O > function ) {
109- return Futures .lazyTransform (future , function );
106+ private static <I , O > ApiFuture <O > transform (ApiFuture <I > future ,
107+ final Function <? super I , ? extends O > function ) {
108+ return ApiFutures .transform (future , new com .google .api .gax .core .Function <I , O >() {
109+ @ Override
110+ public O apply (I i ) {
111+ return function .apply (i );
112+ }
113+ });
110114 }
111115
112116 private abstract static class BasePageFetcher <T > implements AsyncPageImpl .NextPageFetcher <T > {
@@ -143,7 +147,7 @@ private static class SinkPageFetcher extends BasePageFetcher<Sink> {
143147
144148
145149 @ Override
146- public Future <AsyncPage <Sink >> getNextPage () {
150+ public ApiFuture <AsyncPage <Sink >> getNextPage () {
147151 return listSinksAsync (serviceOptions (), requestOptions ());
148152 }
149153 }
@@ -160,7 +164,7 @@ private static class MonitoredResourceDescriptorPageFetcher
160164
161165
162166 @ Override
163- public Future <AsyncPage <MonitoredResourceDescriptor >> getNextPage () {
167+ public ApiFuture <AsyncPage <MonitoredResourceDescriptor >> getNextPage () {
164168 return listMonitoredResourceDescriptorsAsync (serviceOptions (), requestOptions ());
165169 }
166170 }
@@ -176,7 +180,7 @@ private static class MetricPageFetcher extends BasePageFetcher<Metric> {
176180
177181
178182 @ Override
179- public Future <AsyncPage <Metric >> getNextPage () {
183+ public ApiFuture <AsyncPage <Metric >> getNextPage () {
180184 return listMetricsAsync (serviceOptions (), requestOptions ());
181185 }
182186 }
@@ -192,7 +196,7 @@ private static class LogEntryPageFetcher extends BasePageFetcher<LogEntry> {
192196
193197
194198 @ Override
195- public Future <AsyncPage <LogEntry >> getNextPage () {
199+ public ApiFuture <AsyncPage <LogEntry >> getNextPage () {
196200 return listLogEntriesAsync (serviceOptions (), requestOptions ());
197201 }
198202 }
@@ -203,7 +207,7 @@ public Sink create(SinkInfo sink) {
203207 }
204208
205209 @ Override
206- public Future <Sink > createAsync (SinkInfo sink ) {
210+ public ApiFuture <Sink > createAsync (SinkInfo sink ) {
207211 CreateSinkRequest request = CreateSinkRequest .newBuilder ()
208212 .setParent (ProjectName .create (getOptions ().getProjectId ()).toString ())
209213 .setSink (sink .toPb (getOptions ().getProjectId ()))
@@ -217,7 +221,7 @@ public Sink update(SinkInfo sink) {
217221 }
218222
219223 @ Override
220- public Future <Sink > updateAsync (SinkInfo sink ) {
224+ public ApiFuture <Sink > updateAsync (SinkInfo sink ) {
221225 UpdateSinkRequest request = UpdateSinkRequest .newBuilder ()
222226 .setSinkName (SinkName .create (getOptions ().getProjectId (), sink .getName ()).toString ())
223227 .setSink (sink .toPb (getOptions ().getProjectId ()))
@@ -231,7 +235,7 @@ public Sink getSink(String sink) {
231235 }
232236
233237 @ Override
234- public Future <Sink > getSinkAsync (String sink ) {
238+ public ApiFuture <Sink > getSinkAsync (String sink ) {
235239 GetSinkRequest request = GetSinkRequest .newBuilder ()
236240 .setSinkName (SinkName .create (getOptions ().getProjectId (), sink ).toString ())
237241 .build ();
@@ -253,10 +257,10 @@ private static ListSinksRequest listSinksRequest(LoggingOptions serviceOptions,
253257 return builder .build ();
254258 }
255259
256- private static Future <AsyncPage <Sink >> listSinksAsync (final LoggingOptions serviceOptions ,
260+ private static ApiFuture <AsyncPage <Sink >> listSinksAsync (final LoggingOptions serviceOptions ,
257261 final Map <Option .OptionType , ?> options ) {
258262 final ListSinksRequest request = listSinksRequest (serviceOptions , options );
259- Future <ListSinksResponse > list = serviceOptions .getRpc ().list (request );
263+ ApiFuture <ListSinksResponse > list = serviceOptions .getRpc ().list (request );
260264 return transform (list , new Function <ListSinksResponse , AsyncPage <Sink >>() {
261265 @ Override
262266 public AsyncPage <Sink > apply (ListSinksResponse listSinksResponse ) {
@@ -277,7 +281,7 @@ public Page<Sink> listSinks(ListOption... options) {
277281 }
278282
279283 @ Override
280- public Future <AsyncPage <Sink >> listSinksAsync (ListOption ... options ) {
284+ public ApiFuture <AsyncPage <Sink >> listSinksAsync (ListOption ... options ) {
281285 return listSinksAsync (getOptions (), optionMap (options ));
282286 }
283287
@@ -287,7 +291,7 @@ public boolean deleteSink(String sink) {
287291 }
288292
289293 @ Override
290- public Future <Boolean > deleteSinkAsync (String sink ) {
294+ public ApiFuture <Boolean > deleteSinkAsync (String sink ) {
291295 DeleteSinkRequest request = DeleteSinkRequest .newBuilder ()
292296 .setSinkName (SinkName .create (getOptions ().getProjectId (), sink ).toString ())
293297 .build ();
@@ -298,7 +302,7 @@ public boolean deleteLog(String log) {
298302 return get (deleteLogAsync (log ));
299303 }
300304
301- public Future <Boolean > deleteLogAsync (String log ) {
305+ public ApiFuture <Boolean > deleteLogAsync (String log ) {
302306 DeleteLogRequest request = DeleteLogRequest .newBuilder ()
303307 .setLogName (LogName .create (getOptions ().getProjectId (), log ).toString ())
304308 .build ();
@@ -320,12 +324,12 @@ private static ListMonitoredResourceDescriptorsRequest listMonitoredResourceDesc
320324 return builder .build ();
321325 }
322326
323- private static Future <AsyncPage <MonitoredResourceDescriptor >>
327+ private static ApiFuture <AsyncPage <MonitoredResourceDescriptor >>
324328 listMonitoredResourceDescriptorsAsync (final LoggingOptions serviceOptions ,
325329 final Map <Option .OptionType , ?> options ) {
326330 final ListMonitoredResourceDescriptorsRequest request =
327331 listMonitoredResourceDescriptorsRequest (options );
328- Future <ListMonitoredResourceDescriptorsResponse > list = serviceOptions .getRpc ().list (request );
332+ ApiFuture <ListMonitoredResourceDescriptorsResponse > list = serviceOptions .getRpc ().list (request );
329333 return transform (list , new Function <ListMonitoredResourceDescriptorsResponse ,
330334 AsyncPage <MonitoredResourceDescriptor >>() {
331335 @ Override
@@ -349,7 +353,7 @@ public Page<MonitoredResourceDescriptor> listMonitoredResourceDescriptors(ListOp
349353 return get (listMonitoredResourceDescriptorsAsync (options ));
350354 }
351355
352- public Future <AsyncPage <MonitoredResourceDescriptor >> listMonitoredResourceDescriptorsAsync (
356+ public ApiFuture <AsyncPage <MonitoredResourceDescriptor >> listMonitoredResourceDescriptorsAsync (
353357 ListOption ... options ) {
354358 return listMonitoredResourceDescriptorsAsync (getOptions (), optionMap (options ));
355359 }
@@ -360,7 +364,7 @@ public Metric create(MetricInfo metric) {
360364 }
361365
362366 @ Override
363- public Future <Metric > createAsync (MetricInfo metric ) {
367+ public ApiFuture <Metric > createAsync (MetricInfo metric ) {
364368 CreateLogMetricRequest request = CreateLogMetricRequest .newBuilder ()
365369 .setParent (ProjectName .create (getOptions ().getProjectId ()).toString ())
366370 .setMetric (metric .toPb ())
@@ -374,7 +378,7 @@ public Metric update(MetricInfo metric) {
374378 }
375379
376380 @ Override
377- public Future <Metric > updateAsync (MetricInfo metric ) {
381+ public ApiFuture <Metric > updateAsync (MetricInfo metric ) {
378382 UpdateLogMetricRequest request = UpdateLogMetricRequest .newBuilder ()
379383 .setMetricName (MetricName .create (getOptions ().getProjectId (), metric .getName ()).toString ())
380384 .setMetric (metric .toPb ())
@@ -388,7 +392,7 @@ public Metric getMetric(String metric) {
388392 }
389393
390394 @ Override
391- public Future <Metric > getMetricAsync (String metric ) {
395+ public ApiFuture <Metric > getMetricAsync (String metric ) {
392396 GetLogMetricRequest request = GetLogMetricRequest .newBuilder ()
393397 .setMetricName (MetricName .create (getOptions ().getProjectId (), metric ).toString ())
394398 .build ();
@@ -410,10 +414,10 @@ private static ListLogMetricsRequest listMetricsRequest(LoggingOptions serviceOp
410414 return builder .build ();
411415 }
412416
413- private static Future <AsyncPage <Metric >> listMetricsAsync (final LoggingOptions serviceOptions ,
417+ private static ApiFuture <AsyncPage <Metric >> listMetricsAsync (final LoggingOptions serviceOptions ,
414418 final Map <Option .OptionType , ?> options ) {
415419 final ListLogMetricsRequest request = listMetricsRequest (serviceOptions , options );
416- Future <ListLogMetricsResponse > list = serviceOptions .getRpc ().list (request );
420+ ApiFuture <ListLogMetricsResponse > list = serviceOptions .getRpc ().list (request );
417421 return transform (list , new Function <ListLogMetricsResponse , AsyncPage <Metric >>() {
418422 @ Override
419423 public AsyncPage <Metric > apply (ListLogMetricsResponse listMetricsResponse ) {
@@ -434,7 +438,7 @@ public Page<Metric> listMetrics(ListOption... options) {
434438 }
435439
436440 @ Override
437- public Future <AsyncPage <Metric >> listMetricsAsync (ListOption ... options ) {
441+ public ApiFuture <AsyncPage <Metric >> listMetricsAsync (ListOption ... options ) {
438442 return listMetricsAsync (getOptions (), optionMap (options ));
439443 }
440444
@@ -444,7 +448,7 @@ public boolean deleteMetric(String metric) {
444448 }
445449
446450 @ Override
447- public Future <Boolean > deleteMetricAsync (String metric ) {
451+ public ApiFuture <Boolean > deleteMetricAsync (String metric ) {
448452 DeleteLogMetricRequest request = DeleteLogMetricRequest .newBuilder ()
449453 .setMetricName (MetricName .create (getOptions ().getProjectId (), metric ).toString ())
450454 .build ();
@@ -475,7 +479,7 @@ public void write(Iterable<LogEntry> logEntries, WriteOption... options) {
475479 get (writeAsync (logEntries , options ));
476480 }
477481
478- public Future <Void > writeAsync (Iterable <LogEntry > logEntries , WriteOption ... options ) {
482+ public ApiFuture <Void > writeAsync (Iterable <LogEntry > logEntries , WriteOption ... options ) {
479483 return transform (
480484 rpc .write (writeLogEntriesRequest (getOptions (), logEntries , optionMap (options ))),
481485 WRITE_RESPONSE_TO_VOID_FUNCTION );
@@ -504,10 +508,10 @@ private static ListLogEntriesRequest listLogEntriesRequest(LoggingOptions servic
504508 return builder .build ();
505509 }
506510
507- private static Future <AsyncPage <LogEntry >> listLogEntriesAsync (
511+ private static ApiFuture <AsyncPage <LogEntry >> listLogEntriesAsync (
508512 final LoggingOptions serviceOptions , final Map <Option .OptionType , ?> options ) {
509513 final ListLogEntriesRequest request = listLogEntriesRequest (serviceOptions , options );
510- Future <ListLogEntriesResponse > list = serviceOptions .getRpc ().list (request );
514+ ApiFuture <ListLogEntriesResponse > list = serviceOptions .getRpc ().list (request );
511515 return transform (list , new Function <ListLogEntriesResponse , AsyncPage <LogEntry >>() {
512516 @ Override
513517 public AsyncPage <LogEntry > apply (ListLogEntriesResponse listLogEntrysResponse ) {
@@ -528,7 +532,7 @@ public Page<LogEntry> listLogEntries(EntryListOption... options) {
528532 }
529533
530534 @ Override
531- public Future <AsyncPage <LogEntry >> listLogEntriesAsync (EntryListOption ... options ) {
535+ public ApiFuture <AsyncPage <LogEntry >> listLogEntriesAsync (EntryListOption ... options ) {
532536 return listLogEntriesAsync (getOptions (), optionMap (options ));
533537 }
534538
0 commit comments