Interface Connection
-
public interface ConnectionThe connection used by a channel to write data to.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default booleanblockUntilWritable(long timeout, java.util.concurrent.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.org.apache.activemq.artemis.api.core.ActiveMQBuffercreateTransportBuffer(int size)Create a new ActiveMQBuffer of the given size.voidfireReady(boolean ready)default voidflush()Request to flush any previous written buffers into the wire.voidforceClose()This should close the internal channel without calling any listeners.TransportConfigurationgetConnectorConfig()Generates aTransportConfigurationto be used to connect to the same target this is connected to.org.apache.activemq.artemis.core.security.ActiveMQPrincipalgetDefaultActiveMQPrincipal()java.lang.ObjectgetID()returns the unique id of this wire.java.lang.StringgetLocalAddress()Returns a string representation of the local address this connection is connected to.RemotingConnectiongetProtocolConnection()java.lang.StringgetRemoteAddress()Returns a string representation of the remote address this connection is connected to.default java.lang.StringgetRouter()default java.lang.StringgetSNIHostName()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 listener)voidsetAutoRead(boolean autoRead)This will disable reading from the channel.voidsetProtocolConnection(RemotingConnection connection)voidwrite(org.apache.activemq.artemis.api.core.ActiveMQBuffer buffer)writes the buffer to the connection with no flushing or batchingvoidwrite(org.apache.activemq.artemis.api.core.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(org.apache.activemq.artemis.api.core.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(org.apache.activemq.artemis.api.core.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.
-
-
-
Method Detail
-
createTransportBuffer
org.apache.activemq.artemis.api.core.ActiveMQBuffer createTransportBuffer(int size)
Create a new ActiveMQBuffer of the given size.- Parameters:
size- the size of buffer to create- Returns:
- the new buffer.
-
getProtocolConnection
RemotingConnection getProtocolConnection()
-
setProtocolConnection
void setProtocolConnection(RemotingConnection connection)
-
isWritable
boolean isWritable(ReadyListener listener)
-
isOpen
boolean isOpen()
-
blockUntilWritable
default boolean blockUntilWritable(long timeout, java.util.concurrent.TimeUnit timeUnit)Causes 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.- Parameters:
timeout- the maximum time to waittimeUnit- the time unit of the timeout argument- Returns:
trueif the connection is writable,falseotherwise- Throws:
java.lang.IllegalStateException- if the connection is closed
-
fireReady
void fireReady(boolean ready)
-
setAutoRead
void setAutoRead(boolean autoRead)
This will disable reading from the channel. This is basically the same as blocking the reading.
-
getID
java.lang.Object getID()
returns the unique id of this wire.- Returns:
- the id
-
write
void write(org.apache.activemq.artemis.api.core.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.- Parameters:
buffer- the buffer to writerequestFlush- whether to request flush onto the wire
-
flush
default void flush()
Request to flush any previous written buffers into the wire.
-
write
void write(org.apache.activemq.artemis.api.core.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.- Parameters:
buffer- the buffer to writeflush- whether to flush the buffers onto the wirebatched- whether the packet is allowed to batched for better performance
-
write
void write(org.apache.activemq.artemis.api.core.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.- Parameters:
buffer- the buffer to writeflush- whether to flush the buffers onto the wirebatched- whether the packet is allowed to batched for better performance
-
write
void write(org.apache.activemq.artemis.api.core.ActiveMQBuffer buffer)
writes the buffer to the connection with no flushing or batching- Parameters:
buffer- the buffer to write
-
forceClose
void forceClose()
This 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.
-
close
void close()
Closes the connection.
-
getRemoteAddress
java.lang.String getRemoteAddress()
Returns a string representation of the remote address this connection is connected to.- Returns:
- the remote address
-
getLocalAddress
java.lang.String getLocalAddress()
Returns 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.- Returns:
- the local address
-
checkFlushBatchBuffer
void checkFlushBatchBuffer()
Called periodically to flush any data in the batch buffer
-
getConnectorConfig
TransportConfiguration getConnectorConfig()
Generates aTransportConfigurationto be used to connect to the same target this is connected to.- Returns:
- TransportConfiguration
-
isDirectDeliver
boolean isDirectDeliver()
-
getDefaultActiveMQPrincipal
org.apache.activemq.artemis.core.security.ActiveMQPrincipal getDefaultActiveMQPrincipal()
-
isUsingProtocolHandling
boolean isUsingProtocolHandling()
the InVM Connection has some special handling as it doesn't use Netty ProtocolChannel we will use this method Instead of using instanceof- Returns:
-
isSameTarget
boolean isSameTarget(TransportConfiguration... configs)
-
getSNIHostName
default java.lang.String getSNIHostName()
-
getRouter
default java.lang.String getRouter()
-
-