BuddyPluginTracker.java

Index Score
com.aelitis.azureus.plugins.net.buddy.tracker
Azureus

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
WHITESPACENumber of whitespace lines
JAVA0145JAVA0145 Tab character used in source file
BLOCKSNumber of blocks
CYCLOMATICCyclomatic complexity
LOCLines of code
COMPARISONSNumber of comparison operators
LOOPSNumber of loops
LINESNumber of lines in the source file
ELOCEffective lines of code
OPERATORSNumber of operators
PROGRAM_LENGTHHalstead program length
LOGICAL_LINESNumber of statements
OPERANDSNumber of operands
EXITSProcedure exits
UNIQUE_OPERANDSNumber of unique operands
SIZESize of the file in bytes
JAVA0117JAVA0117 Missing javadoc: method 'method'
PROGRAM_VOCABHalstead program vocabulary
FUNCTIONSNumber of function declarations
INTERFACE_COMPLEXITYInterface complexity
PARAMSNumber of formal parameter declarations
RETURNSNumber of return points from functions
JAVA0254JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0077JAVA0077 Private field not used in declaring class
JAVA0049JAVA0049 Nested block at depth N (maximum: M)
JAVA0177JAVA0177 Variable declaration missing initializer
JAVA0039JAVA0039 Break statement with label
JAVA0270JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0034JAVA0034 Missing braces in if statement
LINE_COMMENTNumber of line comments
NEST_DEPTHMaximum nesting depth
JAVA0076JAVA0076 Use of magic number
UNIQUE_OPERATORSNumber of unique operators
JAVA0278JAVA0278 Unnecessary use of Boolean constructor
JAVA0116JAVA0116 Missing javadoc: field 'field'
EXEC_COMMENTSComments in executable code
JAVA0170JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0166JAVA0166 Generic exception caught
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
COMMENTSComment lines
DOC_COMMENTNumber of javadoc comment lines
DECL_COMMENTSComments in declarations
/* * Created on May 27, 2008 * Created by Paul Gardner * * Copyright 2008 Vuze, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 of the License only. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */ package com.aelitis.azureus.plugins.net.buddy.tracker; import java.net.InetAddress; import java.nio.ByteBuffer; import java.util.*; import org.gudy.azureus2.core3.global.GlobalManager; import org.gudy.azureus2.core3.global.GlobalManagerAdapter; import org.gudy.azureus2.core3.peer.PEPeerManager; import org.gudy.azureus2.core3.util.AddressUtils; import org.gudy.azureus2.core3.util.Average; import org.gudy.azureus2.core3.util.Constants; import org.gudy.azureus2.core3.util.Debug; import org.gudy.azureus2.core3.util.HashWrapper; import org.gudy.azureus2.core3.util.LightHashMap; import org.gudy.azureus2.core3.util.SHA1; import org.gudy.azureus2.core3.util.SimpleTimer; import org.gudy.azureus2.core3.util.SystemTime; import org.gudy.azureus2.core3.util.TimerEvent; import org.gudy.azureus2.core3.util.TimerEventPerformer; import org.gudy.azureus2.core3.util.TimerEventPeriodic; import org.gudy.azureus2.plugins.download.Download; import org.gudy.azureus2.plugins.download.DownloadAnnounceResult; import org.gudy.azureus2.plugins.download.DownloadListener; import org.gudy.azureus2.plugins.download.DownloadManagerListener; import org.gudy.azureus2.plugins.download.DownloadPeerListener; import org.gudy.azureus2.plugins.download.DownloadScrapeResult; import org.gudy.azureus2.plugins.download.DownloadTrackerListener; import org.gudy.azureus2.plugins.peers.Peer; import org.gudy.azureus2.plugins.peers.PeerEvent; import org.gudy.azureus2.plugins.peers.PeerListener2; import org.gudy.azureus2.plugins.peers.PeerManager; import org.gudy.azureus2.plugins.peers.PeerManagerListener; import org.gudy.azureus2.plugins.peers.PeerStats; import org.gudy.azureus2.plugins.torrent.Torrent; import org.gudy.azureus2.plugins.ui.config.BooleanParameter; import org.gudy.azureus2.plugins.ui.config.Parameter; import org.gudy.azureus2.plugins.ui.config.ParameterListener; import org.gudy.azureus2.plugins.ui.model.BasicPluginConfigModel; import org.gudy.azureus2.pluginsimpl.local.PluginCoreUtils; import com.aelitis.azureus.core.AzureusCoreFactory; import com.aelitis.azureus.core.util.CopyOnWriteList; import com.aelitis.azureus.core.util.CopyOnWriteSet; import com.aelitis.azureus.plugins.net.buddy.*; public class BuddyPluginTracker implements BuddyPluginListener, DownloadManagerListener, BuddyPluginAZ2TrackerListener, DownloadPeerListener { public static final Object PEER_KEY = new Object(); // maps to Download object public static final Object DOWNLOAD_KEY = new Object(); // maps to Integer count of buddy peers private static final Object PEER_STATS_KEY = new Object(); public static final int BUDDY_NETWORK_IDLE = 1; public static final int BUDDY_NETWORK_OUTBOUND = 2; public static final int BUDDY_NETWORK_INBOUND = 3; private static final int TRACK_CHECK_PERIOD = 15*1000; private static final int TRACK_CHECK_TICKS = TRACK_CHECK_PERIOD/BuddyPlugin.TIMER_PERIOD; private static final int PEER_CHECK_PERIOD = 60*1000; private static final int PEER_CHECK_TICKS = PEER_CHECK_PERIOD/BuddyPlugin.TIMER_PERIOD; private static final int PEER_RECHECK_PERIOD = 120*1000; private static final int PEER_RECHECK_TICKS = PEER_RECHECK_PERIOD/BuddyPlugin.TIMER_PERIOD; private static final int TRACK_INTERVAL = 10*60*1000; private static final int SHORT_ID_SIZE = 4; private static final int FULL_ID_SIZE = 20; private static final int REQUEST_TRACKER_SUMMARY = 1; private static final int REPLY_TRACKER_SUMMARY = 2; private static final int REQUEST_TRACKER_STATUS = 3; private static final int REPLY_TRACKER_STATUS = 4; private static final int REQUEST_TRACKER_CHANGE = 5; private static final int REPLY_TRACKER_CHANGE = 6; private static final int REQUEST_TRACKER_ADD = 7; private static final int REPLY_TRACKER_ADD = 8; private static final int RETRY_SEND_MIN = 5*60*1000; private static final int RETRY_SEND_MAX = 60*60*1000; private static final int BUDDY_NO = 0; private static final int BUDDY_MAYBE = 1; private static final int BUDDY_YES = 2; private BuddyPlugin plugin; private boolean plugin_enabled; private boolean tracker_enabled; private boolean seeding_only; private boolean old_plugin_enabled; private boolean old_tracker_enabled; private boolean old_seeding_only; private int network_status = BUDDY_NETWORK_IDLE; private Set online_buddies = new HashSet(); private Map online_buddy_ips = new HashMap(); private Set tracked_downloads = new HashSet(); private int download_set_id; private Set last_processed_download_set; private int last_processed_download_set_id; private Map short_id_map = new HashMap(); private Map full_id_map = new HashMap(); private Set actively_tracking = new HashSet(); private CopyOnWriteSet buddy_peers = new CopyOnWriteSet(); private CopyOnWriteList listeners = new CopyOnWriteList(); private TimerEventPeriodic buddy_stats_timer; private Average buddy_receive_speed = Average.getInstance(1000, 10); private Average buddy_send_speed = Average.getInstance(1000, 10); public BuddyPluginTracker( BuddyPlugin _plugin, BasicPluginConfigModel _config ) { plugin = _plugin; final BooleanParameter te = _config.addBooleanParameter2("azbuddy.tracker.enabled", "azbuddy.tracker.enabled", true ); tracker_enabled = te.getValue(); te.addListener( new ParameterListener() { public void parameterChanged( Parameter param ) { tracker_enabled = te.getValue(); checkEnabledState(); } }); GlobalManager gm = AzureusCoreFactory.getSingleton().getGlobalManager(); gm.addListener( new GlobalManagerAdapter() { public void seedingStatusChanged( boolean seeding_only_mode, boolean potentially_seeding_only ) { seeding_only = potentially_seeding_only; checkEnabledState(); } }, false ); seeding_only = gm.isPotentiallySeedingOnly(); checkEnabledState(); } public void initialise() { plugin_enabled = plugin.isEnabled(); checkEnabledState(); List buddies = plugin.getBuddies(); for (int i=0;i<buddies.size();i++){ buddyAdded((BuddyPluginBuddy)buddies.get(i)); } plugin.addListener( this ); plugin.getAZ2Handler().addTrackerListener( this ); plugin.getPluginInterface().getDownloadManager().addListener( this, true ); } public void tick( int tick_count ) { if ( tick_count % TRACK_CHECK_TICKS == 0 ){ checkTracking(); } if ( ( tick_count-1 ) % TRACK_CHECK_TICKS == 0 ){ doTracking(); } if ( tick_count % PEER_CHECK_TICKS == 0 ){ checkPeers(); } if ( tick_count % PEER_RECHECK_TICKS == 0 ){ recheckPeers(); } } public int getNetworkStatus() { return( network_status ); } public long getNetworkReceiveBytesPerSecond() { return( buddy_receive_speed.getAverage()); } public long getNetworkSendBytesPerSecond() { return( buddy_send_speed.getAverage()); } protected void doTracking() { if ( !( plugin_enabled && tracker_enabled )){ return; } Map to_do = new HashMap(); Set active_set = new HashSet(); synchronized( online_buddies ){ Iterator it = online_buddies.iterator(); while( it.hasNext()){ BuddyPluginBuddy buddy = (BuddyPluginBuddy)it.next(); buddyData buddy_data = getBuddyData( buddy ); Map active = buddy_data.getDownloadsToTrack(); if ( active.size() > 0 ){ Iterator it2 = active.entrySet().iterator(); List track_now = new ArrayList(); while( it2.hasNext()){ Map.Entry entry = (Map.Entry)it2.next(); Download dl = (Download)entry.getKey(); boolean now = ((Boolean)entry.getValue()).booleanValue(); if ( now ){ track_now.add( dl ); } active_set.add( dl ); } if( track_now.size() > 0 ){ to_do.put( buddy, track_now ); } } } } synchronized( actively_tracking ){ Iterator it = active_set.iterator(); while( it.hasNext()){ Download dl = (Download)it.next(); if ( !actively_tracking.contains( dl )){ actively_tracking.add( dl ); trackPeers( dl ); } } it = actively_tracking.iterator(); while( it.hasNext()){ Download dl = (Download)it.next(); if ( !active_set.contains( dl )){ it.remove(); untrackPeers( dl ); } } } Iterator it = to_do.entrySet().iterator(); while( it.hasNext()){ Map.Entry entry = (Map.Entry)it.next(); BuddyPluginBuddy buddy = (BuddyPluginBuddy)entry.getKey(); if ( !buddy.isOnline( false )){ continue; } InetAddress ip = buddy.getAdjustedIP(); if ( ip == null ){ continue; } int tcp_port = buddy.getTCPPort(); int udp_port = buddy.getUDPPort(); List downloads = (List)entry.getValue(); for (int i=0;i<downloads.size();i++){ Download download = (Download)downloads.get(i); PeerManager pm = download.getPeerManager(); if ( pm == null ){ continue; } Peer[] existing_peers = pm.getPeers( ip.getHostAddress()); boolean connected = false; for (int j=0;j<existing_peers.length;j++){ Peer peer = existing_peers[j]; if ( peer.getTCPListenPort() == tcp_port || peer.getUDPListenPort() == udp_port ){ connected = true; break; } } if ( connected ){ log( download.getName() + " - peer " + ip.getHostAddress() + " already connected" ); continue; } log( download.getName() + " - connecting to peer " + ip.getHostAddress()); PEPeerManager c_pm = PluginCoreUtils.unwrap( pm ); Map user_data = new LightHashMap(); user_data.put( PEER_KEY, download ); c_pm.addPeer( ip.getHostAddress(), tcp_port, udp_port, true, user_data ); } } } protected void checkTracking() { if ( !( plugin_enabled && tracker_enabled )){ return; } List online; synchronized( online_buddies ){ online = new ArrayList( online_buddies ); } Set downloads; int downloads_id; synchronized( tracked_downloads ){ boolean downloads_changed = last_processed_download_set_id != download_set_id; if ( downloads_changed ){ last_processed_download_set = new HashSet( tracked_downloads ); last_processed_download_set_id = download_set_id; } downloads = last_processed_download_set; downloads_id = last_processed_download_set_id; } Map diff_map = new HashMap(); for (int i=0;i<online.size();i++){ BuddyPluginBuddy buddy = (BuddyPluginBuddy)online.get(i); buddyData buddy_data = getBuddyData( buddy ); buddy_data.updateLocal( downloads, downloads_id, diff_map ); } } public void initialised( boolean available ) { } public void buddyAdded( BuddyPluginBuddy buddy ) { buddyChanged( buddy ); } public void buddyRemoved( BuddyPluginBuddy buddy ) { buddyChanged( buddy ); } public void buddyChanged( BuddyPluginBuddy buddy ) { if ( buddy.isOnline( false )){ addBuddy( buddy ); }else{ removeBuddy( buddy ); } } protected buddyData getBuddyData( BuddyPluginBuddy buddy ) { synchronized( online_buddies ){ buddyData buddy_data = (buddyData)buddy.getUserData( BuddyPluginTracker.class ); if ( buddy_data == null ){ buddy_data = new buddyData( buddy ); buddy.setUserData( BuddyPluginTracker.class, buddy_data ); } return( buddy_data ); } } protected buddyData addBuddy( BuddyPluginBuddy buddy ) { synchronized( online_buddies ){ if ( !online_buddies.contains( buddy )){ online_buddies.add( buddy ); } buddyData bd = getBuddyData( buddy ); if ( bd.hasIPChanged()){ String ip = bd.getIP(); if ( ip != null ){ List l = (List)online_buddy_ips.get( ip ); if ( l != null ){ l.remove( buddy ); if ( l.size() == 0 ){ online_buddy_ips.remove( ip ); } } } bd.updateIP(); ip = bd.getIP(); if ( ip != null ){ List l = (List)online_buddy_ips.get( ip ); if ( l == null ){ l = new ArrayList(); online_buddy_ips.put( ip, l ); } l.add( buddy ); } } return( bd ); } } protected void removeBuddy( BuddyPluginBuddy buddy ) { synchronized( online_buddies ){ if ( online_buddies.contains( buddy )){ buddyData bd = getBuddyData( buddy ); online_buddies.remove( buddy ); String ip = bd.getIP(); if ( ip != null ){ List l = (List)online_buddy_ips.get( ip ); if ( l != null ){ l.remove( buddy ); if ( l.size() == 0 ){ online_buddy_ips.remove( ip ); } } } } } } protected int isBuddy( Peer peer ) { String peer_ip = peer.getIp(); List ips = AddressUtils.getLANAddresses( peer_ip ); synchronized( online_buddies ){ int result = BUDDY_NO; String tested = ""; outer: for (int i=0;i<ips.size();i++){ String ip = (String)ips.get(i); tested += ip; List buddies =(List)online_buddy_ips.get( ip ); if ( buddies != null ){ if ( peer.getTCPListenPort() == 0 && peer.getUDPListenPort() == 0 ){ result = BUDDY_MAYBE; }else{ for (int j=0;j<buddies.size();j++){ BuddyPluginBuddy buddy = (BuddyPluginBuddy)buddies.get(j); if ( buddy.getTCPPort() == peer.getTCPListenPort() && buddy.getTCPPort() != 0 ){ result = BUDDY_YES; break outer; } if ( buddy.getUDPPort() == peer.getUDPListenPort() && buddy.getUDPPort() != 0 ){ result = BUDDY_YES; break outer; } } } } } // log( "isBuddy: " + peer_ip + " -> " + result + ",tested=" + tested ); return( result ); } } public void messageLogged( String str, boolean error ) { } public void enabledStateChanged( boolean _enabled ) { plugin_enabled = _enabled; checkEnabledState(); } public boolean isEnabled() { synchronized( this ){ return( plugin_enabled && tracker_enabled ); } } protected void checkEnabledState() { boolean seeding_change = false; boolean enabled_change = false; synchronized( this ){ boolean old_enabled = old_plugin_enabled && old_tracker_enabled; if ( plugin_enabled != old_plugin_enabled ){ log( "Plugin enabled state changed to " + plugin_enabled ); old_plugin_enabled = plugin_enabled; } if ( tracker_enabled != old_tracker_enabled ){ log( "Tracker enabled state changed to " + tracker_enabled ); old_tracker_enabled = tracker_enabled; } if ( seeding_only != old_seeding_only ){ log( "Seeding-only state changed to " + seeding_only ); old_seeding_only = seeding_only; seeding_change = true; } enabled_change = old_enabled != ( plugin_enabled && tracker_enabled ); } if ( seeding_change ){ updateSeedingMode(); } if ( enabled_change ){ fireEnabledChanged( isEnabled()); } } protected void updateSeedingMode() { updateNetworkStatus(); List online; synchronized( online_buddies ){ online = new ArrayList( online_buddies ); } for (int i=0;i<online.size();i++){ buddyData buddy_data = getBuddyData((BuddyPluginBuddy)online.get(i)); if ( buddy_data.hasDownloadsInCommon()){ buddy_data.updateStatus(); } } } public void downloadAdded( final Download download ) { Torrent t = download.getTorrent(); if ( t == null ){ return; } if ( t.isPrivate()){ download.addTrackerListener( new DownloadTrackerListener() { public void scrapeResult( DownloadScrapeResult result ) { } public void announceResult( DownloadAnnounceResult result) { if ( okToTrack( download )){ trackDownload( download ); }else{ untrackDownload( download ); } } }, false ); } if ( okToTrack( download )){ trackDownload( download ); } download.addListener( new DownloadListener() { public void stateChanged( Download download, int old_state, int new_state ) { if ( okToTrack( download )){ trackDownload( download ); }else{ untrackDownload( download ); } } public void positionChanged( Download download, int oldPosition, int newPosition ) { } }); } public void downloadRemoved( Download download ) { untrackDownload( download ); } protected void trackDownload( Download download ) { synchronized( tracked_downloads ){ if ( tracked_downloads.contains( download )){ return; } downloadData download_data = new downloadData( download ); download.setUserData( BuddyPluginTracker.class, download_data ); HashWrapper full_id = download_data.getID(); HashWrapper short_id = new HashWrapper( full_id.getHash(), 0, 4 ); full_id_map.put( full_id, download ); List dls = (List)short_id_map.get( short_id ); if ( dls == null ){ dls = new ArrayList(); short_id_map.put( short_id, dls ); } dls.add( download ); tracked_downloads.add( download ); download_set_id++; } } protected void untrackDownload( Download download ) { synchronized( tracked_downloads ){ if ( tracked_downloads.remove( download )){ download_set_id++; downloadData download_data = (downloadData)download.getUserData( BuddyPluginTracker.class ); download.setUserData( BuddyPluginTracker.class, null ); HashWrapper full_id = download_data.getID(); full_id_map.remove( full_id ); HashWrapper short_id = new HashWrapper( full_id.getHash(), 0, SHORT_ID_SIZE ); List dls = (List)short_id_map.get( short_id ); if ( dls != null ){ dls.remove( download ); if ( dls.size() == 0 ){ short_id_map.remove( short_id ); } } } } synchronized( online_buddies ){ Iterator it = online_buddies.iterator(); while( it.hasNext()){ BuddyPluginBuddy buddy = (BuddyPluginBuddy)it.next(); buddyData buddy_data = getBuddyData( buddy ); buddy_data.resetTracking( download ); } } synchronized( actively_tracking ){ actively_tracking.remove( download ); } } protected void trackPeers( final Download download ) { PeerManager pm = download.getPeerManager(); // not running if ( pm == null ){ synchronized( actively_tracking ){ actively_tracking.remove( download ); } }else{ log( "Tracking peers for " + download.getName()); download.addPeerListener( this ); } } public void peerManagerAdded( Download download, PeerManager peer_manager ) { trackPeers( download, peer_manager ); } public void peerManagerRemoved( Download download, PeerManager peer_manager ) { synchronized( actively_tracking ){ actively_tracking.remove( download ); } download.removePeerListener( this ); } protected void trackPeers( final Download download, PeerManager pm ) { pm.addListener( new PeerManagerListener() { public void peerAdded( PeerManager manager, Peer peer ) { synchronized( actively_tracking ){ if ( !actively_tracking.contains( download )){ manager.removeListener( this ); return; } } trackPeer( download, peer ); } public void peerRemoved( PeerManager manager, Peer peer ) { } }); Peer[] peers = pm.getPeers(); for (int i=0;i<peers.length;i++){ trackPeer( download, peers[i] ); } } protected void trackPeer( final Download download, final Peer peer ) { int type = isBuddy( peer ); if ( type == BUDDY_YES ){ markBuddyPeer( download, peer ); }else if ( type == BUDDY_MAYBE ){ // mark as peer early so that we get optimistic disconnect if needed markBuddyPeer( download, peer ); PeerListener2 listener = new PeerListener2() { public void eventOccurred( PeerEvent event ) { if ( event.getType() == PeerEvent.ET_STATE_CHANGED ){ if (((Integer)event.getData()).intValue() == Peer.TRANSFERING ){ peer.removeListener( this ); // withdraw buddy marker if it turns out our earlier optimism // was misplaced if ( isBuddy( peer ) != BUDDY_YES ){ unmarkBuddyPeer( peer ); } } } } }; peer.addListener( listener ); if ( peer.getState() == Peer.TRANSFERING ){ peer.removeListener( listener ); // withdraw buddy marker if it turns out our earlier optimism // was misplaced if ( isBuddy( peer ) != BUDDY_YES ){ unmarkBuddyPeer( peer ); } } } } protected void untrackPeers( Download download ) { log( "Not tracking peers for " + download.getName()); download.removePeerListener( this ); PeerManager pm = download.getPeerManager(); if ( pm != null ){ Peer[] peers = pm.getPeers(); for (int i=0;i<peers.length;i++){ Peer peer = peers[i]; unmarkBuddyPeer( peer ); } } } protected void markBuddyPeer( final Download download, final Peer peer ) { boolean state_changed = false; synchronized( buddy_peers ){ if ( !buddy_peers.contains( peer )){ log( "Adding buddy peer " + peer.getIp()); if ( buddy_peers.size() == 0 ){ if ( buddy_stats_timer == null ){ buddy_stats_timer = SimpleTimer.addPeriodicEvent( "BuddyTracker:stats", 1000, new TimerEventPerformer() { public void perform( TimerEvent event ) { Iterator it = buddy_peers.iterator(); long total_sent = 0; long total_received = 0; while( it.hasNext()){ Peer p = (Peer)it.next(); PeerStats ps = p.getStats(); long sent = ps.getTotalSent(); long received = ps.getTotalReceived(); long[] last = (long[])p.getUserData( PEER_STATS_KEY ); if ( last != null ){ total_sent += sent - last[0]; total_received += received - last[1]; } p.setUserData( PEER_STATS_KEY, new long[]{ sent, received }); } buddy_receive_speed.addValue( total_received ); buddy_send_speed.addValue( total_sent ); } }); } state_changed = true; } buddy_peers.add( peer ); peer.setUserData( PEER_KEY, download ); Integer count = (Integer)download.getUserData( DOWNLOAD_KEY ); if ( count == null ){ count = new Integer(1); }else{ count = new Integer( count.intValue() + 1 ); } download.setUserData( DOWNLOAD_KEY, count ); log( download.getName() + ": adding buddy peer " + peer.getIp() + ", count=" + count ); peer.addListener( new PeerListener2() { public void eventOccurred( PeerEvent event ) { if ( event.getType() == PeerEvent.ET_STATE_CHANGED ){ int state = ((Integer)event.getData()).intValue(); if ( state == Peer.CLOSING || state == Peer.DISCONNECTED ){ peer.removeListener( this ); unmarkBuddyPeer( peer ); } } } }); } } if ( peer.getState() == Peer.CLOSING || peer.getState() == Peer.DISCONNECTED ){ unmarkBuddyPeer( peer ); } if ( state_changed ){ updateNetworkStatus(); } } protected void unmarkBuddyPeer( Peer peer ) { boolean state_changed = false; synchronized( buddy_peers ){ Download download = (Download)peer.getUserData( PEER_KEY ); if ( download == null ){ return; } if ( buddy_peers.remove( peer )){ if ( buddy_peers.size() == 0 ){ state_changed = true; if ( buddy_stats_timer != null ){ buddy_stats_timer.cancel(); buddy_stats_timer = null; } } Integer count = (Integer)download.getUserData( DOWNLOAD_KEY ); int val = 0; if ( count != null ){ val = count.intValue() - 1; if ( val == 0 ){ download.setUserData( DOWNLOAD_KEY, null ); }else{ download.setUserData( DOWNLOAD_KEY, new Integer( val )); } } log( download.getName() + ": removing buddy peer " + peer.getIp() + ", count=" + val ); } peer.setUserData( PEER_KEY, null ); } if ( state_changed ){ updateNetworkStatus(); } } protected void checkPeers() { List to_unmark = new ArrayList(); synchronized( buddy_peers ){ Iterator it = buddy_peers.iterator(); while( it.hasNext()){ Peer peer = (Peer)it.next(); if ( peer.getState() == Peer.CLOSING || peer.getState() == Peer.DISCONNECTED ){ to_unmark.add( peer ); } } } for (int i=0;i<to_unmark.size();i++){ unmarkBuddyPeer((Peer)to_unmark.get(i)); } } protected void recheckPeers() { // go over peers for active torrents to see if we've missed and. can really only // happen with multi-homed LAN setups where a new (and utilised) route is found // after we start tracking synchronized( actively_tracking ){ Iterator it = actively_tracking.iterator(); while( it.hasNext()){ Download download = (Download)it.next(); PeerManager pm = download.getPeerManager(); if ( pm != null ){ Peer[] peers = pm.getPeers(); for (int i=0;i<peers.length;i++){ trackPeer( download, peers[i] ); } } } } } protected void updateNetworkStatus() { int new_status; boolean changed = false; synchronized( buddy_peers ){ if ( buddy_peers.size() == 0 ){ new_status = BUDDY_NETWORK_IDLE; }else{ new_status = seeding_only?BUDDY_NETWORK_OUTBOUND:BUDDY_NETWORK_INBOUND; } if ( new_status != network_status ){ network_status = new_status; changed = true; } } if ( changed ){ fireStateChange( new_status ); } } public void addListener( BuddyPluginTrackerListener l ) { listeners.add( l ); } public void removeListener( BuddyPluginTrackerListener l ) { listeners.remove( l ); } protected void fireStateChange( int state ) { Iterator it = listeners.iterator(); while( it.hasNext()){ try{ ((BuddyPluginTrackerListener)it.next()).networkStatusChanged( this, state ); }catch( Throwable e ){ Debug.out( e ); } } } protected void fireEnabledChanged( boolean enabled ) { Iterator it = listeners.iterator(); while( it.hasNext()){ try{ ((BuddyPluginTrackerListener)it.next()).enabledStateChanged( this, enabled ); }catch( Throwable e ){ Debug.out( e ); } } } protected void sendMessage( BuddyPluginBuddy buddy, int type, Map body ) { Map msg = new HashMap(); msg.put( "type", new Long( type )); msg.put( "msg", body ); plugin.getAZ2Handler().sendAZ2TrackerMessage( buddy, msg, BuddyPluginTracker.this ); } public Map messageReceived( BuddyPluginBuddy buddy, Map message ) { buddyData buddy_data = buddyAlive( buddy ); int type = ((Long)message.get( "type" )).intValue(); Map msg = (Map)message.get( "msg" ); return( buddy_data.receiveMessage( type, msg )); } public void messageFailed( BuddyPluginBuddy buddy, Throwable cause ) { log( "Failed to send message to " + buddy.getName(), cause ); buddyDead( buddy ); } protected buddyData buddyAlive( BuddyPluginBuddy buddy ) { buddyData buddy_data = addBuddy( buddy ); buddy_data.setAlive( true ); return( buddy_data ); } protected void buddyDead( BuddyPluginBuddy buddy ) { buddyData buddy_data = getBuddyData( buddy ); if ( buddy_data != null ){ buddy_data.setAlive( false ); } } protected boolean okToTrack( Download d ) { Torrent t = d.getTorrent(); if ( t == null ){ return( false ); } // only track private torrents if we have successfully received peers from tracker // which means we have the torrent legitimately. As this rule is enforced by both // ends of the tracking operation it means we will only track between peers that // both have a legitimate copy of the torrent. if ( t.isPrivate()){ DownloadAnnounceResult announce = d.getLastAnnounceResult(); if ( announce == null || announce.getResponseType() != DownloadAnnounceResult.RT_SUCCESS || announce.getPeers().length < 2 ){ return( false ); } } int state = d.getState(); return( state != Download.ST_ERROR && state != Download.ST_STOPPING && state != Download.ST_STOPPED ); } protected void log( String str ) { plugin.log( "Tracker: " + str ); } protected void log( String str, boolean verbose ) { if ( verbose ){ if ( Constants.isCVSVersion()){ log( str ); } }else{ log( str ); } } protected void log( String str, Throwable e ) { plugin.log( "Tracker: " + str, e ); } private class buddyData { private BuddyPluginBuddy buddy; private Set downloads_sent; private int downloads_sent_id; private Map downloads_in_common; private boolean buddy_seeding_only; private int consecutive_fails; private long last_fail; private String current_ip; protected buddyData( BuddyPluginBuddy _buddy ) { buddy = _buddy; } protected void updateIP() { current_ip = buddy.getAdjustedIP().getHostAddress(); log( "IP set to " + current_ip ); } protected boolean hasIPChanged() { InetAddress latest_ip = buddy.getAdjustedIP(); if ( latest_ip == null && current_ip == null ){ return( false ); }else if ( latest_ip == null || current_ip == null ){ return( true ); }else{ return( !current_ip.equals( latest_ip.getHostAddress())); } } protected String getIP() { return( current_ip ); } protected boolean hasDownloadsInCommon() { synchronized( this ){ return( downloads_in_common != null ); } } protected void setAlive( boolean alive ) { synchronized( this ){ if ( alive ){ consecutive_fails = 0; last_fail = 0; }else{ consecutive_fails++; last_fail = SystemTime.getMonotonousTime(); } } } protected void updateLocal( Set downloads, int id, Map diff_map ) { if ( consecutive_fails > 0 ){ long retry_millis = RETRY_SEND_MIN; for (int i=0;i<consecutive_fails-1;i++){ retry_millis <<= 2; if ( retry_millis > RETRY_SEND_MAX ){ retry_millis = RETRY_SEND_MAX; break; } } long now = SystemTime.getMonotonousTime(); if ( now - last_fail >= retry_millis ){ last_fail = now; // assume we're going to fail so we avoid // falling through here multiple times before // actuallt failing again downloads_sent = null; downloads_sent_id = 0; } } // first check to see if completion state changed for any common downloads List comp_changed = new ArrayList(); synchronized( this ){ if ( downloads_in_common != null ){ Iterator it = downloads_in_common.entrySet().iterator(); while( it.hasNext()){ Map.Entry entry = (Map.Entry)it.next(); Download d = (Download)entry.getKey(); buddyDownloadData bdd = (buddyDownloadData)entry.getValue(); boolean local_complete = d.isComplete( false ); if ( local_complete != bdd.isLocalComplete()){ bdd.setLocalComplete( local_complete ); comp_changed.add( d ); } } } } if ( comp_changed.size() > 0 ){ byte[][] change_details = exportFullIDs( comp_changed ); if( change_details[0].length > 0 ){ Map msg = new HashMap(); msg.put( "seeding", new Long( seeding_only?1:0 )); msg.put( "change", change_details[0] ); msg.put( "change_s", change_details[1] ); sendMessage( buddy, REQUEST_TRACKER_CHANGE, msg ); } } if ( id == downloads_sent_id ){ return; } Long key = new Long(((long)id) << 32 | (long)downloads_sent_id); Object[] diffs = (Object[])diff_map.get( key ); boolean incremental = downloads_sent != null; byte[] added_bytes; byte[] removed_bytes; if ( diffs == null ){ List added; List removed = new ArrayList(); if ( downloads_sent == null ){ added = new ArrayList( downloads ); }else{ added = new ArrayList(); Iterator it1 = downloads.iterator(); while( it1.hasNext()){ Download download = (Download)it1.next(); if ( okToTrack( download )){ if ( !downloads_sent.contains( download )){ added.add( download ); } } } Iterator it2 = downloads_sent.iterator(); while( it2.hasNext()){ Download download = (Download)it2.next(); if ( !downloads.contains( download )){ removed.add( download ); } } } added_bytes = exportShortIDs( added ); removed_bytes = exportFullIDs( removed )[0]; diff_map.put( key, new Object[]{ added_bytes, removed_bytes }); }else{ added_bytes = (byte[])diffs[0]; removed_bytes = (byte[])diffs[1]; } downloads_sent = downloads; downloads_sent_id = id; if ( added_bytes.length == 0 && removed_bytes.length == 0 ){ return; } Map msg = new HashMap(); if ( added_bytes.length > 0 ){ msg.put( "added", added_bytes ); } if ( removed_bytes.length > 0 ){ msg.put( "removed", removed_bytes ); } msg.put( "inc", new Long( incremental?1:0 )); msg.put( "seeding", new Long( seeding_only?1:0 )); sendMessage( buddy, REQUEST_TRACKER_SUMMARY, msg ); } protected Map updateRemote( Map msg ) { List added = importShortIDs((byte[])msg.get( "added" )); Map reply = new HashMap(); byte[][] add_details = exportFullIDs( added ); if( add_details[0].length > 0 ){ reply.put( "added", add_details[0] ); reply.put( "added_s", add_details[1] ); } synchronized( this ){ if ( downloads_in_common != null ){ Map removed = importFullIDs( (byte[])msg.get( "removed" ), null ); Iterator it = removed.keySet().iterator(); while( it.hasNext()){ Download d = (Download)it.next(); if ( downloads_in_common.remove( d ) != null ){ log( "Removed " + d.getName() + " common download", false, true ); } } if ( downloads_in_common.size() == 0 ){ downloads_in_common = null; } } } return( reply ); } protected void updateCommonDownloads( Map downloads, boolean incremental ) { synchronized( this ){ if ( downloads_in_common == null ){ downloads_in_common = new HashMap(); }else{ // if not incremental then remove any downloads that no longer // are in common if ( !incremental ){ Iterator it = downloads_in_common.keySet().iterator(); while( it.hasNext()){ Download download = (Download)it.next(); if ( !downloads.containsKey( download )){ log( "Removing " + download.getName() + " from common downloads", false, true ); it.remove(); } } } } Iterator it = downloads.entrySet().iterator(); while( it.hasNext()){ Map.Entry entry = (Map.Entry)it.next(); Download d = (Download)entry.getKey(); buddyDownloadData bdd = (buddyDownloadData)entry.getValue(); buddyDownloadData existing = (buddyDownloadData)downloads_in_common.get( d ); if ( existing == null ){ log( "Adding " + d.getName() + " to common downloads (bdd=" + bdd.getString() + ")", false, true ); downloads_in_common.put( d, bdd ); }else{ boolean old_rc = existing.isRemoteComplete(); boolean new_rc = bdd.isRemoteComplete(); if ( old_rc != new_rc ){ existing.setRemoteComplete( new_rc ); log( "Changing " + d.getName() + " common downloads (bdd=" + existing.getString() + ")", false, true ); } } } if ( downloads_in_common.size() == 0 ){ downloads_in_common = null; } } } protected void updateStatus() { Map msg = new HashMap(); msg.put( "seeding", new Long( seeding_only?1:0 )); sendMessage( buddy, REQUEST_TRACKER_STATUS, msg ); } protected Map receiveMessage( int type, Map msg_in ) { int reply_type = -1; Map msg_out = null; Long l_seeding = (Long)msg_in.get( "seeding" ); if( l_seeding != null ){ boolean old = buddy_seeding_only; buddy_seeding_only = l_seeding.intValue() == 1; if ( old != buddy_seeding_only ){ log( "Seeding only changed to " + buddy_seeding_only ); } } if ( type == REQUEST_TRACKER_SUMMARY ){ reply_type = REPLY_TRACKER_SUMMARY; msg_out = updateRemote( msg_in ); msg_out.put( "inc", msg_in.get( "inc" )); }else if ( type == REQUEST_TRACKER_STATUS ){ reply_type = REPLY_TRACKER_STATUS; }else if ( type == REQUEST_TRACKER_CHANGE ){ reply_type = REPLY_TRACKER_STATUS; Map downloads = importFullIDs( (byte[])msg_in.get( "changed" ), (byte[])msg_in.get( "changed_s" ) ); updateCommonDownloads( downloads, true ); }else if ( type == REQUEST_TRACKER_ADD ){ reply_type = REPLY_TRACKER_ADD; Map downloads = importFullIDs( (byte[])msg_in.get( "added" ), (byte[])msg_in.get( "added_s" ) ); updateCommonDownloads( downloads, true ); }else if ( type == REPLY_TRACKER_SUMMARY ){ // full hashes on reply byte[] possible_matches = (byte[])msg_in.get( "added" ); byte[] possible_match_states = (byte[])msg_in.get( "added_s" ); boolean incremental = ((Long)msg_in.get( "inc" )).intValue() == 1; if ( possible_matches != null && possible_match_states != null ){ Map downloads = importFullIDs( possible_matches, possible_match_states ); if ( downloads.size() > 0 ){ updateCommonDownloads( downloads, incremental ); byte[][] common_details = exportFullIDs( new ArrayList( downloads.keySet())); if( common_details[0].length > 0 ){ Map msg = new HashMap(); msg.put( "seeding", new Long( seeding_only?1:0 )); msg.put( "added", common_details[0] ); msg.put( "added_s", common_details[1] ); sendMessage( buddy, REQUEST_TRACKER_ADD, msg ); } } } }else if ( type == REPLY_TRACKER_CHANGE || type == REPLY_TRACKER_STATUS || type == REPLY_TRACKER_ADD ){ // nothing interesting in reply for these }else{ log( "Unrecognised type " + type ); } if ( reply_type != -1 ){ Map reply = new HashMap(); reply.put( "type", new Long( reply_type )); if ( msg_out == null ){ msg_out = new HashMap(); } msg_out.put( "seeding", new Long( seeding_only?1:0 )); reply.put( "msg", msg_out ); return( reply ); } return( null ); } protected byte[] exportShortIDs( List downloads ) { byte[] res = new byte[ SHORT_ID_SIZE * downloads.size() ]; for (int i=0;i<downloads.size();i++ ){ Download download = (Download)downloads.get(i); downloadData download_data = (downloadData)download.getUserData( BuddyPluginTracker.class ); if ( download_data != null ){ System.arraycopy( download_data.getID().getBytes(), 0, res, i * SHORT_ID_SIZE, SHORT_ID_SIZE ); } } return( res ); } protected List importShortIDs( byte[] ids ) { List res = new ArrayList(); if ( ids != null ){ synchronized( tracked_downloads ){ for (int i=0;i<ids.length;i+= SHORT_ID_SIZE ){ List dls = (List)short_id_map.get( new HashWrapper( ids, i, SHORT_ID_SIZE )); if ( dls != null ){ res.addAll( dls ); } } } } return( res ); } protected byte[][] exportFullIDs( List downloads ) { byte[] hashes = new byte[ FULL_ID_SIZE * downloads.size() ]; byte[] states = new byte[ downloads.size()]; for (int i=0;i<downloads.size();i++ ){ Download download = (Download)downloads.get(i); downloadData download_data = (downloadData)download.getUserData( BuddyPluginTracker.class ); if ( download_data != null ){ System.arraycopy( download_data.getID().getBytes(), 0, hashes, i * FULL_ID_SIZE, FULL_ID_SIZE ); states[i] = download.isComplete( false )?(byte)0x01:(byte)0x00; } } return( new byte[][]{ hashes, states }); } protected Map importFullIDs( byte[] ids, byte[] states ) { Map res = new HashMap(); if ( ids != null ){ synchronized( tracked_downloads ){ for (int i=0;i<ids.length;i+= FULL_ID_SIZE ){ Download dl = (Download)full_id_map.get( new HashWrapper( ids, i, FULL_ID_SIZE )); if ( dl != null ){ buddyDownloadData bdd = new buddyDownloadData( dl ); if ( states != null ){ bdd.setRemoteComplete(( states[i/FULL_ID_SIZE] & 0x01 ) != 0 ); } res.put( dl, bdd ); } } } } return( res ); } protected Map getDownloadsToTrack() { Map res = new HashMap(); if ( seeding_only == buddy_seeding_only ){ log( "Not tracking, buddy and me both " + (seeding_only?"seeding":"downloading"), true, false ); return( res ); } long now = SystemTime.getMonotonousTime(); synchronized( this ){ if ( downloads_in_common == null ){ log( "Not tracking, buddy has nothing in common", true, false ); return( res ); } Iterator it = downloads_in_common.entrySet().iterator(); while( it.hasNext()){ Map.Entry entry = (Map.Entry)it.next(); Download d = (Download)entry.getKey(); buddyDownloadData bdd = (buddyDownloadData)entry.getValue(); if ( d.isComplete( false ) && bdd.isRemoteComplete()){ // both complete, nothing to do! log( d.getName() + " - not tracking, both complete", true, true ); }else{ long last_track = bdd.getTrackTime(); if ( last_track == 0 || now - last_track >= TRACK_INTERVAL ){ log( d.getName() + " - tracking", false, true ); bdd.setTrackTime( now ); res.put( d, new Boolean( true )); }else{ res.put( d, new Boolean( false )); } } } } return( res ); } protected void resetTracking( Download download ) { synchronized( this ){ if ( downloads_in_common == null ){ return; } buddyDownloadData bdd = (buddyDownloadData)downloads_in_common.get( download ); if ( bdd != null ){ bdd.resetTrackTime(); } } } protected void log( String str ) { BuddyPluginTracker.this.log( buddy.getName() + ": " + str ); } protected void log( String str, boolean verbose, boolean no_buddy ) { BuddyPluginTracker.this.log( (no_buddy?"":( buddy.getName() + ": ")) + str, verbose ); } } private static class buddyDownloadData { private boolean local_is_complete; private boolean remote_is_complete; private long last_track; protected buddyDownloadData( Download download ) { local_is_complete = download.isComplete( false ); } protected void setLocalComplete( boolean b ) { local_is_complete = b; } protected boolean isLocalComplete() { return( local_is_complete ); } protected void setRemoteComplete( boolean b ) { remote_is_complete = b; } protected boolean isRemoteComplete() { return( remote_is_complete ); } protected void setTrackTime( long time ) { last_track = time; } protected long getTrackTime() { return( last_track ); } protected void resetTrackTime() { last_track = 0; } protected String getString() { return( "lic=" + local_is_complete + ",ric=" + remote_is_complete + ",lt=" + last_track ); } } private static class downloadData { private static final byte[] IV = {(byte)0x7A, (byte)0x7A, (byte)0xAD, (byte)0xAB, (byte)0x8E, (byte)0xBF, (byte)0xCD, (byte)0x39, (byte)0x87, (byte)0x0, (byte)0xA4, (byte)0xB8, (byte)0xFE, (byte)0x40, (byte)0xA2, (byte)0xE8 }; private HashWrapper id; protected downloadData( Download download ) { Torrent t = download.getTorrent(); if ( t != null ){ byte[] hash = t.getHash(); SHA1 sha1 = new SHA1(); sha1.update( ByteBuffer.wrap( IV )); sha1.update( ByteBuffer.wrap( hash )); id = new HashWrapper( sha1.digest() ); } } protected HashWrapper getID() { return( id ); } } }

The table below shows all metrics for BuddyPluginTracker.java.

MetricValueDescription
BLOCKS321.00Number of blocks
BLOCK_COMMENT19.00Number of block comment lines
COMMENTS41.00Comment lines
COMMENT_DENSITY 0.04Comment density
COMPARISONS218.00Number of comparison operators
CYCLOMATIC303.00Cyclomatic complexity
DECL_COMMENTS 1.00Comments in declarations
DOC_COMMENT 0.00Number of javadoc comment lines
ELOC1160.00Effective lines of code
EXEC_COMMENTS13.00Comments in executable code
EXITS169.00Procedure exits
FUNCTIONS90.00Number of function declarations
HALSTEAD_DIFFICULTY115.13Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY201.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 0.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 0.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA0034 0.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 2.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA004910.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 0.00JAVA0075 Method parameter hides field
JAVA0076 7.00JAVA0076 Use of magic number
JAVA007713.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 1.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA0108 0.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 0.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 0.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 0.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 5.00JAVA0116 Missing javadoc: field 'field'
JAVA011767.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 1.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 0.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 1.00JAVA0144 Line exceeds maximum M characters
JAVA01458263.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 2.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 2.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 8.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA025415.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 1.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 4.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 2.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA0285 0.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES2343.00Number of lines in the source file
LINE_COMMENT22.00Number of line comments
LOC1560.00Lines of code
LOGICAL_LINES635.00Number of statements
LOOPS34.00Number of loops
NEST_DEPTH 8.00Maximum nesting depth
OPERANDS2863.00Number of operands
OPERATORS5901.00Number of operators
PARAMS93.00Number of formal parameter declarations
PROGRAM_LENGTH8764.00Halstead program length
PROGRAM_VOCAB806.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS108.00Number of return points from functions
SIZE47937.00Size of the file in bytes
UNIQUE_OPERANDS746.00Number of unique operands
UNIQUE_OPERATORS60.00Number of unique operators
WHITESPACE742.00Number of whitespace lines