Skip navigation links

Oracle® Coherence Java API Reference
Release 3.6.0.0

E15725-01


com.tangosol.net
Class TcpDatagramSocket.Impl

java.lang.Object
  extended by java.net.DatagramSocketImpl
      extended by com.tangosol.net.TcpDatagramSocket.Impl

All Implemented Interfaces:
SocketOptions
Direct Known Subclasses:
NonBlockingTcpDatagramSocket.Impl
Enclosing class:
TcpDatagramSocket

public static class TcpDatagramSocket.Impl
extends DatagramSocketImpl

Field Summary
static int HEADER_SIZE
          The fixed header size for packets.
static int PROTOCOL_MAGIC
          Protcol identifier used to identify that peers are also TcpDatagramSockets.

 

Fields inherited from class java.net.DatagramSocketImpl
fd, localPort

 

Fields inherited from interface java.net.SocketOptions
IP_MULTICAST_IF, IP_MULTICAST_IF2, IP_MULTICAST_LOOP, IP_TOS, SO_BINDADDR, SO_BROADCAST, SO_KEEPALIVE, SO_LINGER, SO_OOBINLINE, SO_RCVBUF, SO_REUSEADDR, SO_SNDBUF, SO_TIMEOUT, TCP_NODELAY

 

Constructor Summary
TcpDatagramSocket.Impl()
           
TcpDatagramSocket.Impl(SocketProvider provider)
           

 

Method Summary
protected  void bind(int nPort, InetAddress addr)
          
protected  void bind(SocketAddress addr)
          Bind the socket to the specified address.
protected  void close()
          
protected  void closeInbound(com.tangosol.net.TcpDatagramSocket.Impl.ConnectionStatus status, SocketChannel chan)
           
protected  void closeOutbound(SocketAddress addr)
           
protected  void create()
          
protected  com.tangosol.net.TcpDatagramSocket.Impl.Connection ensureConnection(SocketAddress addr)
          Obtain a Connection for the specified address.
protected static SocketException ensureSocketException(IOException e)
          Convert an IOException into a SocketException.
protected  int getLocalPort()
          
 Object getOption(int nId)
          
protected  int getTimeToLive()
          
protected  byte getTTL()
          
protected  void join(InetAddress inetaddr)
          
protected  void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf)
          
protected  void leave(InetAddress inetaddr)
          
protected  void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf)
          
protected  void logException(SocketAddress addr, IOException e)
          Log an exception which is handled internally by the TcpDatagramSocket.
protected  void logProtocolWarning(SocketAddress addr, com.tangosol.net.TcpDatagramSocket.Impl.ConnectionStatus status, int nMagic)
          Periodically log a warning when connections are made using an unrecogized protocol.
protected  com.tangosol.net.TcpDatagramSocket.Impl.Connection makeConnection(SocketAddress addr)
          Produce a new Connection for the specified destination address
protected  SelectionKey nextKey(ByteBuffer buffPacket)
          Perform a blocking read, waiting for a complete packet.
protected  void onAccept(SelectionKey key)
          Called when a channel is identified as have a new connection to accept.
protected  int onConnectionHeader(com.tangosol.net.TcpDatagramSocket.Impl.ConnectionStatus status, SocketChannel chan)
          Process a pending connection header.
protected  boolean onRead(SelectionKey key, ByteBuffer buffPacket)
          Called when a channel is detected as readable
protected  int peek(InetAddress addr)
          
protected  int peekData(DatagramPacket packet)
          
protected  void processRegistrations()
          Process any scheduled selector registrations.
 SelectorProvider provider()
          Return the SelectorProvider associated with this socket.
protected  void receive(DatagramPacket packet)
          
protected  void scheduleRegistration(SocketChannel chan, com.tangosol.net.TcpDatagramSocket.Impl.ConnectionStatus status)
          Schedule a registration with the selector, and wake it up.
protected  void send(DatagramPacket packet)
          
 void setOption(int nId, Object oValue)
          
 void setPacketMagic(int nMagic, int nMask)
          Specify the packet header which is included at the start of every packet.
