Search in sources :

Example 11 with PEPiece

use of com.biglybt.core.peer.PEPiece in project BiglyBT by BiglySoftware.

the class CompletedItem method refresh.

@Override
public void refresh(TableCell cell) {
    PEPiece piece = (PEPiece) cell.getDataSource();
    long value = (piece == null) ? 0 : piece.getNbWritten();
    if (!cell.setSortValue(value) && cell.isValid()) {
        return;
    }
    cell.setText("" + value);
}
Also used : PEPiece(com.biglybt.core.peer.PEPiece)

Example 12 with PEPiece

use of com.biglybt.core.peer.PEPiece in project BiglyBT by BiglySoftware.

the class DiskManagerRandomReadController method clearHint.

private void clearHint(PEPeerManager pm, int hint_piece) {
    PEPiece piece = pm.getPiece(hint_piece);
    if (piece != null && piece.getReservedBy() != null) {
        piece.setReservedBy(null);
    // System.out.println( "clearing res by for " + hint_piece );
    }
    List<PEPeer> peers = pm.getPeers();
    for (PEPeer peer : peers) {
        int[] res = peer.getReservedPieceNumbers();
        if (res != null) {
            for (int i : res) {
                if (i == hint_piece) {
                    peer.removeReservedPieceNumber(hint_piece);
                // System.out.println( "removing res by on " + peer.getIp() + " for " + hint_piece );
                }
            }
        }
    }
}
Also used : PEPiece(com.biglybt.core.peer.PEPiece) PEPeer(com.biglybt.core.peer.PEPeer)

Example 13 with PEPiece

use of com.biglybt.core.peer.PEPiece in project BiglyBT by BiglySoftware.

the class PieceDistributionView method updateDistribution.

