Documentation ¶
Index ¶
- func ErrUnexpectedMessage(ctx *Context) error
- type Actor
- type ActorFunc
- type Address
- func (a Address) Child(child interface{}) Address
- func (a Address) IsAncestorOf(address Address) bool
- func (a Address) Local() string
- func (a Address) MarshalJSON() ([]byte, error)
- func (a Address) MarshalText() (text []byte, err error)
- func (a Address) Parent() Address
- func (a Address) String() string
- func (a *Address) UnmarshalJSON(data []byte) error
- func (a *Address) UnmarshalText(text []byte) error
- type ChildFailed
- type ChildStopped
- type Context
- func (c *Context) ActorOf(id interface{}, actor Actor) (*Ref, bool)
- func (c *Context) ActorOfFromFactory(id interface{}, factory func() Actor) (*Ref, bool)
- func (c *Context) AddLabel(key string, value interface{})
- func (c *Context) AddLabels(ctx logger.Context)
- func (c *Context) Ask(actor *Ref, message Message) Response
- func (c *Context) AskAll(message Message, actors ...*Ref) Responses
- func (c *Context) Child(id interface{}) *Ref
- func (c *Context) Children() []*Ref
- func (c *Context) ExpectingResponse() bool
- func (c *Context) Kill(id interface{}) bool
- func (c *Context) Log() *log.Entry
- func (c *Context) Message() Message
- func (c *Context) MustActorOf(id interface{}, actor Actor) *Ref
- func (c *Context) Respond(message Message)
- func (c *Context) RespondCheckError(message Message, err error)
- func (c *Context) Self() *Ref
- func (c *Context) Tell(actor *Ref, message Message)
- func (c *Context) TellAll(message Message, actors ...*Ref)
- type Message
- type Messenger
- type Ping
- type PostStop
- type PreStart
- type Ref
- func (r *Ref) Address() Address
- func (r *Ref) AwaitTermination() error
- func (r *Ref) Child(id interface{}) *Ref
- func (r *Ref) Children() []*Ref
- func (r *Ref) MarshalJSON() ([]byte, error)
- func (r *Ref) Parent() *Ref
- func (r *Ref) RegisteredTime() time.Time
- func (r *Ref) Stop()
- func (r *Ref) StopAndAwaitTermination() error
- func (r *Ref) String() string
- func (r *Ref) System() *System
- type Response
- type Responses
- type System
- func (s *System) ActorOf(address Address, actor Actor) (*Ref, bool)
- func (s *System) Ask(actor *Ref, message Message) Response
- func (s *System) AskAll(message Message, actors ...*Ref) Responses
- func (s *System) AskAllTimeout(message Message, timeout time.Duration, actors ...*Ref) Responses
- func (s *System) AskAt(addr Address, message Message) Response
- func (s *System) Get(address Address) *Ref
- func (s *System) MustActorOf(address Address, actor Actor) *Ref
- func (s *System) Tell(actor *Ref, message Message)
- func (s *System) TellAt(addr Address, message Message)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrUnexpectedMessage ¶
ErrUnexpectedMessage is returned by an actor in response to a message that it was not expecting to receive.
Types ¶
type Actor ¶
type Actor interface { // Receive defines the actor's behavior. Receive is called for each message in the inbox until // a request to stop is received or the parent shuts the actor down. Receive(context *Context) error }
Actor is an object that encapsulates both state and behavior.
type ActorFunc ¶
ActorFunc is a function that encapsulates behavior. It is a stateless actor, useful for a mocking.
type Address ¶
type Address struct {
// contains filtered or unexported fields
}
Address is the location of an actor within an actor system.
func Addr ¶
func Addr(rawPath ...interface{}) Address
Addr returns a new address with the provided actor path components. Each of the path components must be URL-safe.
func AddrFromString ¶
AddrFromString is the inverse of `Address.String()`.
func (Address) IsAncestorOf ¶
IsAncestorOf returns true if the provided address is a descendant of this address.
func (Address) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Address) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface.
func (*Address) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (*Address) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface.
type ChildFailed ¶
ChildFailed is a message notifying the actor that one of its children has failed.
type ChildStopped ¶
type ChildStopped struct {
Child *Ref
}
ChildStopped is a message notifying the actor when a child has stopped.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context holds contextual information for the context's recipient and the current message.
func (*Context) ActorOf ¶
ActorOf adds the actor to the system as a child of the context's recipient. If an actor with that ID already exists, that actor's reference is returned instead. The second argument is true if the actor reference was created and false otherwise.
func (*Context) ActorOfFromFactory ¶
ActorOfFromFactory behaves the same as ActorOf but will only create the actor instance if it's needed. It is intended for cases where an actor needs to be looked up many times safely but usually exists.
func (*Context) Ask ¶
Ask sends the specified message to the actor, returning a future to the result of the call. The new context's sender is set to the recipient of this context.
func (*Context) AskAll ¶
AskAll sends the specified message to all actors, returning a future to all results of the call. Results are returned in arbitrary order. The result channel is closed after all actors respond. The new context's sender is set to recipient of this context.
func (*Context) Children ¶
Children returns a list of references to the context's recipient's children.
func (*Context) ExpectingResponse ¶
ExpectingResponse returns true if the sender is expecting a response and false otherwise.
func (*Context) Kill ¶
Kill removes the child with the given local ID from this parent. All messages from this child to this actor are ignored.
func (*Context) MustActorOf ¶
MustActorOf adds the actor with the provided address. It panics if a new actor was not created.
func (*Context) Respond ¶
Respond returns a response message for this request message back to the sender.
func (*Context) RespondCheckError ¶
RespondCheckError returns a response message for this request message back to the sender. If the response has an error send that instead.
type Message ¶
type Message interface{}
Message holds the communication protocol between actors. Actors can send messages to other actors and receive messages from other actors.
type Ping ¶
type Ping struct{}
Ping is an actor message that the actor system automatically respond with an empty response back once being processed. It is used for synchronizing that the messages that are previous to this Ping message and received by the actor are processed.
type PostStop ¶
type PostStop struct{}
PostStop notifies the actor that its reference is shutting down.
type Ref ¶
type Ref struct {
// contains filtered or unexported fields
}
Ref is an immutable actor reference to an actor.
func (*Ref) AwaitTermination ¶
AwaitTermination waits for the actor to stop, returning an error if the actor has failed during its lifecycle.
func (*Ref) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (*Ref) RegisteredTime ¶
RegisteredTime returns the time that the actor registered with the system.
func (*Ref) StopAndAwaitTermination ¶
StopAndAwaitTermination synchronously stops the actor, returning an error if the actor fails to close properly.
type Response ¶
type Response interface { // Source returns the source of the response. Source() *Ref // Get returns the result of the `Ask` or nil if the actor did not respond. Get() Message // GetOrTimeout returns the result of the `Ask` or nil if the actor did not respond. If the // timeout is reached, nil is returned and the second result returns false. GetOrTimeout(timeout time.Duration) (Message, bool) // GetOrElse returns the result of the `Ask` or the provided default if the actor did not // respond. GetOrElse(defaultValue Message) Message // GetOrElseTimeout returns the result of the `Ask` or the provided default if the actor did not // respond. If the timeout is reached, the defaultValue is returned and the second result // returns false. GetOrElseTimeout(defaultValue Message, timeout time.Duration) (Message, bool) // Empty returns true if the actor did not respond and false otherwise. Empty() (empty bool) // Error returns the error if the actor returned an error response and nil otherwise. Error() (err error) // ErrorOrTimeout returns the error, or nil if there is none, if the actor returned an error // response within the deadline. If the deadline is exceeded, the bool returned false. ErrorOrTimeout(timeout time.Duration) (bool, error) }
Response holds a reference to the future result of an `Ask` of an actor. Responses are not thread safe.
type Responses ¶
type Responses <-chan Response
Responses wraps a collection of response objects from different actors.
func (Responses) GetAll ¶
GetAll waits for all actors to respond and returns a mapping of all actors and their corresponding responses.
func (Responses) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
type System ¶
type System struct { *Ref // contains filtered or unexported fields }
System is a hierarchical group of actors.
func NewSystemWithRoot ¶
NewSystemWithRoot constructs a new actor system with the specified root actor and starts it.
func (*System) ActorOf ¶
ActorOf adds the actor with the provided address. The second return value denotes whether a new actor was created or not.
func (*System) Ask ¶
Ask sends the specified message to the actor, returning a future to the result of the call. The context's sender is set to `nil`.
func (*System) AskAll ¶
AskAll sends the specified message to all actors, returning a future to all results of the call. Results are returned in arbitrary order. The result channel is closed after all actors respond. The context's sender is set to `nil`.
func (*System) AskAllTimeout ¶
AskAllTimeout sends the specified message to all actors, returning a future to all results of the call. Results are returned in arbitrary order. The result channel is closed after all actors respond. The context's sender is set to `nil`. If the timeout is reached, nil responses are returned.
func (*System) AskAt ¶
AskAt sends the specified message to the actor at the provided address, returning a future to the result of the call. The context's sender is set to `nil`. If an actor does not exist at the exact address we attempt to lookup and send the message to an actor registered at the sibling wildcard address instead.
func (*System) Get ¶
Get returns the actor reference with the id, or nil if no actor with that id is found.
func (*System) MustActorOf ¶
MustActorOf adds the actor with the provided address. It panics if a new actor was not created.