@Override public String toString() { int count; final StringBuilder builder = new StringBuilder() .append("PendingResponse:").append(hashCode()) .append("[messageId=").append(message.getMessageId()); if (isDone()) { return builder.append((isCompletedExceptionally() ? ",Completed exceptionally]" : ",Completed normally]")).toString(); } if ((count = getNumberOfDependents()) != 0) { return builder.append(",Not completed,").append(count).append(" dependents]").toString(); } return builder.append(",Not completed]").toString(); }
public Task cleanup() { // The benchmarks showed that it's faster to iterate over all pending messages // than to keep a priority queue ordered by timeout. // The priority queue forces the application to pay the price of keeping the queue ordered // plus the synchronization cost of adding and removing elements. pendingResponseMap.values() .forEach(top -> { if (top.timeoutAt > runtime.clock().millis()) { // return the message, if there was a concurrent reception the message will be removed on the next cycle. return; } if (!top.isDone()) { final StringBuilder errorMsg = new StringBuilder(); errorMsg.append("Response timeout. "); errorMsg.append(top.message.toString()); top.internalCompleteExceptionally(new TimeoutException(errorMsg.toString())); } pendingResponseMap.remove(top.message.getMessageId()); }); return Task.done(); }
@Override public byte[] serializeMessage(final BasicRuntime runtime, Message message) throws Exception { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ObjectOutput out = createObjectOutput(runtime, baos); out.writeByte(message.getMessageType()); out.writeInt(message.getMessageId()); if (message.getReferenceAddress() != null) { final UUID uuid = message.getReferenceAddress().asUUID(); out.writeLong(uuid.getMostSignificantBits()); out.writeLong(uuid.getLeastSignificantBits()); } else { out.writeLong(0); out.writeLong(0); } out.writeInt(message.getInterfaceId()); out.writeInt(message.getMethodId()); out.writeObject(message.getObjectId()); out.writeObject(message.getHeaders()); out.writeObject(message.getFromNode()); out.writeObject(message.getPayload()); return baos.toByteArray(); }
private void logMessage(final Message message, boolean in) long messageId = message.getMessageId();
public Task<?> writeMessage(HandlerContext ctx, Message message) int messageId = message.getMessageId(); if (messageId != 0)
final int messageId = message.getMessageId(); if (logger.isTraceEnabled()) logger.trace("message received: " + message.getMessageId() + " " + message.getMessageType() + "\r\n"); if (logger.isTraceEnabled()) logger.trace("response received: " + message.getMessageId() + " " + message.getPayload() + "\r\n" + pendingResponse);
@Override public byte[] serializeMessage(BasicRuntime basicRuntime, Message message) throws Exception { return outputPool.run(out -> { return kryoPool.run(kryo -> { out.writeByte(message.getMessageType()); out.writeInt(message.getMessageId()); writeNodeAddress(out, message.getReferenceAddress()); out.writeInt(message.getInterfaceId()); out.writeInt(message.getMethodId()); writeObjectId(kryo, out, message); writeHeaders(kryo, out, message.getHeaders()); writeNodeAddress(out, message.getFromNode()); writePayload(kryo, out, message); out.flush(); return out.getByteArrayOutputStream().toByteArray(); }); }, DEFAULT_BUFFER_SIZE); }