FileDocCategorySizeDatePackage
TCPNetworkManager.javaAPI DocAzureus 3.0.3.47445Tue Apr 10 13:30:42 BST 2007com.aelitis.azureus.core.networkmanager.impl.tcp

TCPNetworkManager

public class TCPNetworkManager extends Object

Fields Summary
private static int
WRITE_SELECT_LOOP_TIME
private static int
READ_SELECT_LOOP_TIME
protected static int
tcp_mss_size
private static final TCPNetworkManager
instance
public static boolean
TCP_INCOMING_ENABLED
public static boolean
TCP_OUTGOING_ENABLED
private final com.aelitis.azureus.core.networkmanager.VirtualChannelSelector
read_selector
private final com.aelitis.azureus.core.networkmanager.VirtualChannelSelector
write_selector
private final TCPConnectionManager
connect_disconnect_manager
private final IncomingSocketChannelManager
incoming_socketchannel_manager
private long
read_select_count
private long
write_select_count
Constructors Summary
protected TCPNetworkManager()

	
	
	
	
	
		Set	types = new HashSet();
		
		types.add( AzureusCoreStats.ST_NET_TCP_SELECT_READ_COUNT );
		types.add( AzureusCoreStats.ST_NET_TCP_SELECT_WRITE_COUNT );

		AzureusCoreStats.registerProvider(
			types,
			new AzureusCoreStatsProvider()
			{
				public void
				updateStats(
					Set		types,
					Map		values )
				{
					if ( types.contains( AzureusCoreStats.ST_NET_TCP_SELECT_READ_COUNT )){
						
						values.put( AzureusCoreStats.ST_NET_TCP_SELECT_READ_COUNT, new Long( read_select_count ));
					}	
					if ( types.contains( AzureusCoreStats.ST_NET_TCP_SELECT_WRITE_COUNT )){
						
						values.put( AzureusCoreStats.ST_NET_TCP_SELECT_WRITE_COUNT, new Long( write_select_count ));
					}					
				}
			});
		
		   //start read selector processing
		
	    Thread read_selector_thread = 
	    	new AEThread( "ReadController:ReadSelector" ) 
	    	{
		    	public void 
		    	runSupport() 
		    	{
		    		while( true ) {
		    	
		    			try{
		    				read_selector.select( READ_SELECT_LOOP_TIME );
		    				
		    				read_select_count++;
		    				
		    			}catch( Throwable t ) {
		    				
		    				Debug.out( "readSelectorLoop() EXCEPTION: ", t );
		    			}      
		    		}
		    	}
	    	};
	    	
	    read_selector_thread.setDaemon( true );
	    read_selector_thread.setPriority( Thread.MAX_PRIORITY - 2 );
	    read_selector_thread.start();
	    
	    	//start write selector processing
	    
	    Thread write_selector_thread = 
	    	new AEThread( "WriteController:WriteSelector" )
	    	{
		    	public void 
		    	runSupport() 
		    	{
		    	    while( true ){
		    	    	
		    	    	try{
		    	    		write_selector.select( WRITE_SELECT_LOOP_TIME );
		    	    		
		    	    		write_select_count++;
		    	    		
		    	    	}catch( Throwable t ) {
		    	    		
		    	    		Debug.out( "writeSelectorLoop() EXCEPTION: ", t );
		    	    	}      
		  		    }
		    	}
	    	};
	    	
	    write_selector_thread.setDaemon( true );
	    write_selector_thread.setPriority( Thread.MAX_PRIORITY - 2 );
	    write_selector_thread.start();	    
	
Methods Summary
public voidclearExplicitBindAddress()

		incoming_socketchannel_manager.clearExplicitBindAddress();
	
public TCPConnectionManagergetConnectDisconnectManager()
Get the socket channel connect / disconnect manager.

return
connect manager

  return connect_disconnect_manager;  
public com.aelitis.azureus.core.networkmanager.VirtualChannelSelectorgetReadSelector()
Get the virtual selector used for socket channel read readiness.

return
read readiness selector

  return read_selector;  
public static com.aelitis.azureus.core.networkmanager.impl.tcp.TCPNetworkManagergetSingleton()


	    return( instance ); 
public intgetTCPListeningPortNumber()
Get port that the TCP server socket is listening for incoming connections on.

return
port number

  return incoming_socketchannel_manager.getTCPListeningPortNumber();  
public static intgetTcpMssSize()
Get the configured TCP MSS (Maximum Segment Size) unit, i.e. the max (preferred) packet payload size. NOTE: MSS is MTU-40bytes for TCPIP headers, usually 1460 (1500-40) for standard ethernet connections, or 1452 (1492-40) for PPPOE connections.

return
mss size in bytes

		COConfigurationManager.addAndFireParameterListener(
				"TCP.Listen.Port.Enable",
				new ParameterListener()
				{
					public void 
					parameterChanged(
						String name )
					{
						TCP_INCOMING_ENABLED = TCP_OUTGOING_ENABLED = COConfigurationManager.getBooleanParameter( name );
					}
				});
		
		COConfigurationManager.addAndFireParameterListeners(
				new String[]{ "network.tcp.read.select.time", "network.tcp.write.select.time"  },
				new ParameterListener()
				{
					public void 
					parameterChanged(
						String name )
					{
						WRITE_SELECT_LOOP_TIME 	= COConfigurationManager.getIntParameter(  "network.tcp.write.select.time" );
						READ_SELECT_LOOP_TIME 	= COConfigurationManager.getIntParameter(  "network.tcp.read.select.time" );
					}
				});
	  return tcp_mss_size;  
public com.aelitis.azureus.core.networkmanager.VirtualChannelSelectorgetWriteSelector()
Get the virtual selector used for socket channel write readiness.

return
write readiness selector

  return write_selector;  
public booleanisEffectiveBindAddress(java.net.InetAddress address)

		return( incoming_socketchannel_manager.isEffectiveBindAddress( address ));
	
public booleanisTCPListenerEnabled()

		return( incoming_socketchannel_manager.isEnabled());
	
public static voidrefreshRates(int min_rate)

		 tcp_mss_size = COConfigurationManager.getIntParameter( "network.tcp.mtu.size" ) - 40; 	        

	    if( tcp_mss_size > min_rate )  tcp_mss_size = min_rate - 1;
	    
	    if( tcp_mss_size < 512 )  tcp_mss_size = 512; 
	
public voidsetExplicitBindAddress(java.net.InetAddress address)

		incoming_socketchannel_manager.setExplicitBindAddress( address );