Class GridIoManager
- java.lang.Object
-
- org.apache.ignite.internal.managers.GridManagerAdapter<CommunicationSpi<Serializable>>
-
- org.apache.ignite.internal.managers.communication.GridIoManager
-
- All Implemented Interfaces:
GridComponent,GridManager
public class GridIoManager extends GridManagerAdapter<CommunicationSpi<Serializable>>
This class represents the internal grid communication (input and output) manager which is placed as a layer of indirection between theIgniteKernalandCommunicationSpi. The IO manager is responsible for controlling CommunicationSPI which in turn is responsible for exchanging data between Ignite nodes.Data exchanging
Communication manager provides a rich API for data exchanging between a pair of cluster nodes. Two types of communication Message-based communication and File-based communication are available. Each of them support sending data to an arbitrary topic on the remote node (see
GridTopicfor an additional information about Ignite topics).Message-based communication
MessageandGridTopicare used to provide a topic-based messaging protocol between cluster nodes. All of messages used for data exchanging can be devided into two general types: internal and user messages.Internal message communication is used by Ignite Kernal. Please, refer to appropriate methods below:
sendToGridTopic(ClusterNode, GridTopic, Message, byte)sendOrderedMessage(ClusterNode, Object, Message, byte, long, boolean)addMessageListener(Object, GridMessageListener)
User message communication is directly exposed to the
IgniteMessagingAPI and provides for user functionality for topic-based message exchanging among nodes within the cluser defined byClusterGroup. Please, refer to appropriate methods below:sendToCustomTopic(ClusterNode, Object, Message, byte)addUserMessageListener(Object, IgniteBiPredicate, UUID)
File-based communication
Sending or receiving binary data (represented by a File) over a SocketChannel is only possible when the build-in
TcpCommunicationSpiimplementation of Communication SPI is used.It is possible to receive a set of files on a particular topic (any of
GridTopic) on the remote node. A transmission handler for desired topic must be registered prior to opening transmission sender to it. Methods below are used to register handlers and open new transmissions:addTransmissionHandler(Object, TransmissionHandler)removeTransmissionHandler(Object)openTransmissionSender(UUID, Object)
Each transmission sender opens a new transmission session to remote node prior to sending files over it. (see description of
GridIoManager.TransmissionSenderfor details). TheGridIoManager.TransmissionSenderwill send all files within single session syncronously one by one.NOTE. It is important to call close() method or use try-with-resource statement to release all resources once you've done with the transmission session. This ensures that all resources are released on remote node in a proper way (i.e. transmission handlers are closed).
- See Also:
TcpCommunicationSpi,IgniteMessaging,TransmissionHandler
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classGridIoManager.TransmissionSenderСlass represents an implementation of transmission file writer.-
Nested classes/interfaces inherited from interface org.apache.ignite.internal.GridComponent
GridComponent.DiscoveryDataExchangeType
-
-
Field Summary
Fields Modifier and Type Field Description static StringCOMM_METRICSIo communication metrics registry name.static MessageFactoryProvider[]EMPTYEmpty array of message factories.static intMAX_CLOSED_TOPICSMax closed topics to store.static StringOUTBOUND_MSG_QUEUE_CNTOutbound message queue size metric name.static StringRCVD_BYTES_CNTReceived bytes count metric name.static StringRCVD_MSGS_CNTReceived messages count metric name.static StringSENT_BYTES_CNTSent bytes count metric name.static StringSENT_MSG_CNTSent messages count metric name.-
Fields inherited from class org.apache.ignite.internal.managers.GridManagerAdapter
ctx, log
-
-
Constructor Summary
Constructors Constructor Description GridIoManager(GridKernalContext ctx)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddDisconnectListener(GridDisconnectListener lsnr)voidaddMessageListener(Object topic, GridMessageListener lsnr)voidaddMessageListener(GridTopic topic, GridMessageListener lsnr)voidaddTransmissionHandler(Object topic, TransmissionHandler hnd)voidaddUserMessageListener(@Nullable Object topic, @Nullable IgniteBiPredicate<UUID,?> p)voidaddUserMessageListener(@Nullable Object topic, @Nullable IgniteBiPredicate<UUID,?> p, UUID nodeId)booleancheckNodeLeft(UUID nodeId, IgniteCheckedException sndErr, boolean ping)static @Nullable BytecurrentPolicy()voiddumpStats()Dumps SPI stats to diagnostic logs in case TcpCommunicationSpi is used, no-op otherwise.MessageFormatterformatter()intgetOutboundMessagesQueueSize()Gets outbound messages queue size.longgetReceivedBytesCount()Gets received bytes count.intgetReceivedMessagesCount()Gets received messages count.longgetSentBytesCount()Gets sent bytes count.intgetSentMessagesCount()Gets sent messages count.MessageFactorymessageFactory()voidonKernalStart0()voidonKernalStop0(boolean cancel)IgniteInternalFuture<?>onReconnected(boolean clusterRestarted)Client reconnected callback.GridIoManager.TransmissionSenderopenTransmissionSender(UUID remoteId, Object topic)voidprintMemoryStats()Prints memory statistics (sizes of internal structures, etc.).voidremoveDisconnectListener(GridDisconnectListener lsnr)booleanremoveMessageListener(Object topic)booleanremoveMessageListener(Object topic, @Nullable GridMessageListener lsnr)booleanremoveMessageListener(GridTopic topic)booleanremoveMessageListener(GridTopic topic, @Nullable GridMessageListener lsnr)voidremoveTransmissionHandler(Object topic)voidremoveUserMessageListener(@Nullable Object topic, IgniteBiPredicate<UUID,?> p)voidresetMetrics()Resets metrics for this manager.voidrunIoTest(long warmup, long duration, int threads, long latencyLimit, int rangesCnt, int payLoadSize, boolean procFromNioThread, List<ClusterNode> nodes)voidsendGeneric(ClusterNode node, Object topic, int topicOrd, Message msg, byte plc)IgniteInternalFuturesendIoTest(List<ClusterNode> nodes, byte[] payload, boolean procFromNioThread)IgniteInternalFuture<List<IgniteIoTestMessage>>sendIoTest(ClusterNode node, byte[] payload, boolean procFromNioThread)voidsendOrderedMessage(ClusterNode node, Object topic, Message msg, byte plc, long timeout, boolean skipOnTimeout)voidsendOrderedMessage(ClusterNode node, Object topic, Message msg, byte plc, long timeout, boolean skipOnTimeout, IgniteInClosure<IgniteException> ackC)voidsendToCustomTopic(UUID nodeId, Object topic, Message msg, byte plc)voidsendToCustomTopic(ClusterNode node, Object topic, Message msg, byte plc)voidsendToGridTopic(Collection<? extends ClusterNode> nodes, GridTopic topic, Message msg, byte plc)voidsendToGridTopic(UUID nodeId, GridTopic topic, Message msg, byte plc)voidsendToGridTopic(ClusterNode node, GridTopic topic, Message msg, byte plc)voidsendToGridTopic(ClusterNode node, GridTopic topic, Message msg, byte plc, Span span)voidsendToGridTopic(ClusterNode node, GridTopic topic, Message msg, byte plc, IgniteInClosure<IgniteException> ackC)voidsendUserMessage(Collection<? extends ClusterNode> nodes, Object msg, @Nullable Object topic, boolean ordered, long timeout, boolean async)Sends a peer deployable user message.voidstart()Starts grid component.voidstop(boolean cancel)Stops grid component.-
Methods inherited from class org.apache.ignite.internal.managers.GridManagerAdapter
assertParameter, collectGridNodeData, collectJoiningNodeData, discoveryDataType, enabled, getSpi, getSpi, getSpis, inject, onAfterSpiStart, onBeforeSpiStart, onDisconnected, onGridDataReceived, onJoiningNodeDataReceived, onKernalStart, onKernalStop, startInfo, startSpi, stopInfo, stopSpi, toString, validateNode, validateNode
-
-
-
-
Field Detail
-
COMM_METRICS
public static final String COMM_METRICS
Io communication metrics registry name.
-
OUTBOUND_MSG_QUEUE_CNT
public static final String OUTBOUND_MSG_QUEUE_CNT
Outbound message queue size metric name.- See Also:
- Constant Field Values
-
SENT_MSG_CNT
public static final String SENT_MSG_CNT
Sent messages count metric name.- See Also:
- Constant Field Values
-
SENT_BYTES_CNT
public static final String SENT_BYTES_CNT
Sent bytes count metric name.- See Also:
- Constant Field Values
-
RCVD_MSGS_CNT
public static final String RCVD_MSGS_CNT
Received messages count metric name.- See Also:
- Constant Field Values
-
RCVD_BYTES_CNT
public static final String RCVD_BYTES_CNT
Received bytes count metric name.- See Also:
- Constant Field Values
-
EMPTY
public static final MessageFactoryProvider[] EMPTY
Empty array of message factories.
-
MAX_CLOSED_TOPICS
public static final int MAX_CLOSED_TOPICS
Max closed topics to store.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
GridIoManager
public GridIoManager(GridKernalContext ctx)
- Parameters:
ctx- Grid kernal context.
-
-
Method Detail
-
messageFactory
public MessageFactory messageFactory()
- Returns:
- Message factory.
-
formatter
public MessageFormatter formatter()
- Returns:
- Message writer factory.
-
resetMetrics
public void resetMetrics()
Resets metrics for this manager.
-
start
public void start() throws IgniteCheckedExceptionStarts grid component.- Throws:
IgniteCheckedException- Throws in case of any errors.
-
onReconnected
public IgniteInternalFuture<?> onReconnected(boolean clusterRestarted) throws IgniteCheckedException
Client reconnected callback.- Specified by:
onReconnectedin interfaceGridComponent- Overrides:
onReconnectedin classGridManagerAdapter<CommunicationSpi<Serializable>>- Parameters:
clusterRestarted- Cluster restarted flag.- Returns:
- Future to wait before completing reconnect future.
- Throws:
IgniteCheckedException- If failed.
-
sendIoTest
public IgniteInternalFuture sendIoTest(List<ClusterNode> nodes, byte[] payload, boolean procFromNioThread)
- Parameters:
nodes- Nodes.payload- Payload.procFromNioThread- Iftruemessage is processed from NIO thread.- Returns:
- Response future.
-
sendIoTest
public IgniteInternalFuture<List<IgniteIoTestMessage>> sendIoTest(ClusterNode node, byte[] payload, boolean procFromNioThread)
- Parameters:
node- Node.payload- Payload.procFromNioThread- Iftruemessage is processed from NIO thread.- Returns:
- Response future.
-
runIoTest
public void runIoTest(long warmup, long duration, int threads, long latencyLimit, int rangesCnt, int payLoadSize, boolean procFromNioThread, List<ClusterNode> nodes)- Parameters:
warmup- Warmup duration in milliseconds.duration- Test duration in milliseconds.threads- Thread count.latencyLimit- Max latency in nanoseconds.rangesCnt- Ranges count in resulting histogram.payLoadSize- Payload size in bytes.procFromNioThread-Trueto process requests in NIO threads.nodes- Nodes participating in test.
-
onKernalStart0
public void onKernalStart0() throws IgniteCheckedException- Overrides:
onKernalStart0in classGridManagerAdapter<CommunicationSpi<Serializable>>- Throws:
IgniteCheckedException- If failed.
-
onKernalStop0
public void onKernalStop0(boolean cancel)
- Overrides:
onKernalStop0in classGridManagerAdapter<CommunicationSpi<Serializable>>- Parameters:
cancel- Cancel flag.
-
stop
public void stop(boolean cancel) throws IgniteCheckedExceptionStops grid component.- Parameters:
cancel- Iftrue, then all ongoing tasks or jobs for relevant components need to be cancelled.- Throws:
IgniteCheckedException- Thrown in case of any errors.
-
currentPolicy
@Nullable public static @Nullable Byte currentPolicy()
- Returns:
- Current IO policy
-
checkNodeLeft
public boolean checkNodeLeft(UUID nodeId, IgniteCheckedException sndErr, boolean ping) throws IgniteClientDisconnectedCheckedException
- Parameters:
nodeId- Node ID.sndErr- Send error.ping-Trueif try ping node.- Returns:
Trueif node left.- Throws:
IgniteClientDisconnectedCheckedException- If ping failed.
-
openTransmissionSender
public GridIoManager.TransmissionSender openTransmissionSender(UUID remoteId, Object topic)
- Parameters:
remoteId- The remote node to connect to.topic- The remote topic to connect to.- Returns:
- The channel instance to communicate with remote.
-
addTransmissionHandler
public void addTransmissionHandler(Object topic, TransmissionHandler hnd)
- Parameters:
topic- TheGridTopicto register handler to.hnd- Handler which will handle file upload requests.
-
removeTransmissionHandler
public void removeTransmissionHandler(Object topic)
- Parameters:
topic- The topic to erase handler from.
-
sendToCustomTopic
public void sendToCustomTopic(UUID nodeId, Object topic, Message msg, byte plc) throws IgniteCheckedException
- Parameters:
nodeId- Id of destination node.topic- Topic to send the message to.msg- Message to send.plc- Type of processing.- Throws:
IgniteCheckedException- Thrown in case of any errors.
-
sendToGridTopic
public void sendToGridTopic(UUID nodeId, GridTopic topic, Message msg, byte plc) throws IgniteCheckedException
- Parameters:
nodeId- Id of destination node.topic- Topic to send the message to.msg- Message to send.plc- Type of processing.- Throws:
IgniteCheckedException- Thrown in case of any errors.
-
sendToGridTopic
public void sendToGridTopic(ClusterNode node, GridTopic topic, Message msg, byte plc) throws IgniteCheckedException
- Parameters:
node- Destination node.topic- Topic to send the message to.msg- Message to send.plc- Type of processing.- Throws:
IgniteCheckedException- Thrown in case of any errors.
-
sendToCustomTopic
public void sendToCustomTopic(ClusterNode node, Object topic, Message msg, byte plc) throws IgniteCheckedException
- Parameters:
node- Destination node.topic- Topic to send the message to.msg- Message to send.plc- Type of processing.- Throws:
IgniteCheckedException- Thrown in case of any errors.
-
sendToGridTopic
public void sendToGridTopic(ClusterNode node, GridTopic topic, Message msg, byte plc, Span span) throws IgniteCheckedException
- Parameters:
node- Destination node.topic- Topic to send the message to.msg- Message to send.plc- Type of processing.span- Current span for tracing.- Throws:
IgniteCheckedException- Thrown in case of any errors.
-
sendGeneric
public void sendGeneric(ClusterNode node, Object topic, int topicOrd, Message msg, byte plc) throws IgniteCheckedException
- Parameters:
node- Destination node.topic- Topic to send the message to.topicOrd- GridTopic enumeration ordinal.msg- Message to send.plc- Type of processing. *- Throws:
IgniteCheckedException- Thrown in case of any errors.
-
sendOrderedMessage
public void sendOrderedMessage(ClusterNode node, Object topic, Message msg, byte plc, long timeout, boolean skipOnTimeout) throws IgniteCheckedException
- Parameters:
node- Destination node.topic- Topic to send the message to.msg- Message to send.plc- Type of processing.timeout- Timeout to keep a message on receiving queue.skipOnTimeout- Whether message can be skipped on timeout.- Throws:
IgniteCheckedException- Thrown in case of any errors.
-
sendToGridTopic
public void sendToGridTopic(ClusterNode node, GridTopic topic, Message msg, byte plc, IgniteInClosure<IgniteException> ackC) throws IgniteCheckedException
- Parameters:
node- Destination nodes.topic- Topic to send the message to.msg- Message to send.plc- Type of processing.ackC- Ack closure.- Throws:
IgniteCheckedException- Thrown in case of any errors.
-
sendToGridTopic
public void sendToGridTopic(Collection<? extends ClusterNode> nodes, GridTopic topic, Message msg, byte plc) throws IgniteCheckedException
- Parameters:
nodes- Destination nodes.topic- Topic to send the message to.msg- Message to send.plc- Type of processing.- Throws:
IgniteCheckedException- Thrown in case of any errors.
-
sendOrderedMessage
public void sendOrderedMessage(ClusterNode node, Object topic, Message msg, byte plc, long timeout, boolean skipOnTimeout, IgniteInClosure<IgniteException> ackC) throws IgniteCheckedException
- Parameters:
node- Destination node.topic- Topic to send the message to.msg- Message to send.plc- Type of processing.timeout- Timeout to keep a message on receiving queue.skipOnTimeout- Whether message can be skipped on timeout.ackC- Ack closure.- Throws:
IgniteCheckedException- Thrown in case of any errors.
-
sendUserMessage
public void sendUserMessage(Collection<? extends ClusterNode> nodes, Object msg, @Nullable @Nullable Object topic, boolean ordered, long timeout, boolean async) throws IgniteCheckedException
Sends a peer deployable user message.- Parameters:
nodes- Destination nodes.msg- Message to send.topic- Message topic to use.ordered- Is message ordered?timeout- Message timeout in milliseconds for ordered messages.async- Async flag.- Throws:
IgniteCheckedException- Thrown in case of any errors.
-
addUserMessageListener
public void addUserMessageListener(@Nullable @Nullable Object topic, @Nullable @Nullable IgniteBiPredicate<UUID,?> p)
-
addUserMessageListener
public void addUserMessageListener(@Nullable @Nullable Object topic, @Nullable @Nullable IgniteBiPredicate<UUID,?> p, UUID nodeId)- Parameters:
topic- Topic to subscribe to.p- Message predicate.
-
removeUserMessageListener
public void removeUserMessageListener(@Nullable @Nullable Object topic, IgniteBiPredicate<UUID,?> p)- Parameters:
topic- Topic to unsubscribe from.p- Message predicate.
-
addMessageListener
public void addMessageListener(GridTopic topic, GridMessageListener lsnr)
- Parameters:
topic- Listener's topic.lsnr- Listener to add.
-
addDisconnectListener
public void addDisconnectListener(GridDisconnectListener lsnr)
- Parameters:
lsnr- Listener to add.
-
removeDisconnectListener
public void removeDisconnectListener(GridDisconnectListener lsnr)
- Parameters:
lsnr- Listener to remove.
-
addMessageListener
public void addMessageListener(Object topic, GridMessageListener lsnr)
- Parameters:
topic- Listener's topic.lsnr- Listener to add.
-
removeMessageListener
public boolean removeMessageListener(GridTopic topic)
- Parameters:
topic- Message topic.- Returns:
- Whether or not listener was indeed removed.
-
removeMessageListener
public boolean removeMessageListener(Object topic)
- Parameters:
topic- Message topic.- Returns:
- Whether or not listener was indeed removed.
-
removeMessageListener
public boolean removeMessageListener(GridTopic topic, @Nullable @Nullable GridMessageListener lsnr)
- Parameters:
topic- Listener's topic.lsnr- Listener to remove.- Returns:
- Whether or not the lsnr was removed.
-
removeMessageListener
public boolean removeMessageListener(Object topic, @Nullable @Nullable GridMessageListener lsnr)
- Parameters:
topic- Listener's topic.lsnr- Listener to remove.- Returns:
- Whether or not the lsnr was removed.
-
getSentMessagesCount
public int getSentMessagesCount()
Gets sent messages count.- Returns:
- Sent messages count.
-
getSentBytesCount
public long getSentBytesCount()
Gets sent bytes count.- Returns:
- Sent bytes count.
-
getReceivedMessagesCount
public int getReceivedMessagesCount()
Gets received messages count.- Returns:
- Received messages count.
-
getReceivedBytesCount
public long getReceivedBytesCount()
Gets received bytes count.- Returns:
- Received bytes count.
-
getOutboundMessagesQueueSize
public int getOutboundMessagesQueueSize()
Gets outbound messages queue size.- Returns:
- Outbound messages queue size.
-
dumpStats
public void dumpStats()
Dumps SPI stats to diagnostic logs in case TcpCommunicationSpi is used, no-op otherwise.
-
printMemoryStats
public void printMemoryStats()
Prints memory statistics (sizes of internal structures, etc.). NOTE: this method is for testing and profiling purposes only.- Specified by:
printMemoryStatsin interfaceGridComponent- Overrides:
printMemoryStatsin classGridManagerAdapter<CommunicationSpi<Serializable>>
-
-