Documentation ¶
Overview ¶
Package grid is a generated protocol buffer package.
It is generated from these files:
wire.proto
It has these top-level messages:
Delivery ActorStart Ack EchoMsg
Index ¶
- Constants
- Variables
- func ContextActorID(c context.Context) (string, error)
- func ContextActorName(c context.Context) (string, error)
- func ContextActorNamespace(c context.Context) (string, error)
- func Register(v interface{}) error
- func RegisterWireServer(s *grpc.Server, srv WireServer)
- type Ack
- type Actor
- type ActorStart
- type Client
- func (c *Client) Close() error
- func (c *Client) Query(timeout time.Duration, filter entityType) ([]*QueryEvent, error)
- func (c *Client) QueryC(ctx context.Context, filter entityType) ([]*QueryEvent, error)
- func (c *Client) QueryWatch(ctx context.Context, filter entityType) ([]*QueryEvent, <-chan *QueryEvent, error)
- func (c *Client) Request(timeout time.Duration, receiver string, msg interface{}) (interface{}, error)
- func (c *Client) RequestC(ctx context.Context, receiver string, msg interface{}) (interface{}, error)
- type ClientCfg
- type Delivery
- type Delivery_Ver
- type EchoMsg
- type EventType
- type Logger
- type Mailbox
- type MakeActor
- type QueryEvent
- type Request
- type Server
- type ServerCfg
- type WireClient
- type WireServer
Constants ¶
const ( // Peers filter for query. Peers entityType = "peer" // Actors filter for query. Actors entityType = "actor" // Mailboxes filter for query. Mailboxes entityType = "mailbox" )
Variables ¶
var ( // ErrInvalidName when name contains invalid character codes. ErrInvalidName = errors.New("grid: invalid name") // ErrInvalidNamespace when namespace contains invalid // character codes. ErrInvalidNamespace = errors.New("grid: invalid namespace") // ErrInvalidActorType when the actor type contains invalid // character codes. ErrInvalidActorType = errors.New("grid: invalid actor type") // ErrInvalidActorName when the actor name contains invalid // character codes. ErrInvalidActorName = errors.New("grid: invalid actor name") // ErrInvalidMailboxName when a mailbox name contains invalid // character codes. ErrInvalidMailboxName = errors.New("grid: invalid mailbox name") )
var ( // ErrReceiverBusy when the message buffer of a mailbox is // full, conisder a larger size when creating the mailbox. ErrReceiverBusy = errors.New("grid: receiver busy") // ErrUnknownMailbox when a message is received by a peer for // a mailbox the peer does not serve, likely the mailbox has // moved between the time of discovery and the message receive. ErrUnknownMailbox = errors.New("grid: unknown mailbox") // ErrUnregisteredMailbox when a mailbox name does not exist in // the registry, likely it was never created or has died. ErrUnregisteredMailbox = errors.New("grid: unregistered mailbox") // ErrContextFinished when the context signals done before the // request could receive a response from the receiver. ErrContextFinished = errors.New("grid: context finished") )
var ( // ErrNilEtcd when the etcd argument is nil. ErrNilEtcd = errors.New("grid: nil etcd") // ErrNilActor when an actor definition has been registered // but returns a nil actor and nil error when creating an actor. ErrNilActor = errors.New("grid: nil actor") // ErrInvalidContext when a context does not contain // the requested values. ErrInvalidContext = errors.New("grid: invalid context") // ErrDefNotRegistered when a actor type which has never // been registered is requested for start. ErrDefNotRegistered = errors.New("grid: def not registered") // ErrServerNotRunning when an operation which requires the // server be running, but is not, is requested. ErrServerNotRunning = errors.New("grid: server not running") // ErrAlreadyRegistered when a mailbox is created but someone // else has already created it. ErrAlreadyRegistered = errors.New("grid: already registered") // ErrWatchClosedUnexpectedly when a query watch closes before // it was requested to close, likely do to some etcd issue. ErrWatchClosedUnexpectedly = errors.New("grid: watch closed unexpectedly") )
var Delivery_Ver_name = map[int32]string{
0: "V1",
}
var Delivery_Ver_value = map[string]int32{
"V1": 0,
}
var ( // ErrAlreadyResponded when respond is called multiple // times on a request. ErrAlreadyResponded = errors.New("already responded") )
Functions ¶
func ContextActorID ¶
ContextActorID returns the ID that is used to register the actor in etcd.
func ContextActorName ¶
ContextActorName returns just the actor name, ie: no namespace, associated with this context.
func ContextActorNamespace ¶
ContextActorNamespace returns the namespace of the grid this actor is associated with.
func Register ¶
func Register(v interface{}) error
Register a message so it may be sent and received. Value v should not be a pointer to a type, but the type itself.
For example:
Register(MyMsg{}) // Correct Register(&MyMsg{}) // Incorrect
func RegisterWireServer ¶
func RegisterWireServer(s *grpc.Server, srv WireServer)
Types ¶
type Ack ¶
type Ack struct { }
func (*Ack) Descriptor ¶
func (*Ack) ProtoMessage ¶
func (*Ack) ProtoMessage()
type ActorStart ¶
type ActorStart struct { Type string `protobuf:"bytes,1,opt,name=type" json:"type,omitempty"` Name string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"` Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` }
func NewActorStart ¶
func NewActorStart(name string, v ...interface{}) *ActorStart
NewActorStart message with the name of the actor to start, its type will be equal to its name unless its changed:
start := NewActorStart("worker")
Format names can also be used for more complicated names, just remember to override the type:
start := NewActorStart("worker-%d-group-%d", i, j) start.Type = "worker"
func (*ActorStart) Descriptor ¶
func (*ActorStart) Descriptor() ([]byte, []int)
func (*ActorStart) GetData ¶
func (m *ActorStart) GetData() []byte
func (*ActorStart) GetName ¶
func (m *ActorStart) GetName() string
func (*ActorStart) GetType ¶
func (m *ActorStart) GetType() string
func (*ActorStart) ProtoMessage ¶
func (*ActorStart) ProtoMessage()
func (*ActorStart) Reset ¶
func (m *ActorStart) Reset()
func (*ActorStart) String ¶
func (m *ActorStart) String() string
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client for grid-actors or non-actors to make requests to grid-actors. The client can be used by multiple go-routines.
func (*Client) Query ¶
func (c *Client) Query(timeout time.Duration, filter entityType) ([]*QueryEvent, error)
Query in this client's namespace. The filter can be any one of Peers, Actors, or Mailboxes.
func (*Client) QueryC ¶
func (c *Client) QueryC(ctx context.Context, filter entityType) ([]*QueryEvent, error)
QueryC (query) in this client's namespace. The filter can be any one of Peers, Actors, or Mailboxes. The context can be used to control cancelation or timeouts.
func (*Client) QueryWatch ¶
func (c *Client) QueryWatch(ctx context.Context, filter entityType) ([]*QueryEvent, <-chan *QueryEvent, error)
QueryWatch monitors the entry and exit of peers, actors, or mailboxes.
Example usage:
client, err := grid.NewClient(...) ... currentpeers, watch, err := client.QueryWatch(ctx, grid.Peers) ... for _, peer := range currentpeers { // Do work regarding peer. } for event := range watch { switch event.Type { case grid.WatchError: // Error occured watching peers, deal with error. case grid.EntityLost: // Existing peer lost, reschedule work on extant peers. case grid.EntityFound: // New peer found, assign work, get data, reschedule, etc. } }
type ClientCfg ¶
type ClientCfg struct { // Namespace of grid. Namespace string // Timeout for communication with etcd, and internal gossip. Timeout time.Duration // PeersRefreshInterval for polling list of peers in etcd. PeersRefreshInterval time.Duration // ConnectionsPerPeer sets the number gRPC connections to // establish to each remote. Default is max(1, numCPUs/2). // More connections allow for more messages per second, // but increases the number of file-handles used. ConnectionsPerPeer int // Logger optionally used for logging, default is to not log. Logger Logger }
ClientCfg where the only required argument is Namespace, other fields with their zero value will receive defaults.
type Delivery ¶
type Delivery struct { Ver Delivery_Ver `protobuf:"varint,1,opt,name=ver,enum=grid.Delivery_Ver" json:"ver,omitempty"` Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` TypeName string `protobuf:"bytes,3,opt,name=typeName" json:"typeName,omitempty"` Receiver string `protobuf:"bytes,4,opt,name=receiver" json:"receiver,omitempty"` }
func (*Delivery) Descriptor ¶
func (*Delivery) GetReceiver ¶
func (*Delivery) GetTypeName ¶
func (*Delivery) GetVer ¶
func (m *Delivery) GetVer() Delivery_Ver
func (*Delivery) ProtoMessage ¶
func (*Delivery) ProtoMessage()
type Delivery_Ver ¶
type Delivery_Ver int32
const (
Delivery_V1 Delivery_Ver = 0
)
func (Delivery_Ver) EnumDescriptor ¶
func (Delivery_Ver) EnumDescriptor() ([]byte, []int)
func (Delivery_Ver) String ¶
func (x Delivery_Ver) String() string
type EchoMsg ¶
type EchoMsg struct {
Msg string `protobuf:"bytes,1,opt,name=msg" json:"msg,omitempty"`
}
func (*EchoMsg) Descriptor ¶
func (*EchoMsg) ProtoMessage ¶
func (*EchoMsg) ProtoMessage()
type Logger ¶
type Logger interface {
Printf(string, ...interface{})
}
Logger hides the logging function Printf behind a simple interface so libraries such as logrus can be used.
type Mailbox ¶
type Mailbox struct { C <-chan Request // contains filtered or unexported fields }
Mailbox for receiving messages.
func NewMailbox ¶
NewMailbox for requests addressed to name. Size will be the mailbox's channel size.
Example Usage:
mailbox, err := NewMailbox(server, "incoming", 10) ... defer mailbox.Close() for { select { case req := <-mailbox.C: // Do something with request, and then respond // or ack. A response or ack is required. switch m := req.Msg().(type) { case HiMsg: req.Respond(&HelloMsg{}) } } }
If the mailbox has already been created, in the calling process or any other process, an error is returned, since only one mailbox can claim a particular name.
Using a mailbox requires that the process creating the mailbox also started a grid Server.
type MakeActor ¶
MakeActor using the given data to parameterize the making of the actor; the data is optional.
type QueryEvent ¶
type QueryEvent struct { Type EventType // contains filtered or unexported fields }
QueryEvent indicating that an entity has been discovered, lost, or some error has occured with the watch.
func (*QueryEvent) Err ¶
func (e *QueryEvent) Err() error
Err caught watching query events. The error is not associated with any particular entity, it's an error with the watch itself or a result of the watch.
func (*QueryEvent) Name ¶
func (e *QueryEvent) Name() string
Name of entity that caused the event. For example, if mailboxes were queried the name is the mailbox name.
func (*QueryEvent) Peer ¶
func (e *QueryEvent) Peer() string
Peer of named entity. For example, if mailboxes were queried then it's the peer the mailbox is running on. If the query was for peers, then methods Name and Peer return the same string.
func (*QueryEvent) String ¶
func (e *QueryEvent) String() string
String representation of query event.
type Request ¶
type Request interface { Context() context.Context Msg() interface{} Ack() error Respond(msg interface{}) error }
Request which must receive an ack or response.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server of a grid.
func NewServer ¶
NewServer for the grid. The namespace must contain only characters in the set: [a-zA-Z0-9-_] and no other.
func (*Server) Context ¶
Context of the server, when it reports done the server is trying to shutdown. Actors automatically get this context, non-actors using mailboxes bound to this server should monitor this context to know when the server is trying to exit.
func (*Server) Process ¶
Process a request and return a response. Implements the interface for gRPC definition of the wire service. Consider this a private method.
func (*Server) RegisterDef ¶
RegisterDef of an actor. When a ActorStart message is sent to a peer it will use the registered definitions to make and run the actor. If an actor with actorType "leader" is registered it will be started automatically when the Serve method is called.
type ServerCfg ¶
type ServerCfg struct { // Namespace of grid. Namespace string // DisalowLeadership to prevent leader from running on a node. DisalowLeadership bool // Timeout for communication with etcd, and internal gossip. Timeout time.Duration // LeaseDuration for data in etcd. LeaseDuration time.Duration // Logger optionally used for logging, default is to not log. Logger Logger }
ServerCfg where the only required argument is Namespace, other fields with their zero value will receive defaults.
type WireClient ¶
type WireClient interface {
Process(ctx context.Context, in *Delivery, opts ...grpc.CallOption) (*Delivery, error)
}
func NewWireClient ¶
func NewWireClient(cc *grpc.ClientConn) WireClient
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
protomessage
Package protomessage is a generated protocol buffer package.
|
Package protomessage is a generated protocol buffer package. |
examples
|
|
requestreply
Package main is a generated protocol buffer package.
|
Package main is a generated protocol buffer package. |