Update psrpc, egressStore interface (#1256)

* Update psrpc, egressStore interface

* psrpc v0.2.0
This commit is contained in:
David Colburn
2022-12-24 00:49:31 -08:00
committed by GitHub
parent 94564f9f93
commit 976d4ea9db
7 changed files with 150 additions and 145 deletions
+70 -43
View File
@@ -1,4 +1,4 @@
// Code generated by protoc-gen-psrpc v0.1.0, DO NOT EDIT.
// Code generated by protoc-gen-psrpc v0.2.0, DO NOT EDIT.
// source: pkg/service/rpc/egress.proto
package rpc
@@ -14,9 +14,9 @@ import livekit3 "github.com/livekit/protocol/livekit"
// ===============================
type EgressInternalClient interface {
StartEgress(context.Context, *livekit3.StartEgressRequest, ...psrpc1.RequestOpt) (*livekit.EgressInfo, error)
StartEgress(context.Context, *livekit3.StartEgressRequest, ...psrpc1.RequestOption) (*livekit.EgressInfo, error)
ListActiveEgress(context.Context, *ListActiveEgressRequest, ...psrpc1.RequestOpt) (<-chan *psrpc1.Response[*ListActiveEgressResponse], error)
ListActiveEgress(context.Context, *ListActiveEgressRequest, ...psrpc1.RequestOption) (<-chan *psrpc1.Response[*ListActiveEgressResponse], error)
}
// ===================================
@@ -35,6 +35,11 @@ type EgressInternalServerImpl interface {
// ===============================
type EgressInternalServer interface {
// Close and wait for pending RPCs to complete
Shutdown()
// Close immediately, without waiting for pending RPCs
Kill()
}
// =====================
@@ -42,11 +47,11 @@ type EgressInternalServer interface {
// =====================
type egressInternalClient struct {
client psrpc1.RPCClient
client *psrpc1.RPCClient
}
// NewEgressInternalClient creates a psrpc client that implements the EgressInternalClient interface.
func NewEgressInternalClient(clientID string, bus psrpc1.MessageBus, opts ...psrpc1.ClientOpt) (EgressInternalClient, error) {
func NewEgressInternalClient(clientID string, bus psrpc1.MessageBus, opts ...psrpc1.ClientOption) (EgressInternalClient, error) {
rpcClient, err := psrpc1.NewRPCClient("EgressInternal", clientID, bus, opts...)
if err != nil {
return nil, err
@@ -57,12 +62,12 @@ func NewEgressInternalClient(clientID string, bus psrpc1.MessageBus, opts ...psr
}, nil
}
func (c *egressInternalClient) StartEgress(ctx context.Context, req *livekit3.StartEgressRequest, opts ...psrpc1.RequestOpt) (*livekit.EgressInfo, error) {
return psrpc1.RequestTopicSingle[*livekit.EgressInfo](ctx, c.client, "StartEgress", "", req, opts...)
func (c *egressInternalClient) StartEgress(ctx context.Context, req *livekit3.StartEgressRequest, opts ...psrpc1.RequestOption) (*livekit.EgressInfo, error) {
return psrpc1.RequestSingle[*livekit.EgressInfo](ctx, c.client, "StartEgress", "", req, opts...)
}
func (c *egressInternalClient) ListActiveEgress(ctx context.Context, req *ListActiveEgressRequest, opts ...psrpc1.RequestOpt) (<-chan *psrpc1.Response[*ListActiveEgressResponse], error) {
return psrpc1.RequestTopicAll[*ListActiveEgressResponse](ctx, c.client, "ListActiveEgress", "", req, opts...)
func (c *egressInternalClient) ListActiveEgress(ctx context.Context, req *ListActiveEgressRequest, opts ...psrpc1.RequestOption) (<-chan *psrpc1.Response[*ListActiveEgressResponse], error) {
return psrpc1.RequestMulti[*ListActiveEgressResponse](ctx, c.client, "ListActiveEgress", "", req, opts...)
}
// =====================
@@ -71,41 +76,49 @@ func (c *egressInternalClient) ListActiveEgress(ctx context.Context, req *ListAc
type egressInternalServer struct {
svc EgressInternalServerImpl
rpc psrpc1.RPCServer
rpc *psrpc1.RPCServer
}
// NewEgressInternalServer builds a RPCServer that can be used to handle
// requests that are routed to the right method in the provided svc implementation.
func NewEgressInternalServer(serverID string, svc EgressInternalServerImpl, bus psrpc1.MessageBus, opts ...psrpc1.ServerOpt) (EgressInternalServer, error) {
rpcServer := psrpc1.NewRPCServer("EgressInternal", serverID, bus, opts...)
// NewEgressInternalServer builds a RPCServer that will route requests
// to the corresponding method in the provided svc implementation.
func NewEgressInternalServer(serverID string, svc EgressInternalServerImpl, bus psrpc1.MessageBus, opts ...psrpc1.ServerOption) (EgressInternalServer, error) {
s := psrpc1.NewRPCServer("EgressInternal", serverID, bus, opts...)
var err error
err = rpcServer.RegisterHandler(psrpc1.NewHandlerWithAffinity("StartEgress", svc.StartEgress, svc.StartEgressAffinity))
err = psrpc1.RegisterHandler(s, "StartEgress", "", svc.StartEgress, svc.StartEgressAffinity)
if err != nil {
rpcServer.Close()
s.Close(false)
return nil, err
}
err = rpcServer.RegisterHandler(psrpc1.NewHandler("ListActiveEgress", svc.ListActiveEgress))
err = psrpc1.RegisterHandler(s, "ListActiveEgress", "", svc.ListActiveEgress, nil)
if err != nil {
rpcServer.Close()
s.Close(false)
return nil, err
}
return &egressInternalServer{
svc: svc,
rpc: rpcServer,
rpc: s,
}, nil
}
func (s *egressInternalServer) Shutdown() {
s.rpc.Close(false)
}
func (s *egressInternalServer) Kill() {
s.rpc.Close(true)
}
// ==============================
// EgressHandler Client Interface
// ==============================
type EgressHandlerClient interface {
UpdateStream(context.Context, string, *livekit.UpdateStreamRequest, ...psrpc1.RequestOpt) (*livekit.EgressInfo, error)
UpdateStream(context.Context, string, *livekit.UpdateStreamRequest, ...psrpc1.RequestOption) (*livekit.EgressInfo, error)
StopEgress(context.Context, string, *livekit.StopEgressRequest, ...psrpc1.RequestOpt) (*livekit.EgressInfo, error)
StopEgress(context.Context, string, *livekit.StopEgressRequest, ...psrpc1.RequestOption) (*livekit.EgressInfo, error)
SubscribeInfoUpdate(context.Context) (psrpc1.Subscription[*livekit.EgressInfo], error)
}
@@ -126,12 +139,18 @@ type EgressHandlerServerImpl interface {
type EgressHandlerServer interface {
RegisterUpdateStreamTopic(string) error
DeregisterUpdateStreamTopic(string) error
DeregisterUpdateStreamTopic(string)
RegisterStopEgressTopic(string) error
DeregisterStopEgressTopic(string) error
DeregisterStopEgressTopic(string)
PublishInfoUpdate(context.Context, *livekit.EgressInfo) error
// Close and wait for pending RPCs to complete
Shutdown()
// Close immediately, without waiting for pending RPCs
Kill()
}
// ====================
@@ -139,11 +158,11 @@ type EgressHandlerServer interface {
// ====================
type egressHandlerClient struct {
client psrpc1.RPCClient
client *psrpc1.RPCClient
}
// NewEgressHandlerClient creates a psrpc client that implements the EgressHandlerClient interface.
func NewEgressHandlerClient(clientID string, bus psrpc1.MessageBus, opts ...psrpc1.ClientOpt) (EgressHandlerClient, error) {
func NewEgressHandlerClient(clientID string, bus psrpc1.MessageBus, opts ...psrpc1.ClientOption) (EgressHandlerClient, error) {
rpcClient, err := psrpc1.NewRPCClient("EgressHandler", clientID, bus, opts...)
if err != nil {
return nil, err
@@ -154,16 +173,16 @@ func NewEgressHandlerClient(clientID string, bus psrpc1.MessageBus, opts ...psrp
}, nil
}
func (c *egressHandlerClient) UpdateStream(ctx context.Context, topic string, req *livekit.UpdateStreamRequest, opts ...psrpc1.RequestOpt) (*livekit.EgressInfo, error) {
return psrpc1.RequestTopicSingle[*livekit.EgressInfo](ctx, c.client, "UpdateStream", topic, req, opts...)
func (c *egressHandlerClient) UpdateStream(ctx context.Context, topic string, req *livekit.UpdateStreamRequest, opts ...psrpc1.RequestOption) (*livekit.EgressInfo, error) {
return psrpc1.RequestSingle[*livekit.EgressInfo](ctx, c.client, "UpdateStream", topic, req, opts...)
}
func (c *egressHandlerClient) StopEgress(ctx context.Context, topic string, req *livekit.StopEgressRequest, opts ...psrpc1.RequestOpt) (*livekit.EgressInfo, error) {
return psrpc1.RequestTopicSingle[*livekit.EgressInfo](ctx, c.client, "StopEgress", topic, req, opts...)
func (c *egressHandlerClient) StopEgress(ctx context.Context, topic string, req *livekit.StopEgressRequest, opts ...psrpc1.RequestOption) (*livekit.EgressInfo, error) {
return psrpc1.RequestSingle[*livekit.EgressInfo](ctx, c.client, "StopEgress", topic, req, opts...)
}
func (c *egressHandlerClient) SubscribeInfoUpdate(ctx context.Context) (psrpc1.Subscription[*livekit.EgressInfo], error) {
return psrpc1.SubscribeTopicQueue[*livekit.EgressInfo](ctx, c.client, "InfoUpdate", "")
return psrpc1.JoinQueue[*livekit.EgressInfo](ctx, c.client, "InfoUpdate", "")
}
// ====================
@@ -172,38 +191,46 @@ func (c *egressHandlerClient) SubscribeInfoUpdate(ctx context.Context) (psrpc1.S
type egressHandlerServer struct {
svc EgressHandlerServerImpl
rpc psrpc1.RPCServer
rpc *psrpc1.RPCServer
}
// NewEgressHandlerServer builds a RPCServer that can be used to handle
// requests that are routed to the right method in the provided svc implementation.
func NewEgressHandlerServer(serverID string, svc EgressHandlerServerImpl, bus psrpc1.MessageBus, opts ...psrpc1.ServerOpt) (EgressHandlerServer, error) {
rpcServer := psrpc1.NewRPCServer("EgressHandler", serverID, bus, opts...)
// NewEgressHandlerServer builds a RPCServer that will route requests
// to the corresponding method in the provided svc implementation.
func NewEgressHandlerServer(serverID string, svc EgressHandlerServerImpl, bus psrpc1.MessageBus, opts ...psrpc1.ServerOption) (EgressHandlerServer, error) {
s := psrpc1.NewRPCServer("EgressHandler", serverID, bus, opts...)
return &egressHandlerServer{
svc: svc,
rpc: rpcServer,
rpc: s,
}, nil
}
func (s *egressHandlerServer) RegisterUpdateStreamTopic(topic string) error {
return s.rpc.RegisterHandler(psrpc1.NewTopicHandler("UpdateStream", topic, s.svc.UpdateStream))
return psrpc1.RegisterHandler(s.rpc, "UpdateStream", topic, s.svc.UpdateStream, nil)
}
func (s *egressHandlerServer) DeregisterUpdateStreamTopic(topic string) error {
return s.rpc.DeregisterTopic("UpdateStream", topic)
func (s *egressHandlerServer) DeregisterUpdateStreamTopic(topic string) {
s.rpc.DeregisterHandler("UpdateStream", topic)
}
func (s *egressHandlerServer) RegisterStopEgressTopic(topic string) error {
return s.rpc.RegisterHandler(psrpc1.NewTopicHandler("StopEgress", topic, s.svc.StopEgress))
return psrpc1.RegisterHandler(s.rpc, "StopEgress", topic, s.svc.StopEgress, nil)
}
func (s *egressHandlerServer) DeregisterStopEgressTopic(topic string) error {
return s.rpc.DeregisterTopic("StopEgress", topic)
func (s *egressHandlerServer) DeregisterStopEgressTopic(topic string) {
s.rpc.DeregisterHandler("StopEgress", topic)
}
func (s *egressHandlerServer) PublishInfoUpdate(ctx context.Context, msg *livekit.EgressInfo) error {
return s.rpc.PublishTopic(ctx, "InfoUpdate", "", msg)
return s.rpc.Publish(ctx, "InfoUpdate", "", msg)
}
func (s *egressHandlerServer) Shutdown() {
s.rpc.Close(false)
}
func (s *egressHandlerServer) Kill() {
s.rpc.Close(true)
}
var psrpcFileDescriptor0 = []byte{