Class NettyConnection
- java.lang.Object
-
- org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnection
-
- All Implemented Interfaces:
Connection
- Direct Known Subclasses:
NettyServerConnection
public class NettyConnection extends Object implements Connection
-
-
Field Summary
Fields Modifier and Type Field Description protected io.netty.channel.Channelchannel
-
Constructor Summary
Constructors Constructor Description NettyConnection(Map<String,Object> configuration, io.netty.channel.Channel channel, BaseConnectionLifeCycleListener<?> listener, boolean batchingEnabled, boolean directDeliver)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanblockUntilWritable(long timeout, TimeUnit timeUnit)Causes the current thread to wait until the connection is writable unless the specified waiting time elapses.voidcheckFlushBatchBuffer()Called periodically to flush any data in the batch buffervoidclose()Closes the connection.ActiveMQBuffercreateTransportBuffer(int size)Create a new ActiveMQBuffer of the given size.voidfireReady(boolean ready)voidflush()Request to flush any previous written buffers into the wire.voidforceClose()This should close the internal channel without calling any listeners.io.netty.channel.ChannelgetChannel()This is exposed so users would have the option to look at any data through interceptorsTransportConfigurationgetConnectorConfig()Generates aTransportConfigurationto be used to connect to the same target this is connected to.ActiveMQPrincipalgetDefaultActiveMQPrincipal()ObjectgetID()returns the unique id of this wire.StringgetLocalAddress()Returns a string representation of the local address this connection is connected to.io.netty.channel.ChannelgetNettyChannel()RemotingConnectiongetProtocolConnection()StringgetRemoteAddress()Returns a string representation of the remote address this connection is connected to.booleanisDirectDeliver()booleanisOpen()booleanisSameTarget(TransportConfiguration... configs)booleanisUsingProtocolHandling()the InVM Connection has some special handling as it doesn't use Netty ProtocolChannel we will use this method Instead of using instanceofbooleanisWritable(ReadyListener callback)voidsetAutoRead(boolean autoRead)This will disable reading from the channel.voidsetProtocolConnection(RemotingConnection protocolConnection)StringtoString()voidwrite(ActiveMQBuffer buffer)writes the buffer to the connection with no flushing or batchingvoidwrite(ActiveMQBuffer buffer, boolean requestFlush)writes the buffer to the connection and if flush is true request to flush the buffer (and any previous un-flushed ones) into the wire.voidwrite(ActiveMQBuffer buffer, boolean flush, boolean batched)writes the buffer to the connection and if flush is true returns only when the buffer has been physically written to the connection.voidwrite(ActiveMQBuffer buffer, boolean flush, boolean batched, io.netty.channel.ChannelFutureListener futureListener)writes the buffer to the connection and if flush is true returns only when the buffer has been physically written to the connection.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.activemq.artemis.spi.core.remoting.Connection
getRouter, getSNIHostName
-
-
-
-
Constructor Detail
-
NettyConnection
public NettyConnection(Map<String,Object> configuration, io.netty.channel.Channel channel, BaseConnectionLifeCycleListener<?> listener, boolean batchingEnabled, boolean directDeliver)
-
-
Method Detail
-
getNettyChannel
public final io.netty.channel.Channel getNettyChannel()
-
setAutoRead
public final void setAutoRead(boolean autoRead)
Description copied from interface:ConnectionThis will disable reading from the channel. This is basically the same as blocking the reading.- Specified by:
setAutoReadin interfaceConnection
-
isWritable
public final boolean isWritable(ReadyListener callback)
- Specified by:
isWritablein interfaceConnection
-
isOpen
public boolean isOpen()
- Specified by:
isOpenin interfaceConnection
-
fireReady
public final void fireReady(boolean ready)
- Specified by:
fireReadyin interfaceConnection
-
forceClose
public final void forceClose()
Description copied from interface:ConnectionThis should close the internal channel without calling any listeners. This is to avoid a situation where the broker is busy writing on an internal thread. This should close the socket releasing any pending threads.- Specified by:
forceClosein interfaceConnection
-
getChannel
public final io.netty.channel.Channel getChannel()
This is exposed so users would have the option to look at any data through interceptors- Returns:
-
getProtocolConnection
public final RemotingConnection getProtocolConnection()
- Specified by:
getProtocolConnectionin interfaceConnection
-
setProtocolConnection
public final void setProtocolConnection(RemotingConnection protocolConnection)
- Specified by:
setProtocolConnectionin interfaceConnection
-
close
public final void close()
Description copied from interface:ConnectionCloses the connection.- Specified by:
closein interfaceConnection
-
createTransportBuffer
public ActiveMQBuffer createTransportBuffer(int size)
Description copied from interface:ConnectionCreate a new ActiveMQBuffer of the given size.- Specified by:
createTransportBufferin interfaceConnection- Parameters:
size- the size of buffer to create- Returns:
- the new buffer.
-
getID
public final Object getID()
Description copied from interface:Connectionreturns the unique id of this wire.- Specified by:
getIDin interfaceConnection- Returns:
- the id
-
checkFlushBatchBuffer
public final void checkFlushBatchBuffer()
Description copied from interface:ConnectionCalled periodically to flush any data in the batch buffer- Specified by:
checkFlushBatchBufferin interfaceConnection
-
write
public final void write(ActiveMQBuffer buffer)
Description copied from interface:Connectionwrites the buffer to the connection with no flushing or batching- Specified by:
writein interfaceConnection- Parameters:
buffer- the buffer to write
-
write
public void write(ActiveMQBuffer buffer, boolean requestFlush)
Description copied from interface:Connectionwrites the buffer to the connection and if flush is true request to flush the buffer (and any previous un-flushed ones) into the wire.- Specified by:
writein interfaceConnection- Parameters:
buffer- the buffer to writerequestFlush- whether to request flush onto the wire
-
flush
public void flush()
Description copied from interface:ConnectionRequest to flush any previous written buffers into the wire.- Specified by:
flushin interfaceConnection
-
write
public final void write(ActiveMQBuffer buffer, boolean flush, boolean batched)
Description copied from interface:Connectionwrites the buffer to the connection and if flush is true returns only when the buffer has been physically written to the connection.- Specified by:
writein interfaceConnection- Parameters:
buffer- the buffer to writeflush- whether to flush the buffers onto the wirebatched- whether the packet is allowed to batched for better performance
-
blockUntilWritable
public final boolean blockUntilWritable(long timeout, TimeUnit timeUnit)Description copied from interface:ConnectionCauses the current thread to wait until the connection is writable unless the specified waiting time elapses. The available capacity of the connection could change concurrently hence this method is suitable to perform precise flow-control only in a single writer case, while its precision decrease inversely proportional with the rate and the number of concurrent writers. If the current thread is not allowed to block the timeout will be ignored dependently on the connection type.- Specified by:
blockUntilWritablein interfaceConnection- Parameters:
timeout- the maximum time to waittimeUnit- the time unit of the timeout argument- Returns:
trueif the connection is writable,falseotherwise
-
write
public final void write(ActiveMQBuffer buffer, boolean flush, boolean batched, io.netty.channel.ChannelFutureListener futureListener)
Description copied from interface:Connectionwrites the buffer to the connection and if flush is true returns only when the buffer has been physically written to the connection.- Specified by:
writein interfaceConnection- Parameters:
buffer- the buffer to writeflush- whether to flush the buffers onto the wirebatched- whether the packet is allowed to batched for better performance
-
getRemoteAddress
public final String getRemoteAddress()
Description copied from interface:ConnectionReturns a string representation of the remote address this connection is connected to.- Specified by:
getRemoteAddressin interfaceConnection- Returns:
- the remote address
-
getLocalAddress
public final String getLocalAddress()
Description copied from interface:ConnectionReturns a string representation of the local address this connection is connected to. This is useful when the server is configured at 0.0.0.0 (or multiple IPs). This will give you the actual IP that's being used.- Specified by:
getLocalAddressin interfaceConnection- Returns:
- the local address
-
isDirectDeliver
public final boolean isDirectDeliver()
- Specified by:
isDirectDeliverin interfaceConnection
-
getDefaultActiveMQPrincipal
public final ActiveMQPrincipal getDefaultActiveMQPrincipal()
- Specified by:
getDefaultActiveMQPrincipalin interfaceConnection
-
getConnectorConfig
public final TransportConfiguration getConnectorConfig()
Description copied from interface:ConnectionGenerates aTransportConfigurationto be used to connect to the same target this is connected to.- Specified by:
getConnectorConfigin interfaceConnection- Returns:
- TransportConfiguration
-
isUsingProtocolHandling
public final boolean isUsingProtocolHandling()
Description copied from interface:Connectionthe InVM Connection has some special handling as it doesn't use Netty ProtocolChannel we will use this method Instead of using instanceof- Specified by:
isUsingProtocolHandlingin interfaceConnection- Returns:
-
isSameTarget
public boolean isSameTarget(TransportConfiguration... configs)
- Specified by:
isSameTargetin interfaceConnection
-
-