iotcs.messaging.client.device.storage module¶
-
class
iotcs.messaging.client.device.storage.
StorageConnectionImpl
(secureConnection)¶ Bases:
iotcs.messaging.client.storage.StorageConnectionBase
StorageConnection 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.Closeable
The StorageDispatcher queues content for automatic upload or download.
The StorageDispatcher uploads/downloads
messaging.client.StorageObject
content 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:
object
A class to convey progress via the
ProgressCallback
.-
class
State
¶ Bases:
enum.Enum
Upload/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.StorageObject
that was queued for which this progress event pertains. :return: themessaging.client.device.StorageObject
-
class
-
class
ProgressCallback
¶ Bases:
object
A 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.StorageObject
is not queued.Parameters: storageObject – the content messaging.client.StorageObject
to be cancelled.
-
classmethod
getStorageDispatcher
(directlyConnectedDevice)¶ Return the
StorageDispatcher
.Return a
StorageDispatcher
for the givenmessaging.client.device.DirectlyConnectedDevice
.:param directlyConnectedDevice the {@link DirectlyConnectedDevice} :return: a
StorageDispatcher
-
queue
(storageObject)¶ Add a
messaging.client.StorageObject
to the queue.The
messaging.client.StorageObject
content is uploaded/downloaded to/from the Storage Cloud.Parameters: storageObject – The
messaging.client.StorageObject
contentmessageing.client.storageObject
to 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.ProgressCallback
to invoke, if None the existing callback is removed
-
class
-
class
iotcs.messaging.client.device.storage.
StorageDispatcherImpl
¶ Bases:
iotcs.messaging.client.device.storage.StorageDispatcher
An implementation of
StorageDispatcher
.StorageDispatcherImpl queues content for automatic upload to or download from the Oracle Storage Cloud Service.
Create a
StorageDispatcherImpl
instance.-
class
ContentTransmitter
(sd)¶ Bases:
threading.Thread
A Thread that initiates pending uploads and downloads.
Create a
ContentTransmitter
instance.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
StorageObjectDelegate
from the queue and calltransferAndCallback()
with the storage object delegate.
-
running
¶
-
sd
¶
-
stop
()¶ Stop the :clas:`.ContentThread`.
-
-
class
ProgressCallbackDispatcher
(progress, callback)¶ Bases:
threading.Thread
A Thread to dispatch a
ProgressCallback
.Create a ProgressCallbackDispatcher instance.
Parameters: - progress – a
Progress
instance - callback – a
ProgressCallbacl
instance
-
callback
¶
-
progress
¶
-
run
()¶ Call the progress callback.
- progress – a
-
class
ProgressImpl
(storageObject)¶ Bases:
iotcs.messaging.client.device.storage.Progress
An implementation of
StorageDispatcher.Progress
.Create a
ProgressImpl
instance.Parameters: storageObject – a messaging.client.device.StorageObjectDelegate
instance-
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.StorageObjectDelegate
instance
-
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 ProgressState
states
-
state
¶
-
storageObject
¶
-
-
cancel
(storageObject)¶ Cancel the transfer of storageObject.
Parameters: storageObject – a messaging.client.device.StorageObjectDelegate
instance
-
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
ProgressCallback
with progress.Parameters: progress – the storage object Progress
-
classmethod
getStorageDispatcher
(directlyConnectedDevice)¶ Return a
StorageDispatcher
.The
StorageDispatcher
returned is mapped to the directlyConnectedDeviceParameters: directlyConnectedDevice – A iotcs.messaging.client.device.DirectlyConnectedDevice
instanceReturns: the StorageDispatcher
associated 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.StorageObjectDelegate
instance
-
queue_
¶
-
requestClose
¶
-
setProgressCallback
(callback)¶ Set the
ProgressCallback
instance.
-
transferAndCallback
(storageObjectDelegate)¶ Transfer the storageObjectDelegate to the storage service.
Transfer the storageObjectDelegate to the storage service and dispatch the
ProgressCallback
Parameters: storageObjectDelegate – a StorageObjectDelegate
instanceReturns: True if the progress
state isProgress.State.COMPLETED
else False
-
class
-
class
iotcs.messaging.client.device.storage.
StorageObjectDelegate
(storageConnection, uri, name, contentType, contentEncoding, dateOfLastModification, length)¶ Bases:
iotcs.messaging.client.storage.StorageObjectDelegate
StorageObjectDelegate to provides progress state.
See
messaging.client.StorageObjectDelegate
Seemessaging.client.StorageObject
SeeStorageDispatcher.Progress.State
This is the device library version of this class. It is instantiated by
iotcs.messaging.client.device.StorageConnectionImpl
Create 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
stream
Parameters: 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
¶
-