/** Destroy the aggregator, along with any pending messages. */ public void destroy() { try { pending_haves_mon.enter(); pending_haves.clear(); destroyed = true; } finally { pending_haves_mon.exit(); } }
private void sendPendingHaves() { if (destroyed) { return; } try { pending_haves_mon.enter(); int num_haves = pending_haves.size(); if (num_haves == 0) { return; } // single have -> use BT if (num_haves == 1 || az_have_version < BTMessageFactory.MESSAGE_VERSION_SUPPORTS_PADDING) { for (int i = 0; i < num_haves; i++) { Integer piece_num = (Integer) pending_haves.get(i); outgoing_message_q.addMessage(new BTHave(piece_num.intValue(), bt_have_version), true); } } else { int[] piece_numbers = new int[num_haves]; for (int i = 0; i < num_haves; i++) { piece_numbers[i] = ((Integer) pending_haves.get(i)).intValue(); } outgoing_message_q.addMessage(new AZHave(piece_numbers, az_have_version), true); } outgoing_message_q.doListenerNotifications(); pending_haves.clear(); } finally { pending_haves_mon.exit(); } }