/** * 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); try { lock_mon.enter(); if (requests.contains(dmr)) { requests.remove(dmr); return; } if (loading_messages.contains(dmr)) { loading_messages.remove(dmr); 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)) { i.remove(); } break; // do manual listener notify } } } finally { lock_mon.exit(); } outgoing_message_queue.doListenerNotifications(); }
public void readFailed(DiskManagerReadRequest request, Throwable cause) { try { lock_mon.enter(); if (!loading_messages.contains(request) || destroyed) { // was canceled return; } loading_messages.remove(request); } finally { lock_mon.exit(); } }
void removeListener(Object o) { boolean unregister_from_downloads = false; try { this_mon.enter(); ArrayList new_listeners = new ArrayList(listeners); new_listeners.remove(o); this.listeners = new_listeners; unregister_from_downloads = this.listeners.isEmpty(); } finally { this_mon.exit(); } if (unregister_from_downloads) { dm.removeListener(this, true); } }
public void readCompleted(DiskManagerReadRequest request, DirectByteBuffer data) { try { lock_mon.enter(); if (!loading_messages.contains(request) || destroyed) { // was canceled data.returnToPool(); return; } loading_messages.remove(request); BTPiece msg = new BTPiece(request.getPieceNumber(), request.getOffset(), data, piece_version); queued_messages.put(msg, request); outgoing_message_queue.addMessage(msg, true); } finally { lock_mon.exit(); } outgoing_message_queue.doListenerNotifications(); }
public static void removeListener(MetaDataUpdateListener l) { metaDataListeners.remove(l); }