Top Description Fields Constructors Methods
io.vertx.core.net.impl

public abstract Class ConnectionBase

extends Object
Class Inheritance
Known Direct Subclasses
io.vertx.core.net.impl.NetSocketImpl, io.vertx.core.datagram.impl.DatagramSocketImpl.Connection, io.vertx.core.http.impl.Http1xConnectionBase, io.vertx.core.http.impl.Http2ConnectionBase
Imports
io.netty.buffer.ByteBuf, .Unpooled, io.netty.channel.*, io.netty.handler.ssl.SslHandler, io.netty.handler.stream.ChunkedNioFile, io.netty.handler.timeout.IdleStateEvent, io.netty.handler.traffic.AbstractTrafficShapingHandler, io.netty.util.AttributeKey, .ReferenceCountUtil, io.netty.util.concurrent.EventExecutor, .FutureListener, io.vertx.core.*, io.vertx.core.impl.ContextInternal, .VertxInternal, io.vertx.core.impl.future.PromiseInternal, io.vertx.core.impl.logging.Logger, .LoggerFactory, io.vertx.core.net.SocketAddress, io.vertx.core.spi.metrics.NetworkMetrics, .TCPMetrics, javax.net.ssl.SSLPeerUnverifiedException, .SSLSession, javax.security.cert.X509Certificate, java.io.IOException, .RandomAccessFile, java.net.InetSocketAddress, java.security.cert.Certificate, java.util.Arrays, .List

Abstract base class for TCP connections. This class is optimised for performance when used on the same event loop. However it can be used safely from other threads. The internal state is protected using the synchronized keyword. If always used on the same event loop, then we benefit from biased locking which makes the overhead of synchronized near zero.
Author
Tim Fox

Field Summary

Modifier and TypeField and Description
protected final ChannelHandlerContext
private boolean
public static final VertxException
CLOSED_EXCEPTION

An exception used to signal a closed connection to an exception handler.

private Future<Void>
private Handler<Void>
private ChannelPromise
protected final ContextInternal
private Handler<Throwable>
public static final AttributeKey<SocketAddress>
private SocketAddress
private static final Logger
private static final int
private Object
private static final long
private static final long
private boolean
private boolean
private SocketAddress
private SocketAddress
private long
private long
public static final AttributeKey<SocketAddress>
private SocketAddress
protected final VertxInternal
public final VoidChannelPromise
private int

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public final Channel

Returns:

the Netty channel - for internal usage only
channel
()

public ChannelPromise
public final ChannelHandlerContext
private SocketAddress
private SocketAddress
private void
pack-priv void
public Future<Void>
close()

Close the connection

public final void
close(Handler<AsyncResult<Void>> handler)

Close the connection and notifies the handler

public Future<Void>

Returns:

a promise that will be completed when the connection becomes closed
closeFuture
()

public synchronized ConnectionBase
public void
private void
public void
public void
pack-priv final void
endReadAndFlush()

This method is exclusively called by VertxHandler to signal read completion on the event-loop thread.

public synchronized ConnectionBase
protected synchronized Handler<Throwable>
public void
fail(Throwable
the Throwable to propagate
error
)

Fail the connection, the error will be sent to the pipeline and the connection will stop processing any further message.

public final void
flush()

Asynchronous flush.

public final void
flush(ChannelPromise
the promise resolved when flush occurred
promise
)

Asynchronous flush.

public void
public void
public final ContextInternal
protected void
protected void
protected void
protected void
handleIdle(IdleStateEvent event)

Called by the Netty handler when the connection becomes idle.

protected abstract void
protected void
public String
public boolean
public boolean
public boolean
public SocketAddress
public SocketAddress
localAddress(boolean real)

public final synchronized void
metric(Object metric)

public final synchronized Object
public abstract NetworkMetrics<S>
public X509Certificate[]
peerCertificateChain()
References Deprecated X509Certificate is deprecated or references (maybe indirectly) at least one deprecated element.

public List<Certificate>
private void
queueForWrite(Object msg, boolean forceFlush, ChannelPromise promise)

pack-priv final void
read(Object msg)

This method is exclusively called by VertxHandler to read a message on the event-loop thread.

public SocketAddress
public SocketAddress
remoteAddress(boolean real)

public String
public final void
public final void
reportBytesRead(long numberOfBytes)

public final void
reportBytesWritten(long numberOfBytes)

public final void
public final ChannelFuture
sendFile(RandomAccessFile raf, long offset, long length)

private void
sendFileRegion(RandomAccessFile
the file to send
file
,
long
the file offset
offset
,
long
the file length
length
,
ChannelPromise
the write future to be completed when the transfer is done or failed
writeFuture
)

