session

package
v0.0.0-...-4faa3c3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = fmt.Errorf("not found")

ErrNotFound indicates that a session was not found

View Source
var SessionTTL = "900s"

Functions

func SendCountOpWithSession

func SendCountOpWithSession(ses *Session, sid, queryWithJSQ string, queryWithObj *tables.Object, out interface{}) error

SendCountOpWithSession sends a query operation using an existing session id

func SendPutOpWithSession

func SendPutOpWithSession(ses *Session, sid string, data interface{}) error

SendPutOpWithSession sends a PUT operation using an existing session id

func SendQueryOp

func SendQueryOp(ses *Session, queryWithJSQ string, queryWithObj *tables.Object, limit int, order string, out interface{}) error

SendQueryOp sends a query operation

func SendQueryOpWithSession

func SendQueryOpWithSession(ses *Session, sid, queryWithJSQ string, queryWithObj *tables.Object, limit int, order string, out interface{}) error

SendQueryOpWithSession sends a query operation using an existing session id

Types

type Agent

type Agent struct {
	sync.Mutex

	Error error
	// contains filtered or unexported fields
}

Agent defines a structure for an agent that holds a database session

func NewAgent

func NewAgent(db patchain.DB, opChan chan *Op) *Agent

NewAgent creates a new agent

func (*Agent) Debug

func (a *Agent) Debug()

Debug turns on logging

func (*Agent) Reset

func (a *Agent) Reset()

Reset resets the agent

func (*Agent) Start

func (a *Agent) Start(endCb func())

Start starts a database transaction session. Only a single operation is allowed to run at any point in time. It closes the operations done/wait channel when it completes and passes any error to the operation

func (*Agent) Stop

func (a *Agent) Stop()

Stop stops the current session

type AgentInfo

type AgentInfo struct {
	OwnerID string
	Agent   *Agent
}

AgentInfo describes an agent and its owner

type ConsulRegistry

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

ConsulRegistry implements a session registry based on consul. It satisfies SessionRegistry interface.

func NewConsulRegistry

func NewConsulRegistry() (r *ConsulRegistry, err error)

NewConsulRegistry creates a new consul registry. Connection to consul is attempted, error is returned on failure to connect.

func (*ConsulRegistry) Add

func (r *ConsulRegistry) Add(item RegItem) error

Add registers a new session

func (*ConsulRegistry) Del

func (r *ConsulRegistry) Del(sid string) (err error)

Del deletes a session. Returns nil if the session was deleted successfully or it doesn't exists

func (*ConsulRegistry) Get

func (r *ConsulRegistry) Get(sid string) (*RegItem, error)

Get gets a session. Returns ErrNotFound if not found

type Op

type Op struct {
	OpType          OpType
	PutData         interface{}
	QueryWithJSQ    string
	QueryWithObject *tables.Object
	Out             interface{}
	Done            chan struct{}
	Limit           int
	OrderBy         string
	Error           error
}

Op represents an agent operation

type OpType

type OpType int

OpType represents a db connection operation

var (

	// OpPutObjects represents an object creation operation.
	OpPutObjects OpType = 1

	// OpGetObjects represents a get object operation
	OpGetObjects OpType = 2

	// OpCountObjects represents a count operation
	OpCountObjects OpType = 3

	// MaxSessionIdleTime is the maximum duration a session can be idle before stopping
	MaxSessionIdleTime = 10 * time.Minute

	// ErrAgentBusy represents an agent in busy state
	ErrAgentBusy = fmt.Errorf("agent is busy")
)

type RegItem

type RegItem struct {
	Address string                 `json:"address"`
	Port    int                    `json:"port"`
	SID     string                 `json:"sid"`
	Meta    map[string]interface{} `json:"meta"`
}

RegItem defines a session registry item

func (*RegItem) ToJSON

func (i *RegItem) ToJSON() []byte

ToJSON returns JSON representation

type Session

type Session struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Session defines a structure for a partition chain session manager

func NewSession

func NewSession(sessionReg SessionRegistry) *Session

NewSession creates a new partition chain session

func (*Session) Commit

func (s *Session) Commit(id string)

Commit commits the current transaction of an agent

func (*Session) CommitEnd

func (s *Session) CommitEnd(id string)

CommitEnd commits the current transaction of an agent and removes the session/agent

func (*Session) CreateSession

func (s *Session) CreateSession(id, identityID string) (string, error)

CreateSession creates a new session agent

func (*Session) CreateUnregisteredSession

func (s *Session) CreateUnregisteredSession(id, identityID string) (sid string)

CreateUnregisteredSession creates a session that is not registered

func (*Session) End

func (s *Session) End(id string)

End stops and removes an agent from memory and registry

func (*Session) GetAgent

func (s *Session) GetAgent(id string) *AgentInfo

GetAgent gets a session agent. Returns nil if session does not exists

func (*Session) GetAgents

func (s *Session) GetAgents() map[string]*AgentInfo

GetAgents returns all agents

func (*Session) HasSession

func (s *Session) HasSession(id string) bool

HasSession checks whether a session exists

func (*Session) NumSessions

func (s *Session) NumSessions() int

NumSessions returns the number of active sessions

func (*Session) Rollback

func (s *Session) Rollback(id string)

Rollback rollbacks the current transaction of an agent

func (*Session) RollbackEnd

func (s *Session) RollbackEnd(id string)

RollbackEnd rolls back the current transaction of an agent and removes the session/agent

func (*Session) SendOp

func (s *Session) SendOp(id string, op *Op) error

SendOp sends an operation to a session agent

func (*Session) SetDB

func (s *Session) SetDB(db patchain.DB)

SetDB sets the db connection to use directly

func (*Session) Stop

func (s *Session) Stop()

Stop all active sessions

type SessionRegistry

type SessionRegistry interface {
	Add(item RegItem) error
	Get(sid string) (*RegItem, error)
	Del(sid string) error
}

SessionRegistry defines an interface for a session registory

Jump to

Keyboard shortcuts

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