refactoring

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

@ -91,14 +91,12 @@ public class AsyncRemoteProxy extends BaseRemoteProxy {
InvocationHandler handler = new InvocationHandler() { InvocationHandler handler = new InvocationHandler() {
@Override @Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String requestId = remoteService.generateRequestId(args);
if (method.getName().equals("toString")) { if (method.getName().equals("toString")) {
return getClass().getSimpleName() + "-" + remoteInterface.getSimpleName() + "-proxy-" + requestId; return proxy.getClass().getName() + "-" + remoteInterface.getName();
} else if (method.getName().equals("equals")) { } else if (method.getName().equals("equals")) {
return proxy == args[0]; return proxy == args[0];
} else if (method.getName().equals("hashCode")) { } else if (method.getName().equals("hashCode")) {
return (getClass().getSimpleName() + "-" + remoteInterface.getSimpleName() + "-proxy-" + requestId).hashCode(); return (proxy.getClass().getName() + "-" + remoteInterface.getName()).hashCode();
} }
if (!optionsCopy.isResultExpected() && !(method.getReturnType().equals(Void.class) if (!optionsCopy.isResultExpected() && !(method.getReturnType().equals(Void.class)
@ -106,11 +104,9 @@ public class AsyncRemoteProxy extends BaseRemoteProxy {
throw new IllegalArgumentException("The noResult option only supports void return value"); throw new IllegalArgumentException("The noResult option only supports void return value");
} }
String requestId = remoteService.generateRequestId(args);
String requestQueueName = getRequestQueueName(syncInterface); String requestQueueName = getRequestQueueName(syncInterface);
Long ackTimeout = optionsCopy.getAckTimeoutInMillis(); Long ackTimeout = optionsCopy.getAckTimeoutInMillis();
RemoteServiceRequest request = new RemoteServiceRequest(executorId, requestId, method.getName(), RemoteServiceRequest request = new RemoteServiceRequest(executorId, requestId, method.getName(),
remoteService.getMethodSignature(method), args, optionsCopy, System.currentTimeMillis()); remoteService.getMethodSignature(method), args, optionsCopy, System.currentTimeMillis());

@ -46,20 +46,20 @@ public class SyncRemoteProxy extends BaseRemoteProxy {
InvocationHandler handler = new InvocationHandler() { InvocationHandler handler = new InvocationHandler() {
@Override @Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String requestId = remoteService.generateRequestId(args);
if (method.getName().equals("toString")) { if (method.getName().equals("toString")) {
return getClass().getSimpleName() + "-" + remoteInterface.getSimpleName() + "-proxy-" + requestId; return proxy.getClass().getName() + "-" + remoteInterface.getName();
} else if (method.getName().equals("equals")) { } else if (method.getName().equals("equals")) {
return proxy == args[0]; return proxy == args[0];
} else if (method.getName().equals("hashCode")) { } else if (method.getName().equals("hashCode")) {
return (getClass().getSimpleName() + "-" + remoteInterface.getSimpleName() + "-proxy-" + requestId).hashCode(); return (proxy.getClass().getName() + "-" + remoteInterface.getName()).hashCode();
} }
if (!optionsCopy.isResultExpected() if (!optionsCopy.isResultExpected()
&& !(method.getReturnType().equals(Void.class) || method.getReturnType().equals(Void.TYPE))) && !(method.getReturnType().equals(Void.class) || method.getReturnType().equals(Void.TYPE))) {
throw new IllegalArgumentException("The noResult option only supports void return value"); throw new IllegalArgumentException("The noResult option only supports void return value");
}
String requestId = remoteService.generateRequestId(args);
String requestQueueName = getRequestQueueName(remoteInterface); String requestQueueName = getRequestQueueName(remoteInterface);
RemoteServiceRequest request = new RemoteServiceRequest(executorId, requestId, method.getName(), RemoteServiceRequest request = new RemoteServiceRequest(executorId, requestId, method.getName(),
remoteService.getMethodSignature(method), args, optionsCopy, System.currentTimeMillis()); remoteService.getMethodSignature(method), args, optionsCopy, System.currentTimeMillis());

@ -669,25 +669,9 @@ public class RedissonRemoteServiceTest extends BaseTest {
RedissonClient client = createInstance(); RedissonClient client = createInstance();
try { try {
RemoteInterface service = client.getRemoteService().get(RemoteInterface.class); RemoteInterface service = client.getRemoteService().get(RemoteInterface.class);
assertThat(service.toString()).contains(RemoteInterface.class.getName());
try { assertThat(service.hashCode()).isEqualTo(service.hashCode());
System.out.println(service.toString()); assertThat(service).isEqualTo(service);
} catch (Exception e) {
Assertions.fail("calling toString on the client service proxy should not make a remote call");
}
try {
assertThat(service.hashCode() == service.hashCode()).isTrue();
} catch (Exception e) {
Assertions.fail("calling hashCode on the client service proxy should not make a remote call");
}
try {
assertThat(service.equals(service)).isTrue();
} catch (Exception e) {
Assertions.fail("calling equals on the client service proxy should not make a remote call");
}
} finally { } finally {
client.shutdown(); client.shutdown();
} }

Loading…
Cancel
Save