Search in sources :

Example 1 with TransferEvent

use of org.sonatype.aether.transfer.TransferEvent in project sonatype-aether by sonatype.

the class CompletionHandler method fireTransferFailed.

void fireTransferFailed() throws IOException {
    final long bytesTransferred = byteTransfered.get();
    final TransferEvent transferEvent = new AsyncTransferEvent() {

        public EventType getType() {
            return TransferEvent.EventType.FAILED;
        }

        public long getTransferredBytes() {
            return bytesTransferred;
        }
    };
    for (Iterator<TransferListener> iter = listeners.iterator(); iter.hasNext(); ) {
        final TransferListener listener = iter.next();
        listener.transferFailed(transferEvent);
    }
}
Also used : TransferListener(org.sonatype.aether.transfer.TransferListener) TransferEvent(org.sonatype.aether.transfer.TransferEvent)

Example 2 with TransferEvent

use of org.sonatype.aether.transfer.TransferEvent in project sonatype-aether by sonatype.

the class CompletionHandler method fireTransferProgressed.

void fireTransferProgressed(final ByteBuffer buffer) throws TransferCancelledException {
    final long bytesTransferred = byteTransfered.addAndGet(buffer.remaining());
    final TransferEvent transferEvent = new AsyncTransferEvent() {

        public EventType getType() {
            return TransferEvent.EventType.PROGRESSED;
        }

        public long getTransferredBytes() {
            return bytesTransferred;
        }

        public ByteBuffer getDataBuffer() {
            return buffer.asReadOnlyBuffer();
        }

        public int getDataLength() {
            return buffer.remaining();
        }
    };
    for (Iterator<TransferListener> iter = listeners.iterator(); iter.hasNext(); ) {
        final TransferListener listener = iter.next();
        listener.transferProgressed(transferEvent);
    }
}
Also used : TransferListener(org.sonatype.aether.transfer.TransferListener) TransferEvent(org.sonatype.aether.transfer.TransferEvent)

Example 3 with TransferEvent

use of org.sonatype.aether.transfer.TransferEvent in project sonatype-aether by sonatype.

the class CompletionHandler method fireTransferSucceeded.

void fireTransferSucceeded(final Response response) throws IOException {
    final long bytesTransferred = byteTransfered.get();
    final TransferEvent transferEvent = new AsyncTransferEvent() {

        public EventType getType() {
            return TransferEvent.EventType.SUCCEEDED;
        }

        public long getTransferredBytes() {
            return bytesTransferred;
        }
    };
    for (Iterator<TransferListener> iter = listeners.iterator(); iter.hasNext(); ) {
        final TransferListener listener = iter.next();
        listener.transferSucceeded(transferEvent);
    }
}
Also used : TransferListener(org.sonatype.aether.transfer.TransferListener) TransferEvent(org.sonatype.aether.transfer.TransferEvent)

Example 4 with TransferEvent

use of org.sonatype.aether.transfer.TransferEvent in project sonatype-aether by sonatype.

the class GetTest method testDownloadCorrupted.

@Test
public void testDownloadCorrupted() throws Exception {
    RecordingTransferListener transferListener = new RecordingTransferListener();
    session().setTransferListener(transferListener);
    addDelivery("gid/aid/version/aid-version-classifier.extension", "artifact");
    addDelivery("gid/aid/version/aid-version-classifier.extension.sha1", "foo");
    addDelivery("gid/aid/version/aid-version-classifier.extension.md5", "bar");
    File f = TestFileUtils.createTempFile("");
    Artifact a = artifact("bla");
    ArtifactDownload down = new ArtifactDownload(a, null, f, RepositoryPolicy.CHECKSUM_POLICY_WARN);
    Collection<? extends ArtifactDownload> downs = Arrays.asList(down);
    connector().get(downs, null);
    TransferEvent corruptedEvent = null;
    for (TransferEvent e : transferListener.getEvents()) {
        if (TransferEvent.EventType.CORRUPTED.equals(e.getType())) {
            corruptedEvent = e;
            break;
        }
    }
    assertNotNull(corruptedEvent);
}
Also used : ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) TransferEvent(org.sonatype.aether.transfer.TransferEvent) RecordingTransferListener(org.sonatype.aether.test.impl.RecordingTransferListener) File(java.io.File) Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Example 5 with TransferEvent

