app

package
v0.0.0-...-20a20cb Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2016 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClusterStateNew      = "new"
	ClusterStateExisting = "existing"
)
View Source
const (
	RpcPktRequest = iota // This packet is a request
	RpcPktReply   = iota // This packet is a reply
)
View Source
const (
	RpcErrNone         = iota // There has been no error
	RpcErrTimeout      = iota // A timeout has occurred
	RpcErrShutdown     = iota // A shutdown occurred whilst processing the request
	RpcErrCouldNotSend = iota // Could not send the request
	RpcErrBadService   = iota // The destination does not recognise the service
	RpcErrBadAddr      = iota // The address is bad
	RpcErrProhibited   = iota // Prohibited by filter list
	RpcErrNotLeader    = iota // The RPC command cannot be executed as it was sent to the leader but the recipient was not the leader at the relevant time
	RpcErrRedirect     = iota // The RPC command is redirected elsewhere
)
View Source
const (
	RpcDirectionTx = iota
	RpcDirectionRx = iota
)

Directions of RPC packet

View Source
const (
	RpcPacketFilterActionNext   = iota // Pass the packet to the next filter in the list (default)
	RpcPacketFilterActionAccept = iota // Accept the packet, and do not pass to the next filter in the list
	RpcPacketFilterActionReject = iota // Reject the packet, and do not pass to the next filter in the list
	RpcPacketFilterActionDrop   = iota // Reject the packet, and do not pass to the next filter in the list
)

Actions for an RpcPacketFilter

Variables

This section is empty.

Functions

func NewRpcPacketFilterList

func NewRpcPacketFilterList() *rpcPacketFilterList

func NewRpcPacketFilterList returns a new list

Types

type App

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

func NewApp

func NewApp(c Config) (*App, error)

func (*App) Close

func (a *App) Close() error

func (*App) Run

func (a *App) Run()

type Cluster

type Cluster interface {
	Close()
	Command(cmd string, params interface{}, timeout time.Duration) error
	Barrier(timeout time.Duration) error
	IsLeader() bool
	LeaderCh() <-chan bool
}

type Config

type Config struct {
	Raft RaftConfig
}

func NewConfig

func NewConfig() Config

type Raft

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

func (*Raft) AddPeer

func (r *Raft) AddPeer(addr string) error

func (*Raft) Barrier

func (r *Raft) Barrier(timeout time.Duration) error

func (*Raft) Close

func (r *Raft) Close()

func (*Raft) Command

func (r *Raft) Command(cmd string, params interface{}, timeout time.Duration) error

func (*Raft) DelPeer

func (r *Raft) DelPeer(addr string) error

func (*Raft) GetPeers

func (r *Raft) GetPeers() ([]string, error)

func (*Raft) IsLeader

func (r *Raft) IsLeader() bool

func (*Raft) Leader

func (r *Raft) Leader() string

func (*Raft) LeaderCh

func (r *Raft) LeaderCh() <-chan bool

func (*Raft) SetPeers

func (r *Raft) SetPeers(addrs []string) error

type RaftConfig

type RaftConfig struct {
	Addr         string
	DataDir      string
	LogDir       string
	Cluster      []string
	ClusterState string
}

type RpcAddress

type RpcAddress interface {
	String() string              // get the textual representation of the address
	GetTransportAddress() string // get the transport layer representation of the address (may e.g. do a DNS lookup)
}

Type RpcAddress is an interface that represents an opaque RPC address

type RpcData

type RpcData interface {
	GetPktType() int // return whether the packet is a request or a reply
}

type RpcData is an interface representing the data within a request or reply packet

type RpcEndpoint

type RpcEndpoint interface {
	Handle(mux *RpcMux, request *RpcPacket) *RpcPacket //  Handle an incoming packet, returning the reply
}

Type RpcEndpoint is an interface handling packets of a particular service

type RpcError

type RpcError struct {
	ErrorType int // The type of the error
}

RpcError holds an error type

func (RpcError) String

func (e RpcError) String() string

func String() converts an RpcError to a string

type RpcInMemoryAddress

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

type RpcInMemoryAddress implements RpcAddress

func (*RpcInMemoryAddress) GetTransportAddress

func (a *RpcInMemoryAddress) GetTransportAddress() string

func (*RpcInMemoryAddress) String

func (a *RpcInMemoryAddress) String() string

type RpcInMemoryTransport

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

type RpcInMemoryTransport implements RpcTransport

func NewRpcInMemoryTransport

func NewRpcInMemoryTransport(a RpcAddress) *RpcInMemoryTransport

func (*RpcInMemoryTransport) Close

func (t *RpcInMemoryTransport) Close()

func (*RpcInMemoryTransport) GetAddress

func (t *RpcInMemoryTransport) GetAddress() RpcAddress

func (*RpcInMemoryTransport) Run

func (t *RpcInMemoryTransport) Run(mux *RpcMux)

func (*RpcInMemoryTransport) Send

func (t *RpcInMemoryTransport) Send(pkt *RpcPacket) error

type RpcMux

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

Type RpcMux is a struct representing all the registered services, and the service originator

normally there would be one of these per application with a unique generation. The address should not change once created

func NewRpcMux

func NewRpcMux(transport RpcTransport) *RpcMux

func NewRpcMux generates a new RPC mux

The mux initially has no services registered

func (*RpcMux) AddPacketFilter

func (mux *RpcMux) AddPacketFilter(direction int, f *RpcPacketFilter, sequence int64) uint64

