object Tcp extends ExtensionId[TcpExt] with ExtensionIdProvider
TCP Extension for Akka’s IO layer.
For a full description of the design and philosophy behind this IO implementation please refer to the Pekko online documentation.
In order to open an outbound connection send a Tcp.Connect message to the TcpExt#manager.
In order to start listening for inbound connections send a Tcp.Bind message to the TcpExt#manager.
The Java API for generating TCP commands is available at TcpMessage.
- Source
- Tcp.scala
- Alphabetic
- By Inheritance
- Tcp
- ExtensionIdProvider
- ExtensionId
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- final case class Bind(handler: ActorRef, localAddress: InetSocketAddress, backlog: Int = 100, options: Traversable[SocketOption] = Nil, pullMode: Boolean = false) extends Command with Product with Serializable
The Bind message is send to the TCP manager actor, which is obtained via TcpExt#manager in order to bind to a listening socket.
The Bind message is send to the TCP manager actor, which is obtained via TcpExt#manager in order to bind to a listening socket. The manager replies either with a CommandFailed or the actor handling the listen socket replies with a Bound message. If the local port is set to 0 in the Bind message, then the Bound message should be inspected to find the actual port which was bound to.
- handler
The actor which will receive all incoming connection requests in the form of Connected messages.
- localAddress
The socket address to bind to; use port zero for automatic assignment (i.e. an ephemeral port, see Bound)
- backlog
This specifies the number of unaccepted connections the O/S kernel will hold for this port before refusing connections.
- options
Please refer to the
Tcp.SO
object for a list of all supported options.
- Annotations
- @nowarn()
- final case class Bound(localAddress: InetSocketAddress) extends Event with Product with Serializable
The sender of a Bind command will—in case of success—receive confirmation in this form.
The sender of a Bind command will—in case of success—receive confirmation in this form. If the bind address indicated a 0 port number, then the contained
localAddress
can be used to find out which port was automatically assigned. - sealed trait CloseCommand extends Command with DeadLetterSuppression
Common interface for all commands which aim to close down an open connection.
- trait Command extends Message with HasFailureMessage
This is the common trait for all commands understood by TCP actors.
- final case class CommandFailed(cmd: Command) extends Event with Product with Serializable
Whenever a command cannot be completed, the queried actor will reply with this message, wrapping the original command which failed.
- final case class CompoundWrite(head: SimpleWriteCommand, tailCommand: WriteCommand) extends WriteCommand with Iterable[SimpleWriteCommand] with Product with Serializable
A write command which aggregates two other write commands.
A write command which aggregates two other write commands. Using this construct you can chain a number of Write and/or WriteFile commands together in a way that allows them to be handled as a single write which gets written out to the network as quickly as possible. If the sub commands contain
ack
requests they will be honored as soon as the respective write has been written completely. - final case class Connect(remoteAddress: InetSocketAddress, localAddress: Option[InetSocketAddress] = None, options: Traversable[SocketOption] = Nil, timeout: Option[FiniteDuration] = None, pullMode: Boolean = false) extends Command with Product with Serializable
The Connect message is sent to the TCP manager actor, which is obtained via TcpExt#manager.
The Connect message is sent to the TCP manager actor, which is obtained via TcpExt#manager. Either the manager replies with a CommandFailed or the actor handling the new connection replies with a Connected message.
- remoteAddress
is the address to connect to
- localAddress
optionally specifies a specific address to bind to
- options
Please refer to the
Tcp.SO
object for a list of all supported options.
- Annotations
- @nowarn()
- final case class Connected(remoteAddress: InetSocketAddress, localAddress: InetSocketAddress) extends Event with Product with Serializable
The connection actor sends this message either to the sender of a Connect command (for outbound) or to the handler for incoming connections designated in the Bind message.
- sealed trait ConnectionClosed extends Event with DeadLetterSuppression
This is the common interface for all events which indicate that a connection has been closed or half-closed.
- final case class ErrorClosed(cause: String) extends ConnectionClosed with Product with Serializable
The connection has been closed due to an IO error.
- trait Event extends Message
Common interface for all events generated by the TCP layer actors.
- sealed trait Message extends NoSerializationVerificationNeeded
- case class NoAck(token: Any) extends Event with Product with Serializable
Each WriteCommand can optionally request a positive acknowledgment to be sent to the commanding actor.
Each WriteCommand can optionally request a positive acknowledgment to be sent to the commanding actor. If such notification is not desired the SimpleWriteCommand#ack must be set to an instance of this class. The token contained within can be used to recognize which write failed when receiving a CommandFailed message.
- final case class Received(data: ByteString) extends Event with Product with Serializable
Whenever data are read from a socket they will be transferred within this class to the handler actor which was designated in the Register message.
- final case class Register(handler: ActorRef, keepOpenOnPeerClosed: Boolean = false, useResumeWriting: Boolean = true) extends Command with Product with Serializable
This message must be sent to a TCP connection actor after receiving the Connected message.
This message must be sent to a TCP connection actor after receiving the Connected message. The connection will not read any data from the socket until this message is received, because this message defines the actor which will receive all inbound data.
- handler
The actor which will receive all incoming data and which will be informed when the connection is closed.
- keepOpenOnPeerClosed
If this is set to true then the connection is not automatically closed when the peer closes its half, requiring an explicit CloseCommand from our side when finished.
- useResumeWriting
If this is set to true then the connection actor will refuse all further writes after issuing a CommandFailed notification until
ResumeWriting
is received. This can be used to implement NACK-based write backpressure.
- final case class ResumeAccepting(batchSize: Int) extends Command with Product with Serializable
This message enables the accepting of the next connection if read throttling is enabled for connection actors.
This message enables the accepting of the next connection if read throttling is enabled for connection actors.
- batchSize
The number of connections to accept before waiting for the next resume command
- sealed abstract class SimpleWriteCommand extends WriteCommand
- sealed trait Unbound extends Event
The sender of an
Unbind
command will receive confirmation through this message once the listening socket has been closed. - final case class Write(data: ByteString, ack: Event) extends SimpleWriteCommand with Product with Serializable
Write data to the TCP connection.
Write data to the TCP connection. If no ack is needed use the special
NoAck
object. The connection actor will reply with a CommandFailed message if the write could not be enqueued. If SimpleWriteCommand#wantsAck returns true, the connection actor will reply with the supplied SimpleWriteCommand#ack token once the write has been successfully enqueued to the O/S kernel. Note that this does not in any way guarantee that the data will be or have been sent! Unfortunately there is no way to determine whether a particular write has been sent by the O/S. - sealed abstract class WriteCommand extends Command
Common interface for all write commands.
- final case class WritePath(path: Path, position: Long, count: Long, ack: Event) extends SimpleWriteCommand with Product with Serializable
Write
count
bytes starting atposition
from file atfilePath
to the connection.Write
count
bytes starting atposition
from file atfilePath
to the connection. The count must be > 0. The connection actor will reply with a CommandFailed message if the write could not be enqueued. If SimpleWriteCommand#wantsAck returns true, the connection actor will reply with the supplied SimpleWriteCommand#ack token once the write has been successfully enqueued to the O/S kernel. Note that this does not in any way guarantee that the data will be or have been sent! Unfortunately there is no way to determine whether a particular write has been sent by the O/S. - sealed trait WritingResumed extends Event
When
useResumeWriting
is in effect as indicated in the Register message, theResumeWriting
command will be acknowledged by this message type, upon which it is safe to send at least one write.When
useResumeWriting
is in effect as indicated in the Register message, theResumeWriting
command will be acknowledged by this message type, upon which it is safe to send at least one write. This means that all writes preceding the first CommandFailed message have been enqueued to the O/S kernel at this point.
Deprecated Type Members
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def apply(system: ClassicActorSystemProvider): TcpExt
Returns an instance of the extension identified by this ExtensionId instance.
Returns an instance of the extension identified by this ExtensionId instance.
- Definition Classes
- ExtensionId
- def apply(system: ActorSystem): TcpExt
Returns an instance of the extension identified by this ExtensionId instance.
Returns an instance of the extension identified by this ExtensionId instance.
- Definition Classes
- ExtensionId
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @HotSpotIntrinsicCandidate() @native()
- def createExtension(system: ExtendedActorSystem): TcpExt
Is used by Pekko to instantiate the Extension identified by this ExtensionId, internal use only.
Is used by Pekko to instantiate the Extension identified by this ExtensionId, internal use only.
- Definition Classes
- Tcp → ExtensionId
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def equals(other: Any): Boolean
- Definition Classes
- ExtensionId → AnyRef → Any
- def get(system: ClassicActorSystemProvider): TcpExt
Returns an instance of the extension identified by this ExtensionId instance.
Returns an instance of the extension identified by this ExtensionId instance. Java API For extensions written in Scala that are to be used from Java also, this method should be overridden to get correct return type.
override def get(system: ClassicActorSystemProvider): TheExtension = super.get(system)
- Definition Classes
- Tcp → ExtensionId
- def get(system: ActorSystem): TcpExt
Java API: retrieve the Tcp extension for the given system.
Java API: retrieve the Tcp extension for the given system.
- Definition Classes
- Tcp → ExtensionId
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @HotSpotIntrinsicCandidate() @native()
- final def hashCode(): Int
- Definition Classes
- ExtensionId → AnyRef → Any
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def lookup: Tcp
Returns the canonical ExtensionId for this Extension
Returns the canonical ExtensionId for this Extension
- Definition Classes
- Tcp → ExtensionIdProvider
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @HotSpotIntrinsicCandidate() @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @HotSpotIntrinsicCandidate() @native()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- case object Abort extends CloseCommand with Product with Serializable
An abort operation will not flush pending writes and will issue a TCP ABORT command to the O/S kernel which should result in a TCP_RST packet being sent to the peer.
An abort operation will not flush pending writes and will issue a TCP ABORT command to the O/S kernel which should result in a TCP_RST packet being sent to the peer. The sender of this command and the registered handler for incoming data will both be notified once the socket is closed using a
Aborted
message. - case object Aborted extends ConnectionClosed with Product with Serializable
The connection has been aborted in response to an
Abort
command. - case object Close extends CloseCommand with Product with Serializable
A normal close operation will first flush pending writes and then close the socket.
A normal close operation will first flush pending writes and then close the socket. The sender of this command and the registered handler for incoming data will both be notified once the socket is closed using a
Closed
message. - case object Closed extends ConnectionClosed with Product with Serializable
The connection has been closed normally in response to a
Close
command. - case object ConfirmedClose extends CloseCommand with Product with Serializable
A confirmed close operation will flush pending writes and half-close the connection, waiting for the peer to close the other half.
A confirmed close operation will flush pending writes and half-close the connection, waiting for the peer to close the other half. The sender of this command and the registered handler for incoming data will both be notified once the socket is closed using a
ConfirmedClosed
message. - case object ConfirmedClosed extends ConnectionClosed with Product with Serializable
The connection has been half-closed by us and then half-close by the peer in response to a
ConfirmedClose
command. - object NoAck extends NoAck
Default NoAck instance which is used when no acknowledgment information is explicitly provided.
Default NoAck instance which is used when no acknowledgment information is explicitly provided. Its “token” is
null
. - case object PeerClosed extends ConnectionClosed with Product with Serializable
The peer has closed its writing half of the connection.
- case object ResumeReading extends Command with DeadLetterSuppression with Product with Serializable
This command needs to be sent to the connection actor after a
SuspendReading
command in order to resume reading from the socket.This command needs to be sent to the connection actor after a
SuspendReading
command in order to resume reading from the socket.(This message is marked with DeadLetterSuppression as it is prone to end up in DeadLetters when the connection is torn down at the same time as the user wants to resume reading on that connection.)
- case object ResumeWriting extends Command with Product with Serializable
When
useResumeWriting
is in effect as was indicated in the Register message then this command needs to be sent to the connection actor in order to re-enable writing after a CommandFailed event.When
useResumeWriting
is in effect as was indicated in the Register message then this command needs to be sent to the connection actor in order to re-enable writing after a CommandFailed event. All WriteCommand processed by the connection actor between the first CommandFailed and subsequent reception of this message will also be rejected with CommandFailed. - object SO extends SoForwarders
Scala API: this object contains all applicable socket options for TCP.
Scala API: this object contains all applicable socket options for TCP.
For the Java API see TcpSO.
- case object SuspendReading extends Command with Product with Serializable
Sending this command to the connection actor will disable reading from the TCP socket.
Sending this command to the connection actor will disable reading from the TCP socket. TCP flow-control will then propagate backpressure to the sender side as buffers fill up on either end. To re-enable reading send
ResumeReading
. - case object Unbind extends Command with Product with Serializable
In order to close down a listening socket, send this message to that socket’s actor (that is the actor which previously had sent the Bound message).
- case object Unbound extends Unbound with Product with Serializable
- object Write extends Serializable
- object WriteCommand
- case object WritingResumed extends WritingResumed with Product with Serializable