Dashboard > GridGain User Guide > Table Of Contents > Developers Guide > Communication SPI > GridTcpCommunicationSpi
GridTcpCommunicationSpi
Added by user-1-ds, last edited by morpheus on Feb 05, 2008  (view change)
Labels: 
(None)


Click on Javadoc link to open Javadoc documentation.

Package

org.gridgain.grid.spi.communication.tcp Javadoc

Description

GridTcpCommunicationSpi Javadoc is default communication SPI which uses TCP/IP protocol to communicate with other nodes.

To enable communication with other nodes, this SPI adds GridTcpCommuncationSpi.ATTR_ADDR Javadoc and GridTcpCommuncationSpi.ATTR_PORT Javadoc local node attributes. Messages to multiple nodes (see GridTcpCommuncationSpi.sendMessage(Collection<GridNode>, Serializable) Javadoc method) are sent concurrently. The upper limit of messages sent concurrently is set by GridTcpCommuncationSpi.setParallelSendCount(int) Javadoc method.

At startup, this SPI tries to start listening to local port specified by GridTcpCommuncationSpi.setLocalPort(int) Javadoc method. If local port is occupied, then SPI will automatically increment the port number until it can successfully bind for listening. GridTcpCommuncationSpi.setLocalPortRange(int) Javadoc configuration parameter controls maximum number of ports that SPI will try before it fails. Port range comes very handy when starting multiple grid nodes on the same machine or even in the same VM. In this case all nodes can be brought up without a single change in configuration.

Configuration

The following configuration parameters can be used to configure GridTcpCommuncationSpi

Setter Method Description Optional Default
setLocalAddress(String) Javadoc Sets local host address for socket binding. Yes Any available local IP address.
setLocalPort(int) Javadoc Sets local port for socket binding. Yes 47100 (specified in GridTcpCommunicationSpi.DFLT_PORT Javadoc )
setLocalPortRange(int) Javadoc Controls maximum number of local ports tried if all previously tried ports are occupied. Yes 10 (specified in GridTcpCommunicationSpi.DFLT_PORT_RANGE Javadoc )
setParallelSendCount(int) Javadoc Sets number of messages sent concurrently to remote nodes. Used in GridTcpCommuncationSpi.sendMessage(Collection<GridNode>, Serializable) to send message concurrently to remote nodes Yes 10 (specified in GridTcpCommunicationSpi.DFLT_PARALLEL_SEND_COUNT Javadoc )
setDirectBuffer(boolean) Javadoc Switches between using NIO direct and NIO heap allocation buffers. Although direct buffers perform better, in some cases (especially on Windows) they may cause JVM crashes. If that happens in your environment, set this property to false. Yes true

Examples

GridTcpCommunicationSpi is used by default and should be explicitly configured only if some SPI configuration parameters need to be overridden.

GridTcpCommunicationSpi commSpi = new GridTcpCommunicationSpi();

// Override local port.
commSpi.setLocalPort(4321);

GridConfigurationAdapter cfg = new GridConfigurationAdapter();
 
// Override default communication SPI.
cfg.setCommunicationSpi(commSpi);

// Start grid.
GridFactory.start(cfg);

or from Spring configuration file

<bean id="grid.custom.cfg" class="org.gridgain.grid.GridConfigurationAdapter" singleton="true">
     ...
     <property name="communicationSpi">
         <bean class="org.gridgain.grid.spi.communication.tcp.GridTcpCommunicationSpi">
             <!-- Override local port. -->
             <property name="localPort" value="4321"/>
         </bean>
     </property>
     ...
 </bean>


For more information about using Spring framework for configuration click here.

Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.10 Build:#528 Nov 29, 2006) - Bug/feature request - Contact Administrators