gocomet

package module
v0.0.0-...-36d22d9 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2014 License: MIT Imports: 12 Imported by: 0

README

gocomet

A Go implementation of the Bayeux Protocol.

Installation

go get github.com/balzaczyy/gocomet

Usage

import comet "github.com/balzaczyy/gocomet"
...
http.Handle("/cometd", comet.New())

License

MIT, see LICENSE.txt.

Documentation

Index

Constants

View Source
const (
	VERSION          = "1.0"
	MINIMUM_VERSION  = "1.0"
	DEFAULT_INTERVAL = 0
)
View Source
const MAILBOX_SIZE = 1000

The unsent messages are kept temporarily in a mailbox. But only last MAILBOX_SIZE messages are kept.

View Source
const MAX_ID_GEN_RETRY = 100

Maximum number of retry to avoid conflict

View Source
const MAX_ID_KEPT_TIME = 30 * time.Minute

Maximum time to keep IDs from being auto-released

View Source
const MAX_SESSION_IDEL time.Duration = 1 * time.Minute

Maximum allowed session idel. After that, the session is considered as disconnected.

Variables

This section is empty.

Functions

This section is empty.

Types

type Advice

type Advice struct {
	Reconnect string `json:"reconnect,omitempty"`
	Timeout   int64  `json:"timeout,omitempty"`
	Interval  int    `json:"interval,omitempty"`
}

type Broker

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

A simple Message Broker that transmits text messages between clients through subscribed channels.

type EventMessage

type EventMessage struct {
	Channel   string      `json:"channel"`
	Data      string      `json:"data"`
	Id        string      `json:"id,omitempty"`
	ClientId  string      `json:"clientId,omitempty"`
	Extension interface{} `json:"ext,omitempty"`
	Advice    *Advice     `json:"advice,omitempty"`
}

type Instance

type Instance struct {
	*Server
	// contains filtered or unexported fields
}

func New

func New() *Instance

Create a simple cometd instace.

func (*Instance) AddService

func (c *Instance) AddService(channel string, handler func(session *Session, message *MetaMessage)) *Instance

Add new handler to listen and process messages sent to /service/** channel. It doesn't check for conflict and will override existing one with the same name. The returned Instance object allows flow style configuration.

func (*Instance) ServeHTTP

func (inst *Instance) ServeHTTP(w http.ResponseWriter, r *http.Request)

type LongPolling

type LongPolling struct {
}

From [The Bayeux Protocol](http://cometd.org/documentation/bayeux/spec):

"Long-polling" is a poolling transport that attempts to minimize both latency in sever-client message delivery, and the processing/network resources required for the cnnection.

type Message

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

func (*Message) String

func (msg *Message) String() string

type MetaMessage

type MetaMessage struct {
	Channel                  string          `json:"channel"`
	Version                  string          `json:"version,omitempty"`
	MinimumVersion           string          `json:"minimumVersion,omitempty"`
	SupportedConnectionTypes []string        `json:"supportedConnectionTypes,omitempty"`
	ClientId                 string          `json:"clientId,omitempty"`
	Advice                   *Advice         `json:"advice,omitempty"`
	ConnectionType           string          `json:"connectionType,omitempty"`
	Id                       string          `json:"id,omitempty"`
	Timestamp                string          `json:"timestamp,omitempty"`
	Data                     json.RawMessage `json:"data,omitempty"`
	Successful               bool            `json:"successful"`
	Subscription             string          `json:"subscription,omitempty"`
	Error                    string          `json:"error,omitempty"`
	Extension                interface{}     `json:"ext,omitempty"`
}

func (*MetaMessage) String

func (mm *MetaMessage) String() string

type Router

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

A simple router that accepts mutiple matching rules, responds to path query, and returns the matching client IDs.

Internally, it uses a Trie to do path matching. Adding or removing rule will change the internal Trie structure. The lookup efficiency is proportional to the approximte number of path segments.

Note: it's thread-safe and can be shared in different goroutines.

func (*Router) String

func (r *Router) String() string

type Rule

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

func (*Rule) String

func (rule *Rule) String() string

type Server

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

The Bayeux protocol implementation V1.0.

A common scenario is that, the client should handshake the server first, to determine which version of the protocol is used. It doesn't have any transport related fields or logic either becuase they should be already taken care of before it's used.

func (*Server) Send

func (c *Server) Send(toClientId, channel, data string) bool

Send message directly to target client.

type Session

type Session struct {
	ID string
	// contains filtered or unexported fields
}

func (*Session) ListenOnRemoval

func (ss *Session) ListenOnRemoval(listener func(session *Session, timeout bool))

Attach a listener for session destroy event.

type SessionRemovalListener

type SessionRemovalListener func(session *Session, timeout bool)

type UniqueStringPool

type UniqueStringPool struct {
	sync.Locker
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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