Documentation ¶
Index ¶
- Constants
- Variables
- type CallCmd
- type Command
- type InterruptCmd
- type RegisterCmd
- type RemoteCall
- func (call *RemoteCall) Abandon() error
- func (call *RemoteCall) Execute() error
- func (call *RemoteCall) GoExecute() *RemoteCall
- func (call *RemoteCall) Interrupt() error
- func (call *RemoteCall) Resolved() <-chan struct{}
- func (call *RemoteCall) ReturnCode() ReturnCode
- func (call *RemoteCall) UnmarshalReturnValue(dst interface{}) error
- func (call *RemoteCall) Wait() error
- type RemoteCallReply
- type RemoteRequest
- type RequestHandler
- type RequestID
- type ReturnCode
- type Service
- func (srv *Service) Close() error
- func (srv *Service) Closed() <-chan struct{}
- func (exec Service) MustRegisterMethod(method string, handler RequestHandler)
- func (disp Service) NewRemoteCall(method string, args interface{}) *RemoteCall
- func (exec Service) RegisterMethod(method string, handler RequestHandler) (err error)
- func (exec Service) UnregisterMethod(method string) (err error)
- func (srv *Service) Wait() error
- type ServiceFactory
- type StreamFrame
- type StreamTag
- type Transport
- type UnregisterCmd
Constants ¶
const ( CmdRegister int = iota CmdUnregister CmdCall CmdInterrupt CmdSignalProgress CmdSendStreamFrame CmdReply CmdClose )
Variables ¶
var ( ErrAlreadyRegistered = errors.New("method already registered") ErrNotRegistered = errors.New("method not registered") )
var ( ErrInterrupted = errors.New("interrupted") ErrTerminated = &services.ErrTerminated{"RPC service"} )
var (
ErrNotResolvedYet = errors.New("call not resolved yet")
)
Functions ¶
This section is empty.
Types ¶
type InterruptCmd ¶
type RegisterCmd ¶
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 RequestHandler ¶
type RequestHandler func(request RemoteRequest)
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) 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 ¶
type ServiceFactory ¶
type StreamFrame ¶
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.