Documentation
¶
Index ¶
- type Client
- type DB
- type Job
- type JobHandler
- type Server
- func (srv *Server) ListenAndServe(proto, addr string) error
- func (srv *Server) RegisterJob(name string, h JobHandler)
- func (srv *Server) Serve(l net.Listener) error
- func (srv *Server) ServeConn(conn net.Conn) error
- func (srv *Server) ServeJob(name string, args []string, env map[string]string, streams Streamer, db DB) error
- type Streamer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
Transport io.ReadWriteCloser
}
type Job ¶
type JobHandler ¶
type JobHandler func(name string, args []string, env map[string]string, streams Streamer, db DB) error
A JobHandler is a function which can be invoked as a job by beam clients. The API for invoking jobs resembles that of unix processes:
- A job is invoked under a certain <name>.
- It may receive arguments as a string array (<args>).
- It may receive an environment as a map of key-value pairs (<env>).
- It may read from, and write to, streams of binary data. (<streams>).
- It returns value which can either indicate "success" or a variety of error conditions.
Additionally, a job may modify the server's database, which is shared with all other jobs. This is similar to how multiple unix processes share access to the same filesystem.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) ListenAndServe ¶
ListenAndServe listens on the address <addr> at protocol <proto> and then handles incoming requests following the beam protocol.
func (*Server) RegisterJob ¶
func (srv *Server) RegisterJob(name string, h JobHandler)
RegisterJob exposes the function <h> as a remote job to be invoked by clients under the name <name>.
func (*Server) Serve ¶
Serve accepts incoming Beam connections on the listener l, and then serves requests on them.
func (*Server) ServeJob ¶
func (srv *Server) ServeJob(name string, args []string, env map[string]string, streams Streamer, db DB) error
ServeJob is the server's default job handler. It is called every time a new job is created. It looks up a handler registered at <name>, and calls it with the same arguments. If no handler is registered, it returns an error.
type Streamer ¶
type Streamer interface {
// OpenRead returns a read-only interface to receive data on the stream <name>.
// If the stream hasn't been open for read access before, it is advertised as such to the peer.
OpenRead(name string) io.Reader
// ReadFrom opens a read-only interface on the stream <name>, and copies data
// to that interface from <src> until EOF or error.
// The return value n is the number of bytes read.
// Any error encountered during the write is also returned.
ReadFrom(src io.Reader, name string) (int64, error)
// OpenWrite returns a write-only interface to send data on the stream <name>.
// If the stream hasn't been open for write access before, it is advertised as such to the peer.
OpenWrite(name string) io.Writer
// WriteTo opens a write-only interface on the stream <name>, and copies data
// from that interface to <dst> until there's no more data to write or when an error occurs.
// The return value n is the number of bytes written.
// Any error encountered during the write is also returned.
WriteTo(dst io.Writer, name string) (int64, error)
// OpenReadWrite returns a read-write interface to send and receive on the stream <name>.
// If the stream hasn't been open for read or write access before, it is advertised as such to the peer.
OpenReadWrite(name string) io.ReadWriter
// Close closes the stream <name>. All future reads will return io.EOF, and writes will return
// io.ErrClosedPipe
Close(name string)
// Shutdown waits until all streams with read access are closed and
// all WriteTo and ReadFrom operations are completed,
// then it stops accepting remote messages for its streams,
// then it returns.
Shutdown() error
}