base

package
v0.0.0-...-ef9407b Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2017 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServiceCommandStart = 0
	ServiceCommandStop  = 1
)

Variables

View Source
var (
	IotErrorNotFound   = errors.New("Resource not found")
	IotErrorAuthFailed = errors.New("Iot authentication failed")
)

Functions

func AsyncProduceMessage

func AsyncProduceMessage(c core.Config, topic string, value sarama.Encoder) error

func CheckAllRegisteredServices

func CheckAllRegisteredServices() error

CheckAllRegisteredServices check all registered service simplily

func RegisterService

func RegisterService(name string, configs map[string]string, factory ServiceFactory)

RegisterService register service with name and protocol specified

func SyncProduceMessage

func SyncProduceMessage(c core.Config, topic string, value sarama.Encoder) error

Types

type ClientInfo

type ClientInfo struct {
	UserName     string
	CleanSession bool
	PeerName     string
	ConnectTime  string
}

ClientInfo

type DecodeFeedback

type DecodeFeedback interface {
	// SetTruncated should be called if during decoding you notice that
	// a packet is shorter than internal layer variables
	SetTruncated()
}

type HubNodeInfo

type HubNodeInfo struct {
	NodeName  string
	NodeIp    string
	CreatedAt string
}

type Metrics

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

Metrics declarations

func NewMetrics

func NewMetrics(withlock bool) *Metrics

func (*Metrics) AddMetrics

func (m *Metrics) AddMetrics(metrics *Metrics)

func (*Metrics) Get

func (m *Metrics) Get() map[string]uint64

type NilDecodeFeedback

type NilDecodeFeedback struct{}

func (NilDecodeFeedback) SetTruncated

func (NilDecodeFeedback) SetTruncated()

type Packet

type Packet interface {
	// PacketType return type name of packet
	PacketType() string

	// DecodeFromReader decode packet from given reader
	DecodeFromReader(r io.Reader, df DecodeFeedback) error

	// DecodeFromBytes decode packet from given
	DecodeFromBytes(data []uint8, df DecodeFeedback) error

	// SerializeTo writes the serialized form of the packet into the serialize buffer
	SerializeTo(buf SerializeBuffer, opts SerializeOptions) error

	// Clear clear packet content and payload
	Clear()

	// Length return length of the packet
	Length() int
}

type ProtocolService

type ProtocolService interface {
	// Service Infomation
	GetServiceInfo() *ServiceInfo

	// Stats and Metrics
	GetStats() *Stats
	GetMetrics() *Metrics

	// Client
	GetClients() []*ClientInfo
	GetClient(id string) *ClientInfo
	KickoffClient(id string) error

	// Session
	GetSessions(conditions map[string]bool) []*SessionInfo
	GetSession(id string) *SessionInfo

	// Route info
	GetRoutes() []*RouteInfo
	GetRoute(id string) *RouteInfo

	// Topic info
	GetTopics() []*TopicInfo
	GetTopic(id string) *TopicInfo

	// SubscriptionInfo
	GetSubscriptions() []*SubscriptionInfo
	GetSubscription(id string) *SubscriptionInfo
}

type RouteInfo

type RouteInfo struct {
	Topic string
	Route []string
}

RouteInfo

type SerializeBuffer

type SerializeBuffer interface {
	// Bytes return the continguous set of bytes
	Bytes() []byte
	// PrependBytes return a set of bytes which prepends the curent bytes
	// in this buffer
	PrependBytes(num int) ([]byte, error)
	// AppendBytes return a set of bytes which append the current bytes
	// in this buffer
	AppendBytes(num int) ([]byte, error)
	// Clear reset the SerializeBuffer to a new
	Clear() error
}

type SerializeOptions

type SerializeOptions struct {
	// Fixlengths determines whether layers should fix the values for any
	// length field that depends on the payload during serialization
	FixLengths bool
	// ComputeChecksums determines wethers layers should recompute checksums
	// based on their payloads
	ComputeChecksums bool
}

type Service

type Service interface {
	Info() *ServiceInfo
	Start() error
	Stop()
}

func CreateService

func CreateService(name string, c core.Config, ch chan ServiceCommand) (Service, error)

CreateService create service instance according to service name

type ServiceCommand

type ServiceCommand int

type ServiceFactory

type ServiceFactory interface {
	New(name string, c core.Config, ch chan ServiceCommand) (Service, error)
}

type ServiceInfo

type ServiceInfo struct {
	ServiceName    string
	Listen         string
	Acceptors      uint64
	MaxClients     uint64
	CurrentClients uint64
	ShutdownCount  uint64
}

ServiceInfo

type ServiceManager

type ServiceManager struct {
	sync.Once
	// contains filtered or unexported fields
}

func GetServiceManager

func GetServiceManager() *ServiceManager

GetServiceManager create service manager and all supported service The function should be called in service

func NewServiceManager

func NewServiceManager(c core.Config) (*ServiceManager, error)

NewServiceManager create ServiceManager only in main context

func (*ServiceManager) GetAllProtocolServices

func (s *ServiceManager) GetAllProtocolServices() []ProtocolService

GetAllProtocolServices() return all protocol services

