public class NetSocketImpl extends ConnectionBase implements NetSocket
channel, closeHandler, context, exceptionHandler, metrics, vertx
Constructor and Description |
---|
NetSocketImpl(VertxInternal vertx,
io.netty.channel.Channel channel,
ContextImpl context,
SSLHelper helper,
boolean client,
TCPMetrics metrics,
Object metric) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the connection
|
NetSocket |
closeHandler(Handler<Void> handler)
Set a handler that will be called when the NetSocket is closed
|
NetSocket |
drainHandler(Handler<Void> drainHandler)
Set a drain handler on the stream.
|
NetSocket |
endHandler(Handler<Void> endHandler)
Set an end handler.
|
NetSocket |
exceptionHandler(Handler<Throwable> handler)
Set an exception handler on the read stream.
|
protected void |
handleClosed() |
protected void |
handleInterestedOpsChanged() |
NetSocket |
handler(Handler<Buffer> dataHandler)
Set a data handler.
|
boolean |
isSsl() |
SocketAddress |
localAddress() |
protected Object |
metric() |
NetSocket |
pause()
Pause the
ReadSupport . |
X509Certificate[] |
peerCertificateChain() |
SocketAddress |
remoteAddress() |
NetSocket |
resume()
Resume reading.
|
NetSocket |
sendFile(String filename)
Tell the operating system to stream a file as specified by
filename directly from disk to the outgoing connection,
bypassing userspace altogether (where supported by the underlying operating system. |
NetSocket |
sendFile(String filename,
Handler<AsyncResult<Void>> resultHandler)
Same as
NetSocket.sendFile(String) but also takes a handler that will be called when the send has completed or
a failure has occurred |
protected void |
setMetric(Object metric) |
NetSocket |
setWriteQueueMaxSize(int maxSize)
Set the maximum size of the write queue to
maxSize . |
NetSocket |
upgradeToSsl(Handler<Void> handler)
Upgrade channel to use SSL/TLS.
|
NetSocket |
write(Buffer data)
Write some data to the stream.
|
NetSocket |
write(String str)
Write a
String to the connection, encoded in UTF-8. |
NetSocket |
write(String str,
String enc)
Write a
String to the connection, encoded using the encoding enc . |
String |
writeHandlerID()
When a
NetSocket is created it automatically registers an event handler with the event bus, the ID of that
handler is given by writeHandlerID . |
boolean |
writeQueueFull()
This will return
true if there are more bytes in the write queue than the value set using WriteStream.setWriteQueueMaxSize(int) |
addFuture, checkContext, doPause, doResume, doSetWriteQueueMaxSize, endReadAndFlush, getContext, getPeerCertificateChain, handleException, isNotWritable, queueForWrite, reportBytesRead, reportBytesWritten, sendFile, startRead, supportsFileRegion, writeToChannel
public NetSocketImpl(VertxInternal vertx, io.netty.channel.Channel channel, ContextImpl context, SSLHelper helper, boolean client, TCPMetrics metrics, Object metric)
protected void setMetric(Object metric)
protected Object metric()
metric
in class ConnectionBase
public String writeHandlerID()
NetSocket
NetSocket
is created it automatically registers an event handler with the event bus, the ID of that
handler is given by writeHandlerID
.
Given this ID, a different event loop can send a buffer to that event handler using the event bus and that buffer will be received by this instance in its own event loop and written to the underlying connection. This allows you to write data to other connections which are owned by different event loops.
writeHandlerID
in interface NetSocket
public NetSocket write(Buffer data)
WriteStream
WriteStream.writeQueueFull()
method before writing. This is done automatically if using a Pump
.write
in interface NetSocket
write
in interface WriteStream<Buffer>
data
- the data to writepublic NetSocket write(String str)
NetSocket
String
to the connection, encoded in UTF-8.public NetSocket write(String str, String enc)
NetSocket
String
to the connection, encoded using the encoding enc
.public NetSocket handler(Handler<Buffer> dataHandler)
ReadStream
handler
in interface NetSocket
handler
in interface ReadStream<Buffer>
public NetSocket pause()
ReadStream
ReadSupport
. While it's paused, no data will be sent to the dataHandler
pause
in interface NetSocket
pause
in interface ReadStream<Buffer>
public NetSocket resume()
ReadStream
ReadSupport
has been paused, reading will recommence on it.resume
in interface NetSocket
resume
in interface ReadStream<Buffer>
public NetSocket setWriteQueueMaxSize(int maxSize)
WriteStream
maxSize
. You will still be able to write to the stream even
if there is more than maxSize
bytes in the write queue. This is used as an indicator by classes such as
Pump
to provide flow control.setWriteQueueMaxSize
in interface NetSocket
setWriteQueueMaxSize
in interface WriteStream<Buffer>
maxSize
- the max size of the write streampublic boolean writeQueueFull()
WriteStream
true
if there are more bytes in the write queue than the value set using WriteStream.setWriteQueueMaxSize(int)
writeQueueFull
in interface WriteStream<Buffer>
public NetSocket endHandler(Handler<Void> endHandler)
ReadStream
endHandler
in interface NetSocket
endHandler
in interface ReadStream<Buffer>
public NetSocket drainHandler(Handler<Void> drainHandler)
WriteStream
Pump
for an example of this being used.drainHandler
in interface NetSocket
drainHandler
in interface WriteStream<Buffer>
drainHandler
- the handlerpublic NetSocket sendFile(String filename)
NetSocket
filename
directly from disk to the outgoing connection,
bypassing userspace altogether (where supported by the underlying operating system. This is a very efficient way to stream files.public NetSocket sendFile(String filename, Handler<AsyncResult<Void>> resultHandler)
NetSocket
NetSocket.sendFile(String)
but also takes a handler that will be called when the send has completed or
a failure has occurredpublic SocketAddress remoteAddress()
remoteAddress
in interface NetSocket
remoteAddress
in class ConnectionBase
public SocketAddress localAddress()
localAddress
in interface NetSocket
localAddress
in class ConnectionBase
public NetSocket exceptionHandler(Handler<Throwable> handler)
ReadStream
exceptionHandler
in interface NetSocket
exceptionHandler
in interface ReadStream<Buffer>
exceptionHandler
in interface StreamBase
exceptionHandler
in interface WriteStream<Buffer>
handler
- the exception handlerpublic NetSocket closeHandler(Handler<Void> handler)
NetSocket
closeHandler
in interface NetSocket
handler
- the handlerpublic void close()
ConnectionBase
close
in interface NetSocket
close
in class ConnectionBase
public NetSocket upgradeToSsl(Handler<Void> handler)
NetSocket
upgradeToSsl
in interface NetSocket
handler
- the handler will be notified when it's upgradedpublic boolean isSsl()
public X509Certificate[] peerCertificateChain() throws SSLPeerUnverifiedException
peerCertificateChain
in interface NetSocket
SSLPeerUnverifiedException
- SSL peer's identity has not been verified.protected void handleInterestedOpsChanged()
handleInterestedOpsChanged
in class ConnectionBase
protected void handleClosed()
handleClosed
in class ConnectionBase
Copyright © 2015. All Rights Reserved.