FileDocCategorySizeDatePackage
OutgoingMessageQueueImpl.javaAPI DocAzureus 3.0.3.45362Thu Feb 09 19:42:50 GMT 2006org.gudy.azureus2.pluginsimpl.local.network

OutgoingMessageQueueImpl

public class OutgoingMessageQueueImpl extends Object implements OutgoingMessageQueue

Fields Summary
private final com.aelitis.azureus.core.networkmanager.OutgoingMessageQueue
core_queue
private final HashMap
registrations
Constructors Summary
protected OutgoingMessageQueueImpl(com.aelitis.azureus.core.networkmanager.OutgoingMessageQueue core_queue)

  
  
       
    this.core_queue = core_queue;
  
Methods Summary
public voidderegisterListener(OutgoingMessageQueueListener listener)

    //retrieve saved mapping
    com.aelitis.azureus.core.networkmanager.OutgoingMessageQueue.MessageQueueListener core_listener =
      (com.aelitis.azureus.core.networkmanager.OutgoingMessageQueue.MessageQueueListener)registrations.remove( listener );
    
    if( core_listener != null ) {
      core_queue.cancelQueueListener( core_listener );
    }
  
public intgetPercentDoneOfCurrentMessage()

    return core_queue.getPercentDoneOfCurrentMessage();
  
public voidnotifyOfExternalSend(Message message)

    if( message instanceof MessageAdapter ) {
      //the message must have been originally created by core and wrapped
      //so just use original core message...i.e. unwrap out of MessageAdapter
      core_queue.notifyOfExternallySentMessage( ((MessageAdapter)message).getCoreMessage() );
      return;
    }
    
    //message originally created by plugin
    core_queue.notifyOfExternallySentMessage( new MessageAdapter( message ) );
  
public voidregisterListener(OutgoingMessageQueueListener listener)

    com.aelitis.azureus.core.networkmanager.OutgoingMessageQueue.MessageQueueListener core_listener =
      new com.aelitis.azureus.core.networkmanager.OutgoingMessageQueue.MessageQueueListener() {
      
        public boolean messageAdded( com.aelitis.azureus.core.peermanager.messaging.Message message ) {
          if( message instanceof MessageAdapter ) {
            //the message must have been originally created by plugin encoder and wrapped
            //so just use original plugin message...i.e. unwrap out of MessageAdapter
            return listener.messageAdded( ((MessageAdapter)message).getPluginMessage() );
          }
          
          //message originally created by core
          return listener.messageAdded( new MessageAdapter( message ) );
        }

        public void messageQueued( com.aelitis.azureus.core.peermanager.messaging.Message message ) {  /*nothing*/  }
        public void messageRemoved( com.aelitis.azureus.core.peermanager.messaging.Message message ) {  /*nothing*/  }

        public void messageSent( com.aelitis.azureus.core.peermanager.messaging.Message message ) {
          if( message instanceof MessageAdapter ) {
            //the message must have been originally created by plugin encoder and wrapped
            //so just use original plugin message...i.e. unwrap out of MessageAdapter
            listener.messageSent( ((MessageAdapter)message).getPluginMessage() );
            return;
          }
          
          //message originally created by core
          listener.messageSent( new MessageAdapter( message ) );
        }

        public void protocolBytesSent( int byte_count ) {  listener.bytesSent( byte_count );  }

        public void dataBytesSent( int byte_count ) {  listener.bytesSent( byte_count );  }
    };
    
    registrations.put( listener, core_listener );  //save this mapping for later
    
    core_queue.registerQueueListener( core_listener );
  
public voidsendMessage(Message message)

    if( message instanceof MessageAdapter ) {
      //the message must have been originally created by core and wrapped
      //so just use original core message...i.e. unwrap out of MessageAdapter
      core_queue.addMessage( ((MessageAdapter)message).getCoreMessage(), false );
      return;
    }
    
    //message originally created by plugin
    core_queue.addMessage( new MessageAdapter( message ), false );
  
public voidsetEncoder(MessageStreamEncoder encoder)

    core_queue.setEncoder( new MessageStreamEncoderAdapter( encoder ) );