Interface ChannelProvider
- All Known Implementing Classes:
DatagramChannelProvider
,SocketChannelProvider
public interface ChannelProvider
Used by
ChannelConnection
s for I/O and wraps a java.nio
channel.-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes the underlyingjava.nio
channel.boolean
connect
(SocketAddress remote, int timeout) Connects the underlyingjava.nio
channel to the given remote address.Returns theSelectionKey
of thisChannelProvider
.void
init
(ChannelConnection connection, SelectionKey key) Initialized thisChannelProvider
.boolean
Returnstrue
if the underlyingjava.nio
channel is connected.int
read
(ByteBuffer buf) Reads data from the underlyingjava.nio
channel into the given buffer.void
setReadBlock
(boolean block) If giventrue
, the underlying selection key should stop listening for read ops.int
write
(ByteBuffer buf) Writes data from the given buffer to the underlyingjava.nio
channel.void
Called by theChannelConnection
to indicate write backlog has ended.void
Called by theChannelConnection
to indicate write backlog has started because the outgoing socket buffer is full.
-
Method Details
-
init
Initialized thisChannelProvider
.- Parameters:
connection
- TheChannelConnection
thisChannelProvider
is forkey
- The selection key of the connection
-
connect
Connects the underlyingjava.nio
channel to the given remote address.- Parameters:
remote
- The remote addresstimeout
- If applicable, the connection attempt will cancel after this time in milliseconds- Returns:
true
if the channel connected immediately- Throws:
IOException
- If an IO error occurs
-
close
Closes the underlyingjava.nio
channel.- Throws:
IOException
- If an IO error occurs
-
read
Reads data from the underlyingjava.nio
channel 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.nio
channel.- 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 theChannelConnection
to indicate write backlog has started because the outgoing socket buffer is full. -
writeBacklogEnded
void writeBacklogEnded()Called by theChannelConnection
to 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()Returnstrue
if the underlyingjava.nio
channel is connected.- Returns:
true
if the channel is connected
-
getSelectionKey
SelectionKey getSelectionKey()Returns theSelectionKey
of thisChannelProvider
.- Returns:
- The
SelectionKey
- Since:
- 1.6.1
-