• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017 Google LLC
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google LLC nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 package com.google.api.gax.httpjson;
31 
32 import com.google.api.core.InternalExtensionOnly;
33 import com.google.api.gax.rpc.TransportChannel;
34 import com.google.auto.value.AutoValue;
35 import java.util.concurrent.TimeUnit;
36 
37 /** Implementation of TransportChannel based on http/json. */
38 @AutoValue
39 @InternalExtensionOnly
40 public abstract class HttpJsonTransportChannel implements TransportChannel {
41 
42   /** The name of the Http-JSON transport. */
getHttpJsonTransportName()43   public static String getHttpJsonTransportName() {
44     return "httpjson";
45   }
46 
47   @Override
getTransportName()48   public String getTransportName() {
49     return getHttpJsonTransportName();
50   }
51 
52   @Override
getEmptyCallContext()53   public HttpJsonCallContext getEmptyCallContext() {
54     return HttpJsonCallContext.createDefault();
55   }
56 
57   /** The channel in use. */
getManagedChannel()58   public abstract ManagedHttpJsonChannel getManagedChannel();
59 
60   /** The channel in use. */
getChannel()61   public HttpJsonChannel getChannel() {
62     return getManagedChannel();
63   }
64 
65   @Override
shutdown()66   public void shutdown() {
67     getManagedChannel().shutdown();
68   }
69 
70   @Override
isShutdown()71   public boolean isShutdown() {
72     return getManagedChannel().isShutdown();
73   }
74 
75   @Override
isTerminated()76   public boolean isTerminated() {
77     return getManagedChannel().isTerminated();
78   }
79 
80   @Override
shutdownNow()81   public void shutdownNow() {
82     getManagedChannel().shutdownNow();
83   }
84 
85   @Override
awaitTermination(long duration, TimeUnit unit)86   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
87     return getManagedChannel().awaitTermination(duration, unit);
88   }
89 
90   @Override
close()91   public void close() {
92     getManagedChannel().shutdown();
93   }
94 
newBuilder()95   public static Builder newBuilder() {
96     return new AutoValue_HttpJsonTransportChannel.Builder();
97   }
98 
create(ManagedHttpJsonChannel channel)99   public static HttpJsonTransportChannel create(ManagedHttpJsonChannel channel) {
100     return newBuilder().setManagedChannel(channel).build();
101   }
102 
103   @AutoValue.Builder
104   public abstract static class Builder {
setManagedChannel(ManagedHttpJsonChannel value)105     public abstract Builder setManagedChannel(ManagedHttpJsonChannel value);
106 
build()107     public abstract HttpJsonTransportChannel build();
108   }
109 }
110