Search in sources :

Example 6 with TransferResource

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

the class ConsoleTransferListener method transferProgressed.

@Override
public void transferProgressed(TransferEvent event) {
    TransferResource resource = event.getResource();
    downloads.put(resource, Long.valueOf(event.getTransferredBytes()));
    StringBuilder buffer = new StringBuilder(64);
    for (Map.Entry<TransferResource, Long> entry : downloads.entrySet()) {
        long total = entry.getKey().getContentLength();
        long complete = entry.getValue().longValue();
        buffer.append(getStatus(complete, total)).append("  ");
    }
    int pad = lastLength - buffer.length();
    lastLength = buffer.length();
    pad(buffer, pad);
    buffer.append('\r');
    out.print(buffer);
}
Also used : TransferResource(org.sonatype.aether.transfer.TransferResource) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 7 with TransferResource

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

the class TransferEventTester method checkEvents.

private static void checkEvents(Queue<TransferEvent> events, long expectedBytes) {
    TransferEvent currentEvent = events.poll();
    String msg = "initiate event is missing";
    assertNotNull(msg, currentEvent);
    assertEquals(msg, INITIATED, currentEvent.getType());
    checkProperties(currentEvent);
    TransferResource expectedResource = currentEvent.getResource();
    currentEvent = events.poll();
    msg = "start event is missing";
    assertNotNull(msg, currentEvent);
    assertEquals(msg, TransferEvent.EventType.STARTED, currentEvent.getType());
    assertEquals("bad content length", expectedBytes, currentEvent.getResource().getContentLength());
    checkProperties(currentEvent);
    assertResourceEquals(expectedResource, currentEvent.getResource());
    EventType progressed = TransferEvent.EventType.PROGRESSED;
    EventType succeeded = TransferEvent.EventType.SUCCEEDED;
    TransferEvent succeedEvent = null;
    int dataLength = 0;
    long transferredBytes = 0;
    while ((currentEvent = events.poll()) != null) {
        EventType currentType = currentEvent.getType();
        assertResourceEquals(expectedResource, currentEvent.getResource());
        if (succeeded.equals(currentType)) {
            succeedEvent = currentEvent;
            checkProperties(currentEvent);
            break;
        } else {
            assertTrue("event is not 'succeeded' and not 'progressed'", progressed.equals(currentType));
            assertTrue("wrong order of progressed events, transferredSize got smaller, last = " + transferredBytes + ", current = " + currentEvent.getTransferredBytes(), currentEvent.getTransferredBytes() >= transferredBytes);
            assertEquals("bad content length", expectedBytes, currentEvent.getResource().getContentLength());
            transferredBytes = currentEvent.getTransferredBytes();
            dataLength += currentEvent.getDataBuffer().remaining();
            checkProperties(currentEvent);
        }
    }
    // all events consumed
    assertEquals("too many events left: " + events.toString(), 0, events.size());
    // test transferred size
    assertEquals("progress events transferred bytes don't match: data length does not add up", expectedBytes, dataLength);
    assertEquals("succeed event transferred bytes don't match", expectedBytes, succeedEvent.getTransferredBytes());
}
Also used : EventType(org.sonatype.aether.transfer.TransferEvent.EventType) TransferResource(org.sonatype.aether.transfer.TransferResource) TransferEvent(org.sonatype.aether.transfer.TransferEvent)

Aggregations

TransferResource (org.sonatype.aether.transfer.TransferResource)7 DecimalFormat (java.text.DecimalFormat)2 DecimalFormatSymbols (java.text.DecimalFormatSymbols)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 File (java.io.File)1 RemoteException (java.rmi.RemoteException)1 TransferEvent (org.sonatype.aether.transfer.TransferEvent)1 EventType (org.sonatype.aether.transfer.TransferEvent.EventType)1