/** * 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 peerHasPiece(PEPeer peer) { try { class_mon.enter(); // System.out.println("piece: #"+pieceNumber+" , old level:"+level+", // timeFirstDistributed:"+timeFirstDistributed+ "/ // timetoreachanotherpeer:"+timeToReachAnotherPeer); if (level < 2) { // first time that somebody tells us this piece exists elsewhere // if peer=null, it is due to bitfield scan, so firstreceiver gets NULL firstReceiver = peer; timeFirstDistributed = SystemTime.getCurrentTime(); // numberOfPeersWhenFirstReceived = manager.getNbPeers(); level = 2; } else { // level=2 or 3 and we arrive here when somebody has got the piece, either BT_HAVE or // bitfield scan // if we are here due to bitfield scan, 'peer' = null --> do nothing // if level=2 --> mark piece redistributed, set speedstatus of firstreceiver, bump level to // 3 // if level=3 --> this piece has been already seen at 3rd party earlier, do nothing if (peer != null && firstReceiver != null && level == 2) { timeToReachAnotherPeer = (int) (SystemTime.getCurrentTime() - timeFirstDistributed); firstReceiver.setUploadHint(timeToReachAnotherPeer); level = 3; } } } finally { class_mon.exit(); } }
public static void registerDecoders(Map _decoders) { try { class_mon.enter(); Map new_decoders = new HashMap(packet_decoders); Iterator it = _decoders.keySet().iterator(); while (it.hasNext()) { Integer action = (Integer) it.next(); if (packet_decoders.containsKey(action)) { Debug.out("Duplicate codec! " + action); } } new_decoders.putAll(_decoders); packet_decoders = new_decoders; } finally { class_mon.exit(); } }
public void messageSent(Message message) { if (message.getID().equals(BTMessage.ID_BT_PIECE)) { try { lock_mon.enter(); // due to timing issues we can get in here with a message already removed queued_messages.remove(message); } finally { lock_mon.exit(); } /* if ( peer.getIp().equals( "64.71.5.2" )){ outgoing_message_queue.setTrace( true ); // BTPiece p = (BTPiece)message; // TimeFormatter.milliTrace( "obt sent: " + p.getPieceNumber() + "/" + p.getPieceOffset()); } */ doReadAheadLoads(); } }
public UPnPPluginService[] getServices(UPnPDevice device) { String target_usn = device.getRootDevice().getUSN(); List<UPnPPluginService> res = new ArrayList<UPnPPluginService>(); try { this_mon.enter(); for (UPnPPluginService service : services) { String this_usn = service.getService().getGenericService().getDevice().getRootDevice().getUSN(); if (this_usn.equals(target_usn)) { res.add(service); } } } finally { this_mon.exit(); } return (res.toArray(new UPnPPluginService[res.size()])); }
public void unregister(PeerControlInstance instance) { try { this_mon.enter(); Map<PeerControlInstance, instanceWrapper> new_map = new HashMap<PeerControlInstance, instanceWrapper>(instance_map); instanceWrapper wrapper = new_map.remove(instance); if (wrapper == null) { Debug.out("instance wrapper not found"); return; } wrapper.unregister(); instance_map = new_map; registrations_changed = true; } finally { this_mon.exit(); } }
public String[] getExternalIPAddresses() { List res = new ArrayList(); try { this_mon.enter(); for (int j = 0; j < services.size(); j++) { UPnPPluginService service = (UPnPPluginService) services.get(j); try { String address = service.getService().getExternalIPAddress(); if (address != null) { res.add(address); } } catch (Throwable e) { Debug.printStackTrace(e); } } } finally { this_mon.exit(); } return ((String[]) res.toArray(new String[res.size()])); }
protected boolean checkConnectionId(String client_address, long id) { try { random_mon.enter(); Long key = new Long(id); connectionData data = (connectionData) connection_id_map.get(key); if (data == null) { // System.out.println( "TRTrackerServerProcessorUDP: rejected:" + id + ", data not found" ); return (false); } else { if (SystemTime.getMonotonousTime() - data.getTime() > CONNECTION_ID_LIFETIME) { return (false); } } boolean ok = data.getAddress().equals(client_address); // System.out.println( "TRTrackerServerProcessorUDP: tested:" + id + "/" + client_address + " // -> " + ok ); return (ok); } finally { random_mon.exit(); } }
/** * Add the given entity to the controller for read processing. * * @param entity to process reads for */ public void addReadEntity(RateControlledEntity entity) { try { entities_mon.enter(); if (entity.getPriority() == RateControlledEntity.PRIORITY_HIGH) { // copy-on-write ArrayList<RateControlledEntity> high_new = new ArrayList<RateControlledEntity>(high_priority_entities.size() + 1); high_new.addAll(high_priority_entities); high_new.add(entity); high_priority_entities = high_new; } else { // copy-on-write ArrayList<RateControlledEntity> norm_new = new ArrayList<RateControlledEntity>(normal_priority_entities.size() + 1); norm_new.addAll(normal_priority_entities); norm_new.add(entity); normal_priority_entities = norm_new; } entity_count = normal_priority_entities.size() + high_priority_entities.size(); } finally { entities_mon.exit(); } read_waiter.eventOccurred(); }
public void setStorageType(int new_type) throws FMFileManagerException { try { this_mon.enter(); boolean was_open = isOpen(); if (was_open) { closeSupport(false); } try { file_access.setStorageType(new_type); } finally { if (was_open) { openSupport("Re-open after storage type change"); } } } finally { this_mon.exit(); } }
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 ( peer.getIp().equals( "64.71.5.2")){ TimeFormatter.milliTrace( "obt read_ahead: -> " + (to_submit==null?0:to_submit.size()) + " [lo=" + loading_messages.size() + ",qm=" + queued_messages.size() + ",re=" + requests.size() + ",rl=" + request_read_ahead + "]"); } */ 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); } } }
public static Test getSingleton() { try { class_mon.enter(); if (singleton == null) { new AEThread("plugin initialiser") { public void runSupport() { PluginManager.registerPlugin(Test.class); Properties props = new Properties(); props.put(PluginManager.PR_MULTI_INSTANCE, "true"); PluginManager.startAzureus(PluginManager.UI_SWT, props); } }.start(); init_sem.reserve(); } return (singleton); } finally { class_mon.exit(); } }
/** 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(); } }
public void pieceRevealedToPeer() { try { class_mon.enter(); level = 1; } finally { class_mon.exit(); } }
public void removeListener(TableStructureModificationListener listener) { try { listeners_mon.enter(); listeners.remove(listener); } finally { listeners_mon.exit(); } }
public static void removeListener(TRTrackerServerFactoryListener l) { try { class_mon.enter(); listeners.remove(l); } finally { class_mon.exit(); } }
public UPnPPluginService[] getServices() { try { this_mon.enter(); return ((UPnPPluginService[]) services.toArray(new UPnPPluginService[services.size()])); } finally { this_mon.exit(); } }
public PasswordAuthentication getAuthentication(String realm, URL tracker) { try { this_mon.enter(); return (getAuthentication( realm, tracker.getProtocol(), tracker.getHost(), tracker.getPort())); } finally { this_mon.exit(); } }
public void setAuthenticationOutcome(String realm, URL tracker, boolean success) { try { this_mon.enter(); setAuthenticationOutcome( realm, tracker.getProtocol(), tracker.getHost(), tracker.getPort(), success); } finally { this_mon.exit(); } }
protected static void generateEvidence(IndentWriter writer) { writer.println(file_map.size() + " FMFile Reservations"); try { writer.indent(); try { file_map_mon.enter(); Iterator it = file_map.keySet().iterator(); while (it.hasNext()) { String key = (String) it.next(); List owners = (List) file_map.get(key); Iterator it2 = owners.iterator(); String str = ""; while (it2.hasNext()) { Object[] entry = (Object[]) it2.next(); FMFileOwner owner = (FMFileOwner) entry[0]; Boolean write = (Boolean) entry[1]; String reason = (String) entry[2]; str += (str.length() == 0 ? "" : ", ") + owner.getName() + "[" + (write.booleanValue() ? "write" : "read") + "/" + reason + "]"; } writer.println(Debug.secretFileName(key) + " -> " + str); } } finally { file_map_mon.exit(); } FMFileManagerImpl.generateEvidence(writer); } finally { writer.exdent(); } }
public void addListener(TableStructureModificationListener listener) { try { listeners_mon.enter(); if (!listeners.contains(listener)) { listeners.add(listener); } } finally { listeners_mon.exit(); } }
public void clearPasswords() { try { this_mon.enter(); auth_cache = new HashMap(); saveAuthCache(); } finally { this_mon.exit(); } }
private void error(int errCode, String err) { try { this_mon.enter(); // what's the point of this? this.state = STATE_ERROR; this.setError(errCode, err); this.cleanUpFile(); this.notifyListener(); } finally { this_mon.exit(); } }
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(); } }
private void reserveFile() throws FMFileManagerException { if (clone) { return; } try { file_map_mon.enter(); // System.out.println( "FMFile::reserveFile:" + canonical_path + "("+ owner.getName() + ")" + // " - " + Debug.getCompressedStackTrace() ); List owners = (List) file_map.get(canonical_path); if (owners == null) { owners = new ArrayList(); // System.out.println( " creating new owners entr" ); file_map.put(canonical_path, owners); } for (Iterator it = owners.iterator(); it.hasNext(); ) { Object[] entry = (Object[]) it.next(); String entry_name = ((FMFileOwner) entry[0]).getName(); // System.out.println( " existing entry: " + entry_name ); if (owner.getName().equals(entry_name)) { // already present, start off read-access Debug.out("reserve file - entry already present"); entry[1] = new Boolean(false); return; } } owners.add(new Object[] {owner, new Boolean(false), "<reservation>"}); } finally { file_map_mon.exit(); } }
public static TableStructureEventDispatcher getInstance(String tableID) { try { class_mon.enter(); TableStructureEventDispatcher instance = instances.get(tableID); if (instance == null) { instance = new TableStructureEventDispatcher(); instances.put(tableID, instance); } return instance; } finally { class_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); } }
void addListener(Object o) { boolean register_with_downloads = false; try { this_mon.enter(); register_with_downloads = listeners.isEmpty(); ArrayList new_listeners = new ArrayList(listeners); new_listeners.add(o); this.listeners = new_listeners; } finally { this_mon.exit(); } if (register_with_downloads) { dm.addListener(this, true); } }
public static ConfigurationManager getInstance(Map data) { try { class_mon.enter(); if (config == null) { config = new ConfigurationManager(data); } return config; } finally { class_mon.exit(); } }
public void destroy() { try { lock_mon.enter(); removeAllPieceRequests(); queued_messages.clear(); destroyed = true; outgoing_message_queue.cancelQueueListener(sent_message_listener); } finally { lock_mon.exit(); } }