public class ShardingWritableByteChannel extends Object implements WritableByteChannel
This provides writeToShard(int, java.nio.ByteBuffer), which takes a shard number for
writing to a particular shard.
The channel is considered open if all downstream channels are open, and closes all downstream channels when closed.
| Modifier and Type | Field and Description |
|---|---|
static int |
ALL_SHARDS
Special shard number that causes a write to all shards.
|
| Constructor and Description |
|---|
ShardingWritableByteChannel() |
| Modifier and Type | Method and Description |
|---|---|
void |
addChannel(WritableByteChannel writer)
Adds another shard output channel.
|
void |
close() |
WritableByteChannel |
getChannel(int shardNum)
Returns the WritableByteChannel associated with the given shard number.
|
int |
getNumShards()
Returns the number of output shards.
|
boolean |
isOpen() |
int |
write(ByteBuffer src)
Writes a buffer to all shards.
|
int |
writeToShard(int shardNum,
ByteBuffer src)
Writes the buffer to the given shard.
|
public static final int ALL_SHARDS
public int getNumShards()
public void addChannel(WritableByteChannel writer)
public WritableByteChannel getChannel(int shardNum)
public int writeToShard(int shardNum,
ByteBuffer src)
throws IOException
This does not change the current output shard.
ALL_SHARDS, then the total is the sum of each individual shard
write.IOExceptionpublic int write(ByteBuffer src) throws IOException
Same as calling writeToShard(ALL_SHARDS, buf).
write in interface WritableByteChannelIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableclose in interface ChannelIOException