Package ome.formats.importer.transfers
Class TransferState
- java.lang.Object
-
- ome.formats.importer.transfers.TransferState
-
- All Implemented Interfaces:
TimeEstimator
public class TransferState extends java.lang.Object implements TimeEstimator
Non-thread-safe argument holder forFileTransfer
implementations. A single instance will be created per invocation ofFileTransfer.transfer(TransferState)
. Several instance methods are provided for common reporting actions (See usage in existingFileTransfer
implementations.- Since:
- 5.0
-
-
Constructor Summary
Constructors Constructor Description TransferState(java.io.File file, int index, int total, ImportProcessPrx proc, ImportLibrary library, TimeEstimator estimator, ome.util.checksum.ChecksumProvider cp, byte[] buf)
State of the current file transfer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
closeUploader()
CallStatefulServiceInterfacePrx.close()
on the cached uploader instance if non-null and null the instance.byte[]
getBuffer()
(Not thread safe) Get a moderately large buffer for use in reading/writing data.java.lang.String
getChecksum()
Get the digest string for the local file.ome.util.checksum.ChecksumProvider
getChecksumProvider()
Get theChecksumProvider
passed to the constructor.java.io.File
getFile()
Return the target file passed to the constructor.long
getLength()
Return the length of thetarget file
.OriginalFile
getOriginalFile()
Find original file as defined by the ID in theRawFileStorePrx
regardless of group.OriginalFile
getRootFile()
Find original file represented by the managed repository that import is taking place to.RawFileStorePrx
getUploader()
RawFileStorePrx
getUploader(java.lang.String mode)
Return theRawFileStorePrx
instance for this index setting the mode if not null.long
getUploadTimeLeft()
void
save()
CallsRawFileStorePrx.save()
and stores the resultantOriginalFile
for future inspection along with the local checksum.void
start()
Starts the time counting.void
stop()
Stops the time counting and updates the internal time counter.void
stop(long uploadedBytes)
Stops the time counting and updates the internal updates the internal time counter and counter of total number of transmitted bytes.void
uploadBytes(long offset)
Raise theImportEvent.FILE_UPLOAD_BYTES
event to all observers.void
uploadComplete(long offset)
Raise theImportEvent.FILE_UPLOAD_COMPLETE
event to all observers.void
uploadStarted()
Raise theImportEvent.FILE_UPLOAD_STARTED
event to all observers.
-
-
-
Constructor Detail
-
TransferState
public TransferState(java.io.File file, int index, int total, ImportProcessPrx proc, ImportLibrary library, TimeEstimator estimator, ome.util.checksum.ChecksumProvider cp, byte[] buf) throws java.io.IOException, ServerError
State of the current file transfer.- Parameters:
file
- Source file which is to be transferred.index
- Which of the total files to upload this is.total
- Total number of files to upload.proc
-ImportProcessPrx
which is being imported to.library
-ImportLibrary
to use for notifications.estimator
- a time-to-completion estimator.cp
- a checksum provider, for calculating file content checksums.buf
- optional buffer. Need not be used or updated.- Throws:
java.io.IOException
- I/O exceptionServerError
- server error
-
-
Method Detail
-
save
public void save() throws ServerError
CallsRawFileStorePrx.save()
and stores the resultantOriginalFile
for future inspection along with the local checksum. (The remote checksum is available from theOriginalFile
.- Throws:
ServerError
- server error
-
getBuffer
public byte[] getBuffer()
(Not thread safe) Get a moderately large buffer for use in reading/writing data. To prevent the creation of many MB-sized byte arrays, this value can be re-used but requires external synchronization.- Returns:
- the buffer
-
getChecksum
public java.lang.String getChecksum()
Get the digest string for the local file. This will only be available, i.e. non-null, aftersave()
has been called.- Returns:
- the checksum
-
getChecksumProvider
public ome.util.checksum.ChecksumProvider getChecksumProvider()
Get theChecksumProvider
passed to the constructor. Since theChecksumProvider
has a number of different usage styles,TransferState
doesn't attempt to delegate but just returns the instance.- Returns:
- the checksum provider used for calculating the checksum
-
getFile
public java.io.File getFile()
Return the target file passed to the constructor.- Returns:
- the source file
-
getLength
public long getLength()
Return the length of thetarget file
.- Returns:
- the length of the source file
-
getOriginalFile
public OriginalFile getOriginalFile() throws ServerError
Find original file as defined by the ID in theRawFileStorePrx
regardless of group.- Returns:
- the original file from the upload process
- Throws:
ServerError
- server error
-
getRootFile
public OriginalFile getRootFile() throws ServerError
Find original file represented by the managed repository that import is taking place to.- Returns:
- the original file at the root of the repository targeted by the upload process
- Throws:
ServerError
- server error
-
getUploader
public RawFileStorePrx getUploader() throws ServerError
- Returns:
- the
RawFileStorePrx
instance for this index - Throws:
ServerError
- server error
-
getUploader
public RawFileStorePrx getUploader(java.lang.String mode) throws ServerError
Return theRawFileStorePrx
instance for this index setting the mode if not null. Valid values include "r" and "rw". If a non-null uploader is available, it will be returned instead. Every instance which is returned from this method should eventually haveStatefulServiceInterfacePrx.close()
called on it.StatefulServiceInterfacePrx.close()
can be used to facilitate this.- Parameters:
mode
- the mode as understood byPublicRepositoryI.file(String, String, Ice.Current)
- Returns:
- the
RawFileStorePrx
instance - Throws:
ServerError
- server error
-
closeUploader
public void closeUploader()
CallStatefulServiceInterfacePrx.close()
on the cached uploader instance if non-null and null the instance. IfObjectNotExistException
is thrown, the service is assumed closed. All other exceptions will be printed at WARN.
-
uploadStarted
public void uploadStarted()
Raise theImportEvent.FILE_UPLOAD_STARTED
event to all observers.
-
uploadBytes
public void uploadBytes(long offset)
Raise theImportEvent.FILE_UPLOAD_BYTES
event to all observers.- Parameters:
offset
- how many bytes are uploaded
-
uploadComplete
public void uploadComplete(long offset)
Raise theImportEvent.FILE_UPLOAD_COMPLETE
event to all observers.- Parameters:
offset
- how many bytes are uploaded
-
start
public void start()
Description copied from interface:TimeEstimator
Starts the time counting.- Specified by:
start
in interfaceTimeEstimator
-
stop
public void stop()
Description copied from interface:TimeEstimator
Stops the time counting and updates the internal time counter.- Specified by:
stop
in interfaceTimeEstimator
-
stop
public void stop(long uploadedBytes)
Description copied from interface:TimeEstimator
Stops the time counting and updates the internal updates the internal time counter and counter of total number of transmitted bytes.- Specified by:
stop
in interfaceTimeEstimator
- Parameters:
uploadedBytes
- Number of bytes uploaded in a single time frame that is being sampled.
-
getUploadTimeLeft
public long getUploadTimeLeft()
Description copied from interface:TimeEstimator
- Specified by:
getUploadTimeLeft
in interfaceTimeEstimator
- Returns:
- The estimated time remaining. The value 0 is returned if
stop
hasn't been called at least once before calling this method.
-
-