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

Use Class.forName(String name, boolean initialize,ClassLoader loader) to get the MessagingAccessPoint.class #92

Open
ruanwenjun opened this issue Aug 9, 2021 · 0 comments

Comments

@ruanwenjun
Copy link

Sometimes we use OMS.builder().build(properties) to create the MessagingAccessPoint, it can work well in most scenarios.
But sometimes there are existed problem.

If we load the openmessaging-api in moduleA, and we use a customized ClassLoader to load the driver class, then we cannot get the driver class by Class.forName(driverImpl)

It is better to use Class.forName(String name, boolean initialize,ClassLoader loader) to get the driver class in line 50.

public static MessagingAccessPoint getMessagingAccessPoint(String url, KeyValue attributes) {
AccessPointURI accessPointURI = new AccessPointURI(url);
String driverImpl = parseDriverImpl(accessPointURI.getDriverType(), attributes);
attributes.put(OMSBuiltinKeys.ACCESS_POINTS, accessPointURI.getHosts());
attributes.put(OMSBuiltinKeys.DRIVER_IMPL, driverImpl);
attributes.put(OMSBuiltinKeys.REGION, accessPointURI.getRegion());
attributes.put(OMSBuiltinKeys.ACCOUNT_ID, accessPointURI.getAccountId());
try {
Class<?> driverImplClass = Class.forName(driverImpl);
Constructor constructor = driverImplClass.getConstructor(KeyValue.class);
MessagingAccessPoint vendorImpl = (MessagingAccessPoint) constructor.newInstance(attributes);
checkSpecVersion(OMS.specVersion, vendorImpl.version());
return vendorImpl;
} catch (Throwable e) {
throw generateException(OMSResponseStatus.STATUS_10000, url);
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant