Search in sources :

Example 1 with RepositoryCache

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);
}
Also used : AsyncHttpProvider(com.ning.http.client.AsyncHttpProvider) NettyAsyncHttpProvider(com.ning.http.client.providers.netty.NettyAsyncHttpProvider) RepositoryCache(org.sonatype.aether.RepositoryCache) AsyncHttpClientConfig(com.ning.http.client.AsyncHttpClientConfig) OverlappingFileLockException(java.nio.channels.OverlappingFileLockException) NoRepositoryConnectorException(org.sonatype.aether.transfer.NoRepositoryConnectorException) ArtifactTransferException(org.sonatype.aether.transfer.ArtifactTransferException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ChecksumFailureException(org.sonatype.aether.transfer.ChecksumFailureException) MetadataNotFoundException(org.sonatype.aether.transfer.MetadataNotFoundException) ArtifactNotFoundException(org.sonatype.aether.transfer.ArtifactNotFoundException) ConnectException(java.net.ConnectException) MetadataTransferException(org.sonatype.aether.transfer.MetadataTransferException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

AsyncHttpClientConfig (com.ning.http.client.AsyncHttpClientConfig)1 AsyncHttpProvider (com.ning.http.client.AsyncHttpProvider)1 NettyAsyncHttpProvider (com.ning.http.client.providers.netty.NettyAsyncHttpProvider)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ConnectException (java.net.ConnectException)1 OverlappingFileLockException (java.nio.channels.OverlappingFileLockException)1 ExecutionException (java.util.concurrent.ExecutionException)1 RepositoryCache (org.sonatype.aether.RepositoryCache)1 ArtifactNotFoundException (org.sonatype.aether.transfer.ArtifactNotFoundException)1 ArtifactTransferException (org.sonatype.aether.transfer.ArtifactTransferException)1 ChecksumFailureException (org.sonatype.aether.transfer.ChecksumFailureException)1 MetadataNotFoundException (org.sonatype.aether.transfer.MetadataNotFoundException)1 MetadataTransferException (org.sonatype.aether.transfer.MetadataTransferException)1 NoRepositoryConnectorException (org.sonatype.aether.transfer.NoRepositoryConnectorException)1