message

package
v2.0.437+incompatible Latest Latest
Warning

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

Go to latest
Published: May 5, 2018 License: AGPL-3.0 Imports: 8 Imported by: 12

Documentation

Index

Constants

View Source
const (
	SubscriberDirect = SubscriberType(iota)
	SubscriberRemote
)

Subscriber types

Variables

View Source
var Query = Ssid{system, query}

Query represents a constant SSID for a query.

Functions

This section is empty.

Types

type Awaiter

type Awaiter interface {
	Gather(time.Duration) [][]byte
}

Awaiter represents an asynchronously awaiting response channel.

type Counter

type Counter struct {
	Ssid    Ssid
	Channel []byte
	Counter int
}

Counter represents a single subscription counter.

type Counters

type Counters struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Counters represents a subscription counting map.

func NewCounters

func NewCounters() *Counters

NewCounters creates a new container.

func (*Counters) All

func (s *Counters) All() []Counter

All returns all counters.

func (*Counters) Decrement

func (s *Counters) Decrement(ssid Ssid) (last bool)

Decrement decrements a subscription counter.

func (*Counters) Increment

func (s *Counters) Increment(ssid Ssid, channel []byte) (first bool)

Increment increments the subscription counter.

type Frame

type Frame []Message

Frame represents a message frame which is sent through the wire to the remote server and contains a set of messages.

func DecodeFrame

func DecodeFrame(buf []byte) (out Frame, err error)

DecodeFrame decodes the message frame from the decoder.

func NewFrame

func NewFrame(capacity int) Frame

NewFrame creates a new frame with the specified capacity

func (*Frame) Append

func (f *Frame) Append(time int64, ssid Ssid, channel, payload []byte)

Append appends the message to a frame.

func (*Frame) Encode

func (f *Frame) Encode() (out []byte, err error)

Encode encodes the message frame

type Message

type Message struct {
	Time    int64  `json:"ts,omitempty"`   // The timestamp of the message
	Ssid    Ssid   `json:"ssid,omitempty"` // The Ssid of the message
	Channel []byte `json:"chan,omitempty"` // The channel of the message
	Payload []byte `json:"data,omitempty"` // The payload of the message
	TTL     uint32 `json:"ttl,omitempty"`  // The time-to-live of the message
}

Message represents a message which has to be forwarded or stored.

func (*Message) Size

func (m *Message) Size() int64

Size returns the byte size of the message.

type Ssid

type Ssid []uint32

Ssid represents a subscription ID which contains a contract and a list of hashes for various parts of the channel.

func NewSsid

func NewSsid(contract uint32, c *security.Channel) Ssid

NewSsid creates a new SSID.

func NewSsidForPresence

func NewSsidForPresence(original Ssid) Ssid

NewSsidForPresence creates a new SSID for presence.

func (Ssid) Contract

func (s Ssid) Contract() uint32

Contract gets the contract part from SSID.

func (Ssid) Encode

func (s Ssid) Encode() string

Encode encodes the SSID to a binary format

func (Ssid) GetHashCode

func (s Ssid) GetHashCode() uint32

GetHashCode combines the SSID into a single hash.

type Subscriber

type Subscriber interface {
	ID() string
	Type() SubscriberType
	Send(*Message) error
}

Subscriber is a value associated with a subscription.

type SubscriberType

type SubscriberType uint8

SubscriberType represents a type of subscriber

type Subscribers

type Subscribers []Subscriber

Subscribers represents a subscriber set which can contain only unique values.

func (*Subscribers) AddUnique

func (s *Subscribers) AddUnique(value Subscriber)

AddUnique adds a subscriber to the set.

func (*Subscribers) Contains

func (s *Subscribers) Contains(value Subscriber) bool

Contains checks whether a subscriber is in the set.

func (*Subscribers) Remove

func (s *Subscribers) Remove(value Subscriber)

Remove removes a subscriber from the set.

type Subscription

type Subscription struct {
	Ssid       Ssid       // Gets or sets the SSID (parsed channel) for this subscription.
	Subscriber Subscriber // Gets or sets the subscriber for this subscription.
}

Subscription represents a topic subscription.

type Trie

type Trie struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Trie represents an efficient collection of subscriptions with lookup capability.

func NewTrie

func NewTrie() *Trie

NewTrie creates a new matcher for the subscriptions.

func (*Trie) Lookup

func (t *Trie) Lookup(query Ssid) (subs Subscribers)

Lookup returns the Subscribers for the given topic.

func (*Trie) Subscribe

func (t *Trie) Subscribe(ssid Ssid, sub Subscriber) (*Subscription, error)

Subscribe adds the Subscriber to the topic and returns a Subscription.

func (*Trie) Unsubscribe

func (t *Trie) Unsubscribe(ssid Ssid, subscriber Subscriber)

Unsubscribe removes the Subscription.

Jump to

Keyboard shortcuts

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