UDPSelectorpublic class UDPSelector extends Object
Fields Summary |
---|
private static final int | POLL_FREQUENCY | private List | ready_set | private org.gudy.azureus2.core3.util.AESemaphore | ready_sem | private volatile boolean | destroyed |
Constructors Summary |
---|
protected UDPSelector(UDPConnectionManager manager)
new AEThread( "UDPSelector", true )
{
public void
runSupport()
{
boolean quit = false;
long last_poll = 0;
while( !quit ){
if ( destroyed ){
// one last dispatch cycle
quit = true;
}
long now = SystemTime.getCurrentTime();
if ( now < last_poll || now - last_poll >= POLL_FREQUENCY ){
manager.poll();
last_poll = now;
}
if ( ready_sem.reserve(POLL_FREQUENCY/2)){
Object[] entry;
synchronized( ready_set ){
if ( ready_set.size() == 0 ){
continue;
}
entry = (Object[])ready_set.remove(0);
}
TransportHelper transport = (TransportHelper)entry[0];
TransportHelper.selectListener listener = (TransportHelper.selectListener)entry[1];
if ( listener == null ){
Debug.out( "Null listener" );
}else{
Object attachment = entry[2];
try{
if ( entry.length == 3 ){
listener.selectSuccess( transport, attachment );
}else{
listener.selectFailure( transport, attachment, (Throwable)entry[3] );
}
}catch( Throwable e ){
Debug.printStackTrace(e);
}
}
}
}
}
}.start();
|
Methods Summary |
---|
protected void | cancel(com.aelitis.azureus.core.networkmanager.impl.TransportHelper transport, TransportHelper.selectListener listener)
synchronized( ready_set ){
Iterator it = ready_set.iterator();
while( it.hasNext()){
Object[] entry = (Object[])it.next();
if ( entry[0] == transport && entry[1] == listener ){
it.remove();
break;
}
}
}
| protected void | destroy()
synchronized( ready_set ){
destroyed = true;
}
| protected void | ready(com.aelitis.azureus.core.networkmanager.impl.TransportHelper transport, TransportHelper.selectListener listener, java.lang.Object attachment)
boolean removed = false;
synchronized( ready_set ){
if( destroyed ){
Debug.out( "Selector has been destroyed" );
throw( new RuntimeException( "Selector has been destroyed" ));
}
Iterator it = ready_set.iterator();
while( it.hasNext()){
Object[] entry = (Object[])it.next();
if ( entry[1] == listener ){
it.remove();
removed = true;
break;
}
}
ready_set.add( new Object[]{ transport, listener, attachment });
}
if ( !removed ){
ready_sem.release();
}
| protected void | ready(com.aelitis.azureus.core.networkmanager.impl.TransportHelper transport, TransportHelper.selectListener listener, java.lang.Object attachment, java.lang.Throwable error)
boolean removed = false;
synchronized( ready_set ){
if( destroyed ){
Debug.out( "Selector has been destroyed" );
throw( new RuntimeException( "Selector has been destroyed" ));
}
Iterator it = ready_set.iterator();
while( it.hasNext()){
Object[] entry = (Object[])it.next();
if ( entry[1] == listener ){
it.remove();
removed = true;
break;
}
}
ready_set.add( new Object[]{ transport, listener, attachment, error });
}
if ( !removed ){
ready_sem.release();
}
|
|