Skip to content

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

Open
@ruanwenjun

Description

@ruanwenjun

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);
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions