All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.thrift.TBaseProcessor Maven / Gradle / Ivy

package org.apache.thrift;

import static dev.vality.woody.api.trace.context.TraceContext.getCurrentTraceData;

import dev.vality.woody.api.trace.MetadataProperties;
import java.util.Collections;
import java.util.Map;
import org.apache.thrift.protocol.TMessage;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.protocol.TProtocolUtil;
import org.apache.thrift.protocol.TType;

public abstract class TBaseProcessor implements TProcessor {
  private final I iface;
  private final Map> processMap;

  protected TBaseProcessor(
      I iface, Map> processFunctionMap) {
    this.iface = iface;
    this.processMap = processFunctionMap;
  }

  public Map> getProcessMapView() {
    return Collections.unmodifiableMap(processMap);
  }

  @Override
  public void process(TProtocol in, TProtocol out) throws TException {
    TMessage msg = in.readMessageBegin();
    getCurrentTraceData()
        .getServiceSpan()
        .getMetadata()
        .putValue(MetadataProperties.CALL_NAME, msg.name);
    ProcessFunction fn = processMap.get(msg.name);
    if (fn == null) {
      TProtocolUtil.skip(in, TType.STRUCT);
      in.readMessageEnd();
      throw new TApplicationException(
          TApplicationException.UNKNOWN_METHOD, "Invalid method name: '" + msg.name + "'");
    } else {
      fn.process(msg.seqid, in, out, iface);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy