Package com.tangosol.net
Class TcpDatagramSocket.Impl
- java.lang.Object
-
- java.net.DatagramSocketImpl
-
- com.tangosol.net.TcpDatagramSocket.Impl
-
- All Implemented Interfaces:
SocketOptions
- Direct Known Subclasses:
NonBlockingTcpDatagramSocket.Impl
- Enclosing class:
- TcpDatagramSocket
public static class TcpDatagramSocket.Impl extends DatagramSocketImpl
A specialized version ofDatagramSocketImpl.
-
-
Field Summary
Fields Modifier and Type Field Description static intHEADER_SIZEThe fixed header size for packets.static intPROTOCOL_MAGICProtcol 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_REUSEPORT, SO_SNDBUF, SO_TIMEOUT, TCP_NODELAY
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidbind(int nPort, InetAddress addr)protected voidbind(SocketAddress addr)Bind the socket to the specified address.protected voidclose()protected voidcloseInbound(com.tangosol.net.TcpDatagramSocket.Impl.ConnectionStatus status, SocketChannel chan)Close the inboundchannel.protected voidcloseOutbound(SocketAddress addr)Close the outbound socket.protected voidcreate()protected com.tangosol.net.TcpDatagramSocket.Impl.ConnectionensureConnection(SocketAddress addr)Obtain a Connection for the specified address.protected static SocketExceptionensureSocketException(IOException e)Convert an IOException into a SocketException.protected intgetLocalPort()ObjectgetOption(int nId)protected intgetTimeToLive()protected bytegetTTL()protected voidjoin(InetAddress inetaddr)protected voidjoinGroup(SocketAddress mcastaddr, NetworkInterface netIf)protected voidleave(InetAddress inetaddr)protected voidleaveGroup(SocketAddress mcastaddr, NetworkInterface netIf)protected voidlogException(SocketAddress addr, IOException e)Log an exception which is handled internally by the TcpDatagramSocket.protected voidlogProtocolWarning(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.ConnectionmakeConnection(SocketAddress addr)Produce a new Connection for the specified destination address.protected SelectionKeynextKey(ByteBuffer buffPacket)Perform a blocking read, waiting for a complete packet.protected voidonAccept(SelectionKey key)Called when a channel is identified as have a new connection to accept.protected booleanonConnectionHeader(com.tangosol.net.TcpDatagramSocket.Impl.ConnectionStatus status, SocketChannel chan)Process a pending connection header.protected booleanonRead(SelectionKey key, ByteBuffer buffPacket)Called when a channel is detected as readable.protected intpeek(InetAddress addr)protected intpeekData(DatagramPacket packet)protected voidprocessRegistrations()Process any scheduled selector registrations.SelectorProviderprovider()Return the SelectorProvider associated with this socket.protected voidreceive(DatagramPacket packet)protected voidscheduleRegistration(SocketChannel chan, com.tangosol.net.TcpDatagramSocket.Impl.ConnectionStatus status)Schedule a registration with the selector, and wake it up.protected voidsend(DatagramPacket packet)voidsetOption(int nId, Object oValue)voidsetPacketMagic(int nMagic, int nMask)Specify the packet header which is included at the start of every packet.protected voidsetTimeToLive(int ttl)protected voidsetTTL(byte ttl)StringtoString()protected inttransferBytes(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, getOption, setOption, supportedOptions
-
-
-
-
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
-
Impl
public Impl() throws SocketExceptionCreate a new new Impl.- Throws:
SocketException- if any error happens during the bind, or if the port is unavailable
-
Impl
public Impl(com.oracle.coherence.common.net.SocketProvider provider) throws SocketExceptionCreate a new Impl using aprovider.- Parameters:
provider- theproviderused to create internal sockets- Throws:
SocketException- if any error happens during the bind, or if the port is unavailable
-
-
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 headernMask- the packet header bitmask identifying the bits used the mask must be in byte increments
-
create
protected void create() throws SocketException- Specified by:
createin classDatagramSocketImpl- Throws:
SocketException
-
bind
protected void bind(int nPort, InetAddress addr) throws SocketException- Specified by:
bindin classDatagramSocketImpl- Throws:
SocketException
-
getLocalPort
protected int getLocalPort()
- Overrides:
getLocalPortin classDatagramSocketImpl
-
send
protected void send(DatagramPacket packet) throws IOException
- Specified by:
sendin classDatagramSocketImpl- Throws:
IOException
-
peek
protected int peek(InetAddress addr) throws IOException
- Specified by:
peekin classDatagramSocketImpl- Throws:
IOException
-
peekData
protected int peekData(DatagramPacket packet) throws IOException
- Specified by:
peekDatain classDatagramSocketImpl- Throws:
IOException
-
receive
protected void receive(DatagramPacket packet) throws IOException
- Specified by:
receivein classDatagramSocketImpl- 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 exceededIOException
-
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 SelectionKeybuffPacket- 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, SocketChannel chan) throws IOExceptionProcess a pending connection header.- Parameters:
status- the associated ConnectionStatuschan- the associated channel- Returns:
- true if EOS has been reached
- Throws:
IOException- if an I/O error occurs
-
close
protected void close()
- Specified by:
closein classDatagramSocketImpl
-
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:
setTTLin classDatagramSocketImpl- Throws:
IOException
-
getTTL
protected byte getTTL() throws IOException- Specified by:
getTTLin classDatagramSocketImpl- Throws:
IOException
-
setTimeToLive
protected void setTimeToLive(int ttl) throws IOException- Specified by:
setTimeToLivein classDatagramSocketImpl- Throws:
IOException
-
getTimeToLive
protected int getTimeToLive() throws IOException- Specified by:
getTimeToLivein classDatagramSocketImpl- Throws:
IOException
-
join
protected void join(InetAddress inetaddr) throws IOException
- Specified by:
joinin classDatagramSocketImpl- Throws:
IOException
-
leave
protected void leave(InetAddress inetaddr) throws IOException
- Specified by:
leavein classDatagramSocketImpl- Throws:
IOException
-
joinGroup
protected void joinGroup(SocketAddress mcastaddr, NetworkInterface netIf) throws IOException
- Specified by:
joinGroupin classDatagramSocketImpl- Throws:
IOException
-
leaveGroup
protected void leaveGroup(SocketAddress mcastaddr, NetworkInterface netIf) throws IOException
- Specified by:
leaveGroupin classDatagramSocketImpl- 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)Close the inboundchannel.- Parameters:
status- theConnectionStatuscorresponding to the channelchan- the channel to close
-
closeOutbound
protected void closeOutbound(SocketAddress addr)
Close the outbound socket.- Parameters:
addr- theaddressof the outbound socket
-
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 forstatus- 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 bufferbuffDst- 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 addresse- 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 unrecognized protocol.- Parameters:
addr- the source address of the connectionstatus- the connection statusnMagic- the "magic" header they sent
-
-