public MessageOut<HintMessage> createMessageOut() { return new MessageOut<>(MessagingService.Verb.HINT, this, serializer); }
/** * returns the appropriate connection based on message type. * returns null if a connection could not be established. */ OutboundTcpConnection getConnection(MessageOut msg) { if (Stage.GOSSIP == msg.getStage()) return gossipMessages; return msg.payloadSize(smallMessages.getTargetVersion()) > LARGE_MESSAGE_THRESHOLD ? largeMessages : smallMessages; }
/** don't drop a non-droppable message just because it's timestamp is expired */ boolean isTimedOut(long nowNanos) { long messageTimeoutNanos = TimeUnit.MILLISECONDS.toNanos(message.getTimeout()); return droppable && nowNanos - timestampNanos > messageTimeoutNanos; }
private void logErrorAndSendFailureResponse(String errorMessage, InetAddress to, int id) { logger.error(errorMessage); MessageOut reply = new MessageOut(MessagingService.Verb.INTERNAL_RESPONSE) .withParameter(MessagingService.FAILURE_RESPONSE_PARAM, MessagingService.ONE_BYTE); MessagingService.instance().sendReply(reply, id, to); } }
/** * Send a mutation message or a Paxos Commit to a given endpoint. This method specifies a callback * which is invoked with the actual response. * Also holds the message (only mutation messages) to determine if it * needs to trigger a hint (uses StorageProxy for that). * * @param message message to be sent. * @param to endpoint to which the message needs to be sent * @param handler callback interface which is used to pass the responses or * suggest that a timeout occurred to the invoker of the send(). * @return an reference to message id used to match with the result */ public int sendRR(MessageOut<?> message, InetAddress to, AbstractWriteResponseHandler<?> handler, boolean allowHints) { int id = addCallback(handler, message, to, message.getTimeout(), handler.consistencyLevel, allowHints); updateBackPressureOnSend(to, handler, message); sendOneWay(message.withParameter(FAILURE_CALLBACK_PARAM, ONE_BYTE), id, to); return id; }
/** * returns the appropriate connection based on message type. * returns null if a connection could not be established. */ OutboundTcpConnection getConnection(MessageOut msg) { Stage stage = msg.getStage(); return stage == Stage.REQUEST_RESPONSE || stage == Stage.INTERNAL_RESPONSE || stage == Stage.GOSSIP ? ackCon : cmdCon; }
private void writeInternal(MessageOut<?> message, int id, long timestamp) throws IOException { out.writeInt(MessagingService.PROTOCOL_MAGIC); if (targetVersion < MessagingService.VERSION_20) out.writeUTF(String.valueOf(id)); else out.writeInt(id); // int cast cuts off the high-order half of the timestamp, which we can assume remains // the same between now and when the recipient reconstructs it. out.writeInt((int) timestamp); message.serialize(out, targetVersion); }
/** * Send a non-mutation message to a given endpoint. This method specifies a callback * which is invoked with the actual response. * * @param message message to be sent. * @param to endpoint to which the message needs to be sent * @param cb callback interface which is used to pass the responses or * suggest that a timeout occurred to the invoker of the send(). * @param timeout the timeout used for expiration * @return an reference to message id used to match with the result */ public int sendRR(MessageOut message, InetAddress to, IAsyncCallback cb, long timeout, boolean failureCallback) { int id = addCallback(cb, message, to, timeout, failureCallback); sendOneWay(failureCallback ? message.withParameter(FAILURE_CALLBACK_PARAM, ONE_BYTE) : message, id, to); return id; }
public int serializedSize(int version) { int size = CompactEndpointSerializationHelper.serializedSize(from); size += TypeSizes.sizeof(verb.ordinal()); size += TypeSizes.sizeof(parameters.size()); for (Map.Entry<String, byte[]> entry : parameters.entrySet()) { size += TypeSizes.sizeof(entry.getKey()); size += TypeSizes.sizeof(entry.getValue().length); size += entry.getValue().length; } long longSize = payloadSize(version); assert longSize <= Integer.MAX_VALUE; // larger values are supported in sstables but not messages size += TypeSizes.sizeof((int) longSize); size += longSize; return size; }
rateLimiter.acquire(message.serializedSize(MessagingService.current_version)); Runnable callback = new Runnable()
private void logErrorAndSendFailureResponse(String errorMessage, InetAddress to, int id) { logger.error(errorMessage); MessageOut reply = new MessageOut(MessagingService.Verb.INTERNAL_RESPONSE) .withParameter(MessagingService.FAILURE_RESPONSE_PARAM, MessagingService.ONE_BYTE); MessagingService.instance().sendReply(reply, id, to); } }
/** * Send a mutation message or a Paxos Commit to a given endpoint. This method specifies a callback * which is invoked with the actual response. * Also holds the message (only mutation messages) to determine if it * needs to trigger a hint (uses StorageProxy for that). * * @param message message to be sent. * @param to endpoint to which the message needs to be sent * @param handler callback interface which is used to pass the responses or * suggest that a timeout occurred to the invoker of the send(). * @return an reference to message id used to match with the result */ public int sendRR(MessageOut<?> message, InetAddress to, AbstractWriteResponseHandler<?> handler, boolean allowHints) { int id = addCallback(handler, message, to, message.getTimeout(), handler.consistencyLevel, allowHints); updateBackPressureOnSend(to, handler, message); sendOneWay(message.withParameter(FAILURE_CALLBACK_PARAM, ONE_BYTE), id, to); return id; }
public String toString() { StringBuilder sbuf = new StringBuilder(); sbuf.append("TYPE:").append(getStage()).append(" VERB:").append(verb); return sbuf.toString(); }
private void writeInternal(MessageOut<?> message, int id, long timestamp) throws IOException { out.writeInt(MessagingService.PROTOCOL_MAGIC); if (targetVersion < MessagingService.VERSION_20) out.writeUTF(String.valueOf(id)); else out.writeInt(id); // int cast cuts off the high-order half of the timestamp, which we can assume remains // the same between now and when the recipient reconstructs it. out.writeInt((int) timestamp); message.serialize(out, targetVersion); }
/** * Send a non-mutation message to a given endpoint. This method specifies a callback * which is invoked with the actual response. * * @param message message to be sent. * @param to endpoint to which the message needs to be sent * @param cb callback interface which is used to pass the responses or * suggest that a timeout occurred to the invoker of the send(). * @param timeout the timeout used for expiration * @return an reference to message id used to match with the result */ public int sendRR(MessageOut message, InetAddress to, IAsyncCallback cb, long timeout, boolean failureCallback) { int id = addCallback(cb, message, to, timeout, failureCallback); updateBackPressureOnSend(to, cb, message); sendOneWay(failureCallback ? message.withParameter(FAILURE_CALLBACK_PARAM, ONE_BYTE) : message, id, to); return id; }
public int serializedSize(int version) { int size = CompactEndpointSerializationHelper.serializedSize(from); size += TypeSizes.sizeof(verb.ordinal()); size += TypeSizes.sizeof(parameters.size()); for (Map.Entry<String, byte[]> entry : parameters.entrySet()) { size += TypeSizes.sizeof(entry.getKey()); size += TypeSizes.sizeof(entry.getValue().length); size += entry.getValue().length; } long longSize = payloadSize(version); assert longSize <= Integer.MAX_VALUE; // larger values are supported in sstables but not messages size += TypeSizes.sizeof((int) longSize); size += longSize; return size; }
public MessageOut<CounterMutation> makeMutationMessage() { return new MessageOut<>(MessagingService.Verb.COUNTER_MUTATION, this, serializer); }
private void logErrorAndSendFailureResponse(String errorMessage, InetAddress to, int id) { logger.error(errorMessage); MessageOut reply = new MessageOut(MessagingService.Verb.INTERNAL_RESPONSE) .withParameter(MessagingService.FAILURE_RESPONSE_PARAM, MessagingService.ONE_BYTE); MessagingService.instance().sendReply(reply, id, to); } }
/** * Send a mutation message or a Paxos Commit to a given endpoint. This method specifies a callback * which is invoked with the actual response. * Also holds the message (only mutation messages) to determine if it * needs to trigger a hint (uses StorageProxy for that). * * @param message message to be sent. * @param to endpoint to which the message needs to be sent * @param handler callback interface which is used to pass the responses or * suggest that a timeout occurred to the invoker of the send(). * @return an reference to message id used to match with the result */ public int sendRR(MessageOut<?> message, InetAddress to, AbstractWriteResponseHandler<?> handler, boolean allowHints) { int id = addCallback(handler, message, to, message.getTimeout(), handler.consistencyLevel, allowHints); updateBackPressureOnSend(to, handler, message); sendOneWay(message.withParameter(FAILURE_CALLBACK_PARAM, ONE_BYTE), id, to); return id; }
/** don't drop a non-droppable message just because it's timestamp is expired */ boolean isTimedOut(long nowNanos) { long messageTimeoutNanos = TimeUnit.MILLISECONDS.toNanos(message.getTimeout()); return droppable && nowNanos - timestampNanos > messageTimeoutNanos; }