Merge pull request #15983 from akka/wip-15945-unbind-tcp-and-http-connection-ban
+hco #15945 Make Tcp and Http server binding closeable
This commit is contained in:
commit
386c3ba815
7 changed files with 65 additions and 18 deletions
|
|
@ -6,13 +6,14 @@ package akka.http.model.japi;
|
|||
|
||||
import org.reactivestreams.Publisher;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
/**
|
||||
* The binding of a server. Allows access to its own address and to the stream
|
||||
* of incoming connections.
|
||||
*/
|
||||
public interface ServerBinding {
|
||||
public interface ServerBinding extends Closeable {
|
||||
/**
|
||||
* The local address this server is listening on.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
package akka.http
|
||||
|
||||
import java.io.Closeable
|
||||
import java.net.InetSocketAddress
|
||||
import com.typesafe.config.Config
|
||||
import org.reactivestreams.{ Publisher, Subscriber }
|
||||
|
|
@ -109,12 +110,19 @@ object Http extends ExtensionKey[HttpExt] {
|
|||
apply(new InetSocketAddress(interface, port), backlog, options, serverSettings, materializerSettings)
|
||||
}
|
||||
|
||||
final case class ServerBinding(localAddress: InetSocketAddress,
|
||||
connectionStream: Publisher[IncomingConnection]) extends model.japi.ServerBinding {
|
||||
sealed abstract case class ServerBinding(localAddress: InetSocketAddress,
|
||||
connectionStream: Publisher[IncomingConnection]) extends model.japi.ServerBinding {
|
||||
/** Java API */
|
||||
def getConnectionStream: Publisher[japi.IncomingConnection] = connectionStream.asInstanceOf[Publisher[japi.IncomingConnection]]
|
||||
}
|
||||
|
||||
/** INTERNAL API */
|
||||
private[http] final class InternalServerBinding(_localAddress: InetSocketAddress,
|
||||
_connectionStream: Publisher[IncomingConnection],
|
||||
closeable: Closeable) extends ServerBinding(_localAddress, _connectionStream) {
|
||||
override def close() = closeable.close()
|
||||
}
|
||||
|
||||
final case class IncomingConnection(remoteAddress: InetSocketAddress,
|
||||
requestPublisher: Publisher[HttpRequest],
|
||||
responseSubscriber: Subscriber[HttpResponse]) extends model.japi.IncomingConnection {
|
||||
|
|
|
|||
|
|
@ -60,14 +60,14 @@ private[http] class HttpManager(httpSettings: HttpExt#Settings) extends Actor wi
|
|||
val askTimeout = Timeout(effectiveSettings.bindTimeout + 5.seconds) // FIXME: how can we improve this?
|
||||
val tcpServerBindingFuture = IO(StreamTcp)(context.system).ask(tcpBind)(askTimeout)
|
||||
tcpServerBindingFuture onComplete {
|
||||
case Success(StreamTcp.TcpServerBinding(localAddress, connectionStream)) ⇒
|
||||
case Success(tcpServerBinding @ StreamTcp.TcpServerBinding(localAddress, connectionStream)) ⇒
|
||||
log.info("Bound to {}", endpoint)
|
||||
implicit val materializer = FlowMaterializer()
|
||||
val httpServerPipeline = new HttpServerPipeline(effectiveSettings, log)
|
||||
val httpConnectionStream = Flow(connectionStream)
|
||||
.map(httpServerPipeline)
|
||||
.toPublisher()
|
||||
commander ! Http.ServerBinding(localAddress, httpConnectionStream)
|
||||
commander ! new Http.InternalServerBinding(localAddress, httpConnectionStream, tcpServerBinding)
|
||||
|
||||
case Failure(error) ⇒
|
||||
log.warning("Bind to {} failed due to {}", endpoint, error)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue