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

     1  // Code generated by protoc-gen-psrpc v0.5.1, DO NOT EDIT.
     2  // source: rpc/agent.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  import google_protobuf "google.golang.org/protobuf/types/known/emptypb"
    17  import livekit1 "github.com/livekit/protocol/livekit"
    18  
    19  var _ = version.PsrpcVersion_0_5
    20  
    21  // ==============================
    22  // AgentInternal Client Interface
    23  // ==============================
    24  
    25  type AgentInternalClient interface {
    26  	CheckEnabled(ctx context.Context, req *CheckEnabledRequest, opts ...psrpc.RequestOption) (<-chan *psrpc.Response[*CheckEnabledResponse], error)
    27  
    28  	JobRequest(ctx context.Context, namespace string, jobType string, req *livekit1.Job, opts ...psrpc.RequestOption) (*google_protobuf.Empty, error)
    29  
    30  	SubscribeWorkerRegistered(ctx context.Context, handlerNamespace string) (psrpc.Subscription[*google_protobuf.Empty], error)
    31  }
    32  
    33  // ==================================
    34  // AgentInternal ServerImpl Interface
    35  // ==================================
    36  
    37  type AgentInternalServerImpl interface {
    38  	CheckEnabled(context.Context, *CheckEnabledRequest) (*CheckEnabledResponse, error)
    39  
    40  	JobRequest(context.Context, *livekit1.Job) (*google_protobuf.Empty, error)
    41  	JobRequestAffinity(context.Context, *livekit1.Job) float32
    42  }
    43  
    44  // ==============================
    45  // AgentInternal Server Interface
    46  // ==============================
    47  
    48  type AgentInternalServer interface {
    49  	RegisterJobRequestTopic(namespace string, jobType string) error
    50  	DeregisterJobRequestTopic(namespace string, jobType string)
    51  	PublishWorkerRegistered(ctx context.Context, handlerNamespace string, msg *google_protobuf.Empty) error
    52  
    53  	// Close and wait for pending RPCs to complete
    54  	Shutdown()
    55  
    56  	// Close immediately, without waiting for pending RPCs
    57  	Kill()
    58  }
    59  
    60  // ====================
    61  // AgentInternal Client
    62  // ====================
    63  
    64  type agentInternalClient struct {
    65  	client *client.RPCClient
    66  }
    67  
    68  // NewAgentInternalClient creates a psrpc client that implements the AgentInternalClient interface.
    69  func NewAgentInternalClient(bus psrpc.MessageBus, opts ...psrpc.ClientOption) (AgentInternalClient, error) {
    70  	sd := &info.ServiceDefinition{
    71  		Name: "AgentInternal",
    72  		ID:   rand.NewClientID(),
    73  	}
    74  
    75  	sd.RegisterMethod("CheckEnabled", false, true, false, false)
    76  	sd.RegisterMethod("JobRequest", true, false, true, false)
    77  	sd.RegisterMethod("WorkerRegistered", false, true, false, false)
    78  
    79  	rpcClient, err := client.NewRPCClient(sd, bus, opts...)
    80  	if err != nil {
    81  		return nil, err
    82  	}
    83  
    84  	return &agentInternalClient{
    85  		client: rpcClient,
    86  	}, nil
    87  }
    88  
    89  func (c *agentInternalClient) CheckEnabled(ctx context.Context, req *CheckEnabledRequest, opts ...psrpc.RequestOption) (<-chan *psrpc.Response[*CheckEnabledResponse], error) {
    90  	return client.RequestMulti[*CheckEnabledResponse](ctx, c.client, "CheckEnabled", nil, req, opts...)
    91  }
    92  
    93  func (c *agentInternalClient) JobRequest(ctx context.Context, namespace string, jobType string, req *livekit1.Job, opts ...psrpc.RequestOption) (*google_protobuf.Empty, error) {
    94  	return client.RequestSingle[*google_protobuf.Empty](ctx, c.client, "JobRequest", []string{namespace, jobType}, req, opts...)
    95  }
    96  
    97  func (c *agentInternalClient) SubscribeWorkerRegistered(ctx context.Context, handlerNamespace string) (psrpc.Subscription[*google_protobuf.Empty], error) {
    98  	return client.Join[*google_protobuf.Empty](ctx, c.client, "WorkerRegistered", []string{handlerNamespace})
    99  }
   100  
   101  // ====================
   102  // AgentInternal Server
   103  // ====================
   104  
   105  type agentInternalServer struct {
   106  	svc AgentInternalServerImpl
   107  	rpc *server.RPCServer
   108  }
   109  
   110  // NewAgentInternalServer builds a RPCServer that will route requests
   111  // to the corresponding method in the provided svc implementation.
   112  func NewAgentInternalServer(svc AgentInternalServerImpl, bus psrpc.MessageBus, opts ...psrpc.ServerOption) (AgentInternalServer, error) {
   113  	sd := &info.ServiceDefinition{
   114  		Name: "AgentInternal",
   115  		ID:   rand.NewServerID(),
   116  	}
   117  
   118  	s := server.NewRPCServer(sd, bus, opts...)
   119  
   120  	sd.RegisterMethod("CheckEnabled", false, true, false, false)
   121  	var err error
   122  	err = server.RegisterHandler(s, "CheckEnabled", nil, svc.CheckEnabled, nil)
   123  	if err != nil {
   124  		s.Close(false)
   125  		return nil, err
   126  	}
   127  
   128  	sd.RegisterMethod("JobRequest", true, false, true, false)
   129  	sd.RegisterMethod("WorkerRegistered", false, true, false, false)
   130  	return &agentInternalServer{
   131  		svc: svc,
   132  		rpc: s,
   133  	}, nil
   134  }
   135  
   136  func (s *agentInternalServer) RegisterJobRequestTopic(namespace string, jobType string) error {
   137  	return server.RegisterHandler(s.rpc, "JobRequest", []string{namespace, jobType}, s.svc.JobRequest, s.svc.JobRequestAffinity)
   138  }
   139  
   140  func (s *agentInternalServer) DeregisterJobRequestTopic(namespace string, jobType string) {
   141  	s.rpc.DeregisterHandler("JobRequest", []string{namespace, jobType})
   142  }
   143  
   144  func (s *agentInternalServer) PublishWorkerRegistered(ctx context.Context, handlerNamespace string, msg *google_protobuf.Empty) error {
   145  	return s.rpc.Publish(ctx, "WorkerRegistered", []string{handlerNamespace}, msg)
   146  }
   147  
   148  func (s *agentInternalServer) Shutdown() {
   149  	s.rpc.Close(false)
   150  }
   151  
   152  func (s *agentInternalServer) Kill() {
   153  	s.rpc.Close(true)
   154  }
   155  
   156  var psrpcFileDescriptor0 = []byte{
   157  	// 362 bytes of a gzipped FileDescriptorProto
   158  	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0xd1, 0x6a, 0xdb, 0x30,
   159  	0x14, 0x86, 0x51, 0x32, 0x86, 0xa3, 0x25, 0xcc, 0x51, 0x96, 0x91, 0x79, 0x6c, 0x4b, 0x7c, 0x15,
   160  	0x18, 0xc8, 0x63, 0x7b, 0x81, 0x6c, 0x23, 0x17, 0x0d, 0xf4, 0xc6, 0x50, 0x0a, 0xbd, 0x31, 0x96,
   161  	0x72, 0x6a, 0xbb, 0xb1, 0x25, 0x55, 0x92, 0x0b, 0x79, 0x81, 0x42, 0xde, 0xa1, 0x4f, 0x91, 0x27,
   162  	0x2c, 0x8e, 0x1d, 0x93, 0x42, 0xda, 0xcb, 0xf3, 0x9f, 0x5f, 0xe7, 0x7c, 0xe7, 0x47, 0xf8, 0xa3,
   163  	0x56, 0x3c, 0x88, 0x13, 0x10, 0x96, 0x2a, 0x2d, 0xad, 0x24, 0x5d, 0xad, 0xb8, 0xf7, 0x35, 0x91,
   164  	0x32, 0xc9, 0x21, 0x38, 0x48, 0xac, 0xbc, 0x0d, 0xa0, 0x50, 0x76, 0x5b, 0x3b, 0xbc, 0x81, 0x54,
   165  	0x36, 0x93, 0xc2, 0x34, 0xe5, 0x28, 0xcf, 0x1e, 0x60, 0x93, 0xd9, 0xe8, 0x64, 0x8a, 0x3f, 0xc6,
   166  	0xa3, 0xff, 0x29, 0xf0, 0xcd, 0x52, 0xc4, 0x2c, 0x87, 0x75, 0x08, 0xf7, 0x25, 0x18, 0xeb, 0x3f,
   167  	0x22, 0xfc, 0xe9, 0xa5, 0x6e, 0x94, 0x14, 0x06, 0xc8, 0x0c, 0xf7, 0xb5, 0x94, 0x45, 0x04, 0xb5,
   168  	0x3e, 0x41, 0x53, 0x34, 0x77, 0xc2, 0x0f, 0x95, 0xd6, 0x58, 0xc9, 0x4f, 0x3c, 0x54, 0x25, 0xcb,
   169  	0x33, 0x93, 0x82, 0x6e, 0x7d, 0x9d, 0x83, 0xcf, 0x6d, 0x1b, 0x47, 0xf3, 0x77, 0x8c, 0x45, 0x5c,
   170  	0x80, 0x51, 0x31, 0x07, 0x33, 0xe9, 0x4e, 0xbb, 0xf3, 0x5e, 0x78, 0xa2, 0xfc, 0x7e, 0xea, 0xe0,
   171  	0xc1, 0xdf, 0x8a, 0xf7, 0x42, 0x58, 0xd0, 0x22, 0xce, 0xc9, 0x25, 0xee, 0x9f, 0x92, 0x91, 0x09,
   172  	0xd5, 0x8a, 0xd3, 0x33, 0x47, 0x78, 0x5f, 0xce, 0x74, 0xea, 0x33, 0x7c, 0x67, 0xbf, 0x43, 0xef,
   173  	0x16, 0x9d, 0x39, 0x22, 0x57, 0x18, 0xaf, 0x24, 0x6b, 0x9e, 0x90, 0x3e, 0x6d, 0x42, 0xa2, 0x2b,
   174  	0xc9, 0xbc, 0xcf, 0xb4, 0x8e, 0x97, 0x1e, 0xe3, 0xa5, 0xcb, 0x2a, 0x5e, 0x7f, 0xb6, 0xdf, 0xa1,
   175  	0x6f, 0x2e, 0xf2, 0xc6, 0xa4, 0xd7, 0xa2, 0x12, 0xe7, 0x4e, 0xb2, 0xc8, 0x6e, 0x15, 0x2c, 0xd0,
   176  	0x2f, 0x44, 0x00, 0xbb, 0xd7, 0x52, 0x6f, 0x40, 0x87, 0x90, 0x64, 0xc6, 0x82, 0x86, 0x35, 0x79,
   177  	0x65, 0xdc, 0xdb, 0x6b, 0x1c, 0xe4, 0x22, 0x6f, 0x44, 0x86, 0x69, 0x2c, 0xd6, 0x39, 0xe8, 0xa8,
   178  	0x5d, 0x58, 0xd1, 0xff, 0x9b, 0xdd, 0xfc, 0x48, 0x32, 0x9b, 0x96, 0x8c, 0x72, 0x59, 0x04, 0x0d,
   179  	0x7b, 0xfd, 0x1b, 0xb8, 0xcc, 0x03, 0xad, 0x38, 0x7b, 0x7f, 0xa8, 0xfe, 0x3c, 0x07, 0x00, 0x00,
   180  	0xff, 0xff, 0x0e, 0x5b, 0x92, 0xc6, 0x41, 0x02, 0x00, 0x00,
   181  }