Send a file as a file region for zero copy transfer to the socket.

protected long
private SocketAddress
public SSLSession
protected boolean
private ChannelPromise
private void
write(Object
the message to write
msg
,
Boolean
a null flush value means to flush when there is no read in progress, otherwise it will apply the policy
flush
,
ChannelPromise
the promise receiving the completion event
promise
)

This method is exclusively called on the event-loop thread

private void
writeClose(PromiseInternal<Void>
the promise receiving the completion event
promise
)

This method is exclusively called on the event-loop thread

public final void
public final void
public final void
writeToChannel(Object msg, boolean forceFlush, ChannelPromise promise)

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

chctxback to summary
protected final ChannelHandlerContext chctx
closedback to summary
private boolean closed
CLOSED_EXCEPTIONback to summary
public static final VertxException CLOSED_EXCEPTION

An exception used to signal a closed connection to an exception handler. Exception are expensive to create, this instance can be used for this purpose. It does not capture a stack trace to not be misleading.

closeFutureback to summary
private Future<Void> closeFuture
closeHandlerback to summary
private Handler<Void> closeHandler
closePromiseback to summary
private ChannelPromise closePromise
contextback to summary
protected final ContextInternal context
exceptionHandlerback to summary
private Handler<Throwable> exceptionHandler
LOCAL_ADDRESS_OVERRIDEback to summary
public static final AttributeKey<SocketAddress> LOCAL_ADDRESS_OVERRIDE
localAddressback to summary
private SocketAddress localAddress
logback to summary
private static final Logger log
MAX_REGION_SIZEback to summary
private static final int MAX_REGION_SIZE
metricback to summary
private Object metric
METRICS_REPORTED_BYTES_HIGH_MASKback to summary
private static final long METRICS_REPORTED_BYTES_HIGH_MASK
METRICS_REPORTED_BYTES_LOW_MASKback to summary
private static final long METRICS_REPORTED_BYTES_LOW_MASK
needsFlushback to summary
private boolean needsFlush
readback to summary
private boolean read
realLocalAddressback to summary
private SocketAddress realLocalAddress
realRemoteAddressback to summary
private SocketAddress realRemoteAddress
remainingBytesReadback to summary
private long remainingBytesRead
remainingBytesWrittenback to summary
private long remainingBytesWritten
REMOTE_ADDRESS_OVERRIDEback to summary
public static final AttributeKey<SocketAddress> REMOTE_ADDRESS_OVERRIDE
remoteAddressback to summary
private SocketAddress remoteAddress
vertxback to summary
protected final VertxInternal vertx
voidPromiseback to summary
public final VoidChannelPromise voidPromise
writeInProgressback to summary
private int writeInProgress

Constructor Detail

ConnectionBaseback to summary
protected ConnectionBase(ContextInternal context, ChannelHandlerContext chctx)

Method Detail

channelback to summary
public final Channel channel()
Returns:Channel

the Netty channel - for internal usage only

channelFutureback to summary
public ChannelPromise channelFuture()
channelHandlerContextback to summary
public final ChannelHandlerContext channelHandlerContext()
channelLocalAddressback to summary
private SocketAddress channelLocalAddress()
channelRemoteAddressback to summary
private SocketAddress channelRemoteAddress()
checkCloseHandlerback to summary
private void checkCloseHandler(AsyncResult<Void> ar)
closeback to summary
pack-priv void close(ChannelPromise promise)
closeback to summary
public Future<Void> close()

Close the connection

closeback to summary
public final void close(Handler<AsyncResult<Void>> handler)

Close the connection and notifies the handler

closeFutureback to summary
public Future<Void> closeFuture()
Returns:Future<Void>

a promise that will be completed when the connection becomes closed

closeHandlerback to summary
public synchronized ConnectionBase closeHandler(Handler<Void> handler)
doPauseback to summary
public void doPause()
doReportBytesReadback to summary
private void doReportBytesRead(Object msg, NetworkMetrics<S> metrics)
doResumeback to summary
public void doResume()
doSetWriteQueueMaxSizeback to summary
public void doSetWriteQueueMaxSize(int size)
endReadAndFlushback to summary
pack-priv final void endReadAndFlush()

This method is exclusively called by VertxHandler to signal read completion on the event-loop thread.

exceptionHandlerback to summary
public synchronized ConnectionBase exceptionHandler(Handler<Throwable> handler)
exceptionHandlerback to summary
protected synchronized Handler<Throwable> exceptionHandler()
failback to summary
public void fail(Throwable error)

