Skip to content

Commit

Permalink
remove ThreadLocal in DynamicJvmServiceInvoker
Browse files Browse the repository at this point in the history
  • Loading branch information
致节 committed Mar 18, 2024
1 parent 2e8af92 commit 475ce39
Showing 1 changed file with 13 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,24 @@
*/
public class DynamicJvmServiceInvoker extends ServiceProxy {

private static final Logger LOGGER = SofaBootLoggerFactory
.getLogger(DynamicJvmServiceInvoker.class);
private static final Logger LOGGER = SofaBootLoggerFactory
.getLogger(DynamicJvmServiceInvoker.class);

private final Contract contract;
private final Object targetService;
private final String bizIdentity;
private final ThreadLocal<ClassLoader> clientClassloader = new ThreadLocal<>();
private final boolean serialize;
private final Contract contract;
private final Object targetService;
private final String bizIdentity;
private final ClassLoader clientClassloader;
private final boolean serialize;

static protected final String TOSTRING_METHOD = "toString";
static protected final String EQUALS_METHOD = "equals";
static protected final String HASHCODE_METHOD = "hashCode";
static protected final String TOSTRING_METHOD = "toString";
static protected final String EQUALS_METHOD = "equals";
static protected final String HASHCODE_METHOD = "hashCode";

public DynamicJvmServiceInvoker(ClassLoader clientClassloader, ClassLoader serviceClassLoader,
Object targetService, Contract contract, String bizIdentity,
boolean serialize) {
super(serviceClassLoader);
this.clientClassloader.set(clientClassloader);
this.clientClassloader = clientClassloader;
this.targetService = targetService;
this.contract = contract;
this.bizIdentity = bizIdentity;
Expand Down Expand Up @@ -103,18 +103,17 @@ protected Object doInvoke(MethodInvocation invocation) throws Throwable {
}
} else {
Object[] arguments = (Object[]) hessianTransport(targetArguments, null);
Class[] argumentTypes = (Class[]) hessianTransport(oldArgumentTypes, null);
Class<?>[] argumentTypes = (Class<?>[]) hessianTransport(oldArgumentTypes, null);
transformMethod = getTargetMethod(targetMethod, argumentTypes);
Object retVal = transformMethod.invoke(targetService, arguments);
return hessianTransport(retVal, getClientClassloader());
return hessianTransport(retVal, clientClassloader);
}
} catch (InvocationTargetException ex) {
throw ex.getTargetException();
} finally {
if (DynamicJvmServiceProxyFinder.getInstance().getBizManagerService() != null) {
ReplayContext.clearPlaceHolder();
}
clearClientClassloader();
}
}

Expand All @@ -136,18 +135,6 @@ public Class<?> getInterfaceType() {
return contract.getInterfaceType();
}

public ClassLoader getClientClassloader() {
return clientClassloader.get();
}

public void setClientClassloader(ClassLoader clientClassloader) {
this.clientClassloader.set(clientClassloader);
}

public void clearClientClassloader() {
this.clientClassloader.remove();
}

private Method getTargetMethod(Method method, Class<?>[] argumentTypes) {
try {
return targetService.getClass().getMethod(method.getName(), argumentTypes);
Expand Down

0 comments on commit 475ce39

Please sign in to comment.