private final void updateDistribution() {
    if (!initialized || pem == null || comp == null || pem.getPiecePicker() == null || pem.getDiskManager() == null || !comp.isVisible())
        return;
    Rectangle rect = pieceDistCanvas.getBounds();
    if (rect.height <= 0 || rect.width <= 0)
        return;
    PiecePicker picker = pem.getPiecePicker();
    final int seeds = pem.getNbSeeds() + (pem.isSeeding() ? 1 : 0);
    final int connected = pem.getNbPeers() + seeds + (pem.isSeeding() ? 0 : 1);
    final int upperBound = 1 + (1 << (int) Math.ceil(Math.log(connected + 0.0) / Math.log(2.0)));
    // System.out.println("conn:"+connected+" bound:"+upperBound);
    final int minAvail = (int) picker.getMinAvailability();
    // final int maxAvail = picker.getMaxAvailability();
    final int nbPieces = picker.getNumberOfPieces();
    final int[] availabilties = picker.getAvailability();
    final DiskManagerPiece[] dmPieces = pem.getDiskManager().getPieces();
    final PEPiece[] pePieces = pem.getPieces();
    final int[] globalPiecesPerAvailability = new int[upperBound];
    final int[] datasourcePiecesPerAvailability = new int[upperBound];
    // me-only stuff
    final boolean[] downloading = new boolean[upperBound];
    int avlPeak = 0;
    for (int i = 0; i < nbPieces; i++) {
        if (availabilties[i] >= upperBound)
            // availability and peer lists are OOS, just wait for the next round
            return;
        final int newPeak;
        if (avlPeak < (newPeak = ++globalPiecesPerAvailability[availabilties[i]])) {
            avlPeak = newPeak;
        // avlPeakIdx = availabilties[i];
        }
        if ((isMe && dmPieces[i].isDone()) || (!isMe && hasPieces != null && hasPieces[i]))
            ++datasourcePiecesPerAvailability[availabilties[i]];
        if (isMe && pePieces[i] != null)
            downloading[availabilties[i]] = true;
    }
    Image img = new Image(comp.getDisplay(), pieceDistCanvas.getBounds());
    GC gc = new GC(img);
    try {
        int stepWidthX = rect.width / upperBound;
        int barGap = 1;
        int barWidth = stepWidthX - barGap - 1;
        int barFillingWidth = barWidth - 1;
        double stepWidthY = 1.0 * (rect.height - 1) / avlPeak;
        int offsetY = rect.height;
        gc.setForeground(Colors.green);
        for (int i = 0; i <= connected; i++) {
            Color curColor;
            if (i == 0)
                curColor = Colors.colorError;
            else if (i <= seeds)
                curColor = Colors.green;
            else
                curColor = Colors.blues[Colors.BLUES_DARKEST];
            gc.setBackground(curColor);
            gc.setForeground(curColor);
            if (globalPiecesPerAvailability[i] == 0) {
                gc.setLineWidth(2);
                gc.drawLine(stepWidthX * i, offsetY - 1, stepWidthX * (i + 1) - barGap, offsetY - 1);
            } else {
                gc.setLineWidth(1);
                if (downloading[i])
                    gc.setLineStyle(SWT.LINE_DASH);
                gc.fillRectangle(stepWidthX * i + 1, offsetY - 1, barFillingWidth, (int) (Math.ceil(stepWidthY * datasourcePiecesPerAvailability[i] - 1) * -1));
                gc.drawRectangle(stepWidthX * i, offsetY, barWidth, (int) (Math.ceil(stepWidthY * globalPiecesPerAvailability[i]) + 1) * -1);
            }
            if (i == minAvail) {
                gc.setForeground(Colors.blue);
                gc.drawRectangle(stepWidthX * i + 1, offsetY - 1, barWidth - 2, (int) (Math.ceil(stepWidthY * globalPiecesPerAvailability[i] - 1)) * -1);
            }
            gc.setLineStyle(SWT.LINE_SOLID);
        }
        gc.setLineWidth(1);
        String[] boxContent = new String[] { MessageText.getString("PiecesView.DistributionView.NoAvl"), MessageText.getString("PiecesView.DistributionView.SeedAvl"), MessageText.getString("PiecesView.DistributionView.PeerAvl"), MessageText.getString("PiecesView.DistributionView.RarestAvl", new String[] { globalPiecesPerAvailability[minAvail] + "", minAvail + "" }), MessageText.getString("PiecesView.DistributionView." + (isMe ? "weHave" : "theyHave")), MessageText.getString("PiecesView.DistributionView.weDownload") };
        int charWidth = gc.getFontMetrics().getAverageCharWidth();
        int charHeight = gc.getFontMetrics().getHeight();
        int maxBoxOffsetY = charHeight + 2;
        int maxBoxWidth = 0;
        int maxBoxOffsetX = 0;
        for (int i = 0; i < boxContent.length; i++) maxBoxWidth = Math.max(maxBoxWidth, boxContent[i].length());
        maxBoxOffsetX = (maxBoxWidth + 5) * charWidth;
        maxBoxWidth = ++maxBoxWidth * charWidth;
        int boxNum = 1;
        gc.setForeground(Colors.colorError);
        gc.setBackground(Colors.background);
        gc.drawRectangle(rect.width + (maxBoxOffsetX) * -1, maxBoxOffsetY * boxNum, maxBoxWidth, charHeight);
        gc.drawString(boxContent[boxNum - 1], rect.width + (maxBoxOffsetX - 5) * -1, maxBoxOffsetY * boxNum, true);
        boxNum++;
        gc.setForeground(Colors.green);
        gc.setBackground(Colors.background);
        gc.drawRectangle(rect.width + (maxBoxOffsetX) * -1, maxBoxOffsetY * boxNum, maxBoxWidth, charHeight);
        gc.drawString(boxContent[boxNum - 1], rect.width + (maxBoxOffsetX - 5) * -1, maxBoxOffsetY * boxNum, true);
        boxNum++;
        gc.setForeground(Colors.blues[Colors.BLUES_DARKEST]);
        gc.drawRectangle(rect.width + (maxBoxOffsetX) * -1, maxBoxOffsetY * boxNum, maxBoxWidth, charHeight);
        gc.drawString(boxContent[boxNum - 1], rect.width + (maxBoxOffsetX - 5) * -1, maxBoxOffsetY * boxNum, true);
        boxNum++;
        gc.setForeground(Colors.blue);
        gc.drawRectangle(rect.width + (maxBoxOffsetX) * -1, maxBoxOffsetY * boxNum, maxBoxWidth, charHeight);
        gc.drawString(boxContent[boxNum - 1], rect.width + (maxBoxOffsetX - 5) * -1, maxBoxOffsetY * boxNum, true);
        boxNum++;
        gc.setForeground(Colors.black);
        gc.setBackground(Colors.black);
        gc.drawRectangle(rect.width + (maxBoxOffsetX) * -1, maxBoxOffsetY * boxNum, maxBoxWidth, charHeight);
        gc.fillRectangle(rect.width + (maxBoxOffsetX) * -1, maxBoxOffsetY * boxNum, maxBoxWidth / 2, charHeight);
        gc.setForeground(Colors.grey);
        gc.setBackground(Colors.background);
        gc.drawString(boxContent[boxNum - 1], rect.width + (maxBoxOffsetX - 5) * -1, maxBoxOffsetY * boxNum, true);
        if (isMe) {
            boxNum++;
            gc.setForeground(Colors.black);
            gc.setLineStyle(SWT.LINE_DASH);
            gc.drawRectangle(rect.width + (maxBoxOffsetX) * -1, maxBoxOffsetY * boxNum, maxBoxWidth, charHeight);
            gc.drawString(boxContent[boxNum - 1], rect.width + (maxBoxOffsetX - 5) * -1, maxBoxOffsetY * boxNum, true);
        }
        gc.setLineStyle(SWT.LINE_SOLID);
    } finally {
        gc.dispose();
    }
    if (imgToPaint != null) {
        imgToPaint.dispose();
    }
    imgToPaint = img;
    pieceDistCanvas.redraw();
}
Also used : PiecePicker(com.biglybt.core.peermanager.piecepicker.PiecePicker) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) Image(org.eclipse.swt.graphics.Image) PEPiece(com.biglybt.core.peer.PEPiece) DiskManagerPiece(com.biglybt.core.disk.DiskManagerPiece) GC(org.eclipse.swt.graphics.GC)

