refactoring

pull/4428/head
Nikita Koksharov 3 years ago
parent c959fc6f75
commit 8b12f193d2

@ -141,7 +141,7 @@ public class ScheduledTasksService extends TasksService {
}
@Override
protected String generateRequestId() {
protected String generateRequestId(Object[] args) {
if (requestId == null) {
byte[] id = new byte[17];
ThreadLocalRandom.current().nextBytes(id);

@ -180,7 +180,7 @@ public class TasksService extends BaseRemoteService {
}
@Override
protected String generateRequestId() {
protected String generateRequestId(Object[] args) {
byte[] id = new byte[17];
ThreadLocalRandom.current().nextBytes(id);
id[0] = 00;

@ -91,7 +91,7 @@ public class AsyncRemoteProxy extends BaseRemoteProxy {
InvocationHandler handler = new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String requestId = remoteService.generateRequestId();
String requestId = remoteService.generateRequestId(args);
if (method.getName().equals("toString")) {
return getClass().getSimpleName() + "-" + remoteInterface.getSimpleName() + "-proxy-" + requestId;

@ -16,6 +16,7 @@
package org.redisson.remote;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil;
import io.netty.util.Timeout;
@ -170,10 +171,10 @@ public abstract class BaseRemoteService {
}, 3000, TimeUnit.MILLISECONDS);
}
protected String generateRequestId() {
protected String generateRequestId(Object[] args) {
byte[] id = new byte[16];
ThreadLocalRandom.current().nextBytes(id);
return new String(id);
return ByteBufUtil.hexDump(id);
}
protected abstract CompletableFuture<Boolean> addAsync(String requestQueueName, RemoteServiceRequest request,

@ -43,25 +43,23 @@ public class SyncRemoteProxy extends BaseRemoteProxy {
public <T> T create(Class<T> remoteInterface, RemoteInvocationOptions options) {
// local copy of the options, to prevent mutation
RemoteInvocationOptions optionsCopy = new RemoteInvocationOptions(options);
String toString = getClass().getSimpleName() + "-" + remoteInterface.getSimpleName() + "-proxy-"
+ remoteService.generateRequestId();
InvocationHandler handler = new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String requestId = remoteService.generateRequestId(args);
if (method.getName().equals("toString")) {
return toString;
return getClass().getSimpleName() + "-" + remoteInterface.getSimpleName() + "-proxy-" + requestId;
} else if (method.getName().equals("equals")) {
return proxy == args[0];
} else if (method.getName().equals("hashCode")) {
return toString.hashCode();
return (getClass().getSimpleName() + "-" + remoteInterface.getSimpleName() + "-proxy-" + requestId).hashCode();
}
if (!optionsCopy.isResultExpected()
&& !(method.getReturnType().equals(Void.class) || method.getReturnType().equals(Void.TYPE)))
throw new IllegalArgumentException("The noResult option only supports void return value");
String requestId = remoteService.generateRequestId();
String requestQueueName = getRequestQueueName(remoteInterface);
RemoteServiceRequest request = new RemoteServiceRequest(executorId, requestId, method.getName(),
remoteService.getMethodSignature(method), args, optionsCopy, System.currentTimeMillis());

Loading…
Cancel
Save