Class SocketChannelProvider
java.lang.Object
org.omegazero.net.nio.socket.provider.SocketChannelProvider
- All Implemented Interfaces:
ChannelProvider
A
ChannelProvider for SocketChannels.- API Note:
- Before version 2.1.0, this class was in package
org.omegazero.net.socket.provider.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the underlyingjava.niochannel.booleanconnect(SocketAddress remote, int timeout) Connects the underlyingjava.niochannel to the given remote address.Returns theSelectionKeyof thisChannelProvider.voidinit(ChannelConnection connection, SelectionKey key) Initializes thisChannelProvider.booleanReturnstrueif the underlyingjava.niochannel is connected.intread(ByteBuffer buf) Reads data from the underlyingjava.niochannel into the given buffer.voidsetReadBlock(boolean block) If giventrue, the underlying selection key should stop listening for read ops.intwrite(ByteBuffer buf) Writes data from the given buffer to the underlyingjava.niochannel.voidCalled by theChannelConnectionto indicate write backlog has ended.voidCalled by theChannelConnectionto indicate write backlog has started because the outgoing socket buffer is full.
-
Constructor Details
-
SocketChannelProvider
public SocketChannelProvider()
-
-
Method Details
-
init
Description copied from interface:ChannelProviderInitializes thisChannelProvider.- Specified by:
initin interfaceChannelProvider- Parameters:
connection- TheChannelConnectionthisChannelProvideris forkey- The selection key of the connection
-
connect
Description copied from interface:ChannelProviderConnects the underlyingjava.niochannel to the given remote address.- Specified by:
connectin interfaceChannelProvider- Parameters:
remote- The remote addresstimeout- If applicable, the connection attempt will cancel after this time in milliseconds- Returns:
trueif the channel connected immediately- Throws:
IOException- If an IO error occurs
-
close
Description copied from interface:ChannelProviderCloses the underlyingjava.niochannel.- Specified by:
closein interfaceChannelProvider- Throws:
IOException- If an IO error occurs
-
read
Description copied from interface:ChannelProviderReads data from the underlyingjava.niochannel into the given buffer.- Specified by:
readin interfaceChannelProvider- Parameters:
buf- The buffer to write data to- Returns:
- The number of bytes read
- Throws:
IOException- If an IO error occurs
-
write
Description copied from interface:ChannelProviderWrites data from the given buffer to the underlyingjava.niochannel.- Specified by:
writein interfaceChannelProvider- Parameters:
buf- The buffer to read from- Returns:
- The number of bytes written
- Throws:
IOException- If an IO error occurs
-
writeBacklogStarted
public void writeBacklogStarted()Description copied from interface:ChannelProviderCalled by theChannelConnectionto indicate write backlog has started because the outgoing socket buffer is full.- Specified by:
writeBacklogStartedin interfaceChannelProvider
-
writeBacklogEnded
public void writeBacklogEnded()Description copied from interface:ChannelProviderCalled by theChannelConnectionto indicate write backlog has ended.- Specified by:
writeBacklogEndedin interfaceChannelProvider
-
setReadBlock
public void setReadBlock(boolean block) Description copied from interface:ChannelProviderIf giventrue, the underlying selection key should stop listening for read ops.- Specified by:
setReadBlockin interfaceChannelProvider- Parameters:
block- Whether to block read events
-
isAvailable
public boolean isAvailable()Description copied from interface:ChannelProviderReturnstrueif the underlyingjava.niochannel is connected.- Specified by:
isAvailablein interfaceChannelProvider- Returns:
trueif the channel is connected
-
getSelectionKey
Description copied from interface:ChannelProviderReturns theSelectionKeyof thisChannelProvider.- Specified by:
getSelectionKeyin interfaceChannelProvider- Returns:
- The
SelectionKey
-