Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove ThreadLocal in DynamicJvmServiceInvoker #1297

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;

Check warning on line 49 in sofa-boot-project/sofa-boot-core/ark-sofa-boot/src/main/java/com/alipay/sofa/boot/ark/invoke/DynamicJvmServiceInvoker.java

View check run for this annotation

Codecov / codecov/patch

sofa-boot-project/sofa-boot-core/ark-sofa-boot/src/main/java/com/alipay/sofa/boot/ark/invoke/DynamicJvmServiceInvoker.java#L49

Added line #L49 was not covered by tests
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 @@
}
} else {
Object[] arguments = (Object[]) hessianTransport(targetArguments, null);
Class[] argumentTypes = (Class[]) hessianTransport(oldArgumentTypes, null);
Class<?>[] argumentTypes = (Class<?>[]) hessianTransport(oldArgumentTypes, null);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of hessianTransport method with the clientClassloader as a parameter for deserialization is a good practice. It ensures that the deserialized objects are loaded by the appropriate class loader.

However, consider adding error handling or logging within the hessianTransport method to capture and diagnose class loading or deserialization issues.

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 @@
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
Loading