public class ClientGetter extends BaseClientGetter implements WantsCooldownCallback, FileGetCompletionCallback, java.io.Serializable
blockSetFinalized, cancelled, client, creationTime, failedBlocks, fatallyFailedBlocks, latestFailure, latestSuccess, minSuccessBlocks, priorityClass, realTimeFlag, sentToNetwork, successfulBlocks, totalBlocks
Modifier | Constructor and Description |
---|---|
protected |
ClientGetter()
Required because we implement
Serializable . |
|
ClientGetter(ClientGetCallback client,
FreenetURI uri,
FetchContext ctx,
short priorityClass) |
|
ClientGetter(ClientGetCallback client,
FreenetURI uri,
FetchContext ctx,
short priorityClass,
Bucket returnBucket) |
|
ClientGetter(ClientGetCallback client,
FreenetURI uri,
FetchContext ctx,
short priorityClass,
Bucket returnBucket,
BinaryBlobWriter binaryBlobWriter) |
|
ClientGetter(ClientGetCallback client,
FreenetURI uri,
FetchContext ctx,
short priorityClass,
Bucket returnBucket,
BinaryBlobWriter binaryBlobWriter,
boolean dontFinalizeBlobWriter,
Bucket initialMetadata) |
|
ClientGetter(ClientGetCallback client,
FreenetURI uri,
FetchContext ctx,
short priorityClass,
Bucket returnBucket,
BinaryBlobWriter binaryBlobWriter,
boolean dontFinalizeBlobWriter,
Bucket initialMetadata,
java.lang.String forceCompatibleExtension)
Fetch a key.
|
|
ClientGetter(ClientGetCallback client,
FreenetURI uri,
FetchContext ctx,
short priorityClass,
Bucket returnBucket,
BinaryBlobWriter binaryBlobWriter,
Bucket initialMetadata) |
Modifier and Type | Method and Description |
---|---|
protected void |
addKeyToBinaryBlob(ClientKeyBlock block,
ClientContext context)
Add a block to the binary blob.
|
void |
cancel(ClientContext context)
Cancel the request.
|
boolean |
canRestart()
Can the request be restarted?
|
void |
clearCooldown(ClientGetState state)
The request has unexpectedly left cooldown.
|
protected void |
clearCountersOnRestart() |
protected boolean |
collectingBinaryBlob()
Are we collecting a binary blob?
|
void |
enterCooldown(ClientGetState state,
long wakeupTime,
ClientContext context)
The request has gone into cooldown for some period.
|
java.lang.String |
expectedMIME() |
long |
expectedSize() |
boolean |
finalizedMetadata()
Are we sure the expected MIME and size won't change?
|
Bucket |
getBlobBucket() |
SnoopBucket |
getBucketSnoop()
Get the intermediate data snoop callback
|
protected ClientBaseCallback |
getCallback() |
ClientGetCallback |
getClientCallback() |
byte[] |
getClientDetail(ChecksumChecker checker) |
java.io.File |
getCompletionFile()
Get the final location of the downloaded data.
|
SnoopMetadata |
getMetaSnoop()
Get the metadata snoop callback
|
FreenetURI |
getURI()
What was the URI we were fetching?
|
protected void |
innerNotifyClients(ClientContext context)
Notify clients listening to our ClientEventProducer of the current progress, in the form of a
SplitfileProgressEvent.
|
void |
innerOnResume(ClientContext context)
Called for a persistent request after startup.
|
protected void |
innerToNetwork(ClientContext context)
Notify clients that some part of the request has been sent to the network i.e.
|
boolean |
isCurrentState(ClientGetState state) |
boolean |
isFinished()
Has the fetch completed?
|
void |
onBlockSetFinished(ClientGetState state,
ClientContext context)
Called when no more blocks will be added to the total, and therefore we can confidently display a
percentage for the overall progress.
|
void |
onExpectedMIME(ClientMetadata clientMetadata,
ClientContext context)
Called when we know the MIME type of the final data
|
void |
onExpectedSize(long size,
ClientContext context)
Called when we have some idea of the length of the final data
|
void |
onExpectedTopSize(long size,
long compressed,
int blocksReq,
int blocksTotal,
ClientContext context)
Called when we know the size of the final file, and the number of blocks needed etc.
|
void |
onFailure(FetchException e,
ClientGetState state,
ClientContext context)
Called when the request fails.
|
void |
onFailure(FetchException e,
ClientGetState state,
ClientContext context,
boolean force)
Internal version.
|
void |
onFinalizedMetadata()
Called when we are fairly sure that the expected MIME and size won't change
|
void |
onHashes(HashResult[] hashes,
ClientContext context)
Called when we know the HashResult of the final file.
|
void |
onShutdown(ClientContext context)
Called just before the final write when shutting down the node.
|
void |
onSplitfileCompatibilityMode(InsertContext.CompatibilityMode min,
InsertContext.CompatibilityMode max,
byte[] customSplitfileKey,
boolean dontCompress,
boolean bottomLayer,
boolean definitiveAnyway,
ClientContext context)
Called when we know the settings for the splitfile.
|
void |
onSuccess(java.io.File tempFile,
long length,
ClientMetadata metadata,
ClientGetState state,
ClientContext context)
Call when the download has completed and the tempFile contains the downloaded data, but
may be too long.
|
void |
onSuccess(StreamGenerator streamGenerator,
ClientMetadata clientMetadata,
java.util.List<? extends Compressor> decompressors,
ClientGetState state,
ClientContext context)
Called when the request succeeds.
|
void |
onTransition(ClientGetState oldState,
ClientGetState newState,
ClientContext context)
Called when the current state creates a new state and we switch to that.
|
boolean |
restart(FreenetURI redirect,
boolean filterData,
ClientContext context)
Restart the request.
|
boolean |
resumedFetcher() |
boolean |
resumeFromTrivialProgress(java.io.DataInputStream dis,
ClientContext context) |
SnoopBucket |
setBucketSnoop(SnoopBucket newSnoop)
Set a callback to snoop on buckets (all intermediary data - metadata, containers) during fetches.
|
SnoopMetadata |
setMetaSnoop(SnoopMetadata newSnoop)
Set a callback to snoop on metadata during fetches.
|
boolean |
start(boolean restart,
FreenetURI overrideURI,
ClientContext context)
Start the request.
|
void |
start(ClientContext context) |
java.lang.String |
toString() |
boolean |
writeTrivialProgress(java.io.DataOutputStream dos)
If the request is simple, e.g.
|
addBlock, addBlocks, addMustSucceedBlocks, addRedundantBlocksInsert, blockSetFinalized, cancel, completedBlock, failedBlock, failedBlock, fatallyFailedBlock, getAll, getClient, getClientDetail, getLatestFailure, getLatestSuccess, getPriorityClass, getSchedulerGroup, getTotalBlocks, hashCode, isCancelled, notifyClients, onResume, persistent, realTimeFlag, resetBlocks, setPriorityClass, toNetwork
public ClientGetter(ClientGetCallback client, FreenetURI uri, FetchContext ctx, short priorityClass)
public ClientGetter(ClientGetCallback client, FreenetURI uri, FetchContext ctx, short priorityClass, Bucket returnBucket)
public ClientGetter(ClientGetCallback client, FreenetURI uri, FetchContext ctx, short priorityClass, Bucket returnBucket, BinaryBlobWriter binaryBlobWriter)
public ClientGetter(ClientGetCallback client, FreenetURI uri, FetchContext ctx, short priorityClass, Bucket returnBucket, BinaryBlobWriter binaryBlobWriter, Bucket initialMetadata)
public ClientGetter(ClientGetCallback client, FreenetURI uri, FetchContext ctx, short priorityClass, Bucket returnBucket, BinaryBlobWriter binaryBlobWriter, boolean dontFinalizeBlobWriter, Bucket initialMetadata)
public ClientGetter(ClientGetCallback client, FreenetURI uri, FetchContext ctx, short priorityClass, Bucket returnBucket, BinaryBlobWriter binaryBlobWriter, boolean dontFinalizeBlobWriter, Bucket initialMetadata, java.lang.String forceCompatibleExtension)
client
- The callback we will call when it is completed.uri
- The URI to fetch.ctx
- The config settings for the fetch.priorityClass
- The priority at which to schedule the request.clientContext
- The context object. Used for round-robin query balancing, also indicates whether
the request is persistent.returnBucket
- The bucket to return the data in. Can be null. If not null, the ClientGetter must either
write the data directly to the bucket, or copy it and free the original temporary bucket. Preferably the
former, obviously!binaryBlobWriter
- If non-null, we will write all the keys accessed (or that could have been
accessed in the case of redundant structures such as splitfiles) to this binary blob writer.dontFinalizeBlobWriter
- If true, the caller is responsible for BlobWriter finalizationprotected ClientGetter()
Serializable
.public void start(ClientContext context) throws FetchException
FetchException
public boolean start(boolean restart, FreenetURI overrideURI, ClientContext context) throws FetchException
restart
- If true, restart a finished request.overrideURI
- If non-null, change the URI we are fetching (usually when restarting).container
- The database, null if this is a non-persistent request; if this is a persistent
request, we must be on the database thread, and we will pass the database handle around as needed.context
- The client context, contains important mostly non-persistent global objects.FetchException
- If we were unable to restart.protected void clearCountersOnRestart()
clearCountersOnRestart
in class ClientRequester
public void onSuccess(StreamGenerator streamGenerator, ClientMetadata clientMetadata, java.util.List<? extends Compressor> decompressors, ClientGetState state, ClientContext context)
onSuccess
in interface GetCompletionCallback
state
- The ClientGetState which retrieved the data.public void onSuccess(java.io.File tempFile, long length, ClientMetadata metadata, ClientGetState state, ClientContext context)
FileGetCompletionCallback
onSuccess
in interface FileGetCompletionCallback
tempFile
- A file in the same directory as the completion file, containing the
downloaded data.length
- The length of the downloaded data.metadata
- The MIME type of the downloaded data.state
- The calling ClientGetState.context
- Contains run-time support structures such as executors, temporary storage
factories etc. Not static because we want to be able to run multiple nodes in one VM for
tests etc.public void onFailure(FetchException e, ClientGetState state, ClientContext context)
onFailure
in interface GetCompletionCallback
e
- The reason for failure, in the form of a FetchException.state
- The failing state.public void onFailure(FetchException e, ClientGetState state, ClientContext context, boolean force)
force
- If true, finished may already have been set. This is usually
set when called from onSuccess after it has set finished = true.public void cancel(ClientContext context)
cancel
in class ClientRequester
context
- The ClientContext object including essential but
non-persistent objects such as the schedulers.public boolean isFinished()
isFinished
in class ClientRequester
public FreenetURI getURI()
getURI
in class ClientRequester
protected void innerNotifyClients(ClientContext context)
innerNotifyClients
in class ClientRequester
protected void innerToNetwork(ClientContext context)
innerToNetwork
in class ClientRequester
public void onBlockSetFinished(ClientGetState state, ClientContext context)
onBlockSetFinished
in interface GetCompletionCallback
public void onTransition(ClientGetState oldState, ClientGetState newState, ClientContext context)
onTransition
in interface GetCompletionCallback
onTransition
in class ClientRequester
oldState
- The old ClientGetState.newState
- The new ClientGetState.context
- The database handle. Must not be used by other threads.public boolean canRestart()
public boolean restart(FreenetURI redirect, boolean filterData, ClientContext context) throws FetchException
redirect
- Use this URI instead of the old one.filterData
- context
- The database. We must be on the database thread! See ClientContext for convenience
methods.FetchException
- If something went wrong.public java.lang.String toString()
toString
in class java.lang.Object
protected void addKeyToBinaryBlob(ClientKeyBlock block, ClientContext context)
protected boolean collectingBinaryBlob()
public void onExpectedMIME(ClientMetadata clientMetadata, ClientContext context) throws FetchException
onExpectedMIME
in interface GetCompletionCallback
clientMetadata
- The MIME type, possibly including parameters, as a String.
E.g. "text/html; charset=ISO-8859-1".context
- Utility object containing helpers, mostly not persistent, such as the Ticker, temporary storage factories etc.FetchException
public void onExpectedSize(long size, ClientContext context)
onExpectedSize
in interface GetCompletionCallback
size
- The expected size of the final data.context
- Utility object containing helpers, mostly not persistent, such as the Ticker, temporary storage factories etc.public void onFinalizedMetadata()
onFinalizedMetadata
in interface GetCompletionCallback
public boolean finalizedMetadata()
public java.lang.String expectedMIME()
public long expectedSize()
public ClientGetCallback getClientCallback()
public SnoopMetadata getMetaSnoop()
public SnoopMetadata setMetaSnoop(SnoopMetadata newSnoop)
public SnoopBucket getBucketSnoop()
public SnoopBucket setBucketSnoop(SnoopBucket newSnoop)
public void onExpectedTopSize(long size, long compressed, int blocksReq, int blocksTotal, ClientContext context)
GetCompletionCallback
onExpectedTopSize
in interface GetCompletionCallback
size
- The final size of the data.compressed
- The size of the data after compression / before decompression.blocksReq
- The number of blocks needed to decode the file.blocksTotal
- The total number of blocks available.context
- Utility object containing helpers, mostly not persistent, such as the Ticker, temporary storage factories etc.public void onSplitfileCompatibilityMode(InsertContext.CompatibilityMode min, InsertContext.CompatibilityMode max, byte[] customSplitfileKey, boolean dontCompress, boolean bottomLayer, boolean definitiveAnyway, ClientContext context)
GetCompletionCallback
onSplitfileCompatibilityMode
in interface GetCompletionCallback
min
- The lowest CompatibilityMode that appears to be valid based on what we've fetched so far.max
- The highest CompatibilityMode that appears to be valid based on what we've fetched so far.customSplitfileKey
- The fixed byte[] encryption key used on insert. On anything recent, we generate a single key, randomly for an SSK,
or based on the content for a CHK, and use it for everything. This saves metadata space and improves security for SSKs.dontCompress
- Whether the content is compressed. If false, the dontCompress option was used.bottomLayer
- Whether this report originates at the bottom layer of the splitfile pyramid. I.e. the actual file, not the file containing
the metadata to fetch the file (this can recurse for several levels!)definitiveAnyway
- Whether this report is definitive even though it's not from the bottom layer. This is true of recent splitfiles,
where we store all the data in the top key.context
- Utility object containing helpers, mostly not persistent, such as the Ticker, temporary storage factories etc.public void onHashes(HashResult[] hashes, ClientContext context)
GetCompletionCallback
onHashes
in interface GetCompletionCallback
hashes
- A set of hashes for the final file content.context
- Utility object containing helpers, mostly not persistent, such as the Ticker, temporary storage factories etc.public void enterCooldown(ClientGetState state, long wakeupTime, ClientContext context)
WantsCooldownCallback
enterCooldown
in interface WantsCooldownCallback
public void clearCooldown(ClientGetState state)
WantsCooldownCallback
clearCooldown
in interface WantsCooldownCallback
public Bucket getBlobBucket()
public byte[] getClientDetail(ChecksumChecker checker) throws java.io.IOException
getClientDetail
in class ClientRequester
checker
- Used to checksum and isolate large components where we can recover if they
fail.java.io.IOException
public void innerOnResume(ClientContext context) throws ResumeFailedException
innerOnResume
in class ClientRequester
ResumeFailedException
protected ClientBaseCallback getCallback()
getCallback
in class ClientRequester
public boolean writeTrivialProgress(java.io.DataOutputStream dos) throws java.io.IOException
java.io.IOException
public boolean resumeFromTrivialProgress(java.io.DataInputStream dis, ClientContext context) throws java.io.IOException
java.io.IOException
public boolean resumedFetcher()
public void onShutdown(ClientContext context)
ClientRequester
onShutdown
in class ClientRequester
public boolean isCurrentState(ClientGetState state)
isCurrentState
in class ClientRequester
public java.io.File getCompletionFile()
FileGetCompletionCallback
getCompletionFile
in interface FileGetCompletionCallback