public abstract class NetSocket extends org.vertx.java.core.net.impl.ConnectionBase implements ReadStream, WriteStream
Instances of this class are created on the client side by an NetClient
when a connection to a server is made, or on the server side by a NetServer
when a server accepts a connection.
It implements both ReadStream
and WriteStream
so it can be used with
Pump
to pump data with flow control.
Instances of this class are not thread-safe.
Modifier and Type | Field and Description |
---|---|
java.lang.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 . |
Modifier | Constructor and Description |
---|---|
protected |
NetSocket(org.vertx.java.core.impl.VertxInternal vertx,
org.jboss.netty.channel.Channel channel,
java.lang.String writeHandlerID,
org.vertx.java.core.impl.Context context) |
Modifier and Type | Method and Description |
---|---|
abstract void |
dataHandler(Handler<Buffer> dataHandler)
Set a data handler.
|
abstract void |
drainHandler(Handler<java.lang.Void> drainHandler)
Set a drain handler on the stream.
|
abstract void |
endHandler(Handler<java.lang.Void> endHandler)
Set an end handler.
|
abstract void |
sendFile(java.lang.String filename)
Tell the kernel 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. |
abstract NetSocket |
write(Buffer data)
Write a
Buffer to the request body. |
abstract NetSocket |
write(Buffer data,
Handler<java.lang.Void> doneHandler)
Write a
Buffer to the connection. |
abstract NetSocket |
write(java.lang.String str)
Write a
String to the connection, encoded in UTF-8. |
abstract NetSocket |
write(java.lang.String str,
Handler<java.lang.Void> doneHandler)
Write a
String to the connection, encoded in UTF-8. |
abstract NetSocket |
write(java.lang.String str,
java.lang.String enc)
Write a
String to the connection, encoded using the encoding enc . |
abstract NetSocket |
write(java.lang.String str,
java.lang.String enc,
Handler<java.lang.Void> doneHandler)
Write a
String to the connection, encoded with encoding enc . |
abstract void |
writeBuffer(Buffer data)
Write some data to the stream.
|
addFuture, close, closedHandler, exceptionHandler, getContext, handleClosed, handleException, handleHandlerException, isSSL, pause, resume, sendFile, setContext, setWriteQueueMaxSize, writeQueueFull
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
exceptionHandler, pause, resume
exceptionHandler, setWriteQueueMaxSize, writeQueueFull
public final java.lang.String writeHandlerID
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.
protected NetSocket(org.vertx.java.core.impl.VertxInternal vertx, org.jboss.netty.channel.Channel channel, java.lang.String writeHandlerID, org.vertx.java.core.impl.Context context)
public abstract void writeBuffer(Buffer data)
WriteStream.writeQueueFull()
method before writing. This is done automatically if using a Pump
.writeBuffer
in interface WriteStream
public abstract NetSocket write(Buffer data)
Buffer
to the request body.public abstract NetSocket write(java.lang.String str)
String
to the connection, encoded in UTF-8.public abstract NetSocket write(java.lang.String str, java.lang.String enc)
String
to the connection, encoded using the encoding enc
.public abstract NetSocket write(Buffer data, Handler<java.lang.Void> doneHandler)
Buffer
to the connection. The doneHandler
is called after the buffer is actually written to the wire.public abstract NetSocket write(java.lang.String str, Handler<java.lang.Void> doneHandler)
String
to the connection, encoded in UTF-8. The doneHandler
is called after the buffer is
actually written to the wire.public abstract NetSocket write(java.lang.String str, java.lang.String enc, Handler<java.lang.Void> doneHandler)
String
to the connection, encoded with encoding enc
. The doneHandler
is called after
the buffer is actually written to the wire.public abstract void sendFile(java.lang.String filename)
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 abstract void dataHandler(Handler<Buffer> dataHandler)
dataHandler
in interface ReadStream
public abstract void endHandler(Handler<java.lang.Void> endHandler)
endHandler
in interface ReadStream
public abstract void drainHandler(Handler<java.lang.Void> drainHandler)
Pump
for an example of this being used.drainHandler
in interface WriteStream