Search in sources :

Example 11 with TorrentMetadata

use of com.turn.ttorrent.common.TorrentMetadata in project teamcity-torrent-plugin by JetBrains.

the class TeamcityTorrentClient method downloadAndShareOrFail.

public void downloadAndShareOrFail(@NotNull final File torrentFile, @NotNull final List<String> fileNames, @NotNull final String hexInfoHash, @NotNull final File destFile, @NotNull final File destDir, @NotNull final FileProgress fileDownloadProgress, final int downloadTimeoutMs, final int minSeedersCount, final int maxTimeoutForConnect) throws Exception {
    checkThatTorrentContainsFile(fileNames, destFile);
    destDir.mkdirs();
    if (myCommunicationManager.containsTorrentWithHash(hexInfoHash)) {
        LOG.info("Already seeding torrent with hash " + hexInfoHash + ". Stop seeding and try download again");
        stopSeeding(torrentFile);
    }
    LOG.info(String.format("Will attempt to download uninterruptibly %s into %s. Timeout:%d", destFile.getAbsolutePath(), destDir.getAbsolutePath(), downloadTimeoutMs));
    TorrentMetadataProvider metadataProvider = new FileMetadataProvider(torrentFile.getAbsolutePath());
    TorrentMetadata metadata = metadataProvider.getTorrentMetadata();
    FileCollectionStorage fileCollectionStorage = FileCollectionStorage.create(metadata, destDir);
    PieceStorage pieceStorage = EmptyPieceStorageFactory.INSTANCE.createStorage(metadata, fileCollectionStorage);
    TorrentDownloader torrentDownloader = new TorrentDownloader(metadata, fileDownloadProgress, minSeedersCount, maxTimeoutForConnect, downloadTimeoutMs);
    myCommunicationManager.addTorrent(metadataProvider, pieceStorage, Collections.<TorrentListener>singletonList(torrentDownloader));
    Exception exception = null;
    try {
        torrentDownloader.awaitDownload();
    } catch (Exception e) {
        exception = e;
    }
    try {
        myCommunicationManager.removeTorrent(metadata.getHexInfoHash());
        pieceStorage.close();
    } finally {
        boolean downloadFailed = exception != null;
        if (downloadFailed) {
            fileCollectionStorage.delete();
            throw exception;
        }
    }
}
Also used : FileCollectionStorage(com.turn.ttorrent.client.storage.FileCollectionStorage) PieceStorage(com.turn.ttorrent.client.storage.PieceStorage) TorrentMetadata(com.turn.ttorrent.common.TorrentMetadata) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 12 with TorrentMetadata

use of com.turn.ttorrent.common.TorrentMetadata in project teamcity-torrent-plugin by JetBrains.

the class TorrentsSeederTest method createTorrentFromFile.

private File createTorrentFromFile(File srcFile, File torrentDir) throws InterruptedException, IOException {
    File torrentFile = new File(torrentDir, srcFile.getName() + ".torrent");
    final TorrentMetadata torrent = TorrentCreator.create(srcFile, myTracker.getAnnounceURI(), "Test");
    TorrentUtil.saveTorrentToFile(torrent, torrentFile);
    return torrentFile;
}
Also used : File(java.io.File) TorrentMetadata(com.turn.ttorrent.common.TorrentMetadata)

Aggregations

TorrentMetadata (com.turn.ttorrent.common.TorrentMetadata)12 File (java.io.File)9 IOException (java.io.IOException)6 LoadedTorrent (com.turn.ttorrent.client.LoadedTorrent)4 Tracker (com.turn.ttorrent.tracker.Tracker)3 ArrayList (java.util.ArrayList)3 Nullable (org.jetbrains.annotations.Nullable)3 CommunicationManager (com.turn.ttorrent.client.CommunicationManager)2 WaitFor (com.intellij.util.WaitFor)1 FileCollectionStorage (com.turn.ttorrent.client.storage.FileCollectionStorage)1 PieceStorage (com.turn.ttorrent.client.storage.PieceStorage)1 FileNotFoundException (java.io.FileNotFoundException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1 NoRunningBuildException (jetbrains.buildServer.agent.NoRunningBuildException)1 BuildArtifact (jetbrains.buildServer.serverSide.artifacts.BuildArtifact)1 WaitFor (jetbrains.buildServer.util.WaitFor)1 Mock (org.jmock.Mock)1 Constraint (org.jmock.core.Constraint)1