planet.commonapi.factory
Interface RouteMessagePool

All Superinterfaces:
java.io.Serializable
All Known Implementing Classes:
RouteMessagePoolImpl

public interface RouteMessagePool
extends java.io.Serializable

Shows a pool of RouteMessage, reusing any existing RouteMessage as possible. If it is invoked a getMessage(..) method and no RouteMessage is available, a new instance is built and returned with the specified values.

When a RouteMessage is free with the freeMessage(RouteMessage) method, you must ensure that there are not references of the specified RouteMessage into the current whole network.

For a correct RouteMessagePool operation, the addition of built and reused RouteMessage should be the same as the free ones.

Author:
Jordi Pujol 06-jul-2005

Method Summary
 void freeMessage(RouteMessage msg)
          To free a message only pushing it to be reused.
 int getBuiltRouteMessages()
          Gets the total number of built RouteMessages.
 int getFreeRouteMessages()
          Gets the total number of free RouteMessages.
 RouteMessage getMessage(java.lang.String key, NodeHandle from, NodeHandle to, int type, int mode)
          Return a RouteMessage with the specified values, setting the nextHop field with the to value.
 RouteMessage getMessage(java.lang.String key, NodeHandle from, NodeHandle to, NodeHandle nextHop, int type, int mode, Message msg, java.lang.String appId)
          Builds a new instance of RouteMessage with these specified values.
 int getReusedRouteMessages()
          Gets the total number of reused RouteMessages.
 

Method Detail

getMessage

public RouteMessage getMessage(java.lang.String key,
                               NodeHandle from,
                               NodeHandle to,
                               int type,
                               int mode)
                        throws InitializationException
Return a RouteMessage with the specified values, setting the nextHop field with the to value.

Parameters:
key - Identification of communication.
from - Source node.
to - Destination node.
type - Type of message.
mode - Mode of message.
Returns:
A RouteMessage with the specified values.
Throws:
InitializationException - if occurs any error during the building process.

getMessage

public RouteMessage getMessage(java.lang.String key,
                               NodeHandle from,
                               NodeHandle to,
                               NodeHandle nextHop,
                               int type,
                               int mode,
                               Message msg,
                               java.lang.String appId)
                        throws InitializationException
Builds a new instance of RouteMessage with these specified values.

Parameters:
key - Key of the communication.
from - Source node.
to - Destination node.
nextHop - Identifies the next hop node.
type - Type of the message.
mode - Mode of the message.
msg - Message to be send in this RouteMessage.
appId - Application that has build this msg.
Returns:
A RouteMessage with all specified values.
Throws:
InitializationException - if cannot build a new instance of the RouteMessage.

freeMessage

public void freeMessage(RouteMessage msg)
To free a message only pushing it to be reused. When this method is invoked, you must ensure that this msg never again will be used with the actual values, and there are not references to this msg into the current whole network.

Parameters:
msg - The RouteMessage to be released.

getBuiltRouteMessages

public int getBuiltRouteMessages()
Gets the total number of built RouteMessages.

Returns:
The total number of built RouteMessages.

getReusedRouteMessages

public int getReusedRouteMessages()
Gets the total number of reused RouteMessages.

Returns:
The total number of reused RouteMessages.

getFreeRouteMessages

public int getFreeRouteMessages()
Gets the total number of free RouteMessages.

Returns:
The total number of free RouteMessages.