Search in sources :

Example 1 with AsyncMessage

use of com.backendless.async.message.AsyncMessage in project Android-SDK by Backendless.

the class Cache method get.

public <T> void get(final String key, final AsyncCallback<T> callback) {
    final Type asyncCallbackType = ReflectionUtil.getCallbackGenericType(callback);
    ThreadPoolService.getPoolExecutor().execute(new Runnable() {

        @Override
        public void run() {
            try {
                T result = (T) get(key, (Class) asyncCallbackType);
                ResponseCarrier.getInstance().deliverMessage(new AsyncMessage<T>(result, callback));
            } catch (BackendlessException e) {
                ResponseCarrier.getInstance().deliverMessage(new AsyncMessage<T>(new BackendlessFault(e), callback));
            }
        }
    });
}
Also used : BackendlessException(com.backendless.exceptions.BackendlessException) IAdaptingType(weborb.types.IAdaptingType) Type(java.lang.reflect.Type) AsyncMessage(com.backendless.async.message.AsyncMessage) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Example 2 with AsyncMessage

use of com.backendless.async.message.AsyncMessage in project Android-SDK by Backendless.

the class UploadFileAsyncTask method doInBackground.

private void doInBackground(final File file, final String path) {
    final AsyncUploadMessage asyncUploadMessage = new AsyncUploadMessage(uploadCallback);
    ThreadPoolService.getPoolExecutor().execute(new Runnable() {

        @Override
        public void run() {
            try {
                FileOutputStreamRouter fileOutputStreamRouter = new FileOutputStreamRouter(file, new UploadCallback() {

                    public void onProgressUpdate(Integer progress) {
                        asyncUploadMessage.setCurrentProgress(progress);
                        ResponseCarrier.getInstance().deliverMessage(asyncUploadMessage);
                    }
                });
                BackendlessFile result = Backendless.Files.uploadFromStream(fileOutputStreamRouter, file.getName(), path, overwrite);
                ResponseCarrier.getInstance().deliverMessage(new AsyncMessage<BackendlessFile>(result, responder));
            } catch (Exception e) {
                ResponseCarrier.getInstance().deliverMessage(new AsyncMessage<BackendlessFile>(new BackendlessFault(e), responder));
            }
        }
    });
}
Also used : AsyncUploadMessage(com.backendless.async.message.AsyncUploadMessage) UploadCallback(com.backendless.async.callback.UploadCallback) AsyncMessage(com.backendless.async.message.AsyncMessage) FileOutputStreamRouter(com.backendless.files.router.FileOutputStreamRouter) BackendlessFile(com.backendless.files.BackendlessFile) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Aggregations

AsyncMessage (com.backendless.async.message.AsyncMessage)2 BackendlessFault (com.backendless.exceptions.BackendlessFault)2 UploadCallback (com.backendless.async.callback.UploadCallback)1 AsyncUploadMessage (com.backendless.async.message.AsyncUploadMessage)1 BackendlessException (com.backendless.exceptions.BackendlessException)1 BackendlessFile (com.backendless.files.BackendlessFile)1 FileOutputStreamRouter (com.backendless.files.router.FileOutputStreamRouter)1 Type (java.lang.reflect.Type)1 IAdaptingType (weborb.types.IAdaptingType)1