iotcs.messaging.client.device.storage module¶
-
class
iotcs.messaging.client.device.storage.StorageConnectionImpl(secureConnection)¶ Bases:
iotcs.messaging.client.storage.StorageConnectionBaseStorageConnection transfers content to the Storage Cloud Service.
There is one StorageConnection instance per client.
Create a StorageConnectionImpl instance.
-
class
iotcs.messaging.client.device.storage.StorageDispatcher¶ Bases:
iotcs.common.CloseableThe StorageDispatcher queues content for automatic upload or download.
The StorageDispatcher uploads/downloads
messaging.client.StorageObjectcontent to/from, the Oracle Storage Cloud Service.dcd = DirectlyConnectedDevice(assetsFilePath, assetsFilePassword) storageDispatcher = StorageDispatcher.getStorageDispatcher(dcd) class UploadProgressCallback(StorageDispatcher.ProgressCallback): def progress(self, progress): storageObject = progress.getStorageObject() if storageObject.getName() == "lenna": if progress.getState() == StorageDispatcher.Progress.State.COMPLETED: # Can now safely remove images/Lenna.jpg, if desired. elif progress.getState() == StorageDispatcher.Progress.State.IN_PROGRESS and takingTooLong: storageDispatcher.cancel(storageObject) storageDispatcher.setProgressCallback(UploadProgressCallback()) lenna = dcd.createStorageObject("lenna", "image/jpeg") lenna.setInputStream(pathlib.Path("../images/Lenna.jpg")) storageDispatcher.queue(lenna) # Download example # :class:`.messaging.client.device.DirectlyConnectedDevice` dcd = DirectlyConnectedDevice(assetsFilePath, assetsFilePassword) storageDispatcher = StorageDispatcher.getStorageDispatcher(dcd) class DownloadProgressCallback(StorageDispatcher.ProgressCallback): def progress(self, progress): storageObject = progress.getStorageObject() if storageObject.getName() == "lenna": if progress.getState == StorageDispatcher.Progress.State.COMPLETED: # downloads/Lenna.jpg is ready elif progress.getState() == StorageDispatcher.Progress.State.IN_PROGRESS and takingTooLong: storageDispatcher.cancel(storageObject) storageDispatcher.setProgressCallback(DownloadProgressCallback()) lenna = dcd.createStorageObject(uri) lenna.setOutputStream(pathlib.Path("../images/Lenna.jpg")) storageDispatcher.queue(lenna)
-
class
Progress¶ Bases:
objectA class to convey progress via the
ProgressCallback.-
class
State¶ Bases:
enum.EnumUpload/Download progress states.
-
CANCELLED= 'CANCELLED'¶ Up/download was cancelled before it completed.
-
COMPLETED= 'COMPLETED'¶ Up/download completed successfully.
-
FAILED= 'FAILED'¶ Up/download failed without completing.
-
INITIATED= 'INITIATED'¶ Initial state after upload() or download() is called.
-
IN_PROGRESS= 'IN_PROGRESS'¶ Up/download is currently in progress.
-
QUEUED= 'QUEUED'¶ Up/download is queued and not yet started.
-
-
getBytesTransferred()¶ Return the number of bytes transferred.
This number can be compared to the length of content obtained by calling
StorageObject.getLength(). :return: the number of bytes transferred
-
getFailureCause()¶ Return the exception that resulted in transfer failure.
The exception is either an OSError or
SecurityException. This is useful if the progress state isProgress.State.FAILED:return the exception causing the failure
-
getState()¶ Return the transfer
Progress.State.:return the transfer state
Progress.State
-
getStorageObject()¶ Return the
messaging.client.device.StorageObject.Return the
messaging.client.device.StorageObjectthat was queued for which this progress event pertains. :return: themessaging.client.device.StorageObject
-
class
-
class
ProgressCallback¶ Bases:
objectA callback interface for monitoring progress of queued content.
-
progress(progress)¶ Notify of progress for content transfer.
Parameters: progress – progress data
-
-
cancel(storageObject)¶ Cancel the transfer of content to or from storage.
This call has no effect if the transfer is completed, already cancelled, has failed, or the
messaging.client.StorageObjectis not queued.Parameters: storageObject – the content messaging.client.StorageObjectto be cancelled.
-
classmethod
getStorageDispatcher(directlyConnectedDevice)¶ Return the
StorageDispatcher.Return a
StorageDispatcherfor the givenmessaging.client.device.DirectlyConnectedDevice.:param directlyConnectedDevice the {@link DirectlyConnectedDevice} :return: a
StorageDispatcher
-
queue(storageObject)¶ Add a
messaging.client.StorageObjectto the queue.The
messaging.client.StorageObjectcontent is uploaded/downloaded to/from the Storage Cloud.Parameters: storageObject – The
messaging.client.StorageObjectcontentmessageing.client.storageObjectto be queuedRaises: - ArgumentException – if the storage object is None
- StateException – if the storage object is already queued or in progress
-
setProgressCallback(callback)¶ Set a callback to be notified as the transfer progresses.
Parameters: callback – the StorageDispatcher.ProgressCallbackto invoke, if None the existing callback is removed
-
class
-
class
iotcs.messaging.client.device.storage.StorageDispatcherImpl¶ Bases:
iotcs.messaging.client.device.storage.StorageDispatcherAn implementation of
StorageDispatcher.StorageDispatcherImpl queues content for automatic upload to or download from the Oracle Storage Cloud Service.
Create a
StorageDispatcherImplinstance.-
class
ContentTransmitter(sd)¶ Bases:
threading.ThreadA Thread that initiates pending uploads and downloads.
Create a
ContentTransmitterinstance.Parameters: sd – a instance of StorageDispatcherImpl-
run()¶ Run
ContentTransmitter.If running is not True exit the thread. If a request to close is pending or the queue is empty exit the thread. Get the next
StorageObjectDelegatefrom the queue and calltransferAndCallback()with the storage object delegate.
-
running¶
-
sd¶
-
stop()¶ Stop the :clas:`.ContentThread`.
-
-
class
ProgressCallbackDispatcher(progress, callback)¶ Bases:
threading.ThreadA Thread to dispatch a
ProgressCallback.Create a ProgressCallbackDispatcher instance.
Parameters: - progress – a
Progressinstance - callback – a
ProgressCallbaclinstance
-
callback¶
-
progress¶
-
run()¶ Call the progress callback.
- progress – a
-
class
ProgressImpl(storageObject)¶ Bases:
iotcs.messaging.client.device.storage.ProgressAn implementation of
StorageDispatcher.Progress.Create a
ProgressImplinstance.Parameters: storageObject – a messaging.client.device.StorageObjectDelegateinstance-
bytesTransferred¶
-
exception¶
-
getBytesTransferred()¶ Return the number of bytes transferred.
-
getFailureCause()¶ Return the Exception causing the failure.
-
getState()¶ Return the
ProgressState.
-
getStorageObject()¶ Return the StorageObject.
Returns: the storage object messaging.client.device.StorageObjectDelegateinstance
-
setBytesTransferred(bytesTransferred)¶ Set the number of bytes transferred.
Parameters: bytesTransferred – the number of bytes transferred
-
setFailureCause(e)¶ Set the exception that caused the failure.
Parameters: e – the Exception that caused the failure
-
setState(state)¶ Set the progress state.
Parameters: state – one of the ProgressStatestates
-
state¶
-
storageObject¶
-
-
cancel(storageObject)¶ Cancel the transfer of storageObject.
Parameters: storageObject – a messaging.client.device.StorageObjectDelegateinstance
-
close()¶ Close this StorageDispatcherImpl instance.
When called the contentThread is stopped and this instance is removed from _dispatcherMap.
-
closeLock¶
-
closed¶
-
contentLock¶
-
contentQueued¶
-
contentThread¶
-
dispatchProgressCallback(progress)¶ Dispatch the
ProgressCallbackwith progress.Parameters: progress – the storage object Progress
-
classmethod
getStorageDispatcher(directlyConnectedDevice)¶ Return a
StorageDispatcher.The
StorageDispatcherreturned is mapped to the directlyConnectedDeviceParameters: directlyConnectedDevice – A iotcs.messaging.client.device.DirectlyConnectedDeviceinstanceReturns: the StorageDispatcherassociated with this directlyConnectedDevice
-
isClosed()¶ Return True if this StorageDispatcherImpl is closed.
Returns: True if this instance is closed
-
progressCallback¶
-
queue(storageObject)¶ Add storageObject to the dispatch queue.
Parameters: storageObject – a messaging.client.device.StorageObjectDelegateinstance
-
queue_¶
-
requestClose¶
-
setProgressCallback(callback)¶ Set the
ProgressCallbackinstance.
-
transferAndCallback(storageObjectDelegate)¶ Transfer the storageObjectDelegate to the storage service.
Transfer the storageObjectDelegate to the storage service and dispatch the
ProgressCallbackParameters: storageObjectDelegate – a StorageObjectDelegateinstanceReturns: True if the progressstate isProgress.State.COMPLETEDelse False
-
class
-
class
iotcs.messaging.client.device.storage.StorageObjectDelegate(storageConnection, uri, name, contentType, contentEncoding, dateOfLastModification, length)¶ Bases:
iotcs.messaging.client.storage.StorageObjectDelegateStorageObjectDelegate to provides progress state.
See
messaging.client.StorageObjectDelegateSeemessaging.client.StorageObjectSeeStorageDispatcher.Progress.StateThis is the device library version of this class. It is instantiated by
iotcs.messaging.client.device.StorageConnectionImplCreate a StorageObjectDelegate instance.
-
PROGRESS_UPDATE_INTERVAL= 1048576¶ The number of bytes transferred between progress updates
-
getState()¶ Return the transfer progress state.
-
isCancelled()¶ Return True if the transfer has been cancelled else False.
-
setInputStream(inputStream)¶ Set the upload input
stream
-
setOutputStream(outputStream)¶ Set the download output
streamParameters: outputStream – the download output stream
-
setState(state)¶ Set the transfer progress state.
Parameters: state – an instance of StorageDispatcher.Progress.State
-
setTransferredBytes(transferredBytes)¶ Set the number of bytes transferred.
Parameters: transferredBytes – the number of byts transferred.
-
state¶
-