protected  void setTimeToLive(int ttl)
          
protected  void setTTL(byte ttl)
          
 String toString()
          
protected  int transferBytes(ByteBuffer buffSrc, ByteBuffer buffDst)
          Transfer bytes from the source to the destination buffer based on their limits.

 

Methods inherited from class java.net.DatagramSocketImpl
connect, disconnect, getFileDescriptor

 

Field Detail

HEADER_SIZE

public static final int HEADER_SIZE
The fixed header size for packets.
See Also:
Constant Field Values

PROTOCOL_MAGIC

public static final int PROTOCOL_MAGIC
Protcol identifier used to identify that peers are also TcpDatagramSockets. This is necessary so that we don't try to act upon garbage in this class, for instance trying to allocate a negative or gigabit sized packet.
See Also:
Constant Field Values

Constructor Detail

TcpDatagramSocket.Impl

public TcpDatagramSocket.Impl()
                       throws SocketException
Throws:
SocketException

TcpDatagramSocket.Impl

public TcpDatagramSocket.Impl(SocketProvider provider)
                       throws SocketException
Throws:
SocketException

Method Detail

provider

public SelectorProvider provider()
Return the SelectorProvider associated with this socket.
Returns:
the SelectorProvider

setPacketMagic

public void setPacketMagic(int nMagic,
                           int nMask)
Specify the packet header which is included at the start of every packet. Because this implementation is TCP based these headers can be stripped off, and replaced on the far side without consuming any network resources.
Parameters:
nMagic - the packet header
nMask - the packet header bitmask identifying the bits used the mask must be in byte increments

create

protected void create()
               throws SocketException
Specified by:
create in class DatagramSocketImpl
Throws:
SocketException

bind

protected void bind(int nPort,
                    InetAddress addr)
             throws SocketException
Specified by:
bind in class DatagramSocketImpl
Throws:
SocketException

getLocalPort

protected int getLocalPort()
Overrides:
getLocalPort in class DatagramSocketImpl

send

protected void send(DatagramPacket packet)
             throws IOException
Specified by:
send in class DatagramSocketImpl
Throws:
IOException

peek

protected int peek(InetAddress addr)
            throws IOException
Specified by:
peek in class DatagramSocketImpl
Throws:
IOException

peekData

protected int peekData(DatagramPacket packet)
                throws IOException
Specified by:
peekData in class DatagramSocketImpl
Throws:
IOException

receive

protected void receive(DatagramPacket packet)
                throws IOException
Specified by:
receive in class DatagramSocketImpl
Throws:
IOException

nextKey

protected SelectionKey nextKey(ByteBuffer buffPacket)
                        throws IOException
Perform a blocking read, waiting for a complete packet.
Parameters:
buffPacket - the packet buffer
Returns:
the corresponding SelectionKey
Throws:
SocketTimeoutException - if SO_TIMEOUT is exceeded
IOException

onAccept

protected void onAccept(SelectionKey key)
Called when a channel is identified as have a new connection to accept.
Parameters:
key - the associated SelectionKey

onRead

protected boolean onRead(SelectionKey key,
                         ByteBuffer buffPacket)
Called when a channel is detected as readable
Parameters:
key - the associated SelectionKey
buffPacket - a buffer in which to place any available full packet
Returns:
true iff a packet has been read

onConnectionHeader

protected int onConnectionHeader(com.tangosol.net.TcpDatagramSocket.Impl.ConnectionStatus status,
                                 SocketChannel chan)
                          throws IOException
Process a pending connection header.
Parameters:
status - the associated ConnectionStatus
chan - the associated channel
Returns:
the number of bytes read, or -1 for EOS
Throws:
IOException - if an I/O error occurs

close

protected void close()
Specified by:
close in class DatagramSocketImpl

setOption

public void setOption(int nId,
                      Object oValue)
               throws SocketException
Throws:
SocketException

getOption

public Object getOption(int nId)
                 throws SocketException
