|
|
@ -24,8 +24,7 @@ import org.redisson.client.codec.StringCodec;
|
|
|
|
import org.redisson.client.protocol.RedisCommands;
|
|
|
|
import org.redisson.client.protocol.RedisCommands;
|
|
|
|
import org.redisson.command.CommandAsyncExecutor;
|
|
|
|
import org.redisson.command.CommandAsyncExecutor;
|
|
|
|
import org.redisson.executor.params.TaskParameters;
|
|
|
|
import org.redisson.executor.params.TaskParameters;
|
|
|
|
import org.redisson.misc.RPromise;
|
|
|
|
import org.redisson.misc.CompletableFutureWrapper;
|
|
|
|
import org.redisson.misc.RedissonPromise;
|
|
|
|
|
|
|
|
import org.redisson.remote.*;
|
|
|
|
import org.redisson.remote.*;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Arrays;
|
|
|
@ -144,7 +143,7 @@ public class TasksService extends BaseRemoteService {
|
|
|
|
+ "return 1;"
|
|
|
|
+ "return 1;"
|
|
|
|
+ "end;"
|
|
|
|
+ "end;"
|
|
|
|
+ "return 0;",
|
|
|
|
+ "return 0;",
|
|
|
|
Arrays.<Object>asList(tasksCounterName, statusName, schedulerQueueName, schedulerChannelName,
|
|
|
|
Arrays.asList(tasksCounterName, statusName, schedulerQueueName, schedulerChannelName,
|
|
|
|
tasksName, requestQueueName, tasksRetryIntervalName, tasksExpirationTimeName),
|
|
|
|
tasksName, requestQueueName, tasksRetryIntervalName, tasksExpirationTimeName),
|
|
|
|
retryStartTime, request.getId(), encode(request), tasksRetryInterval, expireTime);
|
|
|
|
retryStartTime, request.getId(), encode(request), tasksRetryInterval, expireTime);
|
|
|
|
return f.toCompletableFuture();
|
|
|
|
return f.toCompletableFuture();
|
|
|
@ -173,7 +172,7 @@ public class TasksService extends BaseRemoteService {
|
|
|
|
+ "return 1; "
|
|
|
|
+ "return 1; "
|
|
|
|
+ "end;"
|
|
|
|
+ "end;"
|
|
|
|
+ "return 0;",
|
|
|
|
+ "return 0;",
|
|
|
|
Arrays.<Object>asList(requestQueueName, schedulerQueueName, tasksCounterName, statusName, terminationTopicName,
|
|
|
|
Arrays.asList(requestQueueName, schedulerQueueName, tasksCounterName, statusName, terminationTopicName,
|
|
|
|
tasksName, tasksRetryIntervalName, tasksExpirationTimeName),
|
|
|
|
tasksName, tasksRetryIntervalName, tasksExpirationTimeName),
|
|
|
|
taskId.toString(), RedissonExecutorService.SHUTDOWN_STATE, RedissonExecutorService.TERMINATED_STATE);
|
|
|
|
taskId.toString(), RedissonExecutorService.SHUTDOWN_STATE, RedissonExecutorService.TERMINATED_STATE);
|
|
|
|
return f.toCompletableFuture();
|
|
|
|
return f.toCompletableFuture();
|
|
|
@ -188,78 +187,67 @@ public class TasksService extends BaseRemoteService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public RFuture<Boolean> cancelExecutionAsync(RequestId requestId) {
|
|
|
|
public RFuture<Boolean> cancelExecutionAsync(RequestId requestId) {
|
|
|
|
RPromise<Boolean> result = new RedissonPromise<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String requestQueueName = getRequestQueueName(RemoteExecutorService.class);
|
|
|
|
String requestQueueName = getRequestQueueName(RemoteExecutorService.class);
|
|
|
|
CompletableFuture<Boolean> removeFuture = removeAsync(requestQueueName, requestId);
|
|
|
|
CompletableFuture<Boolean> removeFuture = removeAsync(requestQueueName, requestId);
|
|
|
|
removeFuture.whenComplete((res, e) -> {
|
|
|
|
CompletableFuture<Boolean> f = removeFuture.thenCompose(res -> {
|
|
|
|
if (e != null) {
|
|
|
|
|
|
|
|
result.tryFailure(e);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (res) {
|
|
|
|
if (res) {
|
|
|
|
result.trySuccess(true);
|
|
|
|
return CompletableFuture.completedFuture(true);
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RMap<String, RemoteServiceCancelRequest> canceledRequests = getMap(cancelRequestMapName);
|
|
|
|
RMap<String, RemoteServiceCancelRequest> canceledRequests = getMap(cancelRequestMapName);
|
|
|
|
canceledRequests.putAsync(requestId.toString(), new RemoteServiceCancelRequest(true, true));
|
|
|
|
canceledRequests.putAsync(requestId.toString(), new RemoteServiceCancelRequest(true, true));
|
|
|
|
canceledRequests.expireAsync(60, TimeUnit.SECONDS);
|
|
|
|
canceledRequests.expireAsync(60, TimeUnit.SECONDS);
|
|
|
|
|
|
|
|
|
|
|
|
commandExecutor.getConnectionManager().newTimeout(timeout -> {
|
|
|
|
CompletableFuture<RemoteServiceCancelResponse> response = scheduleCancelResponseCheck(cancelResponseMapName, requestId);
|
|
|
|
result.trySuccess(false);
|
|
|
|
return response.thenApply(r -> {
|
|
|
|
}, 60, TimeUnit.SECONDS);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RPromise<RemoteServiceCancelResponse> response = new RedissonPromise<>();
|
|
|
|
|
|
|
|
scheduleCancelResponseCheck(cancelResponseMapName, requestId, response);
|
|
|
|
|
|
|
|
response.onComplete((r, ex) -> {
|
|
|
|
|
|
|
|
if (ex != null) {
|
|
|
|
|
|
|
|
result.tryFailure(ex);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (r == null) {
|
|
|
|
if (r == null) {
|
|
|
|
result.trySuccess(false);
|
|
|
|
return false;
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result.trySuccess(r.isCanceled());
|
|
|
|
return r.isCanceled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
removeFuture.thenAccept(r -> {
|
|
|
|
|
|
|
|
commandExecutor.getConnectionManager().newTimeout(timeout -> {
|
|
|
|
|
|
|
|
f.complete(false);
|
|
|
|
|
|
|
|
}, 60, TimeUnit.SECONDS);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new CompletableFutureWrapper<>(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void scheduleCancelResponseCheck(String mapName, RequestId requestId, RPromise<RemoteServiceCancelResponse> cancelResponse) {
|
|
|
|
private CompletableFuture<RemoteServiceCancelResponse> scheduleCancelResponseCheck(String mapName, RequestId requestId) {
|
|
|
|
|
|
|
|
CompletableFuture<RemoteServiceCancelResponse> cancelResponse = new CompletableFuture<>();
|
|
|
|
|
|
|
|
|
|
|
|
commandExecutor.getConnectionManager().newTimeout(timeout -> {
|
|
|
|
commandExecutor.getConnectionManager().newTimeout(timeout -> {
|
|
|
|
if (cancelResponse.isDone()) {
|
|
|
|
if (cancelResponse.isDone()) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RMap<String, RemoteServiceCancelResponse> canceledResponses = getMap(mapName);
|
|
|
|
RMap<String, RemoteServiceCancelResponse> canceledResponses = getMap(mapName);
|
|
|
|
RFuture<RemoteServiceCancelResponse> future = canceledResponses.removeAsync(requestId.toString());
|
|
|
|
RFuture<RemoteServiceCancelResponse> removeFuture = canceledResponses.removeAsync(requestId.toString());
|
|
|
|
future.onComplete((response, ex) -> {
|
|
|
|
CompletableFuture<RemoteServiceCancelResponse> future = removeFuture.thenCompose(response -> {
|
|
|
|
if (ex != null) {
|
|
|
|
|
|
|
|
scheduleCancelResponseCheck(mapName, requestId, cancelResponse);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (response == null) {
|
|
|
|
if (response == null) {
|
|
|
|
RFuture<Boolean> f = hasTaskAsync(requestId.toString());
|
|
|
|
RFuture<Boolean> f = hasTaskAsync(requestId.toString());
|
|
|
|
f.onComplete((r, e) -> {
|
|
|
|
return f.thenCompose(r -> {
|
|
|
|
if (e != null || r) {
|
|
|
|
if (r) {
|
|
|
|
scheduleCancelResponseCheck(mapName, requestId, cancelResponse);
|
|
|
|
return scheduleCancelResponseCheck(mapName, requestId);
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
RemoteServiceCancelResponse resp = new RemoteServiceCancelResponse(requestId.toString(), false);
|
|
|
|
RemoteServiceCancelResponse resp = new RemoteServiceCancelResponse(requestId.toString(), false);
|
|
|
|
cancelResponse.trySuccess(resp);
|
|
|
|
return CompletableFuture.completedFuture(resp);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
|
|
|
|
cancelResponse.trySuccess(response);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return CompletableFuture.completedFuture(response);
|
|
|
|
|
|
|
|
}).whenComplete((r, ex) -> {
|
|
|
|
|
|
|
|
if (ex != null) {
|
|
|
|
|
|
|
|
scheduleCancelResponseCheck(mapName, requestId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}).toCompletableFuture();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
commandExecutor.transfer(future, cancelResponse);
|
|
|
|
}, 3000, TimeUnit.MILLISECONDS);
|
|
|
|
}, 3000, TimeUnit.MILLISECONDS);
|
|
|
|
|
|
|
|
return cancelResponse;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public RFuture<Boolean> hasTaskAsync(String taskId) {
|
|
|
|
public RFuture<Boolean> hasTaskAsync(String taskId) {
|
|
|
|