|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch B.V. under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch B.V. licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package co.elastic.clients.transport.netty; |
| 21 | + |
| 22 | +import co.elastic.clients.json.JsonpMapper; |
| 23 | +import co.elastic.clients.transport.ElasticsearchTransportBase; |
| 24 | +import co.elastic.clients.transport.TransportOptions; |
| 25 | +import co.elastic.clients.transport.http.TransportHttpClient; |
| 26 | + |
| 27 | +import javax.annotation.Nullable; |
| 28 | +import java.io.IOException; |
| 29 | +import java.util.concurrent.CompletableFuture; |
| 30 | + |
| 31 | +public class NettyElasticsearchTransport extends ElasticsearchTransportBase { |
| 32 | + |
| 33 | + public NettyElasticsearchTransport(TransportHttpClient.Node node, TransportOptions options, JsonpMapper jsonpMapper) { |
| 34 | + super(new SingleNodeHttpClient(new NettyTransportHttpClient(), node), options, jsonpMapper); |
| 35 | + } |
| 36 | + |
| 37 | + public static class SingleNodeHttpClient implements TransportHttpClient { |
| 38 | + private final TransportHttpClient client; |
| 39 | + private final Node node; |
| 40 | + |
| 41 | + public SingleNodeHttpClient(TransportHttpClient client, Node node) { |
| 42 | + this.client = client; |
| 43 | + this.node = node; |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public TransportOptions createOptions(@Nullable TransportOptions options) { |
| 48 | + return client.createOptions(options); |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public Response performRequest( |
| 53 | + String endpointId, @Nullable Node ignoredNode, Request request, TransportOptions options |
| 54 | + ) throws IOException { |
| 55 | + return client.performRequest(endpointId, node, request, options); |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public CompletableFuture<Response> performRequestAsync( |
| 60 | + String endpointId, @Nullable Node ignoredNode, Request request, TransportOptions options |
| 61 | + ) { |
| 62 | + return client.performRequestAsync(endpointId, node, request, options); |
| 63 | + } |
| 64 | + |
| 65 | + @Override |
| 66 | + public void close() throws IOException { |
| 67 | + client.close(); |
| 68 | + } |
| 69 | + } |
| 70 | +} |
0 commit comments