nxcore

package
Version: v0.0.0-...-d1034c5 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2016 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrParse            = -32700
	ErrInvalidRequest   = -32600
	ErrMethodNotFound   = -32601
	ErrInvalidParams    = -32602
	ErrInternal         = -32603
	ErrTimeout          = -32000
	ErrCancel           = -32001
	ErrInvalidTask      = -32002
	ErrInvalidPipe      = -32003
	ErrInvalidUser      = -32004
	ErrUserExists       = -32005
	ErrPermissionDenied = -32010
	ErrTtlExpired       = -32011
)

Variables

View Source
var ErrStr = map[int]string{
	ErrParse:            "Parse error",
	ErrInvalidRequest:   "Invalid request",
	ErrMethodNotFound:   "Method not found",
	ErrInvalidParams:    "Invalid params",
	ErrInternal:         "Internal error",
	ErrTimeout:          "Timeout",
	ErrCancel:           "Cancel",
	ErrInvalidTask:      "Invalid task",
	ErrInvalidPipe:      "Invalid pipe",
	ErrInvalidUser:      "Invalid user",
	ErrUserExists:       "User already exists",
	ErrPermissionDenied: "Permission denied",
	ErrTtlExpired:       "TTL expired",
}

Functions

func NewJsonRpcErr

func NewJsonRpcErr(code int, message string, data interface{}) error

NewJsonRpcErr creates new JSON-RPC error.

code is the JSON-RPC error code. message is optional in case of well known error code (negative values). data is an optional extra info object.

Types

type JsonRpcErr

type JsonRpcErr struct {
	Cod  int         `json:"code"`
	Mess string      `json:"message"`
	Dat  interface{} `json:"data,omitempty"`
}

func (*JsonRpcErr) Code

func (e *JsonRpcErr) Code() int

func (*JsonRpcErr) Data

func (e *JsonRpcErr) Data() interface{}

func (*JsonRpcErr) Error

func (e *JsonRpcErr) Error() string

type JsonRpcReq

type JsonRpcReq struct {
	Jsonrpc string      `json:"jsonrpc"`
	Id      uint64      `json:"id,omitempty"`
	Method  string      `json:"method"`
	Params  interface{} `json:"params"`
	// contains filtered or unexported fields
}

type JsonRpcRes

type JsonRpcRes struct {
	Jsonrpc string      `json:"jsonrpc"`
	Id      uint64      `json:"id,omitempty"`
	Result  interface{} `json:"result,omitempty"`
	Error   *JsonRpcErr `json:"error,omitempty"`
}

type Msg

type Msg struct {
	Count int64       // Message counter (unique and correlative)
	Msg   interface{} // Pipe message
}

Msg represents a pipe single message

type NexusConn

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

NexusConn represents the Nexus connection.

func NewNexusConn

func NewNexusConn(conn net.Conn) *NexusConn

NewNexusConn creates new nexus connection from net.conn

func (*NexusConn) Close

func (nc *NexusConn) Close()

Close closes nexus connection.

func (*NexusConn) Closed

func (nc *NexusConn) Closed() bool

Closed returns Nexus connection state.

func (*NexusConn) Exec

func (nc *NexusConn) Exec(method string, params interface{}) (result interface{}, err error)

Exec is a low level JSON-RPC call function.

func (*NexusConn) ExecNoWait

func (nc *NexusConn) ExecNoWait(method string, params interface{}) (id uint64, rch chan *JsonRpcRes, err error)

ExecNoWait is a low level JSON-RPC call function, it don't wait response from server.

func (*NexusConn) GetContext

func (nc *NexusConn) GetContext() context.Context

GetContext returns internal connection context.

func (*NexusConn) Id

func (nc *NexusConn) Id() string

Id returns the connection id after a login.

func (*NexusConn) Lock

func (nc *NexusConn) Lock(lock string) (bool, error)

Lock tries to get a lock. Returns lock success/failure or error.

func (*NexusConn) Login

func (nc *NexusConn) Login(user string, pass string) (interface{}, error)

Login attempts to login using user and pass. Returns the response object from Nexus or error.

func (*NexusConn) NodeList

func (nc *NexusConn) NodeList(limit int, skip int) ([]NodeInfo, error)

Nodes returns info of the nodes state Returns a list of NodeInfo structs or an error

func (*NexusConn) Ping

func (nc *NexusConn) Ping(timeout time.Duration) (err error)

Ping pings Nexus server, timeout is the max time waiting for server response, after that ErrTimeout is returned.

func (*NexusConn) PipeCreate

func (nc *NexusConn) PipeCreate(opts ...*PipeOpts) (*Pipe, error)

PipeCreate creates a new pipe. Returns the new pipe object or error.

func (*NexusConn) PipeOpen

func (nc *NexusConn) PipeOpen(pipeId string) (*Pipe, error)

PipeOpen Creates a new pipe from pipe identification string. Returns the new pipe object or error.

