public class SimpleBlockChooser
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected int |
maxRetries |
Constructor and Description |
---|
SimpleBlockChooser(int blocks,
java.util.Random random,
int maxRetries) |
Modifier and Type | Method and Description |
---|---|
protected boolean |
checkValid(int chosen)
Is the proposed block valid? Override to implement custom logic e.g.
|
int |
chooseKey()
Choose a key to fetch, taking into account retries
|
boolean[] |
copyDownloadedBlocks() |
int |
countFailedBlocks() |
int |
countFetchable() |
int |
getBlockNumber(SplitFileSegmentKeys keys,
NodeCHK key)
Ugly to include this here, but avoids making completed visible ...
|
protected int |
getMaxBlockNumber()
Can be overridden to restrict chooseKey() to a subset of the available blocks.
|
int |
getRetries(int blockNumber) |
boolean |
hasSucceeded(int blockNumber) |
boolean |
hasSucceededAll() |
protected int |
innerOnNonFatalFailure(int blockNo)
Notify when a block has failed.
|
protected void |
onCompletedAll() |
boolean |
onNonFatalFailure(int blockNo) |
boolean |
onSuccess(int blockNo)
Notify when a block has succeeded.
|
void |
onUnSuccess(int blockNo)
Notify that a block has no longer succeeded.
|
void |
read(java.io.DataInputStream dis) |
void |
readRetries(java.io.DataInputStream dis) |
void |
replaceSuccesses(boolean[] used)
Mass replace of success/failure.
|
int |
successCount() |
void |
write(java.io.DataOutputStream dos)
Write everything
|
void |
writeRetries(java.io.DataOutputStream dos)
Write the retry counts only, and only if maxRetries != -1.
|
public SimpleBlockChooser(int blocks, java.util.Random random, int maxRetries)
public int chooseKey()
public boolean onNonFatalFailure(int blockNo)
protected int innerOnNonFatalFailure(int blockNo)
public boolean onSuccess(int blockNo)
public void onUnSuccess(int blockNo)
blockNo
- protected void onCompletedAll()
protected boolean checkValid(int chosen)
protected int getMaxBlockNumber()
public void replaceSuccesses(boolean[] used)
used
- An array of flags indicating whether we have each block.public int successCount()
public int getRetries(int blockNumber)
public int getBlockNumber(SplitFileSegmentKeys keys, NodeCHK key)
public boolean hasSucceeded(int blockNumber)
public void writeRetries(java.io.DataOutputStream dos) throws java.io.IOException
java.io.IOException
public void readRetries(java.io.DataInputStream dis) throws java.io.IOException
java.io.IOException
public void write(java.io.DataOutputStream dos) throws java.io.IOException
java.io.IOException
public void read(java.io.DataInputStream dis) throws StorageFormatException, java.io.IOException
StorageFormatException
java.io.IOException
public int countFailedBlocks()
public boolean[] copyDownloadedBlocks()
public int countFetchable()
public boolean hasSucceededAll()