Documentation
¶
Overview ¶
Package appevent pkg/app/appevent/broadcaster.go c2-vis-appsvc
Package appevent pkg/app/appevent/event.go c2-vis-appsvc
Package appevent pkg/app/appevent/handshake.go c2-vis-appsvc
Package appevent pkg/app/appevent/rpc.go c2-vis-appsvc
Package appevent pkg/app/appevent/subscriber.go c2-vis-appsvc
Package appevent pkg/app/appevent/types.go c2-vis-appsvc
Package appevent pkg/app/appevent/utils.go c2-vis-appsvc
Index ¶
- Constants
- Variables
- func DoReqHandshake(conf appcommon.ProcConfig, subs *Subscriber) (net.Conn, []io.Closer, error)
- func DoRespHandshake(ebc *Broadcaster, conn net.Conn) (*appcommon.Hello, error)
- func PushEvent(s *Subscriber, e *Event) error
- type Broadcaster
- func (mc *Broadcaster) AddClient(c RPCClient)
- func (mc *Broadcaster) Broadcast(ctx context.Context, e *Event) error
- func (mc *Broadcaster) Close() error
- func (eb *Broadcaster) SendTCPDial(ctx context.Context, remoteNet, remoteAddr string)
- func (eb *Broadcaster) SendTPClose(_ context.Context, netType, addr string)
- type Event
- type MockRPCClient
- type RPCClient
- type RPCGateway
- type Subscriber
- type TCPCloseData
- type TCPDialData
Constants ¶
const TCPClose = "tcp_close"
TCPClose represents a close event.
const TCPDial = "tcp_dial"
TCPDial represents a dial event.
Variables ¶
var (
ErrSubscriptionsClosed = errors.New("event subscriptions is closed")
)
Errors associated with the Subscriber type.
Functions ¶
func DoReqHandshake ¶
func DoReqHandshake(conf appcommon.ProcConfig, subs *Subscriber) (net.Conn, []io.Closer, error)
DoReqHandshake performs a request handshake which is initiated from an app. First, it determines whether we need an egress connection (from the app server which sends events) by seeing if there are any subscriptions within 'subs'. If so, a listener is started. Then we send a hello object to the app server which contains the proc key and egress connection info (if needed).
func DoRespHandshake ¶
DoRespHandshake performs a response handshake from the app server side. It reads the hello object from the app, and connects the app to the events broadcast (if needed).
func PushEvent ¶
func PushEvent(s *Subscriber, e *Event) error
PushEvent pushes an event to the relevant subscription channel.
Types ¶
type Broadcaster ¶
type Broadcaster struct {
// contains filtered or unexported fields
}
Broadcaster combines multiple RPCClients (which connects to the RPCGateway of the apps). It is responsible for broadcasting events to apps (if the app is subscribed to the event type).
func NewBroadcaster ¶
func NewBroadcaster(log logrus.FieldLogger, timeout time.Duration) *Broadcaster
NewBroadcaster instantiates a Broadcaster.
func (*Broadcaster) AddClient ¶
func (mc *Broadcaster) AddClient(c RPCClient)
AddClient adds a RPCClient.
func (*Broadcaster) Broadcast ¶
func (mc *Broadcaster) Broadcast(ctx context.Context, e *Event) error
Broadcast broadcasts an event to all subscribed channels of all rpc gateways.
func (*Broadcaster) SendTCPDial ¶
func (eb *Broadcaster) SendTCPDial(ctx context.Context, remoteNet, remoteAddr string)
SendTCPDial sends tcp dial event
func (*Broadcaster) SendTPClose ¶
func (eb *Broadcaster) SendTPClose(_ context.Context, netType, addr string)
SendTPClose sends transport close event
type Event ¶
Event represents an event that is to be broadcasted.
type MockRPCClient ¶
MockRPCClient is an autogenerated mock type for the RPCClient type
func NewMockRPCClient ¶
func NewMockRPCClient(t interface {
mock.TestingT
Cleanup(func())
}) *MockRPCClient
NewMockRPCClient creates a new instance of MockRPCClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockRPCClient) Close ¶
func (_m *MockRPCClient) Close() error
Close provides a mock function with no fields
func (*MockRPCClient) Hello ¶
func (_m *MockRPCClient) Hello() *appcommon.Hello
Hello provides a mock function with no fields
type RPCClient ¶
type RPCClient interface {
io.Closer
Notify(ctx context.Context, e *Event) error
Hello() *appcommon.Hello
}
RPCClient describes the RPC client interface that communicates the NewRPCGateway.
type RPCGateway ¶
type RPCGateway struct {
// contains filtered or unexported fields
}
RPCGateway represents the RPC gateway that opens up an app for incoming events from visor.
func NewRPCGateway ¶
func NewRPCGateway(log logrus.FieldLogger, subs *Subscriber) *RPCGateway
NewRPCGateway returns a new RPCGateway.
func (*RPCGateway) Notify ¶
func (g *RPCGateway) Notify(e *Event, _ *struct{}) (err error)
Notify notifies the app about events.
type Subscriber ¶
type Subscriber struct {
// contains filtered or unexported fields
}
Subscriber is used by apps and contain subscription channels to different event types.
func NewSubscriber ¶
func NewSubscriber() *Subscriber
NewSubscriber returns a new Subscriber struct.
func (*Subscriber) Count ¶
func (s *Subscriber) Count() int
Count returns the number of subscriptions.
func (*Subscriber) OnTCPClose ¶
func (s *Subscriber) OnTCPClose(action func(data TCPCloseData))
OnTCPClose subscribes to the OnTCPClose event channel (if not already). And triggers the contained action func on each subsequent event.
func (*Subscriber) OnTCPDial ¶
func (s *Subscriber) OnTCPDial(action func(data TCPDialData))
OnTCPDial subscribes to the OnTCPDial event channel (if not already). And triggers the contained action func on each subsequent event.
func (*Subscriber) Subscriptions ¶
func (s *Subscriber) Subscriptions() map[string]bool
Subscriptions returns a map of all subscribed event types.
type TCPCloseData ¶
type TCPCloseData struct {
RemoteNet string `json:"remote_net"`
RemoteAddr string `json:"remote_addr"`
}
TCPCloseData contains net close event data.
type TCPDialData ¶
type TCPDialData struct {
RemoteNet string `json:"remote_net"`
RemoteAddr string `json:"remote_addr"`
}
TCPDialData contains net dial event data.