func (*NexusConn) Reload

func (nc *NexusConn) Reload() (interface{}, error)

Reload forces the node owner of the client connection to reload its info (tags) Returns the response object from Nexus or error.

func (*NexusConn) SessionKick

func (nc *NexusConn) SessionKick(connId string) (interface{}, error)

SessionKick forces the node owner of the client connection to close it Returns the response object from Nexus or error.

func (*NexusConn) SessionList

func (nc *NexusConn) SessionList(prefix string, limit int, skip int) ([]UserSessions, error)

Sessions returns info of the users sessions Returns a list of SessionInfo structs or an error

func (*NexusConn) SessionReload

func (nc *NexusConn) SessionReload(connId string) (interface{}, error)

SessionReload forces the node owner of the client connection to reload its info (tags) Returns the response object from Nexus or error.

func (*NexusConn) TaskList

func (nc *NexusConn) TaskList(prefix string, limit int, skip int) (*TaskList, error)

TaskList returns how many push/pulls are happening on a path prefix is the method prefix we want pull Ex. "test.fibonacci" Returns a TaskList or error.

func (*NexusConn) TaskPull

func (nc *NexusConn) TaskPull(prefix string, timeout time.Duration) (*Task, error)

TaskPull pulls a task from Nexus cloud. prefix is the method prefix we want pull Ex. "test.fibonacci" timeout is the maximum time waiting for a task. Returns a new incomming Task or error.

func (*NexusConn) TaskPush

func (nc *NexusConn) TaskPush(method string, params interface{}, timeout time.Duration, opts ...*TaskOpts) (interface{}, error)

TaskPush pushes a task to Nexus cloud. method is the method path Ex. "test.fibonacci.fib" params is the method params object. timeout is the maximum time waiting for response, 0 = no timeout. options (see TaskOpts struct) Returns the task result or error.

func (*NexusConn) TaskPushCh

func (nc *NexusConn) TaskPushCh(method string, params interface{}, timeout time.Duration, opts ...*TaskOpts) (<-chan interface{}, <-chan error)

TaskPushCh pushes a task to Nexus cloud. method is the method path Ex. "test.fibonacci.fib" params is the method params object. timeout is the maximum time waiting for response, 0 = no timeout. options (see TaskOpts struct) Returns two channels (one for result of interface{} type and one for error of error type).

func (*NexusConn) TopicPublish

func (nc *NexusConn) TopicPublish(topic string, msg interface{}) (interface{}, error)

TopicPublish publishes message to a topic. Returns the response object from Nexus or error.

func (*NexusConn) TopicSubscribe

func (nc *NexusConn) TopicSubscribe(pipe *Pipe, topic string) (interface{}, error)

TopicSubscribe subscribes a pipe to a topic. Returns the response object from Nexus or error.

func (*NexusConn) TopicUnsubscribe

func (nc *NexusConn) TopicUnsubscribe(pipe *Pipe, topic string) (interface{}, error)

TopicUnsubscribe unsubscribes a pipe from a topic. Returns the response object from Nexus or error.

func (*NexusConn) Unlock

func (nc *NexusConn) Unlock(lock string) (bool, error)

Unlock tries to free a lock. Returns unlock success/failure or error.

func (*NexusConn) UserAddTemplate

func (nc *NexusConn) UserAddTemplate(user, template string) (interface{}, error)

UserAddTemplate adds a new template to the user. Returns the response object from Nexus or error.

func (*NexusConn) UserCreate

func (nc *NexusConn) UserCreate(user, pass string) (interface{}, error)

UserCreate creates new user in Nexus user's table. Returns the response object from Nexus or error.

func (*NexusConn) UserDelTags

func (nc *NexusConn) UserDelTags(user string, prefix string, tags []string) (interface{}, error)

UserDelTags remove tags from user's prefix. Returns the response object from Nexus or error.

func (*NexusConn) UserDelTemplate

func (nc *NexusConn) UserDelTemplate(user, template string) (interface{}, error)

UserDelTemplate removes a template from the user. Returns the response object from Nexus or error.

func (*NexusConn) UserDelete

func (nc *NexusConn) UserDelete(user string) (interface{}, error)

UserDelete removes user from Nexus user's table. Returns the response object from Nexus or error.

func (*NexusConn) UserList

func (nc *NexusConn) UserList(prefix string, limit int, skip int) ([]UserInfo, error)

UserList lists users from Nexus user's table. Returns a list of UserInfo or error.

func (*NexusConn) UserListTemplate

func (nc *NexusConn) UserListTemplate(user string) (interface{}, error)

UserListTemplate returns the templates from the user. Returns the response object from Nexus or error.

func (*NexusConn) UserSetPass

func (nc *NexusConn) UserSetPass(user string, pass string) (interface{}, error)

UserSetPass sets new user password. Returns the response object from Nexus or error.

func (*NexusConn) UserSetTags

