github.com/livekit/protocol@v1.16.1-0.20240517185851-47e4c6bba773/rpc/keepalive.psrpc.go (about)

     1  // Code generated by protoc-gen-psrpc v0.5.1, DO NOT EDIT.
     2  // source: rpc/keepalive.proto
     3  
     4  package rpc
     5  
     6  import (
     7  	"context"
     8  
     9  	"github.com/livekit/psrpc"
    10  	"github.com/livekit/psrpc/pkg/client"
    11  	"github.com/livekit/psrpc/pkg/info"
    12  	"github.com/livekit/psrpc/pkg/rand"
    13  	"github.com/livekit/psrpc/pkg/server"
    14  	"github.com/livekit/psrpc/version"
    15  )
    16  
    17  var _ = version.PsrpcVersion_0_5
    18  
    19  // ==========================
    20  // Keepalive Client Interface
    21  // ==========================
    22  
    23  type KeepaliveClient[NodeIDTopicType ~string] interface {
    24  	SubscribePing(ctx context.Context, nodeID NodeIDTopicType) (psrpc.Subscription[*KeepalivePing], error)
    25  }
    26  
    27  // ==============================
    28  // Keepalive ServerImpl Interface
    29  // ==============================
    30  
    31  type KeepaliveServerImpl interface {
    32  }
    33  
    34  // ==========================
    35  // Keepalive Server Interface
    36  // ==========================
    37  
    38  type KeepaliveServer[NodeIDTopicType ~string] interface {
    39  	PublishPing(ctx context.Context, nodeID NodeIDTopicType, msg *KeepalivePing) error
    40  
    41  	// Close and wait for pending RPCs to complete
    42  	Shutdown()
    43  
    44  	// Close immediately, without waiting for pending RPCs
    45  	Kill()
    46  }
    47  
    48  // ================
    49  // Keepalive Client
    50  // ================
    51  
    52  type keepaliveClient[NodeIDTopicType ~string] struct {
    53  	client *client.RPCClient
    54  }
    55  
    56  // NewKeepaliveClient creates a psrpc client that implements the KeepaliveClient interface.
    57  func NewKeepaliveClient[NodeIDTopicType ~string](bus psrpc.MessageBus, opts ...psrpc.ClientOption) (KeepaliveClient[NodeIDTopicType], error) {
    58  	sd := &info.ServiceDefinition{
    59  		Name: "Keepalive",
    60  		ID:   rand.NewClientID(),
    61  	}
    62  
    63  	sd.RegisterMethod("Ping", false, true, false, false)
    64  
    65  	rpcClient, err := client.NewRPCClient(sd, bus, opts...)
    66  	if err != nil {
    67  		return nil, err
    68  	}
    69  
    70  	return &keepaliveClient[NodeIDTopicType]{
    71  		client: rpcClient,
    72  	}, nil
    73  }
    74  
    75  func (c *keepaliveClient[NodeIDTopicType]) SubscribePing(ctx context.Context, nodeID NodeIDTopicType) (psrpc.Subscription[*KeepalivePing], error) {
    76  	return client.Join[*KeepalivePing](ctx, c.client, "Ping", []string{string(nodeID)})
    77  }
    78  
    79  // ================
    80  // Keepalive Server
    81  // ================
    82  
    83  type keepaliveServer[NodeIDTopicType ~string] struct {
    84  	svc KeepaliveServerImpl
    85  	rpc *server.RPCServer
    86  }
    87  
    88  // NewKeepaliveServer builds a RPCServer that will route requests
    89  // to the corresponding method in the provided svc implementation.
    90  func NewKeepaliveServer[NodeIDTopicType ~string](svc KeepaliveServerImpl, bus psrpc.MessageBus, opts ...psrpc.ServerOption) (KeepaliveServer[NodeIDTopicType], error) {
    91  	sd := &info.ServiceDefinition{
    92  		Name: "Keepalive",
    93  		ID:   rand.NewServerID(),
    94  	}
    95  
    96  	s := server.NewRPCServer(sd, bus, opts...)
    97  
    98  	sd.RegisterMethod("Ping", false, true, false, false)
    99  	return &keepaliveServer[NodeIDTopicType]{
   100  		svc: svc,
   101  		rpc: s,
   102  	}, nil
   103  }
   104  
   105  func (s *keepaliveServer[NodeIDTopicType]) PublishPing(ctx context.Context, nodeID NodeIDTopicType, msg *KeepalivePing) error {
   106  	return s.rpc.Publish(ctx, "Ping", []string{string(nodeID)}, msg)
   107  }
   108  
   109  func (s *keepaliveServer[NodeIDTopicType]) Shutdown() {
   110  	s.rpc.Close(false)
   111  }
   112  
   113  func (s *keepaliveServer[NodeIDTopicType]) Kill() {
   114  	s.rpc.Close(true)
   115  }
   116  
   117  var psrpcFileDescriptor4 = []byte{
   118  	// 178 bytes of a gzipped FileDescriptorProto
   119  	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2e, 0x2a, 0x48, 0xd6,
   120  	0xcf, 0x4e, 0x4d, 0x2d, 0x48, 0xcc, 0xc9, 0x2c, 0x4b, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17,
   121  	0x62, 0x2e, 0x2a, 0x48, 0x96, 0xe2, 0xcd, 0x2f, 0x28, 0xc9, 0xcc, 0xcf, 0x2b, 0x86, 0x88, 0x29,
   122  	0xe9, 0x72, 0xf1, 0x7a, 0xc3, 0x94, 0x05, 0x64, 0xe6, 0xa5, 0x0b, 0xc9, 0x70, 0x71, 0x96, 0x64,
   123  	0xe6, 0xa6, 0x16, 0x97, 0x24, 0xe6, 0x16, 0x48, 0x30, 0x2a, 0x30, 0x6a, 0x30, 0x07, 0x21, 0x04,
   124  	0x8c, 0x42, 0xb9, 0x38, 0xe1, 0xca, 0x85, 0x3c, 0xb8, 0x58, 0xc0, 0x5a, 0x84, 0xf4, 0x8a, 0x0a,
   125  	0x92, 0xf5, 0x50, 0x8c, 0x91, 0xc2, 0x22, 0xa6, 0x24, 0xb1, 0xa9, 0x93, 0x51, 0x84, 0x83, 0x51,
   126  	0x80, 0x51, 0x8a, 0x4b, 0x88, 0x2d, 0x2f, 0x3f, 0x25, 0xd5, 0xd3, 0x45, 0x82, 0xd1, 0x81, 0x49,
   127  	0x83, 0xd1, 0x49, 0x31, 0x4a, 0x3e, 0x3d, 0xb3, 0x24, 0xa3, 0x34, 0x49, 0x2f, 0x39, 0x3f, 0x57,
   128  	0x1f, 0xa4, 0x21, 0x3b, 0xb3, 0x44, 0x1f, 0xec, 0xc2, 0xe4, 0xfc, 0x1c, 0xfd, 0xa2, 0x82, 0xe4,
   129  	0x24, 0x36, 0x30, 0xcf, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x1f, 0x1d, 0x8f, 0xd1, 0xda, 0x00,
   130  	0x00, 0x00,
   131  }