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
A specialized version of 
DatagramSocketImpl.- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intThe fixed header size for packets.static final intProtcol identifier used to identify that peers are also TcpDatagramSockets.Fields inherited from class java.net.DatagramSocketImplfd, localPortFields inherited from interface java.net.SocketOptionsIP_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
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected 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.ConnectionObtain a Connection for the specified address.protected static SocketExceptionConvert an IOException into a SocketException.protected intgetOption(int nId) protected intprotected 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 voidProcess any scheduled selector registrations.provider()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) voidvoidsetPacketMagic(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) toString()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.DatagramSocketImplconnect, disconnect, getFileDescriptor, getOption, setOption, supportedOptions
- 
Field Details- 
HEADER_SIZEpublic static final int HEADER_SIZEThe fixed header size for packets.- See Also:
 
- 
PROTOCOL_MAGICpublic static final int PROTOCOL_MAGICProtcol 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:
 
 
- 
- 
Constructor Details- 
ImplCreate a new new Impl.- Throws:
- SocketException- if any error happens during the bind, or if the port is unavailable
 
- 
ImplCreate a new Impl using aprovider.- Parameters:
- provider- the- providerused to create internal sockets
- Throws:
- SocketException- if any error happens during the bind, or if the port is unavailable
 
 
- 
- 
Method Details- 
providerReturn the SelectorProvider associated with this socket.- Returns:
- the SelectorProvider
 
- 
setPacketMagicpublic 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- Specified by:
- createin class- DatagramSocketImpl
- Throws:
- SocketException
 
- 
bind- Specified by:
- bindin class- DatagramSocketImpl
- Throws:
- SocketException
 
- 
getLocalPortprotected int getLocalPort()- Overrides:
- getLocalPortin class- DatagramSocketImpl
 
- 
send- Specified by:
- sendin class- DatagramSocketImpl
- Throws:
- IOException
 
- 
peek- Specified by:
- peekin class- DatagramSocketImpl
- Throws:
- IOException
 
- 
peekData- Specified by:
- peekDatain class- DatagramSocketImpl
- Throws:
- IOException
 
- 
receive- Specified by:
- receivein class- DatagramSocketImpl
- Throws:
- IOException
 
- 
nextKeyPerform 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
 
- 
onAcceptCalled when a channel is identified as have a new connection to accept.- Parameters:
- key- the associated SelectionKey
 
- 
onReadCalled 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
 
- 
onConnectionHeaderprotected boolean 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:
- true if EOS has been reached
- Throws:
- IOException- if an I/O error occurs
 
- 
closeprotected void close()- Specified by:
- closein class- DatagramSocketImpl
 
- 
setOption- Throws:
- SocketException
 
- 
getOption- Throws:
- SocketException
 
- 
setTTL- Specified by:
- setTTLin class- DatagramSocketImpl
- Throws:
- IOException
 
- 
getTTL- Specified by:
- getTTLin class- DatagramSocketImpl
- Throws:
- IOException
 
- 
setTimeToLive- Specified by:
- setTimeToLivein class- DatagramSocketImpl
- Throws:
- IOException
 
- 
getTimeToLive- Specified by:
- getTimeToLivein class- DatagramSocketImpl
- Throws:
- IOException
 
- 
join- Specified by:
- joinin class- DatagramSocketImpl
- Throws:
- IOException
 
- 
leave- Specified by:
- leavein class- DatagramSocketImpl
- Throws:
- IOException
 
- 
joinGroup- Specified by:
- joinGroupin class- DatagramSocketImpl
- Throws:
- IOException
 
- 
leaveGroup- Specified by:
- leaveGroupin class- DatagramSocketImpl
- Throws:
- IOException
 
- 
bindBind the socket to the specified address.- Parameters:
- addr- the address to bind to
- Throws:
- SocketException- if an I/O error occurs
 
- 
ensureSocketExceptionConvert an IOException into a SocketException.- Parameters:
- e- the IOExcepotion
- Returns:
- the SocketException
 
- 
makeConnectionprotected 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
 
- 
ensureConnectionprotected 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
 
- 
closeInboundprotected void closeInbound(com.tangosol.net.TcpDatagramSocket.Impl.ConnectionStatus status, SocketChannel chan) Close the inboundchannel.- Parameters:
- status- the- ConnectionStatuscorresponding to the channel
- chan- the channel to close
 
- 
closeOutboundClose the outbound socket.- Parameters:
- addr- the- addressof the outbound socket
 
- 
scheduleRegistrationprotected 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
 
- 
processRegistrationsprotected void processRegistrations()Process any scheduled selector registrations.
- 
transferBytesTransfer 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
 
- 
logExceptionLog an exception which is handled internally by the TcpDatagramSocket.- Parameters:
- addr- the associated address
- e- the exception
 
- 
logProtocolWarningprotected 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 connection
- status- the connection status
- nMagic- the "magic" header they sent
 
- 
toString
 
-