use of org.sonatype.aether.RepositoryCache in project sonatype-aether by sonatype.
the class AsyncRepositoryConnector method getProvider.
private AsyncHttpProvider getProvider(RepositorySystemSession session, AsyncHttpClientConfig config) {
String className = ConfigUtils.getString(session, "", "aether.connector.ahc.provider");
if (className != null && className.length() > 0) {
if ("netty".equals(className)) {
className = "com.ning.http.client.providers.netty.NettyAsyncHttpProvider";
} else if ("jdk".equals(className)) {
className = "com.ning.http.client.providers.jdk.JDKAsyncHttpProvider";
} else if ("apache".equals(className)) {
className = "com.ning.http.client.providers.apache.ApacheAsyncHttpProvider";
}
RepositoryCache cache = session.getCache();
try {
if (cache == null || cache.get(session, className) == null) {
logger.debug("Using AHC provider " + className);
Class<?> providerClass = getClass().getClassLoader().loadClass(className);
Object inst = providerClass.getConstructor(AsyncHttpClientConfig.class).newInstance(config);
return (AsyncHttpProvider) inst;
}
} catch (LinkageError e) {
warn("Could not load AHC provider " + className + ", falling back to default", e);
} catch (ClassNotFoundException e) {
logger.warn("Could not load AHC provider " + className + ", falling back to default");
} catch (ClassCastException e) {
logger.warn("Could not load type-compatible AHC provider " + className + ", falling back to default");
} catch (Exception e) {
Throwable cause = e;
if (e instanceof InvocationTargetException && e.getCause() != null) {
cause = e.getCause();
}
warn("Could not instantiate AHC provider " + className + ", falling back to default", cause);
}
if (cache != null) {
cache.put(session, className, Boolean.TRUE);
}
}
return getDefaultProvider(config);
}
Aggregations