public abstract class StorageDispatcher
extends java.lang.Object
implements java.io.Closeable
// Upload example
com.oracle.iot.client.device.DirectlyConnectedDevice dcd =
new com.oracle.iot.client.device.DirectlyConnectedDevice(assetsFilePath, assetsFilePassword);
StorageDispatcher storageDispatcher = StorageDispatcher.getStorageDispatcher(dcd);
storageDispatcher.setProgressCallback(new ProgressCallback() {
public void progress(Progress progress) {
StorageObject storageObject = progress.getStorageObject();
if (storageObject.getName().equals("lenna")) {
if (progress.getState() == State.COMPLETED) {
// Can now safely remove images/Lenna.jpg, if desired.
} else if (progress.getState() == State.IN_PROGRESS && takingTooLong) {
storageDispatcher.cancel(storageObject);
}
}
}
});
StorageObject lenna = dcd.createStorageObject("lenna","image/jpeg");
lenna.setInputStream(new FileInputStream("../images/Lenna.jpg"));
storageDispatcher.queue(lenna);
// Download example
com.oracle.iot.client.device.DirectlyConnectedDevice dcd =
new com.oracle.iot.client.device.DirectlyConnectedDevice(assetsFilePath, assetsFilePassword);
StorageDispatcher storageDispatcher = StorageDispatcher.getStorageDispatcher(dcd);
storageDispatcher.setProgressCallback(new ProgressCallback() {
public void progress(Progress progress) {
StorageObject storageObject = progress.getStorageObject();
if (storageObject.getName().equals("lenna")) {
if (progress.getState == State.COMPLETED) {
// downloads/Lenna.jpg is ready
} else if (progress.getState() == State.IN_PROGRESS && takingTooLong) {
storageDispatcher.cancel(storageObject);
}
}
}
});
StorageObject lenna = dcd.createStorageObject(uri);
lenna.setOutputStream(new FileOutputStream("../images/Lenna.jpg"));
storageDispatcher.queue(lenna);
| Modifier and Type | Class and Description |
|---|---|
static interface |
StorageDispatcher.Progress
An object for receiving progress via the
ProgressCallback. |
static interface |
StorageDispatcher.ProgressCallback
A callback interface for monitoring progress of queued content.
|
| Constructor and Description |
|---|
StorageDispatcher() |
| Modifier and Type | Method and Description |
|---|---|
abstract void |
cancel(StorageObject storageObject)
Cancel the transfer of content to or from storage.
|
static StorageDispatcher |
getStorageDispatcher(DirectlyConnectedDevice directlyConnectedDevice)
Get the
StorageDispatcher for the given DirectlyConnectedDevice. |
abstract void |
queue(StorageObject storageObject)
Add a
StorageObject to the queue to upload/download content
to/from the Storage Cloud. |
abstract void |
setProgressCallback(StorageDispatcher.ProgressCallback callback)
Set a callback to be notified as the transfer progresses.
|
public static StorageDispatcher getStorageDispatcher(DirectlyConnectedDevice directlyConnectedDevice)
StorageDispatcher for the given DirectlyConnectedDevice.directlyConnectedDevice - the DirectlyConnectedDevicepublic abstract void queue(StorageObject storageObject)
StorageObject to the queue to upload/download content
to/from the Storage Cloud.storageObject - The content storageObject to be queuedjava.lang.IllegalArgumentException - if the storage object is nulljava.lang.IllegalStateException - if the storage object is already queued or
in progresspublic abstract void cancel(StorageObject storageObject)
storageObject is not queued.storageObject - the content storageObject to be cancelled.public abstract void setProgressCallback(StorageDispatcher.ProgressCallback callback)
callback - callback to invoke, if null,
the existing callback will be removed