barchart-udt-core
2.3.0-SNAPSHOT / 2013-05-13T01:37:38.485-0500

com.barchart.udt.nio
Class SocketChannelUDT

java.lang.Object
  extended by java.nio.channels.spi.AbstractInterruptibleChannel
      extended by java.nio.channels.SelectableChannel
          extended by java.nio.channels.spi.AbstractSelectableChannel
              extended by java.nio.channels.SocketChannel
                  extended by com.barchart.udt.nio.SocketChannelUDT
All Implemented Interfaces:
ChannelUDT, Closeable, ByteChannel, Channel, GatheringByteChannel, InterruptibleChannel, ReadableByteChannel, ScatteringByteChannel, WritableByteChannel
Direct Known Subclasses:
RendezvousChannelUDT

public class SocketChannelUDT
extends SocketChannel
implements ChannelUDT

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
protected  Object connectLock
           
protected  boolean isBlockingMode
          local volatile variable, which mirrors super.blocking, to avoid the cost of synchronized call inside isBlocking()
protected  boolean isConnectFinished
           
protected  boolean isConnectionPending
           
protected static org.slf4j.Logger log
           
protected  NioSocketUDT socketAdapter
           
protected  SocketUDT socketUDT
           
 
Constructor Summary
protected SocketChannelUDT(SelectorProviderUDT provider, SocketUDT socketUDT)
           
protected SocketChannelUDT(SelectorProviderUDT provider, SocketUDT socketUDT, boolean isConnected)
           
 
Method Summary
 SocketChannelUDT bind(SocketAddress localAddress)
          java 7
 boolean connect(SocketAddress remote)
           
 boolean finishConnect()
           
protected  void implCloseSelectableChannel()
           
protected  void implConfigureBlocking(boolean block)
           
 boolean isConnected()
           
 boolean isConnectFinished()
          Was connection request connect(java.net.SocketAddress) acknowledged by finishConnect()?
 boolean isConnectionPending()
           
 KindUDT kindUDT()
          The kind of UDT channel.
 SelectorProviderUDT providerUDT()
          UDT specific provider which produced this channel.
 int read(ByteBuffer buffer)
          See SocketChannel.read(ByteBuffer) contract; note: this method does not return (-1) as EOS (end of stream flag)
 long read(ByteBuffer[] dsts, int offset, int length)
           
 NioSocketUDT socket()
           
 SocketUDT socketUDT()
          Underlying UDT socket.
 String toString()
           
 TypeUDT typeUDT()
          The type of UDT socket.
 int write(ByteBuffer buffer)
          See SocketChannel.write(ByteBuffer) contract;
 long write(ByteBuffer[] bufferArray, int offset, int length)
           
 
Methods inherited from class java.nio.channels.SocketChannel
open, open, read, validOps, write
 
Methods inherited from class java.nio.channels.spi.AbstractSelectableChannel
blockingLock, configureBlocking, implCloseChannel, isBlocking, isRegistered, keyFor, provider, register
 
Methods inherited from class java.nio.channels.SelectableChannel
register
 
Methods inherited from class java.nio.channels.spi.AbstractInterruptibleChannel
begin, close, end, isOpen
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.barchart.udt.nio.ChannelUDT
validOps
 
Methods inherited from interface java.nio.channels.Channel
close, isOpen
 

Field Detail

log

protected static final org.slf4j.Logger log

connectLock

protected final Object connectLock

isBlockingMode

protected volatile boolean isBlockingMode
local 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

@ThreadSafe(value="this")
protected NioSocketUDT socketAdapter

socketUDT

protected final SocketUDT socketUDT
Constructor Detail

SocketChannelUDT

protected SocketChannelUDT(SelectorProviderUDT provider,
                           SocketUDT socketUDT)
                    throws ExceptionUDT
Throws:
ExceptionUDT

SocketChannelUDT

