FileDocCategorySizeDatePackage
MessageManager.javaAPI DocAzureus 3.0.3.44187Sun Mar 04 21:08:16 GMT 2007com.aelitis.azureus.core.peermanager.messaging

MessageManager

public class MessageManager extends Object

Fields Summary
private static final MessageManager
instance
private final ByteArrayHashMap
message_map
private final List
messages
protected AEMonitor
this_mon
Constructors Summary
private MessageManager()

  
    
    /*nothing*/
  
Methods Summary
public MessagecreateMessage(byte[] id_bytes, DirectByteBuffer message_data, byte version)
Construct a new message instance from the given message information.

param
id of message
param
message_data payload
return
decoded/deserialized message
throws
MessageException if message creation failed

    
    Message message = (Message)message_map.get( id_bytes );
    
    if( message == null ) {
      throw new MessageException( "message id[" + new String( id_bytes) + "] not registered" );
    }
    
    return message.deserialize( message_data, version );    
  
public voidderegisterMessageType(Message message)
Remove registration of given message type from manager.

param
message type to remove

    try{  this_mon.enter();
     
      message_map.remove( message.getIDBytes() );
      
      messages.remove( message );
    }
    finally{  this_mon.exit();  }
  
public Message[]getRegisteredMessages()
Get a list of the registered messages.

return
messages

    return (Message[])messages.toArray( new Message[messages.size()] );
  
public static com.aelitis.azureus.core.peermanager.messaging.MessageManagergetSingleton()

  return instance;  
public voidinitialize()
Perform manager initialization.

    AZMessageFactory.init();  //register AZ message types
    BTMessageFactory.init();  //register BT message types
  
public MessagelookupMessage(java.lang.String id)
Lookup a registered message type via id and version.

param
id to look for
return
the default registered message instance if found, otherwise returns null if this message type is not registered

    return (Message)message_map.get( id.getBytes());
  
public MessagelookupMessage(byte[] id_bytes)

    return (Message)message_map.get( id_bytes );
  
public voidregisterMessageType(Message message)
Register the given message type with the manager for processing.

param
message instance to use for decoding
throws
MessageException if this message type has already been registered

  	try{
  		this_mon.enter();
	    
  		byte[]	id_bytes = message.getIDBytes();
  		 		
	    if( message_map.containsKey( id_bytes ) ) {
	      throw new MessageException( "message type [" +message.getID()+ "] already registered!" );
	    }
	    
	    message_map.put( id_bytes, message );
	    
	    messages.add( message );
  	}finally{
  		
  		this_mon.exit();
  	}