Fail the connection, the error will be sent to the pipeline and the connection will stop processing any further message.

Parameters
error:Throwable

the Throwable to propagate

flushback to summary
public final void flush()

Asynchronous flush.

flushback to summary
public final void flush(ChannelPromise promise)

Asynchronous flush.

Parameters
promise:ChannelPromise

the promise resolved when flush occurred

flushBytesReadback to summary
public void flushBytesRead()
flushBytesWrittenback to summary
public void flushBytesWritten()
getContextback to summary
public final ContextInternal getContext()
handleClosedback to summary
protected void handleClosed()
handleEventback to summary
protected void handleEvent(Object evt)
handleExceptionback to summary
protected void handleException(Throwable t)
handleIdleback to summary
protected void handleIdle(IdleStateEvent event)

Called by the Netty handler when the connection becomes idle. The default implementation closes the connection.

Subclasses can override it to prevent the idle event to happen (e.g when the connection is pooled) or perform extra work when the idle event happens.

handleInterestedOpsChangedback to summary
protected abstract void handleInterestedOpsChanged()
handleMessageback to summary
protected void handleMessage(Object msg)
indicatedServerNameback to summary
public String indicatedServerName()
isNotWritableback to summary
public boolean isNotWritable()
isSslback to summary
public boolean isSsl()
isTrafficShapedback to summary
public boolean isTrafficShaped()
localAddressback to summary
public SocketAddress localAddress()
localAddressback to summary
public SocketAddress localAddress(boolean real)
metricback to summary
public final synchronized void metric(Object metric)
metricback to summary
public final synchronized Object metric()
metricsback to summary
public abstract NetworkMetrics<S> metrics()
peerCertificateChainback to summary
public X509Certificate[] peerCertificateChain() throws SSLPeerUnverifiedException

References Deprecated

X509Certificate is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

peerCertificatesback to summary
public List<Certificate> peerCertificates() throws SSLPeerUnverifiedException
queueForWriteback to summary
private void queueForWrite(Object msg, boolean forceFlush, ChannelPromise promise)
readback to summary
pack-priv final void read(Object msg)

This method is exclusively called by VertxHandler to read a message on the event-loop thread.

remoteAddressback to summary
public SocketAddress remoteAddress()
remoteAddressback to summary
public SocketAddress remoteAddress(boolean real)
remoteNameback to summary
public String remoteName()
reportBytesReadback to summary
public final void reportBytesRead(Object msg)
reportBytesReadback to summary
public final void reportBytesRead(long numberOfBytes)
reportBytesWrittenback to summary
public final void reportBytesWritten(long numberOfBytes)
reportsBytesWrittenback to summary
public final void reportsBytesWritten(Object msg)
sendFileback to summary
public final ChannelFuture sendFile(RandomAccessFile raf, long offset, long length) throws IOException
sendFileRegionback to summary
private void sendFileRegion(RandomAccessFile file, long offset, long length, ChannelPromise writeFuture)

Send a file as a file region for zero copy transfer to the socket. The implementation splits the file into multiple regions to avoid stalling the pipeline and producing idle timeouts for very large files.

Parameters
file:RandomAccessFile

the file to send

offset:long

the file offset

length:long

the file length

writeFuture:ChannelPromise

the write future to be completed when the transfer is done or failed

sizeofback to summary
protected long sizeof(Object msg)
socketAdressOverrideback to summary
private SocketAddress socketAdressOverride(AttributeKey<SocketAddress> key)
sslSessionback to summary
public SSLSession sslSession()
supportsFileRegionback to summary
protected boolean supportsFileRegion()
wrapback to summary
private ChannelPromise wrap(FutureListener<Void> handler)
writeback to summary
private void write(Object msg, Boolean flush, ChannelPromise promise)

This method is exclusively called on the event-loop thread

Parameters
msg:Object

the message to write

flush:Boolean

a null flush value means to flush when there is no read in progress, otherwise it will apply the policy

promise:ChannelPromise

the promise receiving the completion event

writeCloseback to summary
private void writeClose(PromiseInternal<Void> promise)

This method is exclusively called on the event-loop thread

Parameters
promise:PromiseInternal<Void>

the promise receiving the completion event

writeToChannelback to summary
public final void writeToChannel(Object msg, FutureListener<Void> listener)
writeToChannelback to summary
public final void writeToChannel(Object msg, ChannelPromise promise)
writeToChannelback to summary
public final void writeToChannel(Object msg, boolean forceFlush, ChannelPromise promise)
writeToChannelback to summary
public void writeToChannel(Object obj)