Search in sources :

Example 1 with TransferResource

use of org.sonatype.aether.transfer.TransferResource in project zeppelin by apache.

the class TransferListener method transferSucceeded.

@Override
public void transferSucceeded(TransferEvent event) {
    transferCompleted(event);
    TransferResource resource = event.getResource();
    long contentLength = event.getTransferredBytes();
    if (contentLength >= 0) {
        String type = (event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploaded" : "Downloaded");
        String len = contentLength >= 1024 ? toKB(contentLength) + " KB" : contentLength + " B";
        String throughput = "";
        long duration = System.currentTimeMillis() - resource.getTransferStartTime();
        if (duration > 0) {
            DecimalFormat format = new DecimalFormat("0.0", new DecimalFormatSymbols(Locale.ENGLISH));
            double kbPerSec = (contentLength / 1024.0) / (duration / 1000.0);
            throughput = " at " + format.format(kbPerSec) + " KB/sec";
        }
        logger.info(type + ": " + resource.getRepositoryUrl() + resource.getResourceName() + " (" + len + throughput + ")");
    }
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) TransferResource(org.sonatype.aether.transfer.TransferResource) DecimalFormat(java.text.DecimalFormat)

Example 2 with TransferResource

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

the class Maven30TransferListenerAdapter method transferProgressed.

@Override
public void transferProgressed(TransferEvent event) throws TransferCancelledException {
    checkCanceled();
    TransferResource r = event.getResource();
    long totalLength = r.getContentLength();
    String sizeInfo;
    if (totalLength <= 0) {
        sizeInfo = StringUtil.formatFileSize(event.getTransferredBytes()) + " / ?";
    } else {
        sizeInfo = StringUtil.formatFileSize(event.getTransferredBytes()) + " / " + StringUtil.formatFileSize(totalLength);
    }
    try {
        myIndicator.setText2(formatResourceName(event) + "  (" + sizeInfo + ')');
        if (totalLength <= 0) {
            myIndicator.setIndeterminate(true);
        } else {
            myIndicator.setIndeterminate(false);
            myIndicator.setFraction((double) event.getTransferredBytes() / totalLength);
        }
    } catch (RemoteException e) {
        throw new RuntimeRemoteException(e);
    }
}
Also used : TransferResource(org.sonatype.aether.transfer.TransferResource) RemoteException(java.rmi.RemoteException)

Example 3 with TransferResource

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

the class Maven30TransferListenerAdapter method formatResourceName.

private static String formatResourceName(TransferEvent event) {
    TransferResource resource = event.getResource();
    File file = resource.getFile();
    return (file == null ? resource.getResourceName() : file.getName()) + " [" + resource.getRepositoryUrl() + "]";
}
Also used : TransferResource(org.sonatype.aether.transfer.TransferResource) File(java.io.File)

Example 4 with TransferResource

use of org.sonatype.aether.transfer.TransferResource in project zeppelin by apache.

the class TransferListener 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');
    logger.info(buffer.toString());
}
Also used : TransferResource(org.sonatype.aether.transfer.TransferResource) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 5 with TransferResource

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

the class ConsoleTransferListener method transferSucceeded.

@Override
public void transferSucceeded(TransferEvent event) {
    transferCompleted(event);
    TransferResource resource = event.getResource();
    long contentLength = event.getTransferredBytes();
    if (contentLength >= 0) {
        String type = (event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploaded" : "Downloaded");
        String len = contentLength >= 1024 ? toKB(contentLength) + " KB" : contentLength + " B";
        String throughput = "";
        long duration = System.currentTimeMillis() - resource.getTransferStartTime();
        if (duration > 0) {
            DecimalFormat format = new DecimalFormat("0.0", new DecimalFormatSymbols(Locale.ENGLISH));
            double kbPerSec = (contentLength / 1024.0) / (duration / 1000.0);
            throughput = " at " + format.format(kbPerSec) + " KB/sec";
        }
        out.println(type + ": " + resource.getRepositoryUrl() + resource.getResourceName() + " (" + len + throughput + ")");
    }
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) TransferResource(org.sonatype.aether.transfer.TransferResource) DecimalFormat(java.text.DecimalFormat)

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