FileDocCategorySizeDatePackage
MessageAdapter.javaAPI DocAzureus 3.0.3.44501Sun Mar 04 21:08:16 GMT 2007org.gudy.azureus2.pluginsimpl.local.messaging

MessageAdapter

public class MessageAdapter extends Object implements Message, com.aelitis.azureus.core.peermanager.messaging.Message

Fields Summary
private Message
plug_msg
private com.aelitis.azureus.core.peermanager.messaging.Message
core_msg
Constructors Summary
public MessageAdapter(Message plug_msg)

  
  
       
    this.plug_msg = plug_msg;
  
public MessageAdapter(com.aelitis.azureus.core.peermanager.messaging.Message core_msg)

    this.core_msg = core_msg;
  
Methods Summary
public Messagecreate(java.nio.ByteBuffer data)

    if( core_msg == null ) {
      return plug_msg.create( data );
    }
    
    try{
      return new MessageAdapter( core_msg.deserialize( new DirectByteBuffer( data ), (byte)1 ) );
    }
    catch( com.aelitis.azureus.core.peermanager.messaging.MessageException e ) {
      throw new MessageException( e.getMessage() );
    }
  
public com.aelitis.azureus.core.peermanager.messaging.Messagedeserialize(org.gudy.azureus2.core3.util.DirectByteBuffer data, byte version)

    if( plug_msg == null ) {
      return core_msg.deserialize( data, version );
    }
    
    try{
      return new MessageAdapter( plug_msg.create( data.getBuffer( DirectByteBuffer.SS_MSG ) ) );
    }
    catch( MessageException e ) {
      throw new com.aelitis.azureus.core.peermanager.messaging.MessageException( e.getMessage() );
    }
    finally {
      data.returnToPool();
    }
  
public voiddestroy()

    if( core_msg == null ) plug_msg.destroy();
    else core_msg.destroy();
  
public com.aelitis.azureus.core.peermanager.messaging.MessagegetCoreMessage()

  return core_msg;  
public org.gudy.azureus2.core3.util.DirectByteBuffer[]getData()

    if( plug_msg == null ) {
      return core_msg.getData();
    }
    
    ByteBuffer[] bbs = plug_msg.getPayload();
    DirectByteBuffer[] dbbs = new DirectByteBuffer[ bbs.length ];  //TODO cache it???
    for( int i=0; i < bbs.length; i++ ) {
      dbbs[i] = new DirectByteBuffer( bbs[i] );
    }
    return dbbs;
  
public java.lang.StringgetDescription()

    return core_msg == null ? plug_msg.getDescription() : core_msg.getDescription();
  
public java.lang.StringgetFeatureID()

  return ADVMessage.PLUGIN_MESSAGE_FEATURE_ID;  
public intgetFeatureSubID()

  return -1;  
public java.lang.StringgetID()

    return core_msg == null ? plug_msg.getID() : core_msg.getID();
  
public byte[]getIDBytes()

	    return core_msg == null ? plug_msg.getID().getBytes() : core_msg.getIDBytes();
	  
public java.nio.ByteBuffer[]getPayload()

    if( core_msg == null ) {
      return plug_msg.getPayload();
    }
    
    DirectByteBuffer[] dbbs = core_msg.getData();  
    ByteBuffer[] bbs = new ByteBuffer[ dbbs.length ];  //TODO cache it???
    for( int i=0; i < dbbs.length; i++ ) {
      bbs[i] = dbbs[i].getBuffer( DirectByteBuffer.SS_MSG );
    }
    return bbs;
  
public MessagegetPluginMessage()

  return plug_msg;  
public intgetType()

    return core_msg == null ? plug_msg.getType() : core_msg.getType();
  
public bytegetVersion()

	    return core_msg == null ? (byte)1 : core_msg.getVersion();