github.com/cloudwego/kitex@v0.9.0/pkg/remote/trans_handler.go (about)

     1  /*
     2   * Copyright 2021 CloudWeGo Authors
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package remote
    18  
    19  import (
    20  	"context"
    21  	"net"
    22  
    23  	"github.com/cloudwego/kitex/pkg/endpoint"
    24  )
    25  
    26  // ClientTransHandlerFactory to new TransHandler for client
    27  type ClientTransHandlerFactory interface {
    28  	NewTransHandler(opt *ClientOption) (ClientTransHandler, error)
    29  }
    30  
    31  // ServerTransHandlerFactory to new TransHandler for server
    32  type ServerTransHandlerFactory interface {
    33  	NewTransHandler(opt *ServerOption) (ServerTransHandler, error)
    34  }
    35  
    36  // TransReadWriter .
    37  type TransReadWriter interface {
    38  	Write(ctx context.Context, conn net.Conn, send Message) (nctx context.Context, err error)
    39  	Read(ctx context.Context, conn net.Conn, msg Message) (nctx context.Context, err error)
    40  }
    41  
    42  // TransHandler is similar to the handler role in netty
    43  // Transport can be refactored to support pipeline, and then is able to support other extensions at conn level.
    44  type TransHandler interface {
    45  	TransReadWriter
    46  	OnInactive(ctx context.Context, conn net.Conn)
    47  	OnError(ctx context.Context, err error, conn net.Conn)
    48  	OnMessage(ctx context.Context, args, result Message) (context.Context, error)
    49  	SetPipeline(pipeline *TransPipeline)
    50  }
    51  
    52  // ClientTransHandler is just TransHandler.
    53  type ClientTransHandler interface {
    54  	TransHandler
    55  }
    56  
    57  // ServerTransHandler have some new functions.
    58  type ServerTransHandler interface {
    59  	TransHandler
    60  	OnActive(ctx context.Context, conn net.Conn) (context.Context, error)
    61  	OnRead(ctx context.Context, conn net.Conn) error
    62  }
    63  
    64  // InvokeHandleFuncSetter is used to set invoke handle func.
    65  type InvokeHandleFuncSetter interface {
    66  	SetInvokeHandleFunc(inkHdlFunc endpoint.Endpoint)
    67  }
    68  
    69  // GracefulShutdown supports closing connections in a graceful manner.
    70  type GracefulShutdown interface {
    71  	GracefulShutdown(ctx context.Context) error
    72  }