Throws:
SocketException

setTTL

protected void setTTL(byte ttl)
               throws IOException
Specified by:
setTTL in class DatagramSocketImpl
Throws:
IOException

getTTL

protected byte getTTL()
               throws IOException
Specified by:
getTTL in class DatagramSocketImpl
Throws:
IOException

setTimeToLive

protected void setTimeToLive(int ttl)
                      throws IOException
Specified by:
setTimeToLive in class DatagramSocketImpl
Throws:
IOException

getTimeToLive

protected int getTimeToLive()
                     throws IOException
Specified by:
getTimeToLive in class DatagramSocketImpl
Throws:
IOException

join

protected void join(InetAddress inetaddr)
             throws IOException
Specified by:
join in class DatagramSocketImpl
Throws:
IOException

leave

protected void leave(InetAddress inetaddr)
              throws IOException
Specified by:
leave in class DatagramSocketImpl
Throws:
IOException

joinGroup

protected void joinGroup(SocketAddress mcastaddr,
                         NetworkInterface netIf)
                  throws IOException
Specified by:
joinGroup in class DatagramSocketImpl
Throws:
IOException

leaveGroup

protected void leaveGroup(SocketAddress mcastaddr,
                          NetworkInterface netIf)
                   throws IOException
Specified by:
leaveGroup in class DatagramSocketImpl
Throws:
IOException

bind

protected void bind(SocketAddress addr)
             throws SocketException
Bind the socket to the specified address.
Parameters:
addr - the address to bind to
Throws:
SocketException - if an I/O error occurs

ensureSocketException

protected static SocketException ensureSocketException(IOException e)
Convert an IOException into a SocketException.
Parameters:
e - the IOExcepotion
Returns:
the SocketException

makeConnection

protected com.tangosol.net.TcpDatagramSocket.Impl.Connection makeConnection(SocketAddress addr)
                                                                     throws IOException
Produce a new Connection for the specified destination address
Parameters:
addr - the destination address
Returns:
the corresponding connection
Throws:
IOException - if an I/O error occurs

ensureConnection

protected com.tangosol.net.TcpDatagramSocket.Impl.Connection ensureConnection(SocketAddress addr)
                                                                       throws IOException
Obtain a Connection for the specified address.
Parameters:
addr - the destination address
Returns:
the corresponding connection
Throws:
IOException - if an I/O error occurs

closeInbound

protected void closeInbound(com.tangosol.net.TcpDatagramSocket.Impl.ConnectionStatus status,
                            SocketChannel chan)

closeOutbound

protected void closeOutbound(SocketAddress addr)

scheduleRegistration

protected void scheduleRegistration(SocketChannel chan,
                                    com.tangosol.net.TcpDatagramSocket.Impl.ConnectionStatus status)
Schedule a registration with the selector, and wake it up.
Parameters:
chan - the channel to scheduled registration for
status - the associated ConnectionStatus to register

processRegistrations

protected void processRegistrations()
Process any scheduled selector registrations.

transferBytes

protected int transferBytes(ByteBuffer buffSrc,
                            ByteBuffer buffDst)
Transfer bytes from the source to the destination buffer based on their limits.
Parameters:
buffSrc - the source buffer
buffDst - the destination buffer
Returns:
the number of bytes transfered

logException

protected void logException(SocketAddress addr,
                            IOException e)
Log an exception which is handled internally by the TcpDatagramSocket.
Parameters:
addr - the associated address
e - the exception

logProtocolWarning

protected void logProtocolWarning(SocketAddress addr,
                                  com.tangosol.net.TcpDatagramSocket.Impl.ConnectionStatus status,
                                  int nMagic)
Periodically log a warning when connections are made using an unrecogized protocol.
Parameters:
addr - the source address of the connection
status - the connection status
nMagic - the "magic" header they sent

toString

public String toString()

Skip navigation links

Oracle® Coherence Java API Reference
Release 3.6.0.0

E15725-01


Copyright © 2000, 2010, Oracle and/or its affiliates. All rights reserved.