private String generateParameterHash(Object[] params) { if (params == null || params.length == 0) { return ""; } try { final MessageDigest md = messageDigest.newDigest(); final byte[] hashValue = md.digest(messageSerializer.serializeMessage(runtime, new Message().withPayload(params))); return String.format("%032X", new BigInteger(1, hashValue)); } catch (Exception e) { throw new UncheckedException("Unable to make parameter hash", e); } }
@Override public Message deserializeMessage(final BasicRuntime runtime, final byte[] payload) throws Exception { final ObjectInput in = createObjectInput(runtime, new ByteArrayInputStream(payload)); final Message message = new Message(); message.setMessageType(in.readByte()); message.setMessageId(in.readInt()); long most = in.readLong(); long least = in.readLong(); message.setReferenceAddress(most != 0 && least != 0 ? new NodeAddressImpl(new UUID(most, least)) : null); message.setInterfaceId(in.readInt()); message.setMethodId(in.readInt()); message.setObjectId(in.readObject()); message.setHeaders((Map) in.readObject()); message.setFromNode((NodeAddress) in.readObject()); message.setPayload(in.readObject()); return message; }
private Task sendResponse(HandlerContext ctx, NodeAddress to, int messageType, int messageId, final int classId, final int methodId, Object res) { return ctx.write(new Message() .withToNode(to) .withMessageId(messageId) .withInterfaceId(classId) .withMethodId(methodId) .withMessageType(messageType) .withPayload(res)); }
public Task<?> writeInvocation(final HandlerContext ctx, Invocation invocation) { final Addressable toReference = invocation.getToReference(); final RemoteReference<?> actorReference = (RemoteReference<?>) toReference; final NodeAddress toNode = invocation.getToNode(); Map<String, Object> actualHeaders = null; if (invocation.getHeaders() != null) { actualHeaders = new HashMap<>(); actualHeaders.putAll(invocation.getHeaders()); } final Message message = new Message() .withMessageType(invocation.isOneWay() ? MessageDefinitions.ONE_WAY_MESSAGE : MessageDefinitions.REQUEST_MESSAGE) .withToNode(toNode) .withFromNode(invocation.getFromNode()) .withHeaders(actualHeaders) .withInterfaceId(actorReference._interfaceId()) .withMessageId(invocation.getMessageId()) .withMethodId(invocation.getMethodId()) .withObjectId(RemoteReference.getId(actorReference)) .withPayload(invocation.getParams()) .withReferenceAddress(invocation.getToReference().address); if (logger.isTraceEnabled()) { logger.trace("sending message to " + toReference); } return writeMessage(ctx, message); }
@Override public Message deserializeMessage(BasicRuntime basicRuntime, final byte[] payload) throws Exception { return inputPool.run(in -> { in.setInputStream(new ByteArrayInputStream(payload)); return kryoPool.run(kryo -> { final Message message = new Message(); message.setMessageType(in.readByte()); message.setMessageId(in.readInt()); message.setReferenceAddress(readNodeAddress(in)); message.setInterfaceId(in.readInt()); message.setMethodId(in.readInt()); message.setObjectId(readObjectId(kryo, in)); message.setHeaders(readHeaders(kryo, in)); message.setFromNode(readNodeAddress(in)); message.setPayload(readPayload(kryo, in)); return message; }); }, DEFAULT_BUFFER_SIZE); }