func (nc *NexusConn) UserSetTags(user string, prefix string, tags map[string]interface{}) (interface{}, error)

UserSetTags set tags on user's prefix. Returns the response object from Nexus or error.

type NodeInfo

type NodeInfo struct {
	Load    map[string]float64 `json:"load"`
	Clients int                `json:"clients"`
	NodeId  string             `json:"id"`
}

type Pipe

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

Pipe represents a pipe. Pipes can only be read from the connection that created them and can be written from any conection.

func (*Pipe) Close

func (p *Pipe) Close() (interface{}, error)

Close closes pipe. Returns the response object from Nexus or error.

func (*Pipe) Id

func (p *Pipe) Id() string

Id returns the pipe identification strring.

func (*Pipe) Listen

func (p *Pipe) Listen(ch chan *Msg) chan *Msg

Listen returns a pipe reader channel. ch is the channel used and returned by Listen, if ch is nil Listen creates a new unbuffered channel. channel is closed when pipe is closed or error happens.

func (*Pipe) Read

func (p *Pipe) Read(max int, timeout time.Duration) (*PipeData, error)

Read reads up to (max) messages from pipe or until timeout occurs.

func (*Pipe) TopicListen

func (p *Pipe) TopicListen(ch chan *TopicMsg) chan *TopicMsg

TopicListen returns a pipe topic reader channel. ch is the channel used and returned by Listen, if ch is nil Listen creates a new unbuffered channel. channel is closed when pipe is closed or error happens.

func (*Pipe) TopicRead

func (p *Pipe) TopicRead(max int, timeout time.Duration) (*TopicData, error)

TopicRead reads up to (max) topic messages from pipe or until timeout occurs.

func (*Pipe) Write

func (p *Pipe) Write(msg interface{}) (interface{}, error)

Write writes message to pipe. Returns the response object from Nexus or error.

type PipeData

type PipeData struct {
	Msgs    []*Msg // Messages
	Waiting int    // Number of messages waiting in Nexus server since last read
	Drops   int    // Number of messages dropped (pipe overflows) since last read
}

PipeData represents a pipe messages group obtained in read ops.

type PipeOpts

type PipeOpts struct {
	Length int // Pipe buffer capacity
}

PipeOpts represents pipe creation options

type SessionInfo

type SessionInfo struct {
	Id            string    `json:"id"`
	NodeId        string    `json:"nodeId"`
	RemoteAddress string    `json:"remoteAddress"`
	Protocol      string    `json:"protocol"`
	CreationTime  time.Time `json:"creationTime"`
}

type Task

type Task struct {
	Path   string
	Method string
	Params interface{}
	Prio   int
	Detach bool
	User   string
	Tags   map[string]interface{}
	// contains filtered or unexported fields
}

Task represents a task pushed to Nexus.

func (*Task) Accept

func (t *Task) Accept() (interface{}, error)

Accept accepts a detached task. Is an alias for SendResult(nil).

func (*Task) GetConn

func (t *Task) GetConn() *NexusConn

GetConn retrieves the task underlying nexus connection.

func (*Task) Reject

func (t *Task) Reject() (interface{}, error)

Reject rejects the task. Task is returned to Nexus tasks queue.

func (*Task) SendError

func (t *Task) SendError(code int, message string, data interface{}) (interface{}, error)

SendError closes Task with error. code is the JSON-RPC error code. message is optional in case of well known error code (negative values). data is an optional extra info object. Returns the response object from Nexus or error.

func (*Task) SendResult

func (t *Task) SendResult(res interface{}) (interface{}, error)

SendResult closes Task with result. Returns the response object from Nexus or error.

type TaskList

type TaskList struct {
	Pulls  map[string]int `json:"pulls"`
	Pushes map[string]int `json:"pushes"`
}

type TaskOpts

type TaskOpts struct {
	// Task priority default 0 (Set negative value for lower priority)
	Priority int
	// Task ttl default 5
	Ttl int
	// Task detach. If true, task is detached from creating session.
	// If task is detached and creating session deads, task is not removed from tasks queue.
	Detach bool
}

TaskOpts represents task push options.

type TopicData

type TopicData struct {
	Msgs    []*TopicMsg // Messages
	Waiting int         // Number of messages waiting in Nexus server since last read
	Drops   int         // Number of messages dropped (pipe overflows) since last read
}

TopicData represents a topic messages group obtained in read ops.

type TopicMsg

type TopicMsg struct {
	Topic string      // Topic the message was published to
	Count int64       // Message counter (unique and correlative)
	Msg   interface{} // The message itself
}

TopicMsg represents a single topic message

type UserInfo

type UserInfo struct {
	User string                            `json:"user"`
	Tags map[string]map[string]interface{} `json:"tags"`
}

type UserSessions

type UserSessions struct {
	User     string        `json:"user"`
	Sessions []SessionInfo `json:"sessions"`
	N        int           `json:"n"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL