in tablestore/src/main/java/com/alicloud/openservices/tablestore/timeline/core/TimelineQueueImpl.java [305:381]
private Future<TimelineEntry> doStoreAsync(final long sequenceId, final TimelineMessage message, final PutRowRequest request, final TimelineCallback callback)
{
TableStoreCallback<PutRowRequest, PutRowResponse> tableStoreCallback = null;
if (callback != null) {
tableStoreCallback = new TableStoreCallback<PutRowRequest, PutRowResponse>() {
@Override
public void onCompleted(PutRowRequest request, PutRowResponse response) {
long finalSequenceId = sequenceId;
if (schema.isAutoGenerateSeqId()) {
finalSequenceId = response.getRow()
.getPrimaryKey()
.getPrimaryKeyColumn(schema.getSequenceIdColumnName())
.getValue()
.asLong();
}
TimelineEntry timelineEntry = new TimelineEntry(finalSequenceId, message);
callback.onCompleted(identifier, message, timelineEntry);
}
@Override
public void onFailed(PutRowRequest request, Exception e) {
e = Utils.convertException(e);
callback.onFailed(identifier, message, e);
}
};
}
final Future<PutRowResponse> future = asyncClient.putRow(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 {
PutRowResponse response;
try {
response = future.get();
} catch (InterruptedException e) {
throw e;
} catch (ExecutionException e) {
throw e;
} catch (Exception e) {
throw Utils.convertException(e);
}
return Utils.rowToTimelineEntryWithMessage(schema, response.getRow(), message);
}
@Override
public TimelineEntry get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
PutRowResponse response;
try {
response = 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 Utils.rowToTimelineEntryWithMessage(schema, response.getRow(), message);
}
};
}