Package io.netty.channel.socket
Class DefaultSocketChannelConfig
- java.lang.Object
-
- io.netty.channel.DefaultChannelConfig
-
- io.netty.channel.socket.DefaultSocketChannelConfig
-
- All Implemented Interfaces:
ChannelConfig
,DuplexChannelConfig
,SocketChannelConfig
- Direct Known Subclasses:
DefaultOioSocketChannelConfig
public class DefaultSocketChannelConfig extends DefaultChannelConfig implements SocketChannelConfig
The defaultSocketChannelConfig
implementation.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.net.Socket
javaSocket
-
Fields inherited from class io.netty.channel.DefaultChannelConfig
channel
-
-
Constructor Summary
Constructors Constructor Description DefaultSocketChannelConfig(SocketChannel channel, java.net.Socket javaSocket)
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <T> T
getOption(ChannelOption<T> option)
Return the value of the givenChannelOption
java.util.Map<ChannelOption<?>,java.lang.Object>
getOptions()
Return all setChannelOption
's.int
getReceiveBufferSize()
Gets theStandardSocketOptions.SO_RCVBUF
option.int
getSendBufferSize()
Gets theStandardSocketOptions.SO_SNDBUF
option.int
getSoLinger()
Gets theStandardSocketOptions.SO_LINGER
option.int
getTrafficClass()
Gets theStandardSocketOptions.IP_TOS
option.boolean
isAllowHalfClosure()
Returnstrue
if and only if the channel should not close itself when its remote peer shuts down output to make the connection half-closed.boolean
isKeepAlive()
Gets theStandardSocketOptions.SO_KEEPALIVE
option.boolean
isReuseAddress()
Gets theStandardSocketOptions.SO_REUSEADDR
option.boolean
isTcpNoDelay()
Gets theStandardSocketOptions.TCP_NODELAY
option.SocketChannelConfig
setAllocator(ByteBufAllocator allocator)
Set theByteBufAllocator
which is used for the channel to allocate buffers.SocketChannelConfig
setAllowHalfClosure(boolean allowHalfClosure)
Sets whether the channel should not close itself when its remote peer shuts down output to make the connection half-closed.SocketChannelConfig
setAutoClose(boolean autoClose)
Sets whether theChannel
should be closed automatically and immediately on write failure.SocketChannelConfig
setAutoRead(boolean autoRead)
Sets ifChannelHandlerContext.read()
will be invoked automatically so that a user application doesn't need to call it at all.SocketChannelConfig
setConnectTimeoutMillis(int connectTimeoutMillis)
Sets the connect timeout of the channel in milliseconds.SocketChannelConfig
setKeepAlive(boolean keepAlive)
Sets theStandardSocketOptions.SO_KEEPALIVE
option.SocketChannelConfig
setMaxMessagesPerRead(int maxMessagesPerRead)
Deprecated.SocketChannelConfig
setMessageSizeEstimator(MessageSizeEstimator estimator)
Set theMessageSizeEstimator
which is used for the channel to detect the size of a message.<T> boolean
setOption(ChannelOption<T> option, T value)
Sets a configuration property with the specified name and value.SocketChannelConfig
setPerformancePreferences(int connectionTime, int latency, int bandwidth)
Sets the performance preferences as specified inSocket.setPerformancePreferences(int, int, int)
.SocketChannelConfig
setReceiveBufferSize(int receiveBufferSize)
Sets theStandardSocketOptions.SO_RCVBUF
option.SocketChannelConfig
setRecvByteBufAllocator(RecvByteBufAllocator allocator)
Set theRecvByteBufAllocator
which is used for the channel to allocate receive buffers.SocketChannelConfig
setReuseAddress(boolean reuseAddress)
Sets theStandardSocketOptions.SO_REUSEADDR
option.SocketChannelConfig
setSendBufferSize(int sendBufferSize)
Sets theStandardSocketOptions.SO_SNDBUF
option.SocketChannelConfig
setSoLinger(int soLinger)
Sets theStandardSocketOptions.SO_LINGER
option.SocketChannelConfig
setTcpNoDelay(boolean tcpNoDelay)
Sets theStandardSocketOptions.TCP_NODELAY
option.SocketChannelConfig
setTrafficClass(int trafficClass)
Sets theStandardSocketOptions.IP_TOS
option.SocketChannelConfig
setWriteBufferHighWaterMark(int writeBufferHighWaterMark)
Sets the high water mark of the write buffer.SocketChannelConfig
setWriteBufferLowWaterMark(int writeBufferLowWaterMark)
Sets the low water mark of the write buffer.SocketChannelConfig
setWriteBufferWaterMark(WriteBufferWaterMark writeBufferWaterMark)
Set theWriteBufferWaterMark
which is used for setting the high and low water mark of the write buffer.SocketChannelConfig
setWriteSpinCount(int writeSpinCount)
Sets the maximum loop count for a write operation untilWritableByteChannel.write(ByteBuffer)
returns a non-zero value.-
Methods inherited from class io.netty.channel.DefaultChannelConfig
autoReadCleared, getAllocator, getConnectTimeoutMillis, getMaxMessagesPerRead, getMaxMessagesPerWrite, getMessageSizeEstimator, getOptions, getRecvByteBufAllocator, getWriteBufferHighWaterMark, getWriteBufferLowWaterMark, getWriteBufferWaterMark, getWriteSpinCount, isAutoClose, isAutoRead, setMaxMessagesPerWrite, setOptions, validate
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty.channel.ChannelConfig
getAllocator, getConnectTimeoutMillis, getMaxMessagesPerRead, getMessageSizeEstimator, getRecvByteBufAllocator, getWriteBufferHighWaterMark, getWriteBufferLowWaterMark, getWriteBufferWaterMark, getWriteSpinCount, isAutoClose, isAutoRead, setOptions
-
-
-
-
Constructor Detail
-
DefaultSocketChannelConfig
public DefaultSocketChannelConfig(SocketChannel channel, java.net.Socket javaSocket)
Creates a new instance.
-
-
Method Detail
-
getOptions
public java.util.Map<ChannelOption<?>,java.lang.Object> getOptions()
Description copied from interface:ChannelConfig
Return all setChannelOption
's.- Specified by:
getOptions
in interfaceChannelConfig
- Overrides:
getOptions
in classDefaultChannelConfig
-
getOption
public <T> T getOption(ChannelOption<T> option)
Description copied from interface:ChannelConfig
Return the value of the givenChannelOption
- Specified by:
getOption
in interfaceChannelConfig
- Overrides:
getOption
in classDefaultChannelConfig
-
setOption
public <T> boolean setOption(ChannelOption<T> option, T value)
Description copied from interface:ChannelConfig
Sets a configuration property with the specified name and value. To override this method properly, you must call the super class:public boolean setOption(ChannelOption<T> option, T value) { if (super.setOption(option, value)) { return true; } if (option.equals(additionalOption)) { .... return true; } return false; }
- Specified by:
setOption
in interfaceChannelConfig
- Overrides:
setOption
in classDefaultChannelConfig
- Returns:
true
if and only if the property has been set
-
getReceiveBufferSize
public int getReceiveBufferSize()
Description copied from interface:SocketChannelConfig
Gets theStandardSocketOptions.SO_RCVBUF
option.- Specified by:
getReceiveBufferSize
in interfaceSocketChannelConfig
-
getSendBufferSize
public int getSendBufferSize()
Description copied from interface:SocketChannelConfig
Gets theStandardSocketOptions.SO_SNDBUF
option.- Specified by:
getSendBufferSize
in interfaceSocketChannelConfig
-
getSoLinger
public int getSoLinger()
Description copied from interface:SocketChannelConfig
Gets theStandardSocketOptions.SO_LINGER
option.- Specified by:
getSoLinger
in interfaceSocketChannelConfig
-
getTrafficClass
public int getTrafficClass()
Description copied from interface:SocketChannelConfig
Gets theStandardSocketOptions.IP_TOS
option.- Specified by:
getTrafficClass
in interfaceSocketChannelConfig
-
isKeepAlive
public boolean isKeepAlive()
Description copied from interface:SocketChannelConfig
Gets theStandardSocketOptions.SO_KEEPALIVE
option.- Specified by:
isKeepAlive
in interfaceSocketChannelConfig
-
isReuseAddress
public boolean isReuseAddress()
Description copied from interface:SocketChannelConfig
Gets theStandardSocketOptions.SO_REUSEADDR
option.- Specified by:
isReuseAddress
in interfaceSocketChannelConfig
-
isTcpNoDelay
public boolean isTcpNoDelay()
Description copied from interface:SocketChannelConfig
Gets theStandardSocketOptions.TCP_NODELAY
option. Please note that the default value of this option istrue
unlike the operating system default (false
). However, for some buggy platforms, such as Android, that shows erratic behavior with Nagle's algorithm disabled, the default value remains to befalse
.- Specified by:
isTcpNoDelay
in interfaceSocketChannelConfig
-
setKeepAlive
public SocketChannelConfig setKeepAlive(boolean keepAlive)
Description copied from interface:SocketChannelConfig
Sets theStandardSocketOptions.SO_KEEPALIVE
option.- Specified by:
setKeepAlive
in interfaceSocketChannelConfig
-
setPerformancePreferences
public SocketChannelConfig setPerformancePreferences(int connectionTime, int latency, int bandwidth)
Description copied from interface:SocketChannelConfig
Sets the performance preferences as specified inSocket.setPerformancePreferences(int, int, int)
.- Specified by:
setPerformancePreferences
in interfaceSocketChannelConfig
-
setReceiveBufferSize
public SocketChannelConfig setReceiveBufferSize(int receiveBufferSize)
Description copied from interface:SocketChannelConfig
Sets theStandardSocketOptions.SO_RCVBUF
option.- Specified by:
setReceiveBufferSize
in interfaceSocketChannelConfig
-
setReuseAddress
public SocketChannelConfig setReuseAddress(boolean reuseAddress)
Description copied from interface:SocketChannelConfig
Sets theStandardSocketOptions.SO_REUSEADDR
option.- Specified by:
setReuseAddress
in interfaceSocketChannelConfig
-
setSendBufferSize
public SocketChannelConfig setSendBufferSize(int sendBufferSize)
Description copied from interface:SocketChannelConfig
Sets theStandardSocketOptions.SO_SNDBUF
option.- Specified by:
setSendBufferSize
in interfaceSocketChannelConfig
-
setSoLinger
public SocketChannelConfig setSoLinger(int soLinger)
Description copied from interface:SocketChannelConfig
Sets theStandardSocketOptions.SO_LINGER
option.- Specified by:
setSoLinger
in interfaceSocketChannelConfig
-
setTcpNoDelay
public SocketChannelConfig setTcpNoDelay(boolean tcpNoDelay)
Description copied from interface:SocketChannelConfig
Sets theStandardSocketOptions.TCP_NODELAY
option. Please note that the default value of this option istrue
unlike the operating system default (false
). However, for some buggy platforms, such as Android, that shows erratic behavior with Nagle's algorithm disabled, the default value remains to befalse
.- Specified by:
setTcpNoDelay
in interfaceSocketChannelConfig
-
setTrafficClass
public SocketChannelConfig setTrafficClass(int trafficClass)
Description copied from interface:SocketChannelConfig
Sets theStandardSocketOptions.IP_TOS
option.- Specified by:
setTrafficClass
in interfaceSocketChannelConfig
-
isAllowHalfClosure
public boolean isAllowHalfClosure()
Description copied from interface:DuplexChannelConfig
Returnstrue
if and only if the channel should not close itself when its remote peer shuts down output to make the connection half-closed. Iffalse
, the connection is closed automatically when the remote peer shuts down output.- Specified by:
isAllowHalfClosure
in interfaceDuplexChannelConfig
-
setAllowHalfClosure
public SocketChannelConfig setAllowHalfClosure(boolean allowHalfClosure)
Description copied from interface:DuplexChannelConfig
Sets whether the channel should not close itself when its remote peer shuts down output to make the connection half-closed. Iftrue
the connection is not closed when the remote peer shuts down output. Instead,ChannelInboundHandler.userEventTriggered(ChannelHandlerContext, Object)
is invoked with aChannelInputShutdownEvent
object. Iffalse
, the connection is closed automatically.- Specified by:
setAllowHalfClosure
in interfaceDuplexChannelConfig
- Specified by:
setAllowHalfClosure
in interfaceSocketChannelConfig
-
setConnectTimeoutMillis
public SocketChannelConfig setConnectTimeoutMillis(int connectTimeoutMillis)
Description copied from interface:ChannelConfig
Sets the connect timeout of the channel in milliseconds. If theChannel
does not support connect operation, this property is not used at all, and therefore will be ignored.- Specified by:
setConnectTimeoutMillis
in interfaceChannelConfig
- Specified by:
setConnectTimeoutMillis
in interfaceSocketChannelConfig
- Overrides:
setConnectTimeoutMillis
in classDefaultChannelConfig
- Parameters:
connectTimeoutMillis
- the connect timeout in milliseconds.0
to disable.
-
setMaxMessagesPerRead
@Deprecated public SocketChannelConfig setMaxMessagesPerRead(int maxMessagesPerRead)
Deprecated.Description copied from class:DefaultChannelConfig
- Specified by:
setMaxMessagesPerRead
in interfaceChannelConfig
- Specified by:
setMaxMessagesPerRead
in interfaceDuplexChannelConfig
- Specified by:
setMaxMessagesPerRead
in interfaceSocketChannelConfig
- Overrides:
setMaxMessagesPerRead
in classDefaultChannelConfig
-
setWriteSpinCount
public SocketChannelConfig setWriteSpinCount(int writeSpinCount)
Description copied from interface:ChannelConfig
Sets the maximum loop count for a write operation untilWritableByteChannel.write(ByteBuffer)
returns a non-zero value. It is similar to what a spin lock is used for in concurrency programming. It improves memory utilization and write throughput depending on the platform that JVM runs on. The default value is16
.- Specified by:
setWriteSpinCount
in interfaceChannelConfig
- Specified by:
setWriteSpinCount
in interfaceDuplexChannelConfig
- Specified by:
setWriteSpinCount
in interfaceSocketChannelConfig
- Overrides:
setWriteSpinCount
in classDefaultChannelConfig
-
setAllocator
public SocketChannelConfig setAllocator(ByteBufAllocator allocator)
Description copied from interface:ChannelConfig
Set theByteBufAllocator
which is used for the channel to allocate buffers.- Specified by:
setAllocator
in interfaceChannelConfig
- Specified by:
setAllocator
in interfaceDuplexChannelConfig
- Specified by:
setAllocator
in interfaceSocketChannelConfig
- Overrides:
setAllocator
in classDefaultChannelConfig
-
setRecvByteBufAllocator
public SocketChannelConfig setRecvByteBufAllocator(RecvByteBufAllocator allocator)
Description copied from interface:ChannelConfig
Set theRecvByteBufAllocator
which is used for the channel to allocate receive buffers.- Specified by:
setRecvByteBufAllocator
in interfaceChannelConfig
- Specified by:
setRecvByteBufAllocator
in interfaceDuplexChannelConfig
- Specified by:
setRecvByteBufAllocator
in interfaceSocketChannelConfig
- Overrides:
setRecvByteBufAllocator
in classDefaultChannelConfig
-
setAutoRead
public SocketChannelConfig setAutoRead(boolean autoRead)
Description copied from interface:ChannelConfig
Sets ifChannelHandlerContext.read()
will be invoked automatically so that a user application doesn't need to call it at all. The default value istrue
.- Specified by:
setAutoRead
in interfaceChannelConfig
- Specified by:
setAutoRead
in interfaceDuplexChannelConfig
- Specified by:
setAutoRead
in interfaceSocketChannelConfig
- Overrides:
setAutoRead
in classDefaultChannelConfig
-
setAutoClose
public SocketChannelConfig setAutoClose(boolean autoClose)
Description copied from interface:ChannelConfig
Sets whether theChannel
should be closed automatically and immediately on write failure. The default istrue
.- Specified by:
setAutoClose
in interfaceChannelConfig
- Specified by:
setAutoClose
in interfaceDuplexChannelConfig
- Specified by:
setAutoClose
in interfaceSocketChannelConfig
- Overrides:
setAutoClose
in classDefaultChannelConfig
-
setWriteBufferHighWaterMark
public SocketChannelConfig setWriteBufferHighWaterMark(int writeBufferHighWaterMark)
Description copied from interface:ChannelConfig
Sets the high water mark of the write buffer. If the number of bytes queued in the write buffer exceeds this value,
Channel.isWritable()
will start to returnfalse
.- Specified by:
setWriteBufferHighWaterMark
in interfaceChannelConfig
- Overrides:
setWriteBufferHighWaterMark
in classDefaultChannelConfig
-
setWriteBufferLowWaterMark
public SocketChannelConfig setWriteBufferLowWaterMark(int writeBufferLowWaterMark)
Description copied from interface:ChannelConfig
Sets the low water mark of the write buffer. Once the number of bytes queued in the write buffer exceeded the high water mark and then dropped down below this value,
Channel.isWritable()
will start to returntrue
again.- Specified by:
setWriteBufferLowWaterMark
in interfaceChannelConfig
- Overrides:
setWriteBufferLowWaterMark
in classDefaultChannelConfig
-
setWriteBufferWaterMark
public SocketChannelConfig setWriteBufferWaterMark(WriteBufferWaterMark writeBufferWaterMark)
Description copied from interface:ChannelConfig
Set theWriteBufferWaterMark
which is used for setting the high and low water mark of the write buffer.- Specified by:
setWriteBufferWaterMark
in interfaceChannelConfig
- Specified by:
setWriteBufferWaterMark
in interfaceDuplexChannelConfig
- Specified by:
setWriteBufferWaterMark
in interfaceSocketChannelConfig
- Overrides:
setWriteBufferWaterMark
in classDefaultChannelConfig
-
setMessageSizeEstimator
public SocketChannelConfig setMessageSizeEstimator(MessageSizeEstimator estimator)
Description copied from interface:ChannelConfig
Set theMessageSizeEstimator
which is used for the channel to detect the size of a message.- Specified by:
setMessageSizeEstimator
in interfaceChannelConfig
- Specified by:
setMessageSizeEstimator
in interfaceDuplexChannelConfig
- Specified by:
setMessageSizeEstimator
in interfaceSocketChannelConfig
- Overrides:
setMessageSizeEstimator
in classDefaultChannelConfig
-
-