Example 14 with PEPiece

use of com.biglybt.core.peer.PEPiece in project BiglyBT by BiglySoftware.

the class PieceGraphView method initialize.

// @see com.biglybt.ui.swt.views.AbstractIView#initialize(org.eclipse.swt.widgets.Composite)
private void initialize(Composite parent) {
    blockColors = new Color[] { properties.getColor("color.pieceview.alldone"), properties.getColor("color.pieceview.notdone"), properties.getColor("color.pieceview.uploading"), properties.getColor("color.pieceview.downloading"), properties.getColor("color.pieceview.noavail"), properties.getColor("color.pieceview.havesome") };
    compFindPEPiece = new Comparator() {

        @Override
        public int compare(Object arg0, Object arg1) {
            int arg0no = (arg0 instanceof PEPiece) ? ((PEPiece) arg0).getPieceNumber() : ((Long) arg0).intValue();
            int arg1no = (arg1 instanceof PEPiece) ? ((PEPiece) arg1).getPieceNumber() : ((Long) arg1).intValue();
            return arg0no - arg1no;
        }
    };
    canvas = new Canvas(parent, SWT.NO_BACKGROUND);
    canvas.setLayout(new FillLayout());
    canvas.addPaintListener(new PaintListener() {

        @Override
        public void paintControl(PaintEvent e) {
            if (img != null && !img.isDisposed()) {
                Rectangle bounds = img.getBounds();
                if (bounds.width >= e.width && bounds.height >= e.height) {
                    e.gc.drawImage(img, e.x, e.y, e.width, e.height, e.x, e.y, e.width, e.height);
                }
            } else {
                e.gc.fillRectangle(e.x, e.y, e.width, e.height);
            }
        }
    });
    canvas.addListener(SWT.Resize, new Listener() {

        @Override
        public void handleEvent(Event event) {
            calcBlockSize();
        }
    });
}
Also used : PEPiece(com.biglybt.core.peer.PEPiece) PaintEvent(org.eclipse.swt.events.PaintEvent) UISWTViewCoreEventListener(com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListener) PaintListener(org.eclipse.swt.events.PaintListener) PaintListener(org.eclipse.swt.events.PaintListener) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) PaintEvent(org.eclipse.swt.events.PaintEvent) FillLayout(org.eclipse.swt.layout.FillLayout)

