Package com.barchart.udt.nio
Class SocketChannelUDT
java.lang.Object
java.nio.channels.spi.AbstractInterruptibleChannel
java.nio.channels.SelectableChannel
java.nio.channels.spi.AbstractSelectableChannel
java.nio.channels.SocketChannel
com.barchart.udt.nio.SocketChannelUDT
- All Implemented Interfaces:
ChannelUDT,Closeable,AutoCloseable,ByteChannel,Channel,GatheringByteChannel,InterruptibleChannel,NetworkChannel,ReadableByteChannel,ScatteringByteChannel,WritableByteChannel
- Direct Known Subclasses:
RendezvousChannelUDT
SocketChannel-like wrapper for SocketUDT, can be either
stream or message oriented, depending on TypeUDT
The UDT socket that this SocketChannel wraps will be switched to blocking mode since this is the default for all SocketChannels on construction. If you require non-blocking functionality, you will need to call configureBlocking on the constructed SocketChannel class.
you must use SelectorProviderUDT.openSocketChannel() to obtain
instance of this class; do not use JDK
SocketChannel.open();
example:
SelectorProvider provider = SelectorProviderUDT.DATAGRAM;
SocketChannel clientChannel = provider.openSocketChannel();
clientChannel.configureBlocking(true);
Socket clientSocket = clientChannel.socket();
InetSocketAddress clientAddress = new InetSocketAddress("localhost", 10000);
clientSocket.bind(clientAddress);
assert clientSocket.isBound();
InetSocketAddress serverAddress = new InetSocketAddress("localhost", 12345);
clientChannel.connect(serverAddress);
assert clientSocket.isConnected();
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Objectprotected booleanlocal volatile variable, which mirrors super.blocking, to avoid the cost of synchronized call inside isBlocking()protected booleanprotected booleanprotected static final org.slf4j.Loggerprotected NioSocketUDTprotected final SocketUDT -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSocketChannelUDT(SelectorProviderUDT provider, SocketUDT socketUDT) protectedSocketChannelUDT(SelectorProviderUDT provider, SocketUDT socketUDT, boolean isConnected) -
Method Summary
Modifier and TypeMethodDescriptionbind(SocketAddress localAddress) java 7booleanconnect(SocketAddress remote) boolean<T> TgetOption(SocketOption<T> name) protected voidprotected voidimplConfigureBlocking(boolean block) booleanbooleanWas connection requestconnect(java.net.SocketAddress)acknowledged byfinishConnect()?booleankindUDT()The kind of UDT channel.UDT specific provider which produced this channel.intread(ByteBuffer buffer) SeeSocketChannel.read(ByteBuffer)contract; note: this method does not return (-1) as EOS (end of stream flag)longread(ByteBuffer[] dsts, int offset, int length) <T> SocketChannelUDTsetOption(SocketOption<T> name, T value) socket()Underlying UDT socket.Set<SocketOption<?>> toString()typeUDT()The type of UDT socket.intwrite(ByteBuffer buffer) SeeSocketChannel.write(ByteBuffer)contract;longwrite(ByteBuffer[] bufferArray, int offset, int length) Methods inherited from class java.nio.channels.SocketChannel
open, open, open, read, validOps, writeMethods inherited from class java.nio.channels.spi.AbstractSelectableChannel
blockingLock, configureBlocking, implCloseChannel, isBlocking, isRegistered, keyFor, provider, registerMethods inherited from class java.nio.channels.SelectableChannel
registerMethods inherited from class java.nio.channels.spi.AbstractInterruptibleChannel
begin, close, end, isOpenMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.barchart.udt.nio.ChannelUDT
validOps
-
Field Details
-
log
protected static final org.slf4j.Logger log -
connectLock
-
isBlockingMode
protected volatile boolean isBlockingModelocal volatile variable, which mirrors super.blocking, to avoid the cost of synchronized call inside isBlocking() -
isConnectFinished
protected volatile boolean isConnectFinished -
isConnectionPending
protected volatile boolean isConnectionPending -
socketAdapter
-
socketUDT
-
-
Constructor Details
-
SocketChannelUDT
- Throws:
ExceptionUDT
-
SocketChannelUDT
protected SocketChannelUDT(SelectorProviderUDT provider, SocketUDT socketUDT, boolean isConnected) throws ExceptionUDT - Throws:
ExceptionUDT
-
-
Method Details
-
connect
- Specified by:
connectin classSocketChannel- Throws:
IOException
-
finishConnect
- Specified by:
finishConnectin classSocketChannel- Throws:
IOException
-
implCloseSelectableChannel
- Specified by:
implCloseSelectableChannelin classAbstractSelectableChannel- Throws:
IOException
-
implConfigureBlocking
- Specified by:
implConfigureBlockingin classAbstractSelectableChannel- Throws:
IOException
-
isConnected
public boolean isConnected()- Specified by:
isConnectedin classSocketChannel
-
isConnectFinished
public boolean isConnectFinished()Description copied from interface:ChannelUDTWas connection requestconnect(java.net.SocketAddress)acknowledged byfinishConnect()?- Specified by:
isConnectFinishedin interfaceChannelUDT
-
isConnectionPending
public boolean isConnectionPending()- Specified by:
isConnectionPendingin classSocketChannel
-
kindUDT
Description copied from interface:ChannelUDTThe kind of UDT channel.- Specified by:
kindUDTin interfaceChannelUDT
-
providerUDT
Description copied from interface:ChannelUDTUDT specific provider which produced this channel.- Specified by:
providerUDTin interfaceChannelUDT
-
read
SeeSocketChannel.read(ByteBuffer)contract; note: this method does not return (-1) as EOS (end of stream flag)- Specified by:
readin interfaceReadableByteChannel- Specified by:
readin classSocketChannel- Returns:
invalid input: '<'0should not happen
=0blocking mode: timeout occurred on receive
=0non-blocking mode: nothing is received by the underlying UDT socket
>0actual bytes received count- Throws:
IOException- See Also:
-
read
- Specified by:
readin interfaceScatteringByteChannel- Specified by:
readin classSocketChannel- Throws:
IOException
-
socket
- Specified by:
socketin classSocketChannel
-
socketUDT
Description copied from interface:ChannelUDTUnderlying UDT socket.- Specified by:
socketUDTin interfaceChannelUDT
-
toString
-
write
SeeSocketChannel.write(ByteBuffer)contract;- Specified by:
writein interfaceWritableByteChannel- Specified by:
writein classSocketChannel- Returns:
invalid input: '<'0should not happen
=0blocking mode: timeout occurred on send
=0non-blocking mode: buffer is full in the underlying UDT socket; nothing is sent
>0actual bytes sent count- Throws:
IOException- See Also:
-
write
- Specified by:
writein interfaceGatheringByteChannel- Specified by:
writein classSocketChannel- Throws:
IOException
-
typeUDT
Description copied from interface:ChannelUDTThe type of UDT socket.- Specified by:
typeUDTin interfaceChannelUDT
-
bind
java 7- Specified by:
bindin interfaceNetworkChannel- Specified by:
bindin classSocketChannel- Throws:
IOException
-
getLocalAddress
- Specified by:
getLocalAddressin interfaceNetworkChannel- Specified by:
getLocalAddressin classSocketChannel- Throws:
IOException
-
supportedOptions
- Specified by:
supportedOptionsin interfaceNetworkChannel
-
getOption
- Specified by:
getOptionin interfaceNetworkChannel- Throws:
IOException
-
setOption
- Specified by:
setOptionin interfaceNetworkChannel- Specified by:
setOptionin classSocketChannel- Throws:
IOException
-
getRemoteAddress
- Specified by:
getRemoteAddressin classSocketChannel- Throws:
IOException
-
shutdownInput
- Specified by:
shutdownInputin classSocketChannel- Throws:
IOException
-
shutdownOutput
- Specified by:
shutdownOutputin classSocketChannel- Throws:
IOException
-