FileDocCategorySizeDatePackage
DHTUDPPacketHandlerFactory.javaAPI DocAzureus 3.0.3.45255Thu Jan 11 07:45:38 GMT 2007com.aelitis.azureus.core.dht.transport.udp.impl.packethandler

DHTUDPPacketHandlerFactory

public class DHTUDPPacketHandlerFactory extends Object

Fields Summary
private static DHTUDPPacketHandlerFactory
singleton
private Map
port_map
protected org.gudy.azureus2.core3.util.AEMonitor
this_mon
Constructors Summary
Methods Summary
protected voiddestroy(DHTUDPPacketHandler handler)

		PRUDPPacketHandler	packet_handler = handler.getPacketHandler();
		
		try{
			packet_handler.setRequestHandler(null);
			
		}catch( Throwable e ){
			
			Debug.printStackTrace(e);
		}
		
		int	port 	= packet_handler.getPort();
		int	network = handler.getNetwork();
		
		try{
			this_mon.enter();
			
			Object[]	port_details = (Object[])port_map.remove( new Integer( port ));

			if ( port_details == null ){
			
				return;
			}
		
			Map network_map = (Map)port_details[1];
		
			network_map.remove( new Integer( network ));

		}finally{
			
			this_mon.exit();
		}
	
public static DHTUDPPacketHandlergetHandler(com.aelitis.azureus.core.dht.transport.udp.impl.DHTTransportUDPImpl transport, DHTUDPRequestHandler request_handler)


	
	
	   
	
				
			 
	
		 
	
		return( singleton.getHandlerSupport( transport, request_handler ));
	
protected DHTUDPPacketHandlergetHandlerSupport(com.aelitis.azureus.core.dht.transport.udp.impl.DHTTransportUDPImpl transport, DHTUDPRequestHandler request_handler)

		try{
			this_mon.enter();
			
			int	port	= transport.getPort();
			int	network = transport.getNetwork();
			
			Object[]	port_details = (Object[])port_map.get( new Integer( port ));
			
			if ( port_details == null ){
				
				PRUDPPacketHandler  packet_handler = 
					PRUDPPacketHandlerFactory.getHandler( 
							port, 
							new DHTUDPPacketNetworkHandler( this, port ));
							
				
				port_details = new Object[]{ packet_handler, new HashMap()};
				
				port_map.put( new Integer( port ), port_details );
			}
			
			Map					network_map 	= (Map)port_details[1];
			
			Object[]	network_details = (Object[])network_map.get( new Integer( network ));
						
			if ( network_details != null ){
				
				throw( new DHTUDPPacketHandlerException( "Network already added" ));
			}
			
			DHTUDPPacketHandler ph = new DHTUDPPacketHandler( this, network, (PRUDPPacketHandler)port_details[0], request_handler );
			
			network_map.put( new Integer( network ), new Object[]{ transport, ph });
			
			return( ph );
			
		}finally{
			
			this_mon.exit();
		}
	
public com.aelitis.azureus.core.dht.transport.udp.impl.DHTTransportUDPImplgetTransport(int port, int network)

		Object[]	port_details = (Object[])port_map.get( new Integer( port ));

		if ( port_details == null ){
			
			throw( new IOException( "Port '" + port + "' not registered" ));
		}
		
		Map network_map = (Map)port_details[1];
		
		Object[]	network_details = (Object[])network_map.get( new Integer( network ));

		if ( network_details == null ){
			
			throw( new IOException( "Network '" + network + "' not registered" ));
		}
		
		return((DHTTransportUDPImpl)network_details[0]);
	
protected voidprocess(int port, com.aelitis.azureus.core.dht.transport.udp.impl.DHTUDPPacketRequest request)

		try{
			int	network = request.getNetwork();
			
			/*
			if ( network != 0 ){
				
				System.out.println( "process:" + network + ":" + request.getString());
			}
			*/
			
			Object[]	port_details = (Object[])port_map.get( new Integer( port ));

			if ( port_details == null ){
				
				throw( new IOException( "Port '" + port + "' not registered" ));
			}
			
			Map network_map = (Map)port_details[1];
			
			Object[]	network_details = (Object[])network_map.get( new Integer( network ));

			if ( network_details == null ){
				
				throw( new IOException( "Network '" + network + "' not registered" ));
			}
			
			DHTUDPPacketHandler	res = (DHTUDPPacketHandler)network_details[1];
			
			res.receive( request );
			
		}catch( IOException e ){
			
			Debug.printStackTrace( e );
		}