Example 15 with PEPiece

use of com.biglybt.core.peer.PEPiece in project BiglyBT by BiglySoftware.

the class PiecesView method fillMenu.

@Override
public void fillMenu(String sColumnName, Menu menu) {
    final List<Object> selected = tv.getSelectedDataSources();
    if (selected.size() == 0) {
        return;
    }
    if (manager == null) {
        return;
    }
    PEPeerManager pm = manager.getPeerManager();
    if (pm == null) {
        return;
    }
    final PiecePicker picker = pm.getPiecePicker();
    boolean has_undone = false;
    boolean has_unforced = false;
    for (Object obj : selected) {
        PEPiece piece = (PEPiece) obj;
        if (!piece.getDMPiece().isDone()) {
            has_undone = true;
            if (picker.isForcePiece(piece.getPieceNumber())) {
                has_unforced = true;
            }
        }
    }
    final MenuItem force_piece = new MenuItem(menu, SWT.CHECK);
    Messages.setLanguageText(force_piece, "label.force.piece");
    force_piece.setEnabled(has_undone);
    if (has_undone) {
        force_piece.setSelection(has_unforced);
        force_piece.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                boolean forced = force_piece.getSelection();
                for (Object obj : selected) {
                    PEPiece piece = (PEPiece) obj;
                    if (!piece.getDMPiece().isDone()) {
                        picker.setForcePiece(piece.getPieceNumber(), forced);
                    }
                }
            }
        });
    }
    final MenuItem cancel_reqs_piece = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(cancel_reqs_piece, "label.rerequest.blocks");
    cancel_reqs_piece.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            for (Object obj : selected) {
                PEPiece piece = (PEPiece) obj;
                for (int i = 0; i < piece.getNbBlocks(); i++) {
                    if (piece.isRequested(i)) {
                        piece.clearRequested(i);
                    }
                }
            }
        }
    });
    final MenuItem reset_piece = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(reset_piece, "label.reset.piece");
    reset_piece.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            for (Object obj : selected) {
                PEPiece piece = (PEPiece) obj;
                piece.reset();
            }
        }
    });
    new MenuItem(menu, SWT.SEPARATOR);
}
Also used : PEPiece(com.biglybt.core.peer.PEPiece) PiecePicker(com.biglybt.core.peermanager.piecepicker.PiecePicker) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PEPeerManager(com.biglybt.core.peer.PEPeerManager) MenuItem(org.eclipse.swt.widgets.MenuItem)

Aggregations

PEPiece (com.biglybt.core.peer.PEPiece)26 DiskManagerPiece (com.biglybt.core.disk.DiskManagerPiece)8 PEPeerManager (com.biglybt.core.peer.PEPeerManager)8 PiecePicker (com.biglybt.core.peermanager.piecepicker.PiecePicker)7 DiskManager (com.biglybt.core.disk.DiskManager)6 DownloadManager (com.biglybt.core.download.DownloadManager)4 LogEvent (com.biglybt.core.logging.LogEvent)4 PEPeer (com.biglybt.core.peer.PEPeer)4 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)3 DMPieceList (com.biglybt.core.disk.impl.piecemapper.DMPieceList)3 DMPieceMapEntry (com.biglybt.core.disk.impl.piecemapper.DMPieceMapEntry)3 AERunnable (com.biglybt.core.util.AERunnable)3 UISWTViewEvent (com.biglybt.ui.swt.pif.UISWTViewEvent)3 MenuBuildUtils (com.biglybt.ui.swt.MenuBuildUtils)2 UISWTViewCoreEventListener (com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListener)2 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)2 Color (org.eclipse.swt.graphics.Color)2 GC (org.eclipse.swt.graphics.GC)2 Image (org.eclipse.swt.graphics.Image)2 GridData (org.eclipse.swt.layout.GridData)2