func (*ServiceManager) GetAllServiceInfo

func (s *ServiceManager) GetAllServiceInfo() []*ServiceInfo

GetAllServiceInfo return all service information

func (*ServiceManager) GetClient

func (s *ServiceManager) GetClient(serviceName string, id string) *ClientInfo

GeteClient return client info with specified client id

func (*ServiceManager) GetClients

func (s *ServiceManager) GetClients(serviceName string) []*ClientInfo

GetClients return clients list withspecified service

func (*ServiceManager) GetMetrics

func (s *ServiceManager) GetMetrics(serviceName string) map[string]uint64

GetMetrics return server metrics

func (*ServiceManager) GetNodeInfo

func (s *ServiceManager) GetNodeInfo() *HubNodeInfo

Node info

func (*ServiceManager) GetProtocolServices

func (s *ServiceManager) GetProtocolServices(name string) []ProtocolService

GetProtocolServiceByname return protocol services by name

func (*ServiceManager) GetRoute

func (s *ServiceManager) GetRoute(serviceName string, topic string) *RouteInfo

GetRoute return route information for specified topic

func (*ServiceManager) GetRoutes

func (s *ServiceManager) GetRoutes(serviceName string) []*RouteInfo

GetRoutes return route table information for specified service

func (*ServiceManager) GetServicesByName

func (s *ServiceManager) GetServicesByName(name string) []Service

GetServicesByName return service instance by name, or matched by part of name

func (*ServiceManager) GetSession

func (s *ServiceManager) GetSession(serviceName string, id string) *SessionInfo

GetSession return specified session information with session id

func (*ServiceManager) GetSessions

func (s *ServiceManager) GetSessions(serviceName string, conditions map[string]bool) []*SessionInfo

GetSessions return all sessions information for specified service

func (*ServiceManager) GetStats

func (s *ServiceManager) GetStats(serviceName string) map[string]uint64

GetStats return server's stats

func (*ServiceManager) GetSubscription

func (s *ServiceManager) GetSubscription(serviceName string, sub string) *SubscriptionInfo

GetSubscription return subscription information for specified topic

func (*ServiceManager) GetSubscriptions

func (s *ServiceManager) GetSubscriptions(serviceName string) []*SubscriptionInfo

GetSubscriptions return subscription informaiton for specified service

func (*ServiceManager) GetTopic

func (s *ServiceManager) GetTopic(serviceName string, topic string) *TopicInfo

GetTopic return topic information for specified topic

func (*ServiceManager) GetTopics

func (s *ServiceManager) GetTopics(serviceName string) []*TopicInfo

GetTopics return topic informaiton for specified service

func (*ServiceManager) GetVersion

func (s *ServiceManager) GetVersion() string

Version

func (*ServiceManager) KickoffClient

func (s *ServiceManager) KickoffClient(serviceName string, id string) error

Kickoff Client killoff a client from specified service

func (*ServiceManager) Run

func (s *ServiceManager) Run() error

Run launch all serices and wait to terminate

func (*ServiceManager) StartService

func (s *ServiceManager) StartService(name string) error

StartService launch specified service

func (*ServiceManager) StopService

func (s *ServiceManager) StopService(id string) error

StopService stop specified service

type Session

type Session interface {
	// Identifier get session identifier
	Identifier() string
	// Info return session information
	Info() *SessionInfo
	// GetService get the service ower for current session
	Service() Service
	// Handle indicate service to handle the packet
	Handle() error
	// Destroy will release current session
	Destroy() error
	// RegisterObserver register observer on session
	RegisterObserver(SessionObserver)
	// Get Stats
	GetStats() *Stats
	// Get Metrics
	GetMetrics() *Metrics
}

type SessionInfo

type SessionInfo struct {
	ClientId           string
	CleanSession       bool
	MessageMaxInflight uint64
	MessageInflight    uint64
	MessageInQueue     uint64
	MessageDropped     uint64
	AwaitingRel        uint64
	AwaitingComp       uint64
	AwaitingAck        uint64
	CreatedAt          string
}

SessionInfo

type SessionObserver

type SessionObserver interface {
	OnGetMountPoint() string
	OnConnect(s Session, userdata interface{}) error
	OnDisconnect(s Session, userdta interface{}) error
	OnPublish(s Session, userdata interface{}) error
	OnMessage(s Session, userdata interface{}) error
	OnSubscribe(s Session, userdata interface{}) error
	OnUnsubscribe(s Session, userdata interface{}) error
	OnAuthenticate(s Session, username string, password string) error
}

type Stats

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

Stats declration

func NewStats

func NewStats(withlock bool) *Stats

func (*Stats) AddStat

func (s *Stats) AddStat(name string, value uint64)

func (*Stats) AddStats

func (s *Stats) AddStats(stats *Stats)

func (*Stats) Get

func (s *Stats) Get() map[string]uint64

type SubscriptionInfo

type SubscriptionInfo struct {
	ClientId  string
	Topic     string
	Attribute string
}

SubscriptionInfo

type TopicInfo

type TopicInfo struct {
	Topic     string
	Attribute string
}

TopicInfo

Jump to

Keyboard shortcuts

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