thrift 笔记

TServerEventHandler

TServerEventHandler 是 Thrift Server 的事件处理接口。

public interface TServerEventHandler {

  /**
   * Called before the server begins.
   */
  void preServe();

  /**
   * Called when a new client has connected and is about to being processing.
   */
  ServerContext createContext(TProtocol input,
                              TProtocol output);

  /**
   * Called when a client has finished request-handling to delete server
   * context.
   */
  void deleteContext(ServerContext serverContext,
                             TProtocol input,
                             TProtocol output);

  /**
   * Called when a client is about to call the processor.
   */
  void processContext(ServerContext serverContext,
                              TTransport inputTransport, TTransport outputTransport);

}

方法:

  • preServe () 服务启动前被调用。
  • 一个新的 client 连接,准备开始处理的时候会被调用。
  • 一个 client 准备关掉的时候被调用。
  • client 准备调用 processor(处理业务逻辑)前被调用。

links