planet.generic.commonapi.factory
Class RouteMessagePoolImpl

java.lang.Object
  extended byplanet.generic.commonapi.factory.RouteMessagePoolImpl
All Implemented Interfaces:
RouteMessagePool, java.io.Serializable

public class RouteMessagePoolImpl
extends java.lang.Object
implements RouteMessagePool

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.

This implementation and the released overlays in this distribution accomplish the RouteMessagePool operation: the addition of built and reused RouteMessage should be the same as the free ones.

Author:
Jordi Pujol 06-jul-2005
See Also:
Serialized Form

Field Summary
protected  java.lang.Class routeMessage
          Class reference of the current RouteMessage implementation.
 
Constructor Summary
RouteMessagePoolImpl()
          Builds a RouteMessagePool.
 
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

routeMessage

protected java.lang.Class routeMessage
Class reference of the current RouteMessage implementation.

Constructor Detail

RouteMessagePoolImpl

public RouteMessagePoolImpl()
Builds a RouteMessagePool.

Method Detail

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.

Specified by:
freeMessage in interface RouteMessagePool
Parameters:
msg - The RouteMessage to be released.
See Also:
RouteMessagePool.freeMessage(planet.commonapi.RouteMessage)

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.

Specified by:
getMessage in interface RouteMessagePool
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.
See Also:
RouteMessagePool.getMessage(java.lang.String, planet.commonapi.NodeHandle, planet.commonapi.NodeHandle, int, int)

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.

Specified by:
getMessage in interface RouteMessagePool
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.
See Also:
RouteMessagePool.getMessage(String, NodeHandle, NodeHandle, NodeHandle, int, int, Message, String)

getBuiltRouteMessages

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

Specified by:
getBuiltRouteMessages in interface RouteMessagePool
Returns:
The total number of built RouteMessages.
See Also:
RouteMessagePool.getBuiltRouteMessages()

getFreeRouteMessages

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

Specified by:
getFreeRouteMessages in interface RouteMessagePool
Returns:
The total number of free RouteMessages.
See Also:
RouteMessagePool.getFreeRouteMessages()

getReusedRouteMessages

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

Specified by:
getReusedRouteMessages in interface RouteMessagePool
Returns:
The total number of reused RouteMessages.
See Also:
RouteMessagePool.getReusedRouteMessages()