use of com.biglybt.core.logging.LogEvent in project BiglyBT by BiglySoftware.
the class PeerInfoView method initialize.
private void initialize(Composite composite) {
if (peerInfoComposite != null && !peerInfoComposite.isDisposed()) {
Logger.log(new LogEvent(LogIDs.GUI, LogEvent.LT_ERROR, "PeerInfoView already initialized! Stack: " + Debug.getStackTrace(true, false)));
delete();
}
createPeerInfoPanel(composite);
}
use of com.biglybt.core.logging.LogEvent in project BiglyBT by BiglySoftware.
the class PeerInfoView method refreshInfoCanvas.
/**
* Constructs and image representing the download state of _all_
* the pieces in the torrent. Particularily slow when there's lots of pieces,
* and also wasteful since only a fraction of them ever get painted at
* any given time.
*
* TODO: Construct image for visible area only or something
*/
private void refreshInfoCanvas() {
refreshInfoCanvasQueued = false;
if (peerInfoComposite == null || peerInfoComposite.isDisposed() || !peerInfoComposite.isVisible()) {
return;
}
peerInfoCanvas.layout(true);
Rectangle bounds = peerInfoCanvas.getClientArea();
if (bounds.width <= 0 || bounds.height <= 0)
return;
if (img != null && !img.isDisposed()) {
img.dispose();
img = null;
}
if (peer == null || peer.getPeerState() != PEPeer.TRANSFERING) {
GC gc = new GC(peerInfoCanvas);
gc.fillRectangle(bounds);
gc.dispose();
return;
}
BitFlags peerHavePieces = peer.getAvailable();
if (peerHavePieces == null) {
GC gc = new GC(peerInfoCanvas);
gc.fillRectangle(bounds);
gc.dispose();
return;
}
DiskManagerPiece[] dm_pieces = null;
PEPeerManager pm = peer.getManager();
DiskManager dm = pm.getDiskManager();
dm_pieces = dm.getPieces();
int iNumCols = bounds.width / BLOCK_SIZE;
int iNeededHeight = (((dm.getNbPieces() - 1) / iNumCols) + 1) * BLOCK_SIZE;
if (sc.getMinHeight() != iNeededHeight) {
sc.setMinHeight(iNeededHeight);
sc.layout(true, true);
bounds = peerInfoCanvas.getClientArea();
}
img = new Image(peerInfoCanvas.getDisplay(), bounds.width, iNeededHeight);
GC gcImg = new GC(img);
try {
// use advanced capabilities for faster drawText
gcImg.setAdvanced(true);
gcImg.setBackground(peerInfoCanvas.getBackground());
gcImg.fillRectangle(0, 0, bounds.width, iNeededHeight);
int[] availability = pm.getAvailability();
int iNextDLPieceID = -1;
int iDLPieceID = -1;
int[] ourRequestedPieces = peer.getOutgoingRequestedPieceNumbers();
if (ourRequestedPieces != null) {
if (!peer.isChokingMe()) {
if (ourRequestedPieces.length > 0) {
iDLPieceID = ourRequestedPieces[0];
if (ourRequestedPieces.length > 1)
iNextDLPieceID = ourRequestedPieces[1];
}
} else {
if (ourRequestedPieces.length > 0)
iNextDLPieceID = ourRequestedPieces[0];
}
// if (iNextDLPieceID == -1) {
// iNextDLPieceID = peer.getNextPieceNumberGuess();
// }
}
int[] peerRequestedPieces = peer.getIncomingRequestedPieceNumbers();
if (peerRequestedPieces == null)
peerRequestedPieces = new int[0];
int peerNextRequestedPiece = -1;
if (peerRequestedPieces.length > 0)
peerNextRequestedPiece = peerRequestedPieces[0];
Arrays.sort(peerRequestedPieces);
int iRow = 0;
int iCol = 0;
for (int i = 0; i < peerHavePieces.flags.length; i++) {
int colorIndex;
boolean done = (dm_pieces == null) ? false : dm_pieces[i].isDone();
int iXPos = iCol * BLOCK_SIZE;
int iYPos = iRow * BLOCK_SIZE;
if (done) {
if (peerHavePieces.flags[i])
colorIndex = BLOCKCOLOR_AVAIL_HAVE;
else
colorIndex = BLOCKCOLOR_NOAVAIL_HAVE;
gcImg.setBackground(blockColors[colorIndex]);
gcImg.fillRectangle(iXPos, iYPos, BLOCK_FILLSIZE, BLOCK_FILLSIZE);
} else {
// !done
boolean partiallyDone = (dm_pieces == null) ? false : dm_pieces[i].getNbWritten() > 0;
int x = iXPos;
int width = BLOCK_FILLSIZE;
if (partiallyDone) {
if (peerHavePieces.flags[i])
colorIndex = BLOCKCOLOR_AVAIL_HAVE;
else
colorIndex = BLOCKCOLOR_NOAVAIL_HAVE;
gcImg.setBackground(blockColors[colorIndex]);
// partiallyDone false when dm_pieces null
@SuppressWarnings("null") int iNewWidth = (int) (((float) dm_pieces[i].getNbWritten() / dm_pieces[i].getNbBlocks()) * width);
if (iNewWidth >= width)
iNewWidth = width - 1;
else if (iNewWidth <= 0)
iNewWidth = 1;
gcImg.fillRectangle(x, iYPos, iNewWidth, BLOCK_FILLSIZE);
width -= iNewWidth;
x += iNewWidth;
}
if (peerHavePieces.flags[i])
colorIndex = BLOCKCOLOR_AVAIL_NOHAVE;
else
colorIndex = BLOCKCOLOR_NOAVAIL_NOHAVE;
gcImg.setBackground(blockColors[colorIndex]);
gcImg.fillRectangle(x, iYPos, width, BLOCK_FILLSIZE);
}
// Down Arrow inside box for "dowloading" piece
if (i == iDLPieceID) {
gcImg.setBackground(blockColors[BLOCKCOLOR_TRANSFER]);
gcImg.fillPolygon(new int[] { iXPos, iYPos, iXPos + BLOCK_FILLSIZE, iYPos, iXPos + (BLOCK_FILLSIZE / 2), iYPos + BLOCK_FILLSIZE });
}
// Small Down Arrow inside box for next download piece
if (i == iNextDLPieceID) {
gcImg.setBackground(blockColors[BLOCKCOLOR_NEXT]);
gcImg.fillPolygon(new int[] { iXPos + 2, iYPos + 2, iXPos + BLOCK_FILLSIZE - 1, iYPos + 2, iXPos + (BLOCK_FILLSIZE / 2), iYPos + BLOCK_FILLSIZE - 1 });
}
// Up Arrow in uploading piece
if (i == peerNextRequestedPiece) {
gcImg.setBackground(blockColors[BLOCKCOLOR_TRANSFER]);
gcImg.fillPolygon(new int[] { iXPos, iYPos + BLOCK_FILLSIZE, iXPos + BLOCK_FILLSIZE, iYPos + BLOCK_FILLSIZE, iXPos + (BLOCK_FILLSIZE / 2), iYPos });
} else if (Arrays.binarySearch(peerRequestedPieces, i) >= 0) {
// Small Up Arrow each upload request
gcImg.setBackground(blockColors[BLOCKCOLOR_NEXT]);
gcImg.fillPolygon(new int[] { iXPos + 1, iYPos + BLOCK_FILLSIZE - 2, iXPos + BLOCK_FILLSIZE - 2, iYPos + BLOCK_FILLSIZE - 2, iXPos + (BLOCK_FILLSIZE / 2), iYPos + 2 });
}
if (availability != null && availability[i] < 10) {
gcImg.setFont(font);
String sNumber = String.valueOf(availability[i]);
Point size = gcImg.stringExtent(sNumber);
int x = iXPos + (BLOCK_FILLSIZE / 2) - (size.x / 2);
int y = iYPos + (BLOCK_FILLSIZE / 2) - (size.y / 2);
gcImg.setForeground(blockColors[BLOCKCOLOR_AVAILCOUNT]);
gcImg.drawText(sNumber, x, y, true);
}
iCol++;
if (iCol >= iNumCols) {
iCol = 0;
iRow++;
}
}
} catch (Exception e) {
Logger.log(new LogEvent(LogIDs.GUI, "drawing piece map", e));
} finally {
gcImg.dispose();
}
peerInfoCanvas.redraw();
}
use of com.biglybt.core.logging.LogEvent in project BiglyBT by BiglySoftware.
the class TableCellSWTBase method invokeToolTipListeners.
@Override
public void invokeToolTipListeners(int type) {
if (tableColumn == null)
return;
tableColumn.invokeCellToolTipListeners(this, type);
if (tooltipListeners == null || tooltipErrLoopCount > 2)
return;
int iErrCount = tableColumn.getConsecutiveErrCount();
if (iErrCount > 10)
return;
try {
if (type == TOOLTIPLISTENER_HOVER) {
for (int i = 0; i < tooltipListeners.size(); i++) ((TableCellToolTipListener) (tooltipListeners.get(i))).cellHover(this);
} else {
for (int i = 0; i < tooltipListeners.size(); i++) ((TableCellToolTipListener) (tooltipListeners.get(i))).cellHoverComplete(this);
}
tooltipErrLoopCount = 0;
} catch (Throwable e) {
tooltipErrLoopCount++;
tableColumn.setConsecutiveErrCount(++iErrCount);
pluginError(e);
if (tooltipErrLoopCount > 2)
Logger.log(new LogEvent(LOGID, LogEvent.LT_ERROR, "TableCell's tooltip will not be refreshed anymore this session."));
}
}
use of com.biglybt.core.logging.LogEvent in project BiglyBT by BiglySoftware.
the class DownloadManagerController method activateRequest.
@Override
public boolean activateRequest(InetSocketAddress address) {
if (getState() == DownloadManager.STATE_QUEUED) {
BloomFilter bloom = activation_bloom;
if (bloom == null) {
activation_bloom = bloom = BloomFilterFactory.createAddRemove4Bit(BLOOM_SIZE);
}
byte[] address_bytes = AddressUtils.getAddressBytes(address);
int hit_count = bloom.add(address_bytes);
if (hit_count > 5) {
Logger.log(new LogEvent(this, LogIDs.CORE, LogEvent.LT_WARNING, "Activate request for " + getDisplayName() + " from " + address + " denied as too many recently received"));
return (false);
}
Logger.log(new LogEvent(this, LogIDs.CORE, "Activate request for " + getDisplayName() + " from " + address));
long now = SystemTime.getCurrentTime();
if (now < activation_bloom_create_time || now - activation_bloom_create_time > ACTIVATION_REBUILD_TIME) {
activation_bloom = BloomFilterFactory.createAddRemove4Bit(BLOOM_SIZE);
activation_bloom_create_time = now;
}
activation_count = bloom.getEntryCount();
activation_count_time = now;
return (download_manager.activateRequest(activation_count));
}
return (false);
}
use of com.biglybt.core.logging.LogEvent in project BiglyBT by BiglySoftware.
the class DownloadManagerMoveHandlerUtils method logError.
static void logError(String message, DownloadManager dm, Throwable e) {
LogRelation lr = (dm instanceof LogRelation) ? (LogRelation) dm : null;
if (lr == null) {
return;
}
if (!Logger.isEnabled()) {
return;
}
Logger.log(new LogEvent(lr, LogIDs.CORE, message, e));
}
Aggregations