Skip to content

Commit d2168bf

Browse files
wip
1 parent e2a9906 commit d2168bf

File tree

16 files changed

+777
-630
lines changed

16 files changed

+777
-630
lines changed

src/main/java/com/influxdb/v3/client/InfluxDBApiNettyException.java

Lines changed: 66 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -21,83 +21,84 @@
2121
*/
2222
package com.influxdb.v3.client;
2323

24-
import io.netty.handler.codec.http.HttpHeaders;
25-
26-
import javax.annotation.Nullable;
2724
import java.util.List;
25+
import javax.annotation.Nullable;
26+
27+
import io.netty.handler.codec.http.HttpHeaders;
2828

2929
/**
3030
* The InfluxDBApiNettyException gets thrown whenever an error status is returned
3131
* in the HTTP response. It facilitates recovering from such errors whenever possible.
3232
*/
3333
public class InfluxDBApiNettyException extends InfluxDBApiException {
3434

35-
/**
36-
* The HTTP headers associated with the error.
37-
*/
38-
HttpHeaders headers;
39-
/**
40-
* The HTTP status code associated with the error.
41-
*/
42-
int statusCode;
35+
/**
36+
* The HTTP headers associated with the error.
37+
*/
38+
HttpHeaders headers;
39+
/**
40+
* The HTTP status code associated with the error.
41+
*/
42+
int statusCode;
4343

44-
/**
45-
* Construct a new InfluxDBApiNettyException with statusCode and headers.
46-
*
47-
* @param message the detail message.
48-
* @param headers headers returned in the response.
49-
* @param statusCode statusCode of the response.
50-
*/
51-
public InfluxDBApiNettyException(
52-
@Nullable final String message,
53-
@Nullable final HttpHeaders headers,
54-
final int statusCode) {
55-
super(message);
56-
this.headers = headers;
57-
this.statusCode = statusCode;
58-
}
44+
/**
45+
* Construct a new InfluxDBApiNettyException with statusCode and headers.
46+
*
47+
* @param message the detail message.
48+
* @param headers headers returned in the response.
49+
* @param statusCode statusCode of the response.
50+
*/
51+
public InfluxDBApiNettyException(
52+
@Nullable final String message,
53+
@Nullable final HttpHeaders headers,
54+
final int statusCode) {
55+
super(message);
56+
this.headers = headers;
57+
this.statusCode = statusCode;
58+
}
5959

60-
/**
61-
* Construct a new InfluxDBApiNettyException with statusCode and headers.
62-
*
63-
* @param cause root cause of the exception.
64-
* @param headers headers returned in the response.
65-
* @param statusCode status code of the response.
66-
*/
67-
public InfluxDBApiNettyException(
68-
@Nullable final Throwable cause,
69-
@Nullable final HttpHeaders headers,
70-
final int statusCode) {
71-
super(cause);
72-
this.headers = headers;
73-
this.statusCode = statusCode;
74-
}
60+
/**
61+
* Construct a new InfluxDBApiNettyException with statusCode and headers.
62+
*
63+
* @param cause root cause of the exception.
64+
* @param headers headers returned in the response.
65+
* @param statusCode status code of the response.
66+
*/
67+
public InfluxDBApiNettyException(
68+
@Nullable final Throwable cause,
69+
@Nullable final HttpHeaders headers,
70+
final int statusCode) {
71+
super(cause);
72+
this.headers = headers;
73+
this.statusCode = statusCode;
74+
}
7575

76-
/**
77-
* Gets the HTTP headers property associated with the error.
78-
*
79-
* @return - the headers object.
80-
*/
81-
public HttpHeaders headers() {
82-
return headers;
83-
}
76+
/**
77+
* Gets the HTTP headers property associated with the error.
78+
*
79+
* @return - the headers object.
80+
*/
81+
public HttpHeaders headers() {
82+
return headers;
83+
}
8484

85-
/**
86-
* Helper method to simplify retrieval of specific headers.
87-
*
88-
* @param name - name of the header.
89-
* @return - value matching the header key, or null if the key does not exist.
90-
*/
91-
public List<String> getHeader(final String name) {
92-
return headers.getAll(name);
93-
}
85+
/**
86+
* Helper method to simplify retrieval of specific headers.
87+
*
88+
* @param name - name of the header.
89+
* @return - value matching the header key, or null if the key does not exist.
90+
*/
91+
public List<String> getHeader(final String name) {
92+
return headers.getAll(name);
93+
}
9494

95-
/**
96-
* Gets the HTTP statusCode associated with the error.
97-
* @return - the HTTP statusCode.
98-
*/
99-
public int statusCode() {
100-
return statusCode;
101-
}
95+
/**
96+
* Gets the HTTP statusCode associated with the error.
97+
*
98+
* @return - the HTTP statusCode.
99+
*/
100+
public int statusCode() {
101+
return statusCode;
102+
}
102103

103104
}

