public static void addDefaultExtensionHandler( long id, byte[] message_id ) { default_entension_handlers.put( (byte)id, message_id ); }
public void removeExtensionHandler( byte id ) { extension_handlers.remove( id ); } }
protected Set<UISWTView> getViews() { return( subviews.keySet()); }
public static void addGlobalListener( DownloadManagerStateAttributeListener l, String attribute, int event_type) { CopyOnWriteMap<String,CopyOnWriteList<DownloadManagerStateAttributeListener>> map_to_use = (event_type == DownloadManagerStateAttributeListener.WILL_BE_READ) ? global_listeners_read_map_cow : global_listeners_write_map_cow; CopyOnWriteList<DownloadManagerStateAttributeListener> lst = map_to_use.get(attribute); if (lst == null) { lst = new CopyOnWriteList<>(); map_to_use.put(attribute, lst); } lst.add(l); }
skin_file ); subviews.put(currentView, new ViewHolder( currentView, skin )); ViewHolder subview = subviews.get(currentView); ViewHolder subview = subviews.get(currentView); ViewHolder subview = subviews.get(currentView); ViewHolder subview = subviews.get(currentView); ViewHolder subview = subviews.remove(currentView);
@Override public void removeListener(DownloadManagerStateAttributeListener l, String attribute, int event_type) { CopyOnWriteMap<String,CopyOnWriteList<DownloadManagerStateAttributeListener>> map_to_use = (event_type == DownloadManagerStateAttributeListener.WILL_BE_READ) ? this.listeners_read_map_cow : this.listeners_write_map_cow; CopyOnWriteList<DownloadManagerStateAttributeListener> lst = map_to_use.get(attribute); if (lst != null) {lst.remove(l);} }
public void putAll( CopyOnWriteMap<K,V> m ){ putAll( m.map ); }
/** * * @param l Listener to fire * @param attribute attribute to listen for (null for all) * @param event_type {@link DownloadManagerStateAttributeListener#WILL_BE_READ} or {@link DownloadManagerStateAttributeListener#WRITTEN} */ @Override public void addListener(DownloadManagerStateAttributeListener l, String attribute, int event_type) { CopyOnWriteMap<String,CopyOnWriteList<DownloadManagerStateAttributeListener>> map_to_use = (event_type == DownloadManagerStateAttributeListener.WILL_BE_READ) ? this.listeners_read_map_cow : this.listeners_write_map_cow; CopyOnWriteList<DownloadManagerStateAttributeListener> lst = map_to_use.get(attribute); if (lst == null) { lst = new CopyOnWriteList<>(); map_to_use.put(attribute, lst); } lst.add(l); }
public static void removeGlobalListener( DownloadManagerStateAttributeListener l, String attribute, int event_type) { CopyOnWriteMap<String,CopyOnWriteList<DownloadManagerStateAttributeListener>> map_to_use = (event_type == DownloadManagerStateAttributeListener.WILL_BE_READ) ? global_listeners_read_map_cow : global_listeners_write_map_cow; CopyOnWriteList<DownloadManagerStateAttributeListener> lst = (CopyOnWriteList)map_to_use.get(attribute); if (lst != null) {lst.remove(l);} }
@Override public void addAttributeListener(DownloadAttributeListener listener, TorrentAttribute attr, int event_type) { String attribute = convertAttribute(attr); if (attribute == null) {return;} CopyOnWriteMap attr_map = this.getAttributeMapForType(event_type); CopyOnWriteList listener_list = (CopyOnWriteList)attr_map.get(attribute); boolean add_self = false; if (listener_list == null) { listener_list = new CopyOnWriteList(); attr_map.put(attribute, listener_list); } add_self = listener_list.isEmpty(); listener_list.add(listener); if (add_self) { download_manager.getDownloadState().addListener(this, attribute, event_type); } }
protected void informWritten( final String attribute_name ) { // don't make any of this async as the link management code for cache files etc // relies on callbacks here being synchronous... List<CopyOnWriteList<DownloadManagerStateAttributeListener>> list = new ArrayList<>(); list.add(global_listeners_write_map_cow.get(attribute_name)); list.add(global_listeners_write_map_cow.get(null)); list.add(listeners_write_map_cow.get(attribute_name)); list.add(listeners_write_map_cow.get(null)); for (CopyOnWriteList<DownloadManagerStateAttributeListener> write_listeners : list) { if (write_listeners == null) { continue; } for ( DownloadManagerStateAttributeListener l: write_listeners.getList()){ try{ l.attributeEventOccurred(download_manager, attribute_name, DownloadManagerStateAttributeListener.WRITTEN); }catch (Throwable t){ Debug.printStackTrace(t); } } } }
public void addExtensionHandler( byte id, byte[] message_id ) { extension_handlers.put( id, message_id ); }
public static void removeDefaultExtensionHandler( long id ) { default_entension_handlers.remove( (byte)id ); }
@Override public Proxy setProxy( InetSocketAddress address, Proxy proxy ) { List<Proxy> p = new ArrayList<>(); p.add( proxy ); String address_str = AddressUtils.getHostNameNoResolve( address ) + ":" + address.getPort(); List<Proxy> old = explicit_proxy_map.put( address_str, Collections.unmodifiableList( p )); if ( old != null ){ return( old.get(0)); }else{ return( null ); } }
@Override public Proxy removeProxy( InetSocketAddress address ) { String address_str = AddressUtils.getHostNameNoResolve( address ) + ":" + address.getPort(); List<Proxy> old = explicit_proxy_map.remove( address_str ); if ( old != null ){ return( old.get(0)); }else{ return( null ); } }
@Override public void attributeEventOccurred(DownloadManager download, String attribute, int event_type) { CopyOnWriteMap attr_listener_map = getAttributeMapForType(event_type); TorrentAttribute attr = convertAttribute(attribute); if (attr == null) {return;} List listeners = null; listeners = ((CopyOnWriteList)attr_listener_map.get(attribute)).getList(); if (listeners == null) {return;} for (int i=0; i<listeners.size(); i++) { DownloadAttributeListener dal = (DownloadAttributeListener)listeners.get(i); try {dal.attributeEventOccurred(this, attr, event_type);} catch (Throwable t) {Debug.printStackTrace(t);} } }
@Override public void removeAttributeListener(DownloadAttributeListener listener, TorrentAttribute attr, int event_type) { String attribute = convertAttribute(attr); if (attribute == null) {return;} CopyOnWriteMap attr_map = this.getAttributeMapForType(event_type); CopyOnWriteList listener_list = (CopyOnWriteList)attr_map.get(attribute); boolean remove_self = false; if (listener_list != null) { listener_list.remove(listener); remove_self = listener_list.isEmpty(); } if (remove_self) { download_manager.getDownloadState().removeListener(this, attribute, event_type); } }