LimeWire Consolidated API

com.limegroup.gnutella.messages
Interface MessageFactory

All Known Implementing Classes:
MessageFactoryImpl

public interface MessageFactory

A factory for creating Gnutella messages. MessageFactory delegates the parsing of specific messages to a MessageParser. MessageParsers can be installed using setParser(byte, com.limegroup.gnutella.messages.MessageFactory.MessageParser). When reading a message from a stream, various optional parameters can be provided. In all cases, a Message.Network is required to know which Network the Message was read from. Optional parameters are softMax, which can be used to limit the maximum number of hops a message should travel, headerBuf which can be used as an optimization to reduce byte[] allocations, and addr which can be used to know what host this message was read from.


Nested Class Summary
static interface MessageFactory.MessageParser
          The interface for custom MessageParser(s)
 
Method Summary
 Message createMessage(byte[] header, byte[] payload, Message.Network network, byte softMax, SocketAddress addr)
          Creates a message based on the header & payload.
 MessageFactory.MessageParser getParser(byte functionId)
          Returns a MessageParser for the provided functionId or null if no such MessageParser is registered.
 Message read(InputStream in, Message.Network network)
           
 Message read(InputStream in, Message.Network network, byte softMax)
           
 Message read(InputStream in, Message.Network network, byte[] headerBuf, byte softMax)
           
 Message read(InputStream in, Message.Network network, byte[] headerBuf, byte softMax, SocketAddress addr)
           
 Message read(InputStream in, Message.Network network, byte[] headerBuf, SocketAddress addr)
          Reads a message using the specified buffer & network and the default soft max.
 void setParser(byte functionId, MessageFactory.MessageParser parser)
          Registers a MessageParser under the provided functionId.
 

Method Detail

setParser

void setParser(byte functionId,
               MessageFactory.MessageParser parser)
Registers a MessageParser under the provided functionId.

Parameters:
functionId - the ID of the function (MessageParser)
parser - the MessageParser

getParser

MessageFactory.MessageParser getParser(byte functionId)
Returns a MessageParser for the provided functionId or null if no such MessageParser is registered.


read

Message read(InputStream in,
             Message.Network network,
             byte softMax)
             throws BadPacketException,
                    IOException
Parameters:
network - the network the message was read from.
Throws:
BadPacketException
IOException

read

Message read(InputStream in,
             Message.Network network)
             throws BadPacketException,
                    IOException
Throws:
BadPacketException
IOException

read

Message read(InputStream in,
             Message.Network network,
             byte[] headerBuf,
             byte softMax)
             throws BadPacketException,
                    IOException
Parameters:
network - the network the message was read from.
Throws:
BadPacketException
IOException

read

Message read(InputStream in,
             Message.Network network,
             byte[] headerBuf,
             SocketAddress addr)
             throws BadPacketException,
                    IOException
Reads a message using the specified buffer & network and the default soft max.

Throws:
BadPacketException
IOException

read

Message read(InputStream in,
             Message.Network network,
             byte[] headerBuf,
             byte softMax,
             SocketAddress addr)
             throws BadPacketException,
                    IOException
Parameters:
network - the network this was received from.
Throws:
BadPacketException
IOException

createMessage

Message createMessage(byte[] header,
                      byte[] payload,
                      Message.Network network,
                      byte softMax,
                      SocketAddress addr)
                      throws BadPacketException,
                             IOException
Creates a message based on the header & payload. The header, starting at headerOffset, MUST be >= 19 bytes. Additional headers bytes will be ignored and the byte[] will be discarded. (Note that the header is normally 23 bytes, but we don't need the last 4 here.) The payload MUST be a unique byte[] of that payload. Nothing can write into or change the byte[].

Throws:
BadPacketException
IOException

LimeWire Consolidated API

Copyright © 2009. All Rights Reserved.