private Future doUpdateAsync()

in tablestore/src/main/java/com/alicloud/openservices/tablestore/timeline/core/TimelineQueueImpl.java [383:449]


    private Future<TimelineEntry> doUpdateAsync(final Long sequenceId, final TimelineMessage message, final UpdateRowRequest request, final TimelineCallback callback)
    {
        TableStoreCallback<UpdateRowRequest, UpdateRowResponse> tableStoreCallback = null;
        if (callback != null) {
            tableStoreCallback = new TableStoreCallback<UpdateRowRequest, UpdateRowResponse> () {
                @Override
                public void onCompleted(UpdateRowRequest request, UpdateRowResponse response) {
                    TimelineEntry timelineEntry = new TimelineEntry(sequenceId, message);
                    callback.onCompleted(identifier, message, timelineEntry);
                }

                @Override
                public void onFailed(UpdateRowRequest request, Exception e) {
                    e = Utils.convertException(e);
                    callback.onFailed(identifier, message, e);
                }
            };
        }

        final Future<UpdateRowResponse> future = asyncClient.updateRow(request, tableStoreCallback);
        return new Future<TimelineEntry>() {
            @Override
            public boolean cancel(boolean mayInterruptIfRunning) {
                return future.cancel(mayInterruptIfRunning);
            }

            @Override
            public boolean isCancelled() {
                return future.isCancelled();
            }

            @Override
            public boolean isDone() {
                return future.isDone();
            }

            @Override
            public TimelineEntry get() throws InterruptedException, ExecutionException {
                try {
                    future.get();
                } catch (InterruptedException e) {
                    throw e;
                } catch (ExecutionException e) {
                    throw e;
                }  catch (Exception e) {
                    throw Utils.convertException(e);
                }
                return new TimelineEntry(sequenceId, message);
            }

            @Override
            public TimelineEntry get(long timeout, TimeUnit unit) throws TimelineException, InterruptedException, ExecutionException, TimeoutException {
                try {
                    future.get(timeout, unit);
                } catch (TimeoutException e) {
                    throw e;
                } catch (InterruptedException e) {
                    throw e;
                } catch (ExecutionException e) {
                    throw e;
                }  catch (Exception e) {
                    throw Utils.convertException(e);
                }
                return new TimelineEntry(sequenceId, message);
            }
        };
    }