Class Http.ServerBinding
- java.lang.Object
-
- akka.http.scaladsl.Http.ServerBinding
-
- All Implemented Interfaces:
java.io.Serializable
,scala.Equals
,scala.Product
- Enclosing class:
- Http
public static final class Http.ServerBinding extends java.lang.Object implements scala.Product, java.io.Serializable
Represents a prospective HTTP server binding.param: localAddress The local address of the endpoint bound by the materialization of the
connections
Source
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ServerBinding(java.net.InetSocketAddress localAddress, scala.Function0<scala.concurrent.Future<scala.runtime.BoxedUnit>> unbindAction, scala.Function1<scala.concurrent.duration.FiniteDuration,scala.concurrent.Future<Http.HttpTerminated>> terminateAction)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Http.ServerBinding
addToCoordinatedShutdown(scala.concurrent.duration.FiniteDuration hardTerminationDeadline, akka.actor.ClassicActorSystemProvider system)
Adds thisServerBinding
to the actor system's coordinated shutdown, so thatunbind()
andterminate(scala.concurrent.duration.FiniteDuration)
get called appropriately before the system is shut down.java.net.InetSocketAddress
localAddress()
scala.concurrent.Future<Http.HttpTerminated>
terminate(scala.concurrent.duration.FiniteDuration hardDeadline)
Triggers "graceful" termination request being handled on this connection.scala.concurrent.Future<akka.Done>
unbind()
Asynchronously triggers the unbinding of the port that was bound by the materialization of theconnections
Source
scala.concurrent.Future<Http.HttpTerminated>
whenTerminated()
This future completes when the termination process, as initiated by anterminate(scala.concurrent.duration.FiniteDuration)
call has completed.scala.concurrent.Future<scala.concurrent.duration.Deadline>
whenTerminationSignalIssued()
Completes when theterminate(scala.concurrent.duration.FiniteDuration)
is called and server termination is in progress.
-
-
-
Constructor Detail
-
ServerBinding
public ServerBinding(java.net.InetSocketAddress localAddress, scala.Function0<scala.concurrent.Future<scala.runtime.BoxedUnit>> unbindAction, scala.Function1<scala.concurrent.duration.FiniteDuration,scala.concurrent.Future<Http.HttpTerminated>> terminateAction)
-
-
Method Detail
-
localAddress
public java.net.InetSocketAddress localAddress()
-
unbind
public scala.concurrent.Future<akka.Done> unbind()
Asynchronously triggers the unbinding of the port that was bound by the materialization of theconnections
Source
Note that unbinding does NOT terminate existing connections. Unbinding only means that the server will not accept new connections, and existing connections are allowed to still perform request/response cycles. This can be useful when one wants to let clients finish whichever work they have remaining, while signalling them using some other way that the server will be terminating soon -- e.g. by sending such information in the still being sent out responses, such that the client can switch to a new server when it is ready.
Alternatively you may want to use the
terminate(scala.concurrent.duration.FiniteDuration)
method which unbinds and performs some level of gracefully replying withThe produced
Future
is fulfilled when the unbinding has been completed.Note: rather than unbinding explicitly you can also use
addToCoordinatedShutdown(scala.concurrent.duration.FiniteDuration,akka.actor.ClassicActorSystemProvider)
to add this task to Akka's coordinated shutdown.- Returns:
- (undocumented)
-
terminate
public scala.concurrent.Future<Http.HttpTerminated> terminate(scala.concurrent.duration.FiniteDuration hardDeadline)
Triggers "graceful" termination request being handled on this connection.Termination works as follows:
1) Unbind: - the server port is unbound; no new connections will be accepted.
1.5) Immediately the ServerBinding
whenTerminationSignalIssued
future is completed. This can be used to signal parts of the application that the http server is shutting down and they should clean up as well. Note also that for more advanced shut down scenarios you may want to use the Coordinated Shutdown capabilities of Akka.2) if a connection has no "in-flight" request, it is terminated immediately
3) Handle in-flight request: - if a request is "in-flight" (being handled by user code), it is given
hardDeadline
time to complete, - if user code emits a response within the timeout, then this response is sent to the client with aConnection: close
header and the connection is closed. - however if it is a streaming response, it is also mandated that it shall complete within the deadline, and if it does not the connection will be terminated regardless of status of the streaming response (this is because such response could be infinite, which could trap the server in a situation where it could not terminate if it were to wait for a response to "finish") - existing streaming responses must complete before the deadline as well. When the deadline is reached the connection will be terminated regardless of status of the streaming responses. - if user code does not reply with a response within the deadline we produce a specialakka.http.javadsl.settings.ServerSettings.getTerminationDeadlineExceededResponse
HTTP response (e.g. 503 Service Unavailable)4) Keep draining incoming requests on existing connection: - The existing connection will remain alive for until the
hardDeadline
is exceeded, yet no new requests will be delivered to the user handler. All such drained responses will be replied to with an termination response (as explained in phase 3).5) Close still existing connections - Connections are terminated forcefully once the
hardDeadline
is exceeded. ThewhenTerminated
future is completed as well, so the graceful termination (of theActorSystem
or entire JVM itself can be safely performed, as by then it is known that no connections remain alive to this server).Note that the termination response is configurable in
ServerSettings
, and by default is an503 Service Unavailable
, with an empty response entity.Note: rather than terminating explicitly you can also use
addToCoordinatedShutdown(scala.concurrent.duration.FiniteDuration,akka.actor.ClassicActorSystemProvider)
to add this task to Akka's coordinated shutdown.- Parameters:
hardDeadline
- timeout after which all requests and connections shall be forcefully terminated- Returns:
- future which completes successfully with a marker object once all connections have been terminated
-
whenTerminationSignalIssued
public scala.concurrent.Future<scala.concurrent.duration.Deadline> whenTerminationSignalIssued()
Completes when theterminate(scala.concurrent.duration.FiniteDuration)
is called and server termination is in progress. Can be useful to make parts of your application aware that termination has been issued, and they haveDeadline
time remaining to clean-up before the server will forcefully close existing connections.Note that while termination is in progress, no new connections will be accepted (i.e. termination implies prior
unbind()
).- Returns:
- (undocumented)
-
whenTerminated
public scala.concurrent.Future<Http.HttpTerminated> whenTerminated()
This future completes when the termination process, as initiated by anterminate(scala.concurrent.duration.FiniteDuration)
call has completed. This means that the server is by then: unbound, and has closed all existing connections.This signal can for example be used to safely terminate the underlying ActorSystem.
Note that this signal may be used for Coordinated Shutdown to proceed to next steps in the shutdown. You may also explicitly depend on this future to perform your next shutting down steps.
- Returns:
- (undocumented)
-
addToCoordinatedShutdown
public Http.ServerBinding addToCoordinatedShutdown(scala.concurrent.duration.FiniteDuration hardTerminationDeadline, akka.actor.ClassicActorSystemProvider system)
Adds thisServerBinding
to the actor system's coordinated shutdown, so thatunbind()
andterminate(scala.concurrent.duration.FiniteDuration)
get called appropriately before the system is shut down.- Parameters:
hardTerminationDeadline
- timeout after which all requests and connections shall be forcefully terminatedsystem
- (undocumented)- Returns:
- (undocumented)
-
-