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);
}
}
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);
}
}
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);
}
}
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);
}
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);
}
Aggregations