Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.0.0

E18683-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:
java.net.SocketOptions
Direct Known Subclasses:
NonBlockingTcpDatagramSocket.Impl
Enclosing class:
TcpDatagramSocket

public static class TcpDatagramSocket.Impl
extends java.net.DatagramSocketImpl

A specialized version of 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()
          Create a new new Impl.
TcpDatagramSocket.Impl(SocketProvider provider)
          Create a new Impl using a provider.

 

Method Summary
protected  void bind(int nPort, java.net.InetAddress addr)
          
protected  void bind(java.net.SocketAddress addr)
          Bind the socket to the specified address.
protected  void close()
          
protected  void closeInbound(com.tangosol.net.TcpDatagramSocket.Impl.ConnectionStatus status, java.nio.channels.SocketChannel chan)
          Close the inbound channel.
protected  void closeOutbound(java.net.SocketAddress addr)
          Close the outbound socket.
protected  void create()
          
protected  com.tangosol.net.TcpDatagramSocket.Impl.Connection ensureConnection(java.net.SocketAddress addr)
          Obtain a Connection for the specified address.
protected static java.net.SocketException ensureSocketException(java.io.IOException e)
          Convert an IOException into a SocketException.
protected  int getLocalPort()
          
 java.lang.Object getOption(int nId)
          
protected  int getTimeToLive()
          
protected  byte getTTL()
          
protected  void join(java.net.InetAddress inetaddr)
          
protected  void joinGroup(java.net.SocketAddress mcastaddr, java.net.NetworkInterface netIf)
          
protected  void leave(java.net.InetAddress inetaddr)
          
protected  void leaveGroup(java.net.SocketAddress mcastaddr, java.net.NetworkInterface netIf)
          
protected  void logException(java.net.SocketAddress addr, java.io.IOException e)
          Log an exception which is handled internally by the TcpDatagramSocket.
protected  void logProtocolWarning(java.net.SocketAddress addr, com.tangosol.net.TcpDatagramSocket.Impl.ConnectionStatus status, int nMagic)
          Periodically log a warning when connections are made using an unrecognized protocol.
protected  com.tangosol.net.TcpDatagramSocket.Impl.Connection makeConnection(java.net.SocketAddress addr)
          Produce a new Connection for the specified destination address.
protected  java.nio.channels.SelectionKey nextKey(java.nio.ByteBuffer buffPacket)
          Perform a blocking read, waiting for a complete packet.
protected  void onAccept(java.nio.channels.SelectionKey key)
          Called when a channel is identified as have a new connection to accept.
protected  boolean onConnectionHeader(com.tangosol.net.TcpDatagramSocket.Impl.ConnectionStatus status, java.nio.channels.SocketChannel chan)
          Process a pending connection header.
protected  boolean onRead(java.nio.channels.SelectionKey key, java.nio.ByteBuffer buffPacket)
          Called when a channel is detected as readable.
protected  int peek(java.net.InetAddress addr)
          
protected  int peekData(java.net.DatagramPacket packet)
          
protected  void processRegistrations()
          Process any scheduled selector registrations.
 java.nio.channels.spi.SelectorProvider provider()
          Return the SelectorProvider associated with this socket.
protected  void receive(java.net.DatagramPacket packet)
          
protected  void scheduleRegistration(java.nio.channels.SocketChannel chan, com.tangosol.net.TcpDatagramSocket.Impl.ConnectionStatus status)
          Schedule a registration with the selector, and wake it up.
protected  void send(java.net.DatagramPacket packet)
          
 void setOption(int nId, java.lang.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)
          
 java.lang.String toString()
          
protected  int transferBytes(java.nio.ByteBuffer buffSrc, java.nio.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 java.net.SocketException
Create a new new Impl.
Throws:
java.net.SocketException - if any error happens during the bind, or if the port is unavailable

TcpDatagramSocket.Impl

public TcpDatagramSocket.Impl(SocketProvider provider)
                       throws java.net.SocketException
Create a new Impl using a provider.
Parameters:
provider - the provider used to create internal sockets
Throws:
java.net.SocketException - if any error happens during the bind, or if the port is unavailable

Method Detail

provider

public java.nio.channels.spi.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 java.net.SocketException
Specified by:
create in class java.net.DatagramSocketImpl
Throws:
java.net.SocketException

bind

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

getLocalPort

protected int getLocalPort()
Overrides:
getLocalPort in class java.net.DatagramSocketImpl

send

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

peek

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

peekData

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

receive

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

nextKey

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

onAccept

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

onRead

protected boolean onRead(java.nio.channels.SelectionKey key,
                         java.nio.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 boolean onConnectionHeader(com.tangosol.net.TcpDatagramSocket.Impl.ConnectionStatus status,
                                     java.nio.channels.SocketChannel chan)
                              throws java.io.IOException
Process a pending connection header.
Parameters:
status - the associated ConnectionStatus
chan - the associated channel
Returns:
true if EOS has been reached
Throws:
java.io.IOException - if an I/O error occurs

close

protected void close()
Specified by:
close in class java.net.DatagramSocketImpl

setOption

public void setOption(int nId,
                      java.lang.Object oValue)
               throws java.net.SocketException
Throws:
java.net.SocketException

getOption

public java.lang.Object getOption(int nId)
                           throws java.net.SocketException
Throws:
java.net.SocketException

setTTL

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

getTTL

protected byte getTTL()
               throws java.io.IOException
Specified by:
getTTL in class java.net.DatagramSocketImpl
Throws:
java.io.IOException

setTimeToLive

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

getTimeToLive

protected int getTimeToLive()
                     throws java.io.IOException
Specified by:
getTimeToLive in class java.net.DatagramSocketImpl
Throws:
java.io.IOException

join

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

leave

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

joinGroup

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

leaveGroup

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

bind

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

ensureSocketException

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

makeConnection

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

ensureConnection

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

closeInbound

protected void closeInbound(com.tangosol.net.TcpDatagramSocket.Impl.ConnectionStatus status,
                            java.nio.channels.SocketChannel chan)
Close the inbound channel.
Parameters:
status - the ConnectionStatus corresponding to the channel
chan - the channel to close

closeOutbound

protected void closeOutbound(java.net.SocketAddress addr)
Close the outbound socket.
Parameters:
addr - the address of the outbound socket

scheduleRegistration

protected void scheduleRegistration(java.nio.channels.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(java.nio.ByteBuffer buffSrc,
                            java.nio.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(java.net.SocketAddress addr,
                            java.io.IOException e)
Log an exception which is handled internally by the TcpDatagramSocket.
Parameters:
addr - the associated address
e - the exception

logProtocolWarning

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

toString

public java.lang.String toString()

Skip navigation links

Oracle® Coherence Java API Reference
Release 3.7.0.0

E18683-01


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