FileDocCategorySizeDatePackage
AEProxyConnectionImpl.javaAPI DocAzureus 3.0.3.45536Thu Feb 09 19:42:58 GMT 2006com.aelitis.azureus.core.proxy.impl

AEProxyConnectionImpl

public class AEProxyConnectionImpl extends Object implements AEProxyConnection
author
parg

Fields Summary
private static final LogIDs
LOGID
protected AEProxyImpl
server
protected SocketChannel
source_channel
protected volatile AEProxyState
proxy_read_state
protected volatile AEProxyState
proxy_write_state
protected volatile AEProxyState
proxy_connect_state
protected long
time_stamp
protected boolean
is_connected
protected boolean
is_closed
protected List
listeners
Constructors Summary
protected AEProxyConnectionImpl(AEProxyImpl _server, SocketChannel _socket, AEProxyHandler _handler)

	
	
	
					
				
				 
	
		server			= _server;
		source_channel	= _socket;
		
		setTimeStamp();
	
		try{
			proxy_read_state = _handler.getInitialState( this );
			
		}catch( Throwable e ){
			
			failed(e);
		}
	
Methods Summary
public voidaddListener(AEProxyConnectionListener l)

		listeners.add(l);
	
public voidcancelConnectSelect(java.nio.channels.SocketChannel sc)

		server.cancelConnectSelect( sc );
	
public voidcancelReadSelect(java.nio.channels.SocketChannel sc)

		server.cancelReadSelect( sc );
	
public voidcancelWriteSelect(java.nio.channels.SocketChannel sc)

		server.cancelWriteSelect( sc );
	
public voidclose()

		is_closed	= true;
		
		try{
			try{
				cancelReadSelect( source_channel );
        cancelWriteSelect( source_channel );
				
				source_channel.close();
				
			}catch( Throwable e ){
				
				Debug.printStackTrace(e);
			}
			
			for (int i=0;i<listeners.size();i++){
				
				try{
					((AEProxyConnectionListener)listeners.get(i)).connectionClosed( this );
					
				}catch( Throwable e ){
					
					Debug.printStackTrace(e);
				}
			}
		}finally{
			
			server.close( this );
		}
	
protected booleanconnect(java.nio.channels.SocketChannel sc)

		try{
			return( proxy_connect_state.connect(sc));
			
		}catch( Throwable e ){
			
			failed(e);
			
			return( false );
		}
	
public voidfailed(java.lang.Throwable reason)

		try{
			if (Logger.isEnabled())
				Logger.log(new LogEvent(LOGID, "AEProxyProcessor: " + getName()
						+ " failed", reason));
			
			close();
			
		}catch( Throwable e ){
			
			Debug.printStackTrace(e);
			
		}
	
public java.lang.StringgetName()

		String	name = source_channel.socket().getInetAddress() + ":" + source_channel.socket().getPort() + " -> ";
		
		return( name );
	
public java.nio.channels.SocketChannelgetSourceChannel()

		return( source_channel );
	
protected java.lang.StringgetStateString()

		return( getName() + "connected = " + is_connected + ", closed = " + is_closed + ", " +
				"chan: reg = " + source_channel.isRegistered() + ", open = " + source_channel.isOpen() + ", " +
				"read:" + (proxy_read_state == null?null:proxy_read_state.getStateName()) + ", " +
				"write:" + (proxy_write_state == null?null:proxy_write_state.getStateName()) + ", " +
				"connect:" + (proxy_connect_state == null?null:proxy_connect_state.getStateName()));
	
protected longgetTimeStamp()

		return( time_stamp );
	
public booleanisClosed()

		return( is_closed );
	
protected booleanisConnected()

		return( is_connected );
	
protected booleanread(java.nio.channels.SocketChannel sc)

		try{
			return( proxy_read_state.read(sc));
			
		}catch( Throwable e ){
			
			failed(e);
			
			return( false );
		}
	
public voidremoveListener(AEProxyConnectionListener l)

		listeners.remove(l);
	
public voidrequestConnectSelect(java.nio.channels.SocketChannel sc)

		server.requestConnectSelect( this, sc );
	
public voidrequestReadSelect(java.nio.channels.SocketChannel sc)

		server.requestReadSelect( this, sc );
	
public voidrequestWriteSelect(java.nio.channels.SocketChannel sc)

		server.requestWriteSelect( this, sc );
	
public voidsetConnectState(AEProxyState state)

		proxy_connect_state	= state;
	
public voidsetConnected()

		setTimeStamp();
		
		is_connected	= true;
	
public voidsetReadState(AEProxyState state)

		proxy_read_state	= state;
	
public voidsetTimeStamp()

		time_stamp = SystemTime.getCurrentTime();
	
public voidsetWriteState(AEProxyState state)

		proxy_write_state	= state;
	
protected booleanwrite(java.nio.channels.SocketChannel sc)

		try{
			return( proxy_write_state.write(sc));
			
		}catch( Throwable e ){
			
			failed(e);
			
			return( false );
		}