use of com.biglybt.core.disk.DiskManagerReadRequest in project BiglyBT by BiglySoftware.
the class PEPeerTransportProtocol method resetRequestsTime.
private void resetRequestsTime(final long now) {
try {
requested_mon.enter();
final int requestedSize = requested.size();
for (int i = 0; i < requestedSize; i++) {
final DiskManagerReadRequest request = (DiskManagerReadRequest) requested.get(i);
if (request != null)
request.resetTime(now);
}
} finally {
requested_mon.exit();
}
}
use of com.biglybt.core.disk.DiskManagerReadRequest in project BiglyBT by BiglySoftware.
the class OutgoingBTPieceMessageHandler method doReadAheadLoads.
private void doReadAheadLoads() {
List to_submit = null;
try {
lock_mon.enter();
while (loading_messages.size() + queued_messages.size() < request_read_ahead && !requests.isEmpty() && !destroyed) {
DiskManagerReadRequest dmr = (DiskManagerReadRequest) requests.removeFirst();
loading_messages.add(dmr);
if (to_submit == null)
to_submit = new ArrayList();
to_submit.add(dmr);
}
} finally {
lock_mon.exit();
}
if (to_submit != null) {
for (int i = 0; i < to_submit.size(); i++) {
peer.getManager().getAdapter().enqueueReadRequest(peer, (DiskManagerReadRequest) to_submit.get(i), read_req_listener);
}
}
}
use of com.biglybt.core.disk.DiskManagerReadRequest in project BiglyBT by BiglySoftware.
the class OutgoingBTPieceMessageHandler method getRequestedPieceNumbers.
/**
* Get a list of piece numbers being requested
*
* @return list of Long values
*/
public int[] getRequestedPieceNumbers() {
if (destroyed)
return new int[0];
/**
* Cheap hack to reduce (but not remove all) the # of duplicate entries
*/
int iLastNumber = -1;
int pos = 0;
int[] pieceNumbers;
try {
lock_mon.enter();
// allocate max size needed (we'll shrink it later)
pieceNumbers = new int[queued_messages.size() + loading_messages.size() + requests.size()];
for (Iterator iter = queued_messages.keySet().iterator(); iter.hasNext(); ) {
BTPiece msg = (BTPiece) iter.next();
if (iLastNumber != msg.getPieceNumber()) {
iLastNumber = msg.getPieceNumber();
pieceNumbers[pos++] = iLastNumber;
}
}
for (Iterator iter = loading_messages.iterator(); iter.hasNext(); ) {
DiskManagerReadRequest dmr = (DiskManagerReadRequest) iter.next();
if (iLastNumber != dmr.getPieceNumber()) {
iLastNumber = dmr.getPieceNumber();
pieceNumbers[pos++] = iLastNumber;
}
}
for (Iterator iter = requests.iterator(); iter.hasNext(); ) {
DiskManagerReadRequest dmr = (DiskManagerReadRequest) iter.next();
if (iLastNumber != dmr.getPieceNumber()) {
iLastNumber = dmr.getPieceNumber();
pieceNumbers[pos++] = iLastNumber;
}
}
} finally {
lock_mon.exit();
}
int[] trimmed = new int[pos];
System.arraycopy(pieceNumbers, 0, trimmed, 0, pos);
return trimmed;
}
use of com.biglybt.core.disk.DiskManagerReadRequest in project BiglyBT by BiglySoftware.
the class OutgoingBTPieceMessageHandler method addPieceRequest.
/**
* Register a new piece data request.
* @param piece_number
* @param piece_offset
* @param length
*/
public boolean addPieceRequest(int piece_number, int piece_offset, int length) {
if (destroyed)
return (false);
DiskManagerReadRequest dmr = peer.getManager().getDiskManager().createReadRequest(piece_number, piece_offset, length);
try {
lock_mon.enter();
requests.addLast(dmr);
} finally {
lock_mon.exit();
}
doReadAheadLoads();
return (true);
}
use of com.biglybt.core.disk.DiskManagerReadRequest in project BiglyBT by BiglySoftware.
the class OutgoingBTPieceMessageHandler method removePieceRequest.
/**
* Remove an outstanding piece data request.
* @param piece_number
* @param piece_offset
* @param length
*/
public void removePieceRequest(int piece_number, int piece_offset, int length) {
if (destroyed)
return;
DiskManagerReadRequest dmr = peer.getManager().getDiskManager().createReadRequest(piece_number, piece_offset, length);
boolean inform_rejected = false;
try {
lock_mon.enter();
if (requests.contains(dmr)) {
requests.remove(dmr);
inform_rejected = true;
return;
}
if (loading_messages.contains(dmr)) {
loading_messages.remove(dmr);
inform_rejected = true;
return;
}
for (Iterator i = queued_messages.entrySet().iterator(); i.hasNext(); ) {
Map.Entry entry = (Map.Entry) i.next();
if (entry.getValue().equals(dmr)) {
// it's already been queued
BTPiece msg = (BTPiece) entry.getKey();
if (outgoing_message_queue.removeMessage(msg, true)) {
inform_rejected = true;
i.remove();
}
// do manual listener notify
break;
}
}
} finally {
lock_mon.exit();
if (inform_rejected) {
peer.sendRejectRequest(dmr);
}
}
outgoing_message_queue.doListenerNotifications();
}
Aggregations