-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce http and tcp server channels (#31446)
Historically in TcpTransport server channels were represented by the same channel interface as socket channels. This was necessary as TcpTransport was parameterized by the channel type. This commit introduces TcpServerChannel and HttpServerChannel classes. Additionally, it adds the implementations for the various transports. This allows server channels to have unique functionality and not implement the methods they do not support (such as send and getRemoteAddress). Additionally, with the introduction of HttpServerChannel this commit extracts some of the storing and closing channel work to the abstract http server transport.
- Loading branch information
1 parent
8bfb9aa
commit 9ab1325
Showing
23 changed files
with
501 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpServerChannel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.http.netty4; | ||
|
||
import io.netty.channel.Channel; | ||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.common.concurrent.CompletableContext; | ||
import org.elasticsearch.http.HttpServerChannel; | ||
import org.elasticsearch.transport.netty4.Netty4Utils; | ||
|
||
import java.net.InetSocketAddress; | ||
|
||
public class Netty4HttpServerChannel implements HttpServerChannel { | ||
|
||
private final Channel channel; | ||
private final CompletableContext<Void> closeContext = new CompletableContext<>(); | ||
|
||
Netty4HttpServerChannel(Channel channel) { | ||
this.channel = channel; | ||
this.channel.closeFuture().addListener(f -> { | ||
if (f.isSuccess()) { | ||
closeContext.complete(null); | ||
} else { | ||
Throwable cause = f.cause(); | ||
if (cause instanceof Error) { | ||
Netty4Utils.maybeDie(cause); | ||
closeContext.completeExceptionally(new Exception(cause)); | ||
} else { | ||
closeContext.completeExceptionally((Exception) cause); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public InetSocketAddress getLocalAddress() { | ||
return (InetSocketAddress) channel.localAddress(); | ||
} | ||
|
||
@Override | ||
public void addCloseListener(ActionListener<Void> listener) { | ||
closeContext.addListener(ActionListener.toBiConsumer(listener)); | ||
} | ||
|
||
@Override | ||
public boolean isOpen() { | ||
return channel.isOpen(); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
channel.close(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Netty4HttpChannel{localAddress=" + getLocalAddress() + "}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.