func AddPacketFilter adds a packet filter to a mux for traffic in a specified direction, with a specified sequence

returns the id of the packet filter

func (*RpcMux) ClearPacketFilters

func (mux *RpcMux) ClearPacketFilters(direction int)

func ClearPacketFilters removes all packet filter from a mux for traffic in a specified direction

func (*RpcMux) GetAddress

func (mux *RpcMux) GetAddress() RpcAddress

func GetAddress returns the address of a mux

func (*RpcMux) Handle

func (mux *RpcMux) Handle(pkt *RpcPacket)

func Handle handles an incoming packet

func (*RpcMux) NewService

func (mux *RpcMux) NewService(destination RpcAddress, service string, parameters RpcParameters) *RpcService

func NewService generates a new RpcService

func (*RpcMux) RegisterEndpoint

func (mux *RpcMux) RegisterEndpoint(service string, endpoint RpcEndpoint)

func RegisterEndpoint registers an endpoint as a service with a mux

pass endpoint as 'nil' to deregister. Service names beginning with '_' are reserved

func (*RpcMux) RemovePacketFilter

func (mux *RpcMux) RemovePacketFilter(direction int, f *RpcPacketFilter) bool

func AddPacketFilter removes a packet filter from a mux for traffic in a specified direction

The pointer must be the same as that given on add

func (*RpcMux) RemovePacketFilterById

func (mux *RpcMux) RemovePacketFilterById(direction int, id uint64) bool

func AddPacketFilter removes a packet filter from a mux for traffic in a specified direction

The id must be that returned from add

func (*RpcMux) SendAsync

func (mux *RpcMux) SendAsync(dest *RpcAddress, service string, request *RpcRequest, parameters *RpcParameters, replyChan chan<- RpcReply)

func SendAsync asynchronously sends a request to a given address and service, sending the reply to the specified channel

Note that send errors are transformed into synthesized received packet errors

func (*RpcMux) SendSync

func (mux *RpcMux) SendSync(dest *RpcAddress, service string, request *RpcRequest, parameters *RpcParameters) *RpcReply

func SendSync synchronously sends a request to a given address and service, returning the reply

Note that send errors are transformed into synthesized received packet errors

func (*RpcMux) Shutdown

func (mux *RpcMux) Shutdown()

func Shutdown removes all registered endpoints and sends shutdown errors to all outbound active RPC conversations

type RpcPacket

type RpcPacket struct {
	Source       RpcAddress // The source address
	Dest         RpcAddress // The destination address
	Service      string     // The name of the service
	Id           uint64     // The sequential Id of the request packet to which this relates
	MinUnackedId uint64     // The lowest ID we have used that remains unacknowledged (tx)
	Generation   uint64     // The generation of the requestor to which this relates
	Data         RpcData    // The RPC data
}

Type RpcPacket contains an inflight RPC packet

Note all elements are exported so they are serialized

func (*RpcPacket) MakeError

func (request *RpcPacket) MakeError(source RpcAddress, errNum int) *RpcPacket

func MakeError generates a corresponding error reply packet from a request packet

func (*RpcPacket) MakeReply

func (request *RpcPacket) MakeReply(source RpcAddress) *RpcPacket

func MakeReply generates a corresponding reply packet from a request packet

type RpcPacketFilter

type RpcPacketFilter interface {
	Filter(pkt *RpcPacket) RpcPacketFilterAction // returns a filter action for a packet (or nil)
}

Type RpcPacketFilter is an interface that represents a packet filter for RPC

type RpcPacketFilterAction

type RpcPacketFilterAction struct {
	Action int
}

Type RpcPacketFilterAction encapsulates an RpcPacketFilterAction

func (RpcPacketFilterAction) String

func (a RpcPacketFilterAction) String() string

func String() converts an RpcFilterActionNext to a string

type RpcParameters

type RpcParameters struct {
	Timeout time.Duration // Timeout
	Retries int
}

Type RpcParameters specifies the timeout parameters for an Rpc transaction

type RpcReply

type RpcReply struct {
	ErrorType RpcError    // The type of error (if any)
	Reply     interface{} // The reply
}

Type RpcReply is a struct containing an RPC reply

Note all elements are exported so they are serialized

func (RpcReply) GetPktType

func (d RpcReply) GetPktType() int

func getRequestKey returns the packet type associated with a request

type RpcRequest

type RpcRequest struct {
	Request interface{} // The request
}

Type RpcRequest is a struct containing an RPC request

Note all elements are exported so they are serialized

func (RpcRequest) GetPktType

func (d RpcRequest) GetPktType() int

func getRequestKey returns the packet type associated with a reply

type RpcService

type RpcService struct {
	Destination RpcAddress    // Destination
	Service     string        // Service
	Mux         *RpcMux       // Mux
	Parameters  RpcParameters // Parameters
}

type RpcService is a convenience struct

It allows multiple requests to be sent to the same Destination, Service with the same Mux and Parameters

func (*RpcService) SendAsync

func (rpcs *RpcService) SendAsync(request *RpcRequest, replyChan chan<- RpcReply)

func SendAsync asynchronously sends a request to a service

func (*RpcService) SendSync

func (rpcs *RpcService) SendSync(request *RpcRequest) *RpcReply

func SendAsync synchronously sends a request to a service

type RpcTransport

type RpcTransport interface {
	Send(pkt *RpcPacket) error // send an RPC packet asynchronously
	GetAddress() RpcAddress    // address of the transport
}

Type RpcTransport is an interface that represents an opaque RPC transport

Jump to

Keyboard shortcuts

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