/** * Update message type map. * * @param msg Message. */ private void updateMessageTypeMap(Message msg) { short typeId = msg.directType(); Map<Short, String> msgTypMap0 = msgTypMap; if (msgTypMap0 == null || !msgTypMap0.containsKey(typeId)) { synchronized (msgTypMapMux) { if (msgTypMap == null) { msgTypMap0 = new HashMap<>(); msgTypMap0.put(typeId, msg.getClass().getName()); msgTypMap = msgTypMap0; } else { if (!msgTypMap.containsKey(typeId)) { msgTypMap0 = new HashMap<>(msgTypMap); msgTypMap0.put(typeId, msg.getClass().getName()); msgTypMap = msgTypMap0; } } } } }
/** * Fully writes communication message to provided stream. * * @param msg Message. * @param out Stream to write to. * @param buf Byte buffer that will be passed to {@link Message#writeTo(ByteBuffer, MessageWriter)} method. * @param writer Message writer. * @return Number of written bytes. * @throws IOException In case of error. */ public static int writeMessageFully(Message msg, OutputStream out, ByteBuffer buf, MessageWriter writer) throws IOException { assert msg != null; assert out != null; assert buf != null; assert buf.hasArray(); if (writer != null) writer.setCurrentWriteClass(msg.getClass()); boolean finished = false; int cnt = 0; while (!finished) { finished = msg.writeTo(buf, writer); out.write(buf.array(), 0, buf.position()); cnt += buf.position(); buf.clear(); } return cnt; }
/** {@inheritDoc} */ @Override public void onAckReceived() { msg.onAckReceived(); }
/** * @param m Message. */ private void doTestMarshal(Message m) { ByteBuffer buf = ByteBuffer.allocate(8 * 1024); m.writeTo(buf, writer(proto)); buf.flip(); byte b0 = buf.get(); byte b1 = buf.get(); short type = (short)((b1 & 0xFF) << 8 | b0 & 0xFF); assertEquals(m.directType(), type); GridIoMessageFactory msgFactory = new GridIoMessageFactory(null); Message mx = msgFactory.create(type); mx.readFrom(buf, reader(msgFactory, proto)); assertEquals(m, mx); } }
lastFinished = msg.readFrom(buf, reader);
lastFinished = msg.readFrom(buf, reader);
/** * Collects statistics for message received by SPI. * * @param msg Received message. * @param nodeId Sender node id. */ private void onMessageReceived(Message msg, UUID nodeId) { rcvdMsgsCnt++; LongHolder cntByType = F.addIfAbsent(rcvdMsgsCntByType, msg.directType(), HOLDER_FACTORY); LongHolder cntByNode = F.addIfAbsent(rcvdMsgsCntByNode, nodeId, HOLDER_FACTORY); assert cntByType != null; assert cntByNode != null; cntByType.increment(); cntByNode.increment(); }
/** {@inheritDoc} */ @Override public void writeMessage(Message msg, MessageWriter writer) { if (msg != null) { if (buf.hasRemaining()) { try { writer.beforeInnerMessageWrite(); writer.setCurrentWriteClass(msg.getClass()); lastFinished = msg.writeTo(buf, writer); } finally { writer.afterInnerMessageWrite(lastFinished); } } else lastFinished = false; } else writeShort(Short.MIN_VALUE); }
reader.setCurrentReadClass(msg.getClass()); finished = msg.readFrom(buf, reader);
/** {@inheritDoc} */ @Override public void onAckReceived() { assert msg instanceof Message; ((Message)msg).onAckReceived(); }
/** * Collects statistics for message sent by SPI. * * @param msg Sent message. * @param nodeId Receiver node id. */ private void onMessageSent(Message msg, UUID nodeId) { sentMsgsCnt++; LongHolder cntByType = F.addIfAbsent(sentMsgsCntByType, msg.directType(), HOLDER_FACTORY); LongHolder cntByNode = F.addIfAbsent(sentMsgsCntByNode, nodeId, HOLDER_FACTORY); assert cntByType != null; assert cntByNode != null; cntByType.increment(); cntByNode.increment(); }
/** {@inheritDoc} */ @Override public void writeMessage(Message msg, MessageWriter writer) { if (msg != null) { if (buf.hasRemaining()) { try { writer.beforeInnerMessageWrite(); writer.setCurrentWriteClass(msg.getClass()); lastFinished = msg.writeTo(buf, writer); } finally { writer.afterInnerMessageWrite(lastFinished); } } else lastFinished = false; } else writeShort(Short.MIN_VALUE); }
lastFinished = msg.readFrom(buf, reader);
/** {@inheritDoc} */ @Override public void onAckReceived() { assert msg instanceof Message : msg; ((Message)msg).onAckReceived(); }
/** * Update message type map. * * @param msg Message. */ private void updateMessageTypeMap(Message msg) { short typeId = msg.directType(); Map<Short, String> msgTypMap0 = msgTypMap; if (msgTypMap0 == null || !msgTypMap0.containsKey(typeId)) { synchronized (msgTypMapMux) { if (msgTypMap == null) { msgTypMap0 = new HashMap<>(); msgTypMap0.put(typeId, msg.getClass().getName()); msgTypMap = msgTypMap0; } else { if (!msgTypMap.containsKey(typeId)) { msgTypMap0 = new HashMap<>(msgTypMap); msgTypMap0.put(typeId, msg.getClass().getName()); msgTypMap = msgTypMap0; } } } } }
/** * Fully writes communication message to provided stream. * * @param msg Message. * @param out Stream to write to. * @param buf Byte buffer that will be passed to {@link Message#writeTo(ByteBuffer, MessageWriter)} method. * @param writer Message writer. * @return Number of written bytes. * @throws IOException In case of error. */ public static int writeMessageFully(Message msg, OutputStream out, ByteBuffer buf, MessageWriter writer) throws IOException { assert msg != null; assert out != null; assert buf != null; assert buf.hasArray(); if (writer != null) writer.setCurrentWriteClass(msg.getClass()); boolean finished = false; int cnt = 0; while (!finished) { finished = msg.writeTo(buf, writer); out.write(buf.array(), 0, buf.position()); cnt += buf.position(); buf.clear(); } return cnt; }
lastFinished = msg.readFrom(buf, reader);
/** {@inheritDoc} */ @Override public void onAckReceived() { assert msg instanceof Message : msg; ((Message)msg).onAckReceived(); }
/** * Collects statistics for message sent by SPI. * * @param msg Sent message. * @param nodeId Receiver node id. */ private void onMessageSent(Message msg, UUID nodeId) { sentMsgsCnt++; LongHolder cntByType = F.addIfAbsent(sentMsgsCntByType, msg.directType(), HOLDER_FACTORY); LongHolder cntByNode = F.addIfAbsent(sentMsgsCntByNode, nodeId, HOLDER_FACTORY); assert cntByType != null; assert cntByNode != null; cntByType.increment(); cntByNode.increment(); }
/** {@inheritDoc} */ @Override public void writeMessage(Message msg, MessageWriter writer) { if (msg != null) { if (buf.hasRemaining()) { try { writer.beforeInnerMessageWrite(); writer.setCurrentWriteClass(msg.getClass()); lastFinished = msg.writeTo(buf, writer); } finally { writer.afterInnerMessageWrite(lastFinished); } } else lastFinished = false; } else writeShort(Short.MIN_VALUE); }