hub

package
v0.0.0-...-a3e1a49 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Gate

type Gate struct {
	// contains filtered or unexported fields
}

Gate plays the role of a shard for the hub. It keeps subscriptions for some streams (a particular shard) and is used to broadcast messages to all subscribers of these streams.

func NewGate

func NewGate(ctx context.Context, l *slog.Logger) *Gate

NewGate creates a new gate.

func (*Gate) Broadcast

func (g *Gate) Broadcast(streamMsg *common.StreamMessage)

Broadcast sends a message to all subscribers of the stream.

func (*Gate) Size

func (g *Gate) Size() int

Size returns a number of uniq streams

func (*Gate) Subscribe

func (g *Gate) Subscribe(session HubSession, stream string, identifier string)

Subscribe adds a session to the stream.

func (*Gate) Unsubscribe

func (g *Gate) Unsubscribe(session HubSession, stream string, identifier string)

Unsubscribe removes a session from the stream.

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

Hub stores all the sessions and the corresponding subscriptions info

func NewHub

func NewHub(poolSize int, l *slog.Logger) *Hub

NewHub builds new hub instance

func (*Hub) AddSession

func (h *Hub) AddSession(session HubSession)

func (*Hub) Broadcast

func (h *Hub) Broadcast(stream string, data string)

Broadcast enqueues data broadcasting to a stream

func (*Hub) BroadcastMessage

func (h *Hub) BroadcastMessage(msg *common.StreamMessage)

BroadcastMessage enqueues broadcasting a pre-built StreamMessage

func (*Hub) FindByIdentifier

func (h *Hub) FindByIdentifier(id string) HubSession

func (*Hub) RemoteDisconnect

func (h *Hub) RemoteDisconnect(msg *common.RemoteDisconnectMessage)

RemoteDisconnect enqueues remote disconnect command

func (*Hub) RemoveSession

func (h *Hub) RemoveSession(session HubSession)

func (*Hub) RemoveSessionLater

func (h *Hub) RemoveSessionLater(s HubSession)

RemoveSession enqueues session un-registration

func (*Hub) Run

func (h *Hub) Run()

Run makes hub active

func (*Hub) Sessions

func (h *Hub) Sessions() []HubSession

func (*Hub) Shutdown

func (h *Hub) Shutdown()

Shutdown sends shutdown command to hub

func (*Hub) Size

func (h *Hub) Size() int

Size returns a number of active sessions

func (*Hub) StreamsSize

func (h *Hub) StreamsSize() int

StreamsSize returns a number of uniq streams

func (*Hub) SubscribeSession

func (h *Hub) SubscribeSession(session HubSession, stream string, identifier string)

func (*Hub) UniqSize

func (h *Hub) UniqSize() int

UniqSize returns a number of uniq identifiers

func (*Hub) UnsubscribeSession

func (h *Hub) UnsubscribeSession(session HubSession, stream string, identifier string)

func (*Hub) UnsubscribeSessionFromChannel

func (h *Hub) UnsubscribeSessionFromChannel(session HubSession, targetIdentifier string)

type HubRegistration

type HubRegistration struct {
	// contains filtered or unexported fields
}

HubRegistration represents registration event ("add" or "remove")

type HubSession

type HubSession interface {
	GetID() string
	GetIdentifiers() string
	Send(msg encoders.EncodedMessage)
	DisconnectWithMessage(msg encoders.EncodedMessage, code string)
}

type HubSessionInfo

type HubSessionInfo struct {
	// contains filtered or unexported fields
}

HubSessionInfo is used to track registered sessions

func NewHubSessionInfo

func NewHubSessionInfo(session HubSession) *HubSessionInfo

func (*HubSessionInfo) AddStream

func (hs *HubSessionInfo) AddStream(stream string, identifier string)

func (*HubSessionInfo) RemoveStream

func (hs *HubSessionInfo) RemoveStream(stream string, identifier string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL