public static <T> MessageIn<T> create(InetAddress from, T payload, Map<String, byte[]> parameters, MessagingService.Verb verb, int version) { return new MessageIn<T>(from, payload, parameters, verb, version); }
public void response(ReadResponse result) { MessageIn<ReadResponse> message = MessageIn.create(FBUtilities.getBroadcastAddress(), result, Collections.<String, byte[]>emptyMap(), MessagingService.Verb.INTERNAL_RESPONSE, MessagingService.current_version); response(message); }
public String toString() { StringBuilder sbuf = new StringBuilder(); sbuf.append("FROM:").append(from).append(" TYPE:").append(getMessageType()).append(" VERB:").append(verb); return sbuf.toString(); } }
public void doVerb(MessageIn<ReadCommand> message, int id) { if (StorageService.instance.isBootstrapMode()) { throw new RuntimeException("Cannot service reads while bootstrapping!"); } ReadCommand command = message.payload; command.setMonitoringTime(message.constructionTime, message.isCrossNode(), message.getTimeout(), message.getSlowQueryTimeout()); ReadResponse response; try (ReadExecutionController executionController = command.executionController(); UnfilteredPartitionIterator iterator = command.executeLocally(executionController)) { response = command.createResponse(iterator); } if (!command.complete()) { Tracing.trace("Discarding partial response to {} (timed out)", message.from); MessagingService.instance().incrementDroppedMessages(message, message.getLifetimeInMS()); return; } Tracing.trace("Enqueuing response to {}", message.from); MessageOut<ReadResponse> reply = new MessageOut<>(MessagingService.Verb.REQUEST_RESPONSE, response, serializer()); MessagingService.instance().sendReply(reply, id, message.from); } }
private InetAddress receiveMessage(DataInputPlus input, int version) throws IOException { int id; if (version < MessagingService.VERSION_20) id = Integer.parseInt(input.readUTF()); else id = input.readInt(); long currentTime = ApproximateTime.currentTimeMillis(); MessageIn message = MessageIn.read(input, version, id, MessageIn.readConstructionTime(from, input, currentTime)); if (message == null) { // callback expired; nothing to do return null; } if (version <= MessagingService.current_version) { MessagingService.instance().receive(message, id); } else { logger.trace("Received connection from newer protocol version {}. Ignoring message", version); } return message.from; } }
if (message.isFailureResponse()) ((IAsyncCallbackWithFailure) cb).onFailure(message.from, message.getFailureReason());
public void run() long timeTaken = message.getLifetimeInMS(); if (MessagingService.DROPPABLE_VERBS.contains(verb) && timeTaken > message.getTimeout())
&& System.currentTimeMillis() > constructionTime + message.getTimeout()) if (message.doCallbackOnFailure())
public static <T2> MessageIn<T2> read(DataInputPlus in, int version, int id) throws IOException { return read(in, version, id, ApproximateTime.currentTimeMillis()); }
private void handleFailure(Throwable t) { if (message.doCallbackOnFailure()) { MessageOut response = new MessageOut(MessagingService.Verb.INTERNAL_RESPONSE) .withParameter(MessagingService.FAILURE_RESPONSE_PARAM, MessagingService.ONE_BYTE); if (t instanceof TombstoneOverwhelmingException) { try (DataOutputBuffer out = new DataOutputBuffer()) { out.writeShort(RequestFailureReason.READ_TOO_MANY_TOMBSTONES.code); response = response.withParameter(MessagingService.FAILURE_REASON_PARAM, out.getData()); } catch (IOException ex) { throw new RuntimeException(ex); } } MessagingService.instance().sendReply(response, id, message.from); } }
public void doVerb(MessageIn message, int id) { long latency = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - MessagingService.instance().getRegisteredCallbackAge(id)); CallbackInfo callbackInfo = MessagingService.instance().removeRegisteredCallback(id); if (callbackInfo == null) { String msg = "Callback already removed for {} (from {})"; logger.debug(msg, id, message.from); Tracing.trace(msg, id, message.from); return; } Tracing.trace("Processing response from {}", message.from); IAsyncCallback cb = callbackInfo.callback; if (message.isFailureResponse()) { ((IAsyncCallbackWithFailure) cb).onFailure(message.from); } else { //TODO: Should we add latency only in success cases? MessagingService.instance().maybeAddLatency(cb, message.from, latency); cb.response(message); } } }
public RequestFailureReason getFailureReason() { if (containsFailureReason()) { try (DataInputBuffer in = new DataInputBuffer(parameters.get(MessagingService.FAILURE_REASON_PARAM))) { return RequestFailureReason.fromCode(in.readUnsignedShort()); } catch (IOException ex) { throw new RuntimeException(ex); } } else { return RequestFailureReason.UNKNOWN; } }
public void doVerb(MessageIn<ReadCommand> message, int id) { if (StorageService.instance.isBootstrapMode()) { throw new RuntimeException("Cannot service reads while bootstrapping!"); } ReadCommand command = message.payload; command.setMonitoringTime(message.constructionTime, message.isCrossNode(), message.getTimeout(), message.getSlowQueryTimeout()); ReadResponse response; try (ReadExecutionController executionController = command.executionController(); UnfilteredPartitionIterator iterator = command.executeLocally(executionController)) { response = command.createResponse(iterator); } if (!command.complete()) { Tracing.trace("Discarding partial response to {} (timed out)", message.from); MessagingService.instance().incrementDroppedMessages(message, message.getLifetimeInMS()); return; } Tracing.trace("Enqueuing response to {}", message.from); MessageOut<ReadResponse> reply = new MessageOut<>(MessagingService.Verb.REQUEST_RESPONSE, response, serializer()); MessagingService.instance().sendReply(reply, id, message.from); } }
private InetAddress receiveMessage(DataInputPlus input, int version) throws IOException { int id; if (version < MessagingService.VERSION_20) id = Integer.parseInt(input.readUTF()); else id = input.readInt(); long currentTime = ApproximateTime.currentTimeMillis(); MessageIn message = MessageIn.read(input, version, id, MessageIn.readConstructionTime(from, input, currentTime)); if (message == null) { // callback expired; nothing to do return null; } if (version <= MessagingService.current_version) { MessagingService.instance().receive(message, id); } else { logger.trace("Received connection from newer protocol version {}. Ignoring message", version); } return message.from; } }
if (message.isFailureResponse()) ((IAsyncCallbackWithFailure) cb).onFailure(message.from, message.getFailureReason());
public void run() long timeTaken = message.getLifetimeInMS(); if (MessagingService.DROPPABLE_VERBS.contains(verb) && timeTaken > message.getTimeout())
public static <T2> MessageIn<T2> read(DataInputPlus in, int version, int id) throws IOException { return read(in, version, id, ApproximateTime.currentTimeMillis()); }
private void handleFailure(Throwable t) { if (message.doCallbackOnFailure()) { MessageOut response = new MessageOut(MessagingService.Verb.INTERNAL_RESPONSE) .withParameter(MessagingService.FAILURE_RESPONSE_PARAM, MessagingService.ONE_BYTE); if (t instanceof TombstoneOverwhelmingException) { try (DataOutputBuffer out = new DataOutputBuffer()) { out.writeShort(RequestFailureReason.READ_TOO_MANY_TOMBSTONES.code); response = response.withParameter(MessagingService.FAILURE_REASON_PARAM, out.getData()); } catch (IOException ex) { throw new RuntimeException(ex); } } MessagingService.instance().sendReply(response, id, message.from); } }
public RequestFailureReason getFailureReason() { if (containsFailureReason()) { try (DataInputBuffer in = new DataInputBuffer(parameters.get(MessagingService.FAILURE_REASON_PARAM))) { return RequestFailureReason.fromCode(in.readUnsignedShort()); } catch (IOException ex) { throw new RuntimeException(ex); } } else { return RequestFailureReason.UNKNOWN; } }
public void doVerb(MessageIn<ReadCommand> message, int id) { if (StorageService.instance.isBootstrapMode()) { throw new RuntimeException("Cannot service reads while bootstrapping!"); } ReadCommand command = message.payload; command.setMonitoringTime(message.constructionTime, message.isCrossNode(), message.getTimeout(), message.getSlowQueryTimeout()); ReadResponse response; try (ReadExecutionController executionController = command.executionController(); UnfilteredPartitionIterator iterator = command.executeLocally(executionController)) { response = command.createResponse(iterator); } if (!command.complete()) { Tracing.trace("Discarding partial response to {} (timed out)", message.from); MessagingService.instance().incrementDroppedMessages(message, message.getLifetimeInMS()); return; } Tracing.trace("Enqueuing response to {}", message.from); MessageOut<ReadResponse> reply = new MessageOut<>(MessagingService.Verb.REQUEST_RESPONSE, response, serializer()); MessagingService.instance().sendReply(reply, id, message.from); } }