use of org.commonjava.maven.galley.config.TransportManagerConfig in project galley by Commonjava.
the class GalleyCoreBuilder method initMissingComponents.
public void initMissingComponents() throws GalleyInitException {
if (transportManager == null) {
transportManager = new TransportManagerImpl(transports);
}
handlerExecutor = Executors.newFixedThreadPool(2, new NamedThreadFactory("transfer-handlers", true, 4));
batchExecutor = Executors.newFixedThreadPool(2, new NamedThreadFactory("transfer-batches", true, 4));
if (decorator == null) {
decorator = new NoOpTransferDecorator();
}
if (events == null) {
events = new NoOpFileEventManager();
}
if (nfc == null) {
nfc = new MemoryNotFoundCache();
}
if (transportManagerConfig == null) {
transportManagerConfig = new TransportManagerConfig();
}
final DownloadHandler dh = new DownloadHandler(getNfc(), transportManagerConfig, handlerExecutor);
final UploadHandler uh = new UploadHandler(getNfc(), transportManagerConfig, handlerExecutor);
final ListingHandler lh = new ListingHandler(getNfc());
final ExistenceHandler eh = new ExistenceHandler(getNfc());
if (specialPathManager == null) {
specialPathManager = new SpecialPathManagerImpl();
}
if (pathGenerator == null) {
pathGenerator = new HashedLocationPathGenerator();
}
if (cache == null) {
if (cacheProviderFactory != null) {
cache = cacheProviderFactory.create(pathGenerator, decorator, events);
} else {
throw new GalleyInitException("No CacheProvider / CacheProviderFactory specified!");
}
}
if (transferManager == null) {
transferManager = new TransferManagerImpl(transportManager, getCache(), getNfc(), getFileEvents(), dh, uh, lh, eh, specialPathManager, batchExecutor);
}
if (locationExpander == null) {
logger.debug("Initializing default location expander");
locationExpander = new NoOpLocationExpander();
}
if (locationResolver == null) {
locationResolver = new SimpleUrlLocationResolver(locationExpander, transportManager);
}
if (passwordManager == null) {
passwordManager = new MemoryPasswordManager();
}
}
use of org.commonjava.maven.galley.config.TransportManagerConfig in project galley by Commonjava.
the class TransferManagerImplTest method setup.
@Before
public void setup() {
transport = new TestTransport();
transportMgr = new TransportManagerImpl(transport);
cacheProvider = new FileCacheProvider(temp.newFolder("cache"), new HashedLocationPathGenerator(), new NoOpFileEventManager(), new NoOpTransferDecorator(), true);
nfc = new MemoryNotFoundCache();
fileEvents = new NoOpFileEventManager();
executor = Executors.newSingleThreadExecutor();
TransportManagerConfig transportManagerConfig = new TransportManagerConfig();
final DownloadHandler dh = new DownloadHandler(nfc, transportManagerConfig, executor);
final UploadHandler uh = new UploadHandler(nfc, transportManagerConfig, executor);
final ListingHandler lh = new ListingHandler(nfc);
final ExistenceHandler eh = new ExistenceHandler(nfc);
mgr = new TransferManagerImpl(transportMgr, cacheProvider, nfc, fileEvents, dh, uh, lh, eh, new SpecialPathManagerImpl(), Executors.newFixedThreadPool(2));
}
use of org.commonjava.maven.galley.config.TransportManagerConfig in project galley by Commonjava.
the class DownloadHandlerConcurrencyTest method concurrentDownloadWaitsThenUsesFirstResult_SmallFile.
@BMRules(rules = { @BMRule(name = "init rendezvous", targetClass = "DownloadHandler", targetMethod = "<init>", targetLocation = "ENTRY", action = "debug(\"Creating rendezvous\"); createRendezvous(\"tsync\", 4);"), @BMRule(name = "rendezvous threads", targetClass = "DownloadHandler", targetMethod = "joinOrStart", targetLocation = "ENTRY", action = "debug(\"waiting for rendezvous\"); rendezvous(\"tsync\"); debug(\"proceeding\");") })
@Test
public void concurrentDownloadWaitsThenUsesFirstResult_SmallFile() throws Exception {
final NotFoundCache nfc = new MemoryNotFoundCache();
final TransportManagerConfig mgrConfig = new TransportManagerConfig();
handler = new DownloadHandler(nfc, mgrConfig, executor);
// NOTE: Coordinate with "init" @BMRule above!
final int threads = 4;
final int timeoutSeconds = 10;
final String content = "this is a test " + System.currentTimeMillis();
final String base = "repo";
final String path = "this/is/the/path.txt";
final String baseurl = server.formatUrl(base);
// Serve the content EXACTLY ONCE. It should be cached / cache should be used after that.
server.expect("GET", server.formatUrl(base, path), new ExpectationHandler() {
private boolean sent = false;
@Override
public void handle(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
if (!sent) {
resp.setStatus(HttpServletResponse.SC_OK);
resp.getWriter().write(content);
sent = true;
} else {
throw new ServletException("Cannot write content more than once.");
}
}
});
final ConcreteResource resource = new ConcreteResource(new SimpleLocation(base, baseurl), path);
final Transfer target = cacheProvider.getTransfer(resource);
final CountDownLatch latch = new CountDownLatch(threads);
final AtomicInteger successes = new AtomicInteger(0);
final Logger logger = LoggerFactory.getLogger(getClass());
// start threads, then wait for each to complete, and
for (int i = 0; i < threads; i++) {
executor.execute(new Runnable() {
@Override
public void run() {
String oldName = Thread.currentThread().getName();
try {
Thread.currentThread().setName("Download - " + oldName);
Transfer result = handler.download(resource, target, timeoutSeconds, transport, false, new EventMetadata());
try (InputStream in = result.openInputStream()) {
String resultContent = IOUtils.toString(in);
if (resultContent.equals(content)) {
successes.incrementAndGet();
} else {
logger.error("Expected content: '{}'\nActual content: '{}'", content, resultContent);
}
} catch (IOException e) {
logger.error("Failed to read transfer: " + e.getMessage(), e);
}
} catch (TransferException e) {
logger.error("Failed to retrieve: " + e.getMessage(), e);
} finally {
latch.countDown();
Thread.currentThread().setName(oldName);
}
}
});
}
}
use of org.commonjava.maven.galley.config.TransportManagerConfig in project pom-manipulation-ext by release-engineering.
the class GalleyInfrastructure method init.
private void init(final File targetDirectory, final List<ArtifactRepository> remoteRepositories, final ArtifactRepository localRepository, final Settings settings, final List<String> activeProfiles, final Location customLocation, final Transport customTransport, File cacheDir_) throws ManipulationException {
LocationExpander locationExpander;
try {
final List<Location> custom = customLocation == null ? Collections.<Location>emptyList() : Collections.singletonList(customLocation);
locationExpander = new MavenLocationExpander(custom, remoteRepositories, localRepository, mirrorSelector, settings, activeProfiles);
} catch (final MalformedURLException e) {
throw new ManipulationException("Failed to setup Maven-specific LocationExpander: %s", e, e.getMessage());
}
xml = new XMLInfrastructure();
xpaths = new XPathManager();
final TransportManager transports;
if (customTransport != null) {
transports = new TransportManagerImpl(customTransport);
} else {
transports = new TransportManagerImpl(new HttpClientTransport(new HttpImpl(new MemoryPasswordManager())), new FileTransport(), new ZipJarTransport());
}
cacheDir = cacheDir_;
if (cacheDir == null) {
cacheDir = new File(targetDirectory, "manipulator-cache");
}
final FileEventManager fileEvents = new NoOpFileEventManager();
final CacheProvider cache = new FileCacheProvider(cacheDir, new HashedLocationPathGenerator(), fileEvents, new NoOpTransferDecorator());
final NotFoundCache nfc = new MemoryNotFoundCache();
executor = Executors.newCachedThreadPool();
final TransportManagerConfig config = new TransportManagerConfig();
final TransferManager transfers = new TransferManagerImpl(transports, cache, nfc, fileEvents, new DownloadHandler(nfc, config, executor), new UploadHandler(nfc, config, executor), new ListingHandler(nfc), new ExistenceHandler(nfc), new SpecialPathManagerImpl(), executor);
final TypeMapper types = new StandardTypeMapper();
final ArtifactMetadataManager metadataManager = new ArtifactMetadataManagerImpl(transfers, locationExpander);
final VersionResolver versionResolver = new VersionResolverImpl(new MavenMetadataReader(xml, locationExpander, metadataManager, xpaths));
artifactManager = new ArtifactManagerImpl(transfers, locationExpander, types, versionResolver);
// TODO: auto-adjust this to the current Maven runtime!
final MavenPluginDefaults pluginDefaults = new StandardMaven304PluginDefaults();
final MavenPluginImplications pluginImplications = new StandardMavenPluginImplications(xml);
pomReader = new MavenPomReader(xml, locationExpander, artifactManager, xpaths, pluginDefaults, pluginImplications);
metadataReader = new MavenMetadataReader(xml, locationExpander, metadataManager, xpaths);
}
use of org.commonjava.maven.galley.config.TransportManagerConfig in project indy by Commonjava.
the class TestProvider method setup.
@PostConstruct
public void setup() {
storeDataManager = new MemoryStoreDataManager(true);
nfc = new MemoryNotFoundCache();
objectMapper = new IndyObjectMapper(false);
fileEventManager = new NoOpFileEventManager();
transferDecorator = new NoOpTransferDecorator();
transportManagerConfig = new TransportManagerConfig();
weftConfig = new DefaultWeftConfig();
globalHttpConfiguration = new GlobalHttpConfiguration();
userLifecycleManager = new AlternativeUserLifecycleManager();
temp = new TemporaryFolder();
try {
temp.create();
cacheProvider = new FileCacheProvider(temp.newFolder("storage"), indyPathGenerator, fileEventManager, new TransferDecoratorManager(transferDecorator));
} catch (IOException e) {
fail("Cannot initialize temporary directory structure");
temp.delete();
}
}
Aggregations