rpc

package
v0.0.0-...-06c19a4 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2014 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CmdRegister int = iota
	CmdUnregister
	CmdCall
	CmdInterrupt
	CmdSignalProgress
	CmdSendStreamFrame
	CmdReply
	CmdClose
)

Variables

View Source
var (
	ErrAlreadyRegistered = errors.New("method already registered")
	ErrNotRegistered     = errors.New("method not registered")
)
View Source
var (
	ErrInterrupted = errors.New("interrupted")
	ErrTerminated  = &services.ErrTerminated{"RPC service"}
)
View Source
var (
	ErrNotResolvedYet = errors.New("call not resolved yet")
)

Functions

This section is empty.

Types

type CallCmd

type CallCmd interface {
	Command
	RequestId() RequestID
	Method() string
	Args() interface{}
	StdoutTag() *StreamTag
	StderrTag() *StreamTag
}

type Command

type Command interface {
	Type() int
	ErrorChan() chan<- error
}

type InterruptCmd

type InterruptCmd interface {
	Command
	TargetRequestId() RequestID
}

type RegisterCmd

type RegisterCmd interface {
	Command
	Method() string
}

type RemoteCall

type RemoteCall struct {
	Stdout     io.Writer
	Stderr     io.Writer
	OnProgress func()
	// contains filtered or unexported fields
}

RemoteCall represents an RPC call that is to be executed.

func (*RemoteCall) Abandon

func (call *RemoteCall) Abandon() error

Abandon discards the call. It should be used as the last resort to free resorces connected to the call when Interrupt is not making the call return fast enough.

So, Abandon basically cast an interrupt and then deallocates all the resources occupied by the call. The reply received after Abandon is silently dropped because the call does not exist in the service any more.

func (*RemoteCall) Execute

func (call *RemoteCall) Execute() error

Execute performs the RPC and blocks until the reply is received.

func (*RemoteCall) GoExecute

func (call *RemoteCall) GoExecute() *RemoteCall

GoExecute runs Execute asynchronously. It can block while waiting for the request to be processed, but it does not wait until the reply is received.

func (*RemoteCall) Interrupt

func (call *RemoteCall) Interrupt() error

Interrupt sends a form of SIGINT to the component taking care of the request. The processing component should stop executing the method as soon as possible and return equivalent of EINTR.

Interrupt can be called even before Execute. If that happens, the request is not even sent, it is simply dropped silently.

func (*RemoteCall) Resolved

func (call *RemoteCall) Resolved() <-chan struct{}

Returned returns a channel that is closed when the call is resolved.

func (*RemoteCall) ReturnCode

func (call *RemoteCall) ReturnCode() ReturnCode

ReturnCode returns the resulting return code. The semantics are the same as in the operating system. Zero is treated as success, other return codes must be defined and documented by the method requested.

ReturnCode must be called after Execute or Wait, otherwise it panics.

func (*RemoteCall) UnmarshalReturnValue

func (call *RemoteCall) UnmarshalReturnValue(dst interface{}) error

UnmarshalReturnValue decodes the return value object into dst. The object can and probably will vary depending on the return code.

UnmarshalReturnValue must be called after Execute or Wait, otherwise it panics.

func (*RemoteCall) Wait

func (call *RemoteCall) Wait() error

Wait blocks until the reply is received. It returns an error if Execute fails to dispatch the request. It fits together with GoExecute.

type RemoteCallReply

type RemoteCallReply interface {
	TargetCallId() RequestID
	ReturnCode() ReturnCode
	UnmarshalReturnValue(dst interface{}) error
}

type RemoteRequest

type RemoteRequest interface {
	Sender() string
	Id() RequestID
	Method() string
	UnmarshalArgs(dst interface{}) error
	SignalProgress() error
	Stdout() io.Writer
	Stderr() io.Writer
	Interrupted() <-chan struct{}
	Resolve(returnCode ReturnCode, returnValue interface{}) error
	Resolved() <-chan struct{}
}

type RequestHandler

type RequestHandler func(request RemoteRequest)

type RequestID

type RequestID uint16

type ReturnCode

type ReturnCode byte

type Service

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

func NewService

func NewService(factory ServiceFactory) (srv *Service, err error)

NewService uses factory to construct a Transport instance that is then used for creating the Service instance itself.

factory can panic without any worries, it just makes NewService return an error, so some if-errs can be saved.

func (*Service) Close

func (srv *Service) Close() error

func (*Service) Closed

func (srv *Service) Closed() <-chan struct{}

func (Service) MustRegisterMethod

func (exec Service) MustRegisterMethod(method string, handler RequestHandler)

func (Service) NewRemoteCall

func (disp Service) NewRemoteCall(method string, args interface{}) *RemoteCall

func (Service) RegisterMethod

func (exec Service) RegisterMethod(method string, handler RequestHandler) (err error)

func (Service) UnregisterMethod

func (exec Service) UnregisterMethod(method string) (err error)

func (*Service) Wait

func (srv *Service) Wait() error

type ServiceFactory

type ServiceFactory func() (Transport, error)

type StreamFrame

type StreamFrame interface {
	TargetStreamTag() StreamTag
	Payload() []byte
}

type StreamTag

type StreamTag uint16

type Transport

type Transport interface {
	services.Transport

	RegisterMethod(RegisterCmd)

	UnregisterMethod(UnregisterCmd)

	RequestChan() <-chan RemoteRequest

	Call(CallCmd)

	Interrupt(InterruptCmd)

	ProgressChan() <-chan RequestID

	StreamFrameChan() <-chan StreamFrame

	ReplyChan() <-chan RemoteCallReply

	// ErrChan returns a channel that is sending internal transport errors.
	// Any error sent to this channel is treated as unrecoverable and makes
	// the service using the transport terminate.
	ErrorChan() <-chan error
}

Transport implements the underlying transport for Service, which encapsulates the transport-agnostic part of the functionality.

type UnregisterCmd

type UnregisterCmd interface {
	Command
	Method() string
}

Jump to

Keyboard shortcuts

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