src/main/java/com/influxdb/v3/client/InfluxDBClient.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ public interface InfluxDBClient extends AutoCloseable {
8080
* Write a {@link Point} to the InfluxDB server.
8181
*
8282
* @param point the {@link Point} to write, can be null
83-
* <p>
84-
* Note: the timestamp passed will be converted to nanoseconds since the Unix epoch
85-
* by NanosecondConverter helper class
83+
* <p>
84+
* Note: the timestamp passed will be converted to nanoseconds since the Unix epoch
85+
* by NanosecondConverter helper class
8686
*/
8787
void writePoint(@Nullable final Point point);
8888

@@ -91,19 +91,19 @@ public interface InfluxDBClient extends AutoCloseable {
9191
*
9292
* @param point the {@link Point} to write, can be null
9393
* @param options the options for writing data to InfluxDB
94-
* <p>
95-
* Note: the timestamp passed will be converted to nanoseconds since the Unix epoch
96-
* by NanosecondConverter helper class
94+
* <p>
95+
* Note: the timestamp passed will be converted to nanoseconds since the Unix epoch
96+
* by NanosecondConverter helper class
9797
*/
9898
void writePoint(@Nullable final Point point, @Nonnull final WriteOptions options);
9999

100100
/**
101101
* Write a list of {@link Point} to the InfluxDB server.
102102
*
103103
* @param points the list of {@link Point} to write, cannot be null
104-
* <p>
105-
* Note: the timestamp passed will be converted to nanoseconds since the Unix epoch
106-
* by NanosecondConverter helper class
104+
* <p>
105+
* Note: the timestamp passed will be converted to nanoseconds since the Unix epoch
106+
* by NanosecondConverter helper class
107107
*/
108108
void writePoints(@Nonnull final List<Point> points);
109109

@@ -112,9 +112,9 @@ public interface InfluxDBClient extends AutoCloseable {
112112
*
113113
* @param points the list of {@link Point} to write, cannot be null
114114
* @param options the options for writing data to InfluxDB
115-
* <p>
116-
* Note: the timestamp passed will be converted to nanoseconds since the Unix epoch
117-
* by NanosecondConverter helper class
115+
* <p>
116+
* Note: the timestamp passed will be converted to nanoseconds since the Unix epoch
117+
* by NanosecondConverter helper class
118118
*/
119119
void writePoints(@Nonnull final List<Point> points, @Nonnull final WriteOptions options);
120120

@@ -460,7 +460,8 @@ Stream<VectorSchemaRoot> queryBatches(@Nonnull final String query,
460460
* Returns <code>null</code> if the server version can't be determined.
461461
*/
462462
@Nullable
463-
String getServerVersion() throws RuntimeException, ExecutionException, InterruptedException, JsonProcessingException;
463+
String getServerVersion()
464+
throws RuntimeException, ExecutionException, InterruptedException, JsonProcessingException;
464465

465466
/**
466467
* Creates a new instance of the {@link InfluxDBClient} for interacting with an InfluxDB server, simplifying
@@ -498,7 +499,8 @@ static InfluxDBClient getInstance(@Nonnull final String host,
498499
static InfluxDBClient getInstance(@Nonnull final String host,
499500
@Nullable final char[] token,
500501
@Nullable final String database,
501-
@Nullable Map<String, String> defaultTags) throws URISyntaxException, SSLException {
502+
@Nullable Map<String, String> defaultTags)
503+
throws URISyntaxException, SSLException {
502504

503505
ClientConfig config = new ClientConfig.Builder()
504506
.host(host)

src/main/java/com/influxdb/v3/client/config/ClientConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ public Builder disableGRPCCompression(final boolean disableGRPCCompression) {
731731
}
732732

733733
@Nonnull
734-
public Builder nettyHttpClientConfig(NettyHttpClientConfig nettyHttpClientConfig) {
734+
public Builder nettyHttpClientConfig(final NettyHttpClientConfig nettyHttpClientConfig) {
735735
this.nettyHttpClientConfig = nettyHttpClientConfig;
736736
return this;
737737
}

src/main/java/com/influxdb/v3/client/config/NettyHttpClientConfig.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
122
package com.influxdb.v3.client.config;
223

24+
import java.util.function.Supplier;
25+
import javax.annotation.Nonnull;
26+
327
import io.grpc.ProxyDetector;
428
import io.netty.handler.proxy.HttpProxyHandler;
529
import io.netty.handler.ssl.SslContext;
630

7-
import java.util.function.Supplier;
8-
931
// fixme refactor
1032
public class NettyHttpClientConfig {
1133

@@ -18,16 +40,16 @@ public class NettyHttpClientConfig {
1840
public NettyHttpClientConfig() {
1941
}
2042

21-
public void configureSsl(Supplier<SslContext> configureSsl) {
43+
public void configureSsl(@Nonnull final Supplier<SslContext> configureSsl) {
2244
this.sslContext = configureSsl.get();
2345
}
2446

25-
public void configureChannelProxy(Supplier<HttpProxyHandler> configureHttpProxyHandler) {
47+
public void configureChannelProxy(@Nonnull final Supplier<HttpProxyHandler> configureHttpProxyHandler) {
2648
this.httpProxyHandler = configureHttpProxyHandler.get();
2749
}
2850

29-
public void configureManagedChannelProxy(Supplier<ProxyDetector> configureManagedChannelProxy) {
30-
this.proxyDetector = configureManagedChannelProxy.get();
51+
public void configureManagedChannelProxy(@Nonnull final ProxyDetector configureManagedChannelProxy) {
52+
this.proxyDetector = configureManagedChannelProxy;
3153
}
3254

3355
public SslContext getSslContext() {
Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,69 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
122
package com.influxdb.v3.client.internal;
223

24+
import javax.annotation.Nonnull;
25+
import javax.annotation.Nullable;
26+
27+
import io.netty.channel.ChannelHandler;
328
import io.netty.channel.ChannelInitializer;
429
import io.netty.channel.ChannelPipeline;
5-
import io.netty.channel.socket.SocketChannel;
6-
import io.netty.handler.codec.http.FullHttpResponse;
30+
import io.netty.channel.socket.oio.OioSocketChannel;
731
import io.netty.handler.codec.http.HttpClientCodec;
832
import io.netty.handler.codec.http.HttpObjectAggregator;
933
import io.netty.handler.logging.LogLevel;
1034
import io.netty.handler.logging.LoggingHandler;
1135
import io.netty.handler.proxy.HttpProxyHandler;
1236
import io.netty.handler.proxy.ProxyHandler;
1337
import io.netty.handler.ssl.SslContext;
14-
import io.netty.util.concurrent.Promise;
15-
16-
import javax.annotation.Nonnull;
17-
import javax.annotation.Nullable;
1838

19-
public class ClientChannelInitializer extends ChannelInitializer<SocketChannel> {
39+
public class ClientChannelInitializer extends ChannelInitializer<OioSocketChannel> {
2040

2141
private final SslContext sslCtx;
2242

23-
private final Promise<FullHttpResponse> promise;
24-
2543
private final String host;
2644

2745
private final Integer port;
2846

2947
private final ProxyHandler proxyHandler;
3048

31-
public ClientChannelInitializer(@Nonnull String host,
32-
@Nonnull Integer port,
33-
@Nonnull Promise<FullHttpResponse> promise,
34-
@Nullable SslContext sslCtx,
35-
@Nullable HttpProxyHandler proxyHandler
49+
private ChannelHandler[] h;
50+
51+
public ClientChannelInitializer(@Nonnull final String host,
52+
@Nonnull final Integer port,
53+
@Nullable final SslContext sslCtx,
54+
@Nullable final HttpProxyHandler proxyHandler,
55+
ChannelHandler... handlers
56+
3657
) {
3758
this.sslCtx = sslCtx;
38-
this.promise = promise;
3959
this.host = host;
4060
this.port = port;
4161
this.proxyHandler = proxyHandler;
62+
this.h = handlers;
4263
}
4364

4465
@Override
45-
public void initChannel(SocketChannel ch) {
66+
public void initChannel(final OioSocketChannel ch) {
4667
ChannelPipeline p = ch.pipeline();
4768
p.addLast(new LoggingHandler(LogLevel.INFO));
4869
if (proxyHandler != null) {
@@ -53,6 +74,10 @@ public void initChannel(SocketChannel ch) {
5374
}
5475
p.addLast(new HttpClientCodec());
5576
p.addLast(new HttpObjectAggregator(1048576));
56-
p.addLast(new ClientHandler(this.promise));
77+
if (h != null) {
78+
for (ChannelHandler handler : h) {
79+
p.addLast(handler);
80+
}
81+
}
5782
}
5883
}

0 commit comments

Comments
 (0)