nxcli: github.com/jaracil/nxcli/nxcore Index | Files

package nxcore

import "github.com/jaracil/nxcli/nxcore"

Index

Package Files

locks.go nodes.go nxcore.go pipes.go sessions.go tasks.go topics.go users.go

Constants

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

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",
}

func NewJsonRpcErr Uses

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.

type JsonRpcErr Uses

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

func (*JsonRpcErr) Code Uses

func (e *JsonRpcErr) Code() int

func (*JsonRpcErr) Data Uses

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

func (*JsonRpcErr) Error Uses

func (e *JsonRpcErr) Error() string

type JsonRpcReq Uses

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 Uses

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

type Msg Uses

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

Msg represents a pipe single message

type NexusConn Uses

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

NexusConn represents the Nexus connection.

func NewNexusConn Uses

func NewNexusConn(conn net.Conn) *NexusConn

NewNexusConn creates new nexus connection from net.conn

func (*NexusConn) Close Uses

func (nc *NexusConn) Close()

Close closes nexus connection.

func (*NexusConn) Closed Uses

func (nc *NexusConn) Closed() bool

Closed returns Nexus connection state.

func (*NexusConn) Exec Uses

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

Exec is a low level JSON-RPC call function.

func (*NexusConn) ExecNoWait Uses

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 Uses

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

GetContext returns internal connection context.

func (*NexusConn) Id Uses

func (nc *NexusConn) Id() string

Id returns the connection id after a login.

func (*NexusConn) Lock Uses

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

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

func (*NexusConn) Login Uses

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 Uses

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 Uses

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 Uses

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

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

func (*NexusConn) PipeOpen Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

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

func (*NexusConn) UserAddTemplate Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

type Pipe Uses

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 Uses

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

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

func (*Pipe) Id Uses

func (p *Pipe) Id() string

Id returns the pipe identification strring.

func (*Pipe) Listen Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

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

type PipeData Uses

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 Uses

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

PipeOpts represents pipe creation options

type SessionInfo Uses

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 Uses

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 Uses

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

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

func (*Task) GetConn Uses

func (t *Task) GetConn() *NexusConn

GetConn retrieves the task underlying nexus connection.

func (*Task) Reject Uses

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

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

func (*Task) SendError Uses

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 Uses

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

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

type TaskList Uses

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

type TaskOpts Uses

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 Uses

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 Uses

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 Uses

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

type UserSessions Uses

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

Package nxcore imports 9 packages (graph) and is imported by 7 packages. Updated 2016-08-12. Refresh now. Tools for package owners.