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 forFileTransferimplementations. A single instance will be created per invocation ofFileTransfer.transfer(TransferState). Several instance methods are provided for common reporting actions (See usage in existingFileTransferimplementations.- 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 voidcloseUploader()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.StringgetChecksum()Get the digest string for the local file.ome.util.checksum.ChecksumProvidergetChecksumProvider()Get theChecksumProviderpassed to the constructor.java.io.FilegetFile()Return the target file passed to the constructor.longgetLength()Return the length of thetarget file.OriginalFilegetOriginalFile()Find original file as defined by the ID in theRawFileStorePrxregardless of group.OriginalFilegetRootFile()Find original file represented by the managed repository that import is taking place to.RawFileStorePrxgetUploader()RawFileStorePrxgetUploader(java.lang.String mode)Return theRawFileStorePrxinstance for this index setting the mode if not null.longgetUploadTimeLeft()voidsave()CallsRawFileStorePrx.save()and stores the resultantOriginalFilefor future inspection along with the local checksum.voidstart()Starts the time counting.voidstop()Stops the time counting and updates the internal time counter.voidstop(long uploadedBytes)Stops the time counting and updates the internal updates the internal time counter and counter of total number of transmitted bytes.voiduploadBytes(long offset)Raise theImportEvent.FILE_UPLOAD_BYTESevent to all observers.voiduploadComplete(long offset)Raise theImportEvent.FILE_UPLOAD_COMPLETEevent to all observers.voiduploadStarted()Raise theImportEvent.FILE_UPLOAD_STARTEDevent 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, ServerErrorState 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-ImportProcessPrxwhich is being imported to.library-ImportLibraryto 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 ServerErrorCallsRawFileStorePrx.save()and stores the resultantOriginalFilefor 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 theChecksumProviderpassed to the constructor. Since theChecksumProviderhas a number of different usage styles,TransferStatedoesn'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 theRawFileStorePrxregardless 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
RawFileStorePrxinstance for this index - Throws:
ServerError- server error
-
getUploader
public RawFileStorePrx getUploader(java.lang.String mode) throws ServerError
Return theRawFileStorePrxinstance 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
RawFileStorePrxinstance - Throws:
ServerError- server error
-
closeUploader
public void closeUploader()
CallStatefulServiceInterfacePrx.close()on the cached uploader instance if non-null and null the instance. IfObjectNotExistExceptionis thrown, the service is assumed closed. All other exceptions will be printed at WARN.
-
uploadStarted
public void uploadStarted()
Raise theImportEvent.FILE_UPLOAD_STARTEDevent to all observers.
-
uploadBytes
public void uploadBytes(long offset)
Raise theImportEvent.FILE_UPLOAD_BYTESevent to all observers.- Parameters:
offset- how many bytes are uploaded
-
uploadComplete
public void uploadComplete(long offset)
Raise theImportEvent.FILE_UPLOAD_COMPLETEevent to all observers.- Parameters:
offset- how many bytes are uploaded
-
start
public void start()
Description copied from interface:TimeEstimatorStarts the time counting.- Specified by:
startin interfaceTimeEstimator
-
stop
public void stop()
Description copied from interface:TimeEstimatorStops the time counting and updates the internal time counter.- Specified by:
stopin interfaceTimeEstimator
-
stop
public void stop(long uploadedBytes)
Description copied from interface:TimeEstimatorStops the time counting and updates the internal updates the internal time counter and counter of total number of transmitted bytes.- Specified by:
stopin 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:
getUploadTimeLeftin interfaceTimeEstimator- Returns:
- The estimated time remaining. The value 0 is returned if
stophasn't been called at least once before calling this method.
-
-