@Override public Optional<MethodMetadata> getMethodMetadata(String name) { if (LOG_METHOD_METADATA.getName().equals(name)) { return Optional.of(LOG_METHOD_METADATA); } return Optional.empty(); }
public static MethodMetadata toMethodMetadata(ThriftCodecManager codecManager, ThriftMethodMetadata metadata) { List<ParameterMetadata> parameters = metadata.getParameters().stream() .map(parameter -> new ParameterMetadata( parameter.getId(), parameter.getName(), getCodec(codecManager, parameter.getThriftType()))) .collect(Collectors.toList()); ThriftCodec<Object> resultCodec = getCodec(codecManager, metadata.getReturnType()); Map<Short, ThriftCodec<Object>> exceptionCodecs = ImmutableMap.copyOf( transformEntries(metadata.getExceptions(), (key, value) -> getCodec(codecManager, value))); return new MethodMetadata( metadata.getName(), parameters, resultCodec, exceptionCodecs, metadata.getOneway(), metadata.isIdempotent()); }
throws Exception Optional<Short> exceptionId = methodMetadata.getExceptionId(exception.getClass()); if (exceptionId.isPresent()) { TChannelBufferOutputTransport outputTransport = new TChannelBufferOutputTransport(context.alloc()); methodMetadata.getName(), protocolWriter, sequenceId, "exception", exceptionId.get(), methodMetadata.getExceptionCodecs().get(exceptionId.get()), exception); methodMetadata.getName(), transport, protocol, supportOutOfOrderResponse, type, "Internal error processing " + methodMetadata.getName() + ": " + exception.getMessage(), exception);
try { writeResponse( methodMetadata.getName(), protocol.createProtocol(outputTransport), sequenceId, "success", (short) 0, methodMetadata.getResultCodec(), result);
throw new TApplicationException(INVALID_MESSAGE_TYPE, format("Received invalid message type %s from server", message.type)); if (!message.name.equals(method.getName())) { throw new TApplicationException(WRONG_METHOD_NAME, format("Wrong method name in reply: expected %s but received %s", method.getName(), message.name)); throw new TApplicationException(BAD_SEQUENCE_ID, format("%s failed: out of sequence response", method.getName())); while (reader.nextField()) { if (reader.getFieldId() == 0) { results = reader.readField(method.getResultCodec()); ThriftCodec<Object> exceptionCodec = method.getExceptionCodecs().get(reader.getFieldId()); if (exceptionCodec != null) { exception = (Exception) reader.readField(exceptionCodec); if (method.getResultCodec().getType() == ThriftType.VOID) { return null; throw new TApplicationException(MISSING_RESULT, format("%s failed: unknown result", method.getName()));
protocolWriter.writeMessageBegin(new TMessage(method.getName(), method.isOneway() ? ONEWAY : CALL, sequenceId)); writer.writeStructBegin(method.getName() + "_args"); List<Object> parameters = thriftRequest.getParameters(); for (int i = 0; i < parameters.size(); i++) { Object value = parameters.get(i); ParameterMetadata parameter = method.getParameters().get(i); writer.writeField(parameter.getName(), parameter.getFieldId(), parameter.getCodec(), value);
private static void writeRequest(MethodMetadata method, List<Object> parameters, TProtocol protocol) throws Exception { TMessage requestMessage = new TMessage(method.getName(), CALL, SEQUENCE_ID); protocol.writeMessageBegin(requestMessage); // write the parameters ProtocolWriter writer = new ProtocolWriter(new ThriftToDriftProtocolWriter(protocol)); writer.writeStructBegin(method.getName() + "_args"); for (int i = 0; i < parameters.size(); i++) { Object value = parameters.get(i); ParameterMetadata parameter = method.getParameters().get(i); writer.writeField(parameter.getName(), parameter.getFieldId(), parameter.getCodec(), value); } writer.writeStructEnd(); protocol.writeMessageEnd(); protocol.getTransport().flush(); }
ExceptionClassification exceptionClassification = retryPolicy.classifyException(throwable, metadata.isIdempotent()); metadata.getName(), invocationAttempts, backoffDelay,
(ThriftCodec<Object>) codecManager.getCodec(optionalType)); MethodMetadata methodMetadata = new MethodMetadata( "Log", ImmutableList.of(parameter),
private static Map<Short, Object> readArguments(MethodMetadata method, TProtocolReader protocol) throws Exception Map<Short, Object> arguments = new HashMap<>(method.getParameters().size()); ProtocolReader reader = new ProtocolReader(protocol); short fieldId = reader.getFieldId(); ParameterMetadata parameter = method.getParameterByFieldId(fieldId); if (parameter == null) { reader.skipFieldData(); for (ParameterMetadata parameter : method.getParameters()) { if (!arguments.containsKey(parameter.getFieldId())) { Type argumentType = parameter.getCodec().getType().getJavaType();
public ServiceMethod(ThriftCodecManager codecManager, Object service, ThriftMethodMetadata methodMetadata, List<MethodInvocationFilter> filters) { requireNonNull(codecManager, "codecManager is null"); requireNonNull(service, "service is null"); requireNonNull(methodMetadata, "methodMetadata is null"); this.service = service; this.methodMetadata = toMethodMetadata(codecManager, methodMetadata); invoker = createFilteredMethodInvoker(filters, new ServiceMethodInvoker(service, methodMetadata)); }
throw new TApplicationException(INVALID_MESSAGE_TYPE, format("Received invalid message type %s from server", message.type)); if (!message.name.equals(method.getName())) { throw new TApplicationException(WRONG_METHOD_NAME, format("Wrong method name in reply: expected %s but received %s", method.getName(), message.name)); throw new TApplicationException(BAD_SEQUENCE_ID, format("%s failed: out of sequence response", method.getName())); while (reader.nextField()) { if (reader.getFieldId() == 0) { results = reader.readField(method.getResultCodec()); ThriftCodec<Object> exceptionCodec = method.getExceptionCodecs().get(reader.getFieldId()); if (exceptionCodec != null) { exception = (Exception) reader.readField(exceptionCodec); if (method.getResultCodec().getType() == ThriftType.VOID) { return null; throw new TApplicationException(MISSING_RESULT, format("%s failed: unknown result", method.getName()));
protocolWriter.writeMessageBegin(new TMessage(method.getName(), method.isOneway() ? ONEWAY : CALL, sequenceId)); writer.writeStructBegin(method.getName() + "_args"); List<Object> parameters = thriftRequest.getParameters(); for (int i = 0; i < parameters.size(); i++) { Object value = parameters.get(i); ParameterMetadata parameter = method.getParameters().get(i); writer.writeField(parameter.getName(), parameter.getFieldId(), parameter.getCodec(), value);
private static void writeRequest(MethodMetadata method, List<Object> parameters, TProtocol protocol) throws Exception { TMessage requestMessage = new TMessage(method.getName(), CALL, SEQUENCE_ID); protocol.writeMessageBegin(requestMessage); // write the parameters ProtocolWriter writer = new ProtocolWriter(new ThriftToDriftProtocolWriter(protocol)); writer.writeStructBegin(method.getName() + "_args"); for (int i = 0; i < parameters.size(); i++) { Object value = parameters.get(i); ParameterMetadata parameter = method.getParameters().get(i); writer.writeField(parameter.getName(), parameter.getFieldId(), parameter.getCodec(), value); } writer.writeStructEnd(); protocol.writeMessageEnd(); protocol.getTransport().flush(); }
try { writeResponse( methodMetadata.getName(), protocol.createProtocol(outputTransport), sequenceId, "success", (short) 0, methodMetadata.getResultCodec(), result);
ExceptionClassification exceptionClassification = retryPolicy.classifyException(throwable, metadata.isIdempotent()); metadata.getName(), invocationAttempts, backoffDelay,
new MethodMetadata( "test", ImmutableList.of(),
private static Map<Short, Object> readArguments(MethodMetadata method, TProtocolReader protocol) throws Exception Map<Short, Object> arguments = new HashMap<>(method.getParameters().size()); ProtocolReader reader = new ProtocolReader(protocol); short fieldId = reader.getFieldId(); ParameterMetadata parameter = method.getParameterByFieldId(fieldId); if (parameter == null) { reader.skipFieldData(); for (ParameterMetadata parameter : method.getParameters()) { if (!arguments.containsKey(parameter.getFieldId())) { Type argumentType = parameter.getCodec().getType().getJavaType();
public ServiceMethod(ThriftCodecManager codecManager, Object service, ThriftMethodMetadata methodMetadata, List<MethodInvocationFilter> filters) { requireNonNull(codecManager, "codecManager is null"); requireNonNull(service, "service is null"); requireNonNull(methodMetadata, "methodMetadata is null"); this.service = service; this.methodMetadata = toMethodMetadata(codecManager, methodMetadata); invoker = createFilteredMethodInvoker(filters, new ServiceMethodInvoker(service, methodMetadata)); }
@Override public Optional<MethodMetadata> getMethodMetadata(String name) { if (LOG_METHOD_METADATA.getName().equals(name)) { return Optional.of(LOG_METHOD_METADATA); } return Optional.empty(); }