FileDocCategorySizeDatePackage
NetworkGlueLoopBack.javaAPI DocAzureus 3.0.3.43031Mon Jul 24 16:00:18 BST 2006com.aelitis.azureus.core.networkmanager.impl.udp

NetworkGlueLoopBack

public class NetworkGlueLoopBack extends Object implements NetworkGlue

Fields Summary
private int
latency
private NetworkGlueListener
listener
private List
message_queue
private Random
random
Constructors Summary
protected NetworkGlueLoopBack(NetworkGlueListener _listener)

	
	
	
				 
	
		listener	= _listener;
				
		new AEThread( "NetworkGlueLoopBack", true )
		{
			public void
			runSupport()
			{
				while( true ){
					
					try{
						Thread.sleep(1);
						
					}catch( Throwable e ){
						
					}
				
					InetSocketAddress	target_address 	= null;
					InetSocketAddress	source_address 	= null;
					byte[]				data			= null;
					
					long	now = SystemTime.getCurrentTime();
					
					synchronized( message_queue ){
						
						if ( message_queue.size() > 0 ){
							
							Object[]	entry = (Object[])message_queue.get(0);
							
							if (((Long)entry[0]).longValue() < now ){
								
								message_queue.remove(0);
								
								source_address	= (InetSocketAddress)entry[1];
								target_address 	= (InetSocketAddress)entry[2];
								data			= (byte[])entry[3];
							}
						}
					}
					
					if ( source_address != null ){
	
						listener.receive( target_address.getPort(), source_address, data, data.length );
					}
				}
			}
		}.start();
	
Methods Summary
public long[]getStats()

		return( new long[]{ 0,0,0,0 });
	
public intsend(int local_port, java.net.InetSocketAddress target, byte[] data)

	
		Long	expires = new Long( SystemTime.getCurrentTime() + latency );
			
		InetSocketAddress local_address = new InetSocketAddress( target.getAddress(), local_port );
			
		synchronized( message_queue ){
				
			if ( random.nextInt(4) != 9 ){
					
				message_queue.add( new Object[]{ expires, local_address, target, data });
			}
		}
		
		return( data.length );