Interface ChannelProvider
- All Known Implementing Classes:
DatagramChannelProvider,SocketChannelProvider
public interface ChannelProvider
Used by
ChannelConnections for I/O and wraps a java.nio channel.- API Note:
- Before version 2.1.0, this class was in package
org.omegazero.net.socket.provider.
-
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.
-
Method Details
-
init
Initializes thisChannelProvider.- Parameters:
connection- TheChannelConnectionthisChannelProvideris forkey- The selection key of the connection
-
connect
Connects the underlyingjava.niochannel to the given remote address.- 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
Closes the underlyingjava.niochannel.- Throws:
IOException- If an IO error occurs
-
read
Reads data from the underlyingjava.niochannel into the given buffer.- Parameters:
buf- The buffer to write data to- Returns:
- The number of bytes read
- Throws:
IOException- If an IO error occurs
-
write
Writes data from the given buffer to the underlyingjava.niochannel.- Parameters:
buf- The buffer to read from- Returns:
- The number of bytes written
- Throws:
IOException- If an IO error occurs
-
writeBacklogStarted
void writeBacklogStarted()Called by theChannelConnectionto indicate write backlog has started because the outgoing socket buffer is full. -
writeBacklogEnded
void writeBacklogEnded()Called by theChannelConnectionto indicate write backlog has ended. -
setReadBlock
void setReadBlock(boolean block) If giventrue, the underlying selection key should stop listening for read ops.- Parameters:
block- Whether to block read events
-
isAvailable
boolean isAvailable()Returnstrueif the underlyingjava.niochannel is connected.- Returns:
trueif the channel is connected
-
getSelectionKey
SelectionKey getSelectionKey()Returns theSelectionKeyof thisChannelProvider.- Returns:
- The
SelectionKey - Since:
- 1.6.1
-