@Internal public class ShardingWritableByteChannel extends java.lang.Object implements java.nio.channels.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(java.nio.channels.WritableByteChannel writer)
Adds another shard output channel.
|
void |
close() |
java.nio.channels.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(java.nio.ByteBuffer src)
Writes a buffer to all shards.
|
int |
writeToShard(int shardNum,
java.nio.ByteBuffer src)
Writes the buffer to the given shard.
|
public static final int ALL_SHARDS
public int getNumShards()
public void addChannel(java.nio.channels.WritableByteChannel writer)
public java.nio.channels.WritableByteChannel getChannel(int shardNum)
public int writeToShard(int shardNum, java.nio.ByteBuffer src) throws java.io.IOException
This does not change the current output shard.
ALL_SHARDS
, then the
total is the sum of each individual shard write.java.io.IOException
public int write(java.nio.ByteBuffer src) throws java.io.IOException
Same as calling writeToShard(ALL_SHARDS, buf)
.
write
in interface java.nio.channels.WritableByteChannel
java.io.IOException
public boolean isOpen()
isOpen
in interface java.nio.channels.Channel
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in interface java.nio.channels.Channel
java.io.IOException