use of org.sonatype.aether.transfer.TransferEvent in project sonatype-aether by sonatype.

the class TransferEventTester method testFailedTransferEvents.

/**
     * Test the order of events and their properties for the unsuccessful up- and download of artifact and metadata.
     * Failure is triggered by setting the file to transfer to {@code null} for uploads, and asking for a non-existent
     * item for downloads.
     */
public static void testFailedTransferEvents(RepositoryConnectorFactory factory, TestRepositorySystemSession session, RemoteRepository repository) throws NoRepositoryConnectorException, IOException {
    RecordingTransferListener listener = new RecordingTransferListener(session.getTransferListener());
    session.setTransferListener(listener);
    RepositoryConnector connector = factory.newInstance(session, repository);
    byte[] pattern = "tmpFile".getBytes("us-ascii");
    File tmpFile = TestFileUtils.createTempFile(pattern, 10000);
    Collection<ArtifactUpload> artUps = ConnectorTestUtils.createTransfers(ArtifactUpload.class, 1, null);
    Collection<ArtifactDownload> artDowns = ConnectorTestUtils.createTransfers(ArtifactDownload.class, 1, tmpFile);
    Collection<MetadataUpload> metaUps = ConnectorTestUtils.createTransfers(MetadataUpload.class, 1, null);
    Collection<MetadataDownload> metaDowns = ConnectorTestUtils.createTransfers(MetadataDownload.class, 1, tmpFile);
    connector.put(artUps, null);
    LinkedList<TransferEvent> events = new LinkedList<TransferEvent>(listener.getEvents());
    checkFailedEvents(events, null);
    listener.clear();
    connector.get(artDowns, null);
    events = new LinkedList<TransferEvent>(listener.getEvents());
    checkFailedEvents(events, null);
    listener.clear();
    connector.put(null, metaUps);
    events = new LinkedList<TransferEvent>(listener.getEvents());
    checkFailedEvents(events, null);
    listener.clear();
    connector.get(null, metaDowns);
    events = new LinkedList<TransferEvent>(listener.getEvents());
    checkFailedEvents(events, null);
    connector.close();
    session.setTransferListener(null);
}
Also used : ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) TransferEvent(org.sonatype.aether.transfer.TransferEvent) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) RecordingTransferListener(org.sonatype.aether.test.impl.RecordingTransferListener) LinkedList(java.util.LinkedList) ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) RepositoryConnector(org.sonatype.aether.spi.connector.RepositoryConnector) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) File(java.io.File)

Aggregations

TransferEvent (org.sonatype.aether.transfer.TransferEvent)9 TransferListener (org.sonatype.aether.transfer.TransferListener)4 File (java.io.File)3 ArtifactDownload (org.sonatype.aether.spi.connector.ArtifactDownload)3 RecordingTransferListener (org.sonatype.aether.test.impl.RecordingTransferListener)3 LinkedList (java.util.LinkedList)2 ArtifactUpload (org.sonatype.aether.spi.connector.ArtifactUpload)2 MetadataDownload (org.sonatype.aether.spi.connector.MetadataDownload)2 MetadataUpload (org.sonatype.aether.spi.connector.MetadataUpload)2 RepositoryConnector (org.sonatype.aether.spi.connector.RepositoryConnector)2 IOException (java.io.IOException)1 Test (org.junit.Test)1 Artifact (org.sonatype.aether.artifact.Artifact)1 NoRepositoryConnectorException (org.sonatype.aether.transfer.NoRepositoryConnectorException)1 EventType (org.sonatype.aether.transfer.TransferEvent.EventType)1 TransferResource (org.sonatype.aether.transfer.TransferResource)1