protected SocketChannelUDT(SelectorProviderUDT provider,
                           SocketUDT socketUDT,
                           boolean isConnected)
                    throws ExceptionUDT
Throws:
ExceptionUDT
Method Detail

connect

public boolean connect(SocketAddress remote)
                throws IOException
Specified by:
connect in class SocketChannel
Throws:
IOException

finishConnect

public boolean finishConnect()
                      throws IOException
Specified by:
finishConnect in class SocketChannel
Throws:
IOException

implCloseSelectableChannel

protected void implCloseSelectableChannel()
                                   throws IOException
Specified by:
implCloseSelectableChannel in class AbstractSelectableChannel
Throws:
IOException

implConfigureBlocking

protected void implConfigureBlocking(boolean block)
                              throws IOException
Specified by:
implConfigureBlocking in class AbstractSelectableChannel
Throws:
IOException

isConnected

public boolean isConnected()
Specified by:
isConnected in class SocketChannel

isConnectFinished

public boolean isConnectFinished()
Description copied from interface: ChannelUDT
Was connection request connect(java.net.SocketAddress) acknowledged by finishConnect()?

Specified by:
isConnectFinished in interface ChannelUDT

isConnectionPending

public boolean isConnectionPending()
Specified by:
isConnectionPending in class SocketChannel

kindUDT

public KindUDT kindUDT()
Description copied from interface: ChannelUDT
The kind of UDT channel.

Specified by:
kindUDT in interface ChannelUDT

providerUDT

public SelectorProviderUDT providerUDT()
Description copied from interface: ChannelUDT
UDT specific provider which produced this channel.

Specified by:
providerUDT in interface ChannelUDT

read

public int read(ByteBuffer buffer)
         throws IOException
See SocketChannel.read(ByteBuffer) contract; note: this method does not return (-1) as EOS (end of stream flag)

Specified by:
read in interface ReadableByteChannel
Specified by:
read in class SocketChannel
Returns:
<0 should not happen
=0 blocking mode: timeout occurred on receive
=0 non-blocking mode: nothing is received by the underlying UDT socket
>0 actual bytes received count
Throws:
IOException
See Also:
SocketUDT.receive(ByteBuffer), SocketUDT.receive(byte[], int, int)

read

public long read(ByteBuffer[] dsts,
                 int offset,
                 int length)
          throws IOException
Specified by:
read in interface ScatteringByteChannel
Specified by:
read in class SocketChannel
Throws:
IOException

socket

public NioSocketUDT socket()
Specified by:
socket in class SocketChannel

socketUDT

public SocketUDT socketUDT()
Description copied from interface: ChannelUDT
Underlying UDT socket.

Specified by:
socketUDT in interface ChannelUDT

toString

public String toString()
Overrides:
toString in class Object

write

public int write(ByteBuffer buffer)
          throws IOException
See SocketChannel.write(ByteBuffer) contract;

Specified by:
write in interface WritableByteChannel
Specified by:
write in class SocketChannel
Returns:
<0 should not happen
=0 blocking mode: timeout occurred on send
=0 non-blocking mode: buffer is full in the underlying UDT socket; nothing is sent
>0 actual bytes sent count
Throws:
IOException
See Also:
SocketUDT.send(ByteBuffer), SocketUDT.send(byte[], int, int)

write

public long write(ByteBuffer[] bufferArray,
                  int offset,
                  int length)
           throws IOException
Specified by:
write in interface GatheringByteChannel
Specified by:
write in class SocketChannel
Throws:
IOException

typeUDT

public TypeUDT typeUDT()
Description copied from interface: ChannelUDT
The type of UDT socket.

Specified by:
typeUDT in interface ChannelUDT

bind

public SocketChannelUDT bind(SocketAddress localAddress)
                      throws IOException
java 7

Throws:
IOException

barchart-udt-core
2.3.0-SNAPSHOT / 2013-05-13T01:37:38.485-0500

Copyright © 2009-2013 Barchart, Inc.. All Rights Reserved.