Documentation
¶
Overview ¶
Package stream of GOTOJS offers an interface to expose event or message streams. Stream implementations just need to implement the Source interface and define a Message type which is encodable as JSON.
Index ¶
Constants ¶
const ( DefaultBufferSize = 12 //BitSize MsecTimeDivisor = 1000 * 1000 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
func (*Buffer) Enqueue ¶
Enqueue adds a message to the buffer. If the buffer is fully occupied it will be added to the beginning. Thus it acts as a ringbuffer.
func (*Buffer) Fetch ¶
Fetch returns a slice of Messages that fit the request criteria. If no paramerter is given all available messages will be returned. If one ID is given as parameter, all Messages starting from this ID will be returned. If two IDs are given all messages between the first and the second will be returned.
type Configuration ¶
type FetchRequest ¶
type FetchRequest struct {
// contains filtered or unexported fields
}
func NewFetchRequest ¶
func NewFetchRequest(s *StreamSession) *FetchRequest
type Fetcher ¶
type Fetcher struct {
// contains filtered or unexported fields
}
func NewFetcher ¶
func NewFetcher(source Source, c *Configuration) (ret *Fetcher, err error)
NewFetcher creates a new fetcher which consits of a BacklogRunner process.
func (*Fetcher) BacklogRunner ¶
func (f *Fetcher) BacklogRunner()
BacklogRunner is the worker loop that continoously serves the client (fetch requests) with outstanding messages.
func (*Fetcher) Fetch ¶
func (f *Fetcher) Fetch(fr *FetchRequest) (ret []Message)
Fetch puts a fetchrequest to the backlog queue. The BacklogRunner process is taking care for sending the actual data back to the clients.
type Message ¶
type Message struct { Id ID `json:"id"` Time Timestamp `json:"time"` DTime Timestamp `json:"dtime"` Payload interface{} `json:"payload"` }
func NewMessage ¶
func NewMessage(payload interface{}) Message
NewMessage instantiates an empty Message with the given payload.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
func NewStream ¶
NewStream creates a new Stream based on the given Source implementation. The default configuration can be overwritten by a configuration file named "streamconfig.json"
func (*Stream) Next ¶
Method to be exposed for message retrieval. Cursor information is stored in the users GOTOJS session. Clients may frequently call this method to retrieve new messages.
func (*Stream) Reset ¶
func (t *Stream) Reset(session *Session)
Reset resets the users session. The cursor will be deleted and reinitialized.