-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkit.go
1113 lines (930 loc) · 30.4 KB
/
kit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package actorkit
import (
"time"
"github.com/gokit/es"
"github.com/gokit/xid"
)
const (
stackSize = 1 << 16
// PackageName defines the name for the package used in relationship
// for messages or different types.
PackageName = "actorkit"
)
var (
deadLetterID = xid.New()
deadLetters = es.New()
eventDeathMails = NewEventDeathMail(deadLetters)
)
// DeadMail defines the type of event triggered by the deadletters
// event pipeline.
type DeadMail struct {
To Addr
Message Envelope
}
//***************************************************************************
// Header
//***************************************************************************
// Header defines a map type to hold meta information associated with a Envelope.
type Header map[string]string
// Get returns the associated value from the map within the map.
func (m Header) Get(n string) string {
return m[n]
}
// Map returns a map with contents of header.
func (m Header) Map() map[string]string {
mv := make(map[string]string, len(m))
for k, v := range m {
mv[k] = v
}
return mv
}
// Len returns the length of records within the meta.
func (m Header) Len() int {
return len(m)
}
// Has returns true/false value if key is present.
func (m Header) Has(n string) bool {
_, ok := m[n]
return ok
}
//***************************************************************************
// Envelope
//*************************************** ************************************
// Envelope defines a message to be delivered to a giving
// target destination from another giving source with headers
// and data specific to giving message.
type Envelope struct {
Header
Sender Addr
Ref xid.ID
Data interface{}
}
// CreateEnvelope returns a new instance of an envelope with provided arguments.
func CreateEnvelope(sender Addr, header Header, data interface{}) Envelope {
return Envelope{
Data: data,
Header: header,
Sender: sender,
Ref: xid.New(),
}
}
//***********************************
// Actor
//***********************************
// Actor defines a entity which is the single unit of work/computation.
// It embodies the idea of processing, storage and communication. It is the
// means for work to be done.
//
// Actors as axioms/rules which are:
//
// 1. It can receive a message and create an actor to process giving message.
// 2. It can send messages to actors it has addresses it has before.
// 3. It can designate what to do will the next message to be received.
//
// Actors are defined by the behaviour they embody and use, their are simply
// the management husk for this user defined behaviour and by this behaviors
// all the operations a actor can perform is governed. Usually an actors behaviour
// is represented by it's address, which means an actor can in one instance
// usually have similar address with only difference be their unique id when
// within the same tree ancestry and only differ in the service they offer or
// can be be the same actor offering different services based on the behaviour
// it provides.
type Actor interface {
Killable
Startable
Stoppable
Restartable
Destroyable
Identity
Protocol
Namespace
Addressable
ProtocolAddr
State
Ancestry
Descendants
Spawner
Discovery
Receiver
Escalator
Waiter
Watchable
DeathWatch
Stats
MailboxOwner
}
//***********************************
// Addr
//***********************************
// Addr represent a advertised capability and behavior which an actor provides, it is
// possible for one actor to exhibit ability of processing multiple operations/behaviors
// by being able to be expressed using different service addresses. Address simply express
// a reference handle by which an actor able to provide said service can be communicated with.
//
// Interaction of one service to another is always through an address, which makes them a common
// concept that can be transferable between zones, distributed system and networks.
//
// Addr by their nature can have a one-to-many and many-to-many relations with actors.
//
// A single actor can have multiple addresses pointing to it, based on different services it can render
// or even based on same service type, more so one address can be a means of communicating with multiple
// actors in the case of clustering or distributing messaging through a proxy address.
//
type Addr interface {
Service
Protocol
Identity
Namespace
Addressable
ProtocolAddr
State
Sender
Spawner
Futures
Watchable
DeathWatch
Descendants
Escalatable
AddressActor
AncestralAddr
AddressService
}
//***********************************
// Signals
//***********************************
// Signal represent a series of transitioning
// state which an actor runs through, it also
// provides a efficient means of checking actor's state.
type Signal uint32
// constants of different actor states transition used for signaling purposes.
const (
INACTIVE Signal = 1 << iota
STARTING
RUNNING
RESTARTING
RESTARTED
STOPPING
STOPPED
KILLING
KILLED
DESTRUCTING
DESTROYED
PANICED
REJECTED
RESOLVED
)
// String returns a text version of state.
func (s Signal) String() string {
switch s {
case INACTIVE:
return "INACTIVE"
case STARTING:
return "STARTING"
case RUNNING:
return "RUNNING"
case RESTARTING:
return "RESTARTING"
case RESTARTED:
return "RESTARTED"
case STOPPING:
return "STOPPING"
case RESOLVED:
return "RESOLVED"
case REJECTED:
return "REJECTED"
case STOPPED:
return "STOPPED"
case KILLING:
return "KILLING"
case KILLED:
return "KILLED"
case DESTRUCTING:
return "DESTRUCTING"
case DESTROYED:
return "DESTROYED"
case PANICED:
return "PANICED"
}
return "UNKNOWN"
}
// Signals defines a interesting interface which exposes a method
// for the reception of a current state of an actor. Useful for
// service discovery purposes and more.
type Signals interface {
SignalState(Addr, Signal)
}
// State defines a function which returns the current state of it's implementer.
type State interface {
State() Signal
}
//***********************************
// DeadLetter
//***********************************
// DeadLetter defines an interface which exists for the
// purpose of handling dead mails from terminated actors
// which have unprocessed mails within mailbox.
// It allows counter-measure to be provided to a actor's
// life cycle ending phase.
type DeadLetter interface {
RecoverMail(DeadMail)
}
// EventDeathMail implements the DeadLetter interface, where dead mails
// are delivered to a underline event system.
type EventDeathMail struct {
stream *es.EventStream
}
// NewEventDeathMail returns a new instance of a EventDeathMail.
func NewEventDeathMail(stream *es.EventStream) *EventDeathMail {
return &EventDeathMail{stream: stream}
}
// RecoverMail implements DeadLetter interface. Sending
// mails into event stream.
func (em *EventDeathMail) RecoverMail(mail DeadMail) {
em.stream.Publish(mail)
}
//***********************************
// Descendants
//***********************************
// Descendants exposes methods which allow
// interaction with children of a implementing
// object.
type Descendants interface {
Children() []Addr
GetAddr(addr string) (Addr, error)
GetChild(id string, subID ...string) (Addr, error)
}
//***********************************
// Waiter
//***********************************
// Waiter exposes a single method which blocks
// till a given condition is met.
type Waiter interface {
Wait()
}
//***********************************
// ErrWaiter
//***********************************
// ErrWaiter exposes a single method which blocks
// till a given condition is met or an error occurs that
// causes it to stop blocking and will return the error
// encountered.
type ErrWaiter interface {
Wait() error
}
//***********************************
// MailboxOwner
//***********************************
// MailboxOwner exposes a single method to retrieve an implementer's Mailbox.
type MailboxOwner interface {
Mailbox() Mailbox
}
//***********************************
// Ancestor
//***********************************
// Ancestry defines a single method to get the parent actor
// of a giving actor.
type Ancestry interface {
// Parent is supposed to return the immediate parent of giving
// Actor.
Parent() Actor
// Ancestor is supposed to return the root parent of all actors
// within chain.
Ancestor() Actor
}
//***********************************
// Identity
//***********************************
// Identity provides a method to return the ID of a process.
type Identity interface {
ID() string
}
//***********************************
// Addressable
//***********************************
// Addressable defines an interface which exposes a method for retrieving
// associated address of implementer.
type Addressable interface {
Addr() string
}
// ProtocolAddr defines a self named function which returns a giving value
// representing it's protocol address.
type ProtocolAddr interface {
ProtocolAddr() string
}
// Protocol exposes a self named method to get a giving value for procol of
// implementer.
type Protocol interface {
Protocol() string
}
// Namespace exposes a self named method to get a giving value for namespace of
// implementer.
type Namespace interface {
Namespace() string
}
// AddressService exposes a single method to locate given address for a target
// value, service or namespace.
type AddressService interface {
AddressOf(string, bool) (Addr, error)
}
//***********************************
// Behaviour
//***********************************
// Behaviour defines an interface that exposes a method
// that indicate a giving action to be done.
type Behaviour interface {
Action(Addr, Envelope)
}
// ErrorBehaviour defines an interface that exposes the
// a method which returns an error if one occurred for
// it's operation on a received Envelope.
type ErrorBehaviour interface {
Action(Addr, Envelope) error
}
//***********************************
// Receiver
//***********************************
// Receiver defines an interface that exposes methods
// to receive envelopes and it's own used address.
type Receiver interface {
Receive(Addr, Envelope) error
}
//***********************************
// Escalator
//***********************************
// Escalator defines an interface defines a method provided
// specifically for handle two cases of error:
//
// 1. Normal errors which occur as process operation life cycle
// 2. Critical errors which determine stability of system and ops.
//
// Normal errors will be raised while critical errors will get escalated.
// this means that escalated errors will be parsed up the tree to an actors
// supervisor and parent.
type Escalator interface {
Escalate(interface{}, Addr)
}
// Escalatable exposes a single method to escalate a given value up the implementers
// handling tree.
type Escalatable interface {
Escalate(interface{})
}
//***********************************
// Watchers
//***********************************
// Subscription defines a method which exposes a single method
// to remove giving subscription.
type Subscription interface {
Stop() error
}
// Handler defines a function type which is to be passed
// to a EventStream subscriber function.
type Handler func(interface{})
// Predicate defines a function for filtering
// by returning true/false for a giving value.
type Predicate func(interface{}) bool
// EventStream defines an interface for
type EventStream interface {
Reset()
Publish(interface{})
Subscribe(Handler, Predicate) Subscription
}
// Watchable defines a interface that exposes methods to add
// functions to be called on some status change of the implementing
// instance.
type Watchable interface {
Watch(func(interface{})) Subscription
}
// DeathWatch exposes a method to watch the state transition of
// a giving Addr if possible.
type DeathWatch interface {
DeathWatch(addr Addr) error
}
//***********************************
// Spawner
//***********************************
// Prop defines underline actor operation which are used to
// generate said handlers for an instantiated actor.
type Prop struct {
// ContextLog sets the context logger provider, which will be
// if set to create a Logger which will be used by the actor
// for logging, it's operations.
//
// It's expected child actors will inherit parent's Prop.ContextLogs
// if they are provided none for use in creating Logs instance in
// implementations.
ContextLogs ContextLogs
// Behaviour defines the behaviour to be used for handling
// and processing incoming messages.
Behaviour Behaviour
// Event represent the local events coming from the
// actor. Usually good to isolate events for actor
// only and is what is bounded to by Actor.Watch.
Event EventStream
// Mailbox is the actors's mailbox to be used for queuing
// incoming messages.
Mailbox Mailbox
// Signals is only ever accepted by a root actor who has
// no parent, but instead parent's pass down their own signal
// provider to their children/descendants. It provides a good
// and easy way of accepting signal indicators for a giving
// actor as it transitions between states.
Signals Signals
// Sentinel provides a advisor of behaviours to be performed
// for actors being watched by owner of this prop. This allows
// behaviours to be implemented or optionally provided. You can
// also implement the Sentinel interface on the Behaviour implementer
// instead.
Sentinel Sentinel
// DeadLetters provides a means of receiving dead mails i.e mails which
// could not be processed by actor due to termination.
DeadLetters DeadLetter
// Supervisor defines the supervisor which the actor is to use for managing
// it's state errors and child state errors.
Supervisor Supervisor
// StateInvoker defines the invoker called for update metrics or other uses cases
// for different states of the actor.
StateInvoker StateInvoker
// MessageInvoker defines the invoker called for updating metrics on status of incoming
// messages.
MessageInvoker MessageInvoker
// Discovery provides a overriding discovery service to be used for spawned actor
// instead of inheriting from parent, if parent has any.
Discovery DiscoveryService
// MailInvoker defines the invoker called for updating metrics on mailbox usage.
MailInvoker MailInvoker
}
// Spawner exposes a single method to spawn an underline actor returning
// the address for spawned actor.
//
// Note: Children actors always get their global registry from their parents
// so if your root actor has no registry, then the kids won't get access to any.
type Spawner interface {
Spawn(service string, props Prop) (Addr, error)
}
//***********************************
// Discovery
//***********************************
// Discovery defines an interface that resolves
// a giving address to it's target Actor returning
// actor if found. It accepts a flag which can be
// used to indicate wiliness to search ancestral
// trees.
type Discovery interface {
Discover(service string, ancestral bool) (Addr, error)
}
// DiscoveryService defines an interface which will return
// a giving Actor address for a desired service.
//
// DiscoveryServices provides a great way for adding service or actor discovery
// the actor system where. How the underline actor's who's address is returned is
// up to the implementer, but by abstracting such a system by this interface we
// provide a simple and easy way to add better discovery functionality into actor trees.
//
// DiscoveryServices also provide the means of templated actors, where actors with
// behaviors is already defined by a generating function called 'Templated Functions'.
// Templated functions always return a new actor when called and provide a nice means
// of having a guaranteed behaviour produced for a giving service namespace,
//
//
type DiscoveryService interface {
Discover(service string) (Addr, error)
}
// DiscoveryChain defines a method which adds giving
// Discovery into underline chain else returns an
// error if not possible.
// Discovery has a very important rule, whoever has
// record of giving actor is parent and supervisor
// of said actor. Even if discovery was requested
// at the lowest end, if ancestral search was enabled
// and a higher parent provided such actor, then that
// parent should naturally be supervisor of that actor.
type DiscoveryChain interface {
AddDiscovery(service DiscoveryService) error
}
// DiscoveryServiceFunction defines a function type which will spawn a given
// actor using a provided parent and returns address of spawned actor. This allows
// us allocate management of giving actor to some parent whilst allowing others
// gain access to giving actor.
type DiscoveryServiceFunction func(parent Addr, service string) (Addr, error)
// DiscoveryFor returns a new DiscoveryService which calls giving function
// with service name for returning an actor suitable for handling a giving service.
func DiscoveryFor(parent Addr, fn DiscoveryServiceFunction) DiscoveryService {
return &fnDiscovery{parent: parent, Fn: fn}
}
type fnDiscovery struct {
parent Addr
Fn DiscoveryServiceFunction
}
func (dn *fnDiscovery) Discover(service string) (Addr, error) {
return dn.Fn(dn.parent, service)
}
//***********************************
// Stats
//***********************************
// Stat holds count and time details for a giving target or holder
// of stat.
type Stat struct {
Death time.Time
Creation time.Time
Killed int64
Stopped int64
Delivered int64
Processed int64
Restarted int64
FailedRestarts int64
FailedDelivery int64
}
// Stats exposes a method which returns a giving
// Signal entity for it's implementer.
type Stats interface {
Stats() Stat
}
//***********************************
// Destroyable
//***********************************
// Destroyable defines an interface that exposes methods
// for the total shutdown and removal of an actor from
// all processes.
type Destroyable interface {
Destroy() error
DestroyChildren() error
}
// PreDestroy defines a function to be called after the destruction
// of an actor. It is called after stopping routine.
type PreDestroy interface {
PreDestroy(Addr)
}
// PostDestroy defines a function to be called after the destruction
// of an actor. It is called after stopping routine.
type PostDestroy interface {
PostDestroy(Addr)
}
//***********************************
// Stoppable and Killable
//***********************************
// PreStop defines a function to be called before the stopping
// of an actor. It is called before initiating the stop routine.
type PreStop interface {
PreStop(Addr)
}
// PostStop defines a function to be called after the stopping
// of an actor. It is called after stopping routine.
type PostStop interface {
PostStop(Addr)
}
// Stoppable defines an interface that provides sets of method to gracefully
// stop the operation of a actor.
type Stoppable interface {
Stop() error
StopChildren() error
}
// Killable defines an interface that provides set of method to
// abruptly stop and end the operation of an actor ungracefully.
type Killable interface {
Kill() error
KillChildren() error
}
//***********************************
// Startable
//***********************************
// Startable defines an interface that exposes a method
// which returns a ErrWaiter to indicate completion of
// start process.
type Startable interface {
Start() error
}
// PreStart exposes a method which gets called before the start
// of an actor.
//
// If any error is returned, it will cause the actor to stop and shutdown.
type PreStart interface {
PreStart(Addr) error
}
// PostStart exposes a method which gets called after the start
// of an actor.
//
// If any error is returned, it will cause the actor to stop and shutdown.
type PostStart interface {
PostStart(Addr) error
}
//***********************************
// Restartable
//***********************************
// Restartable defines an interface that exposes a method
// which returns a ErrWaiter to indicate completion of
// restart.
type Restartable interface {
Restart() error
RestartChildren() error
}
// PreRestart exposes a method which gets called before the restart
// of an actor.
//
// If any error is returned, it will cause the actor to stop and shutdown.
type PreRestart interface {
PreRestart(Addr) error
}
// PostRestart exposes a method which gets called after the restart
// of an actor.
//
// If any error is returned, it will cause the actor to stop and shutdown.
type PostRestart interface {
PostRestart(Addr) error
}
//***********************************
// Sentinel
//***********************************
// Sentinel exposes a method which handles necessarily logic
// for advising an action to be done for a watched actor.
// It allows notifications about said actor be handled and
// responded to.
//
// Whilst Sentinel and Signals seem similar, sentinel are
// mainly for the purpose of taking actions against the
// calls of when a Addr is asked to watch another address.
// It allows you to provide a structure which sits to provide
// a means of executing sets of behaviours for when a actor wishes
// to work or act on a giving state of another actor which has no
// parent and child relationship with it, which means such an actor
// does not rely on it's supervisory strategy.
//
// Sentinels will generally be inherited by child actors from parents
// if they do not provide their own, that is their general idea.
type Sentinel interface {
Advice(Addr, SystemMessage)
}
//***********************************
// AddressActor
//***********************************
// AddressActor defines an interface which exposes a method to retrieve
// the actor of an Address.
type AddressActor interface {
Actor() Actor
}
//***********************************
// Futures
//***********************************
// Futures defines an interface which exposes methods creating
// futures from a source
type Futures interface {
// Future returns a new future instance from giving source.
Future() Future
// TimedFuture returns a new timed future instance from giving source.
TimedFuture(time.Duration) Future
}
//***********************************
// Addressable
//***********************************
// Service defines an interface which exposes a method for retrieving
// service name.
type Service interface {
Service() string
}
//***********************************
// Supervisor and Directives
//***********************************
// Directive defines a int type which represents a giving action to be taken
// for an actor.
type Directive int
// directive sets...
const (
IgnoreDirective Directive = iota
PanicDirective
DestroyDirective
KillDirective
StopDirective
RestartDirective
EscalateDirective
)
// Supervisor defines a single method which takes
// an occurred error with addr and actor which are related
// to error and also the parent of giving actor which then handles
// the error based on giving criteria and criticality.
type Supervisor interface {
Handle(err interface{}, targetAddr Addr, target Actor, parent Actor)
}
//***********************************
// Mailbox
//***********************************
// Mailbox defines a underline queue which provides the
// ability to adequately push and release a envelope
// received for later processing. Usually a mailbox is
// associated with a actor and managed by a distributor.
type Mailbox interface {
// Wait will block till a message or set of messages are available.
Wait()
// Clear resets and empties all pending elements of queue.
Clear()
// Signal will broadcast to all listeners to attempt checking for
// new messages from blocking state.
Signal()
// Cap should returns maximum capacity for mailbox else -1 if unbounded.
Cap() int
// Total should return current total message counts in mailbox.
Total() int
// IsEmpty should return true/false if mailbox is empty.
IsEmpty() bool
// Unpop should add giving addr and envelope to head/start of mailbox
// ensuring next retrieved message is this added envelope and address.
Unpop(Addr, Envelope)
// Push adds giving address and envelope to the end of the mailbox.
Push(Addr, Envelope) error
// Pop gets next messages from the top of the mailbox, freeing space
// for more messages.
Pop() (Addr, Envelope, error)
}
//***********************************
// AncestralAddr
//***********************************
// AncestralAddr defines an interface which exposes method to retrieve
// the address of a giving parent of an implementing type.
type AncestralAddr interface {
Parent() Addr
Ancestor() Addr
}
//***********************************
// Sender
//***********************************
// Sender defines an interface that exposes methods
// to sending messages.
type Sender interface {
// Forward forwards giving envelope to actor.
Forward(Envelope) error
// Send will deliver a message to the underline actor
// with Addr set as sender .
Send(interface{}, Addr) error
// SendWithHeader will deliver a message to the underline actor
// with Addr set as sender with a Header.
SendWithHeader(interface{}, Header, Addr) error
}
//***********************************
// Resolvable
//***********************************
// Resolvable defines an interface which exposes a method for
// resolving the implementer.
type Resolvable interface {
Resolve(Envelope)
}
//***********************************
// Invokers
//***********************************
// SupervisionInvoker defines a invocation watcher, which reports
// giving action taken for a giving error.
type SupervisionInvoker interface {
InvokedStop(cause interface{}, stat Stat, addr Addr, target Actor)
InvokedKill(cause interface{}, stat Stat, addr Addr, target Actor)
InvokedDestroy(cause interface{}, stat Stat, addr Addr, target Actor)
InvokedRestart(cause interface{}, stat Stat, addr Addr, target Actor)
}
// MailInvoker defines an interface that exposes methods
// to signal status of a mailbox.
type MailInvoker interface {
InvokedFull()
InvokedEmpty()
InvokedDropped(Addr, Envelope)
InvokedReceived(Addr, Envelope)
InvokedDispatched(Addr, Envelope)
}
// MessageInvoker defines a interface that exposes
// methods to signal different state of a process
// for external systems to plugin.
type MessageInvoker interface {
InvokedRequest(Addr, Envelope)
InvokedProcessed(Addr, Envelope)
InvokedProcessing(Addr, Envelope)
}
// StateInvoker defines an interface which signals an invocation of state
// of it's implementer.
type StateInvoker interface {
InvokedDestroyed(interface{})
InvokedStarted(interface{})
InvokedStopped(interface{})
InvokedKilled(interface{})
InvokedRestarted(interface{})
InvokedPanic(Addr, PanicEvent)
}
//***********************************
// Future
//***********************************
// Future represents the address of a computation ongoing awaiting
// completion but will be completed in the future. It can be sent
// messages and can deliver events in accordance with it's state to
// all listeners. It can also be used to pipe it's resolution to
// other addresses.
type Future interface {
Addr
ErrWaiter
// Pipe adds giving address as a receiver of the result
// of giving future result or error.
Pipe(...Addr)
// PipeAction adds giving function as receiver of result
// of giving future result or error.
PipeAction(...func(Envelope))
// Err returns an error if processing failed or if the timeout elapsed
// or if the future was stopped.
Err() error
// Result returns the response received from the actors finished work.
Result() Envelope
}
//*******************************************************************
// System Messages
//*******************************************************************
// Message defines a giving error string for use as a detail.
type Message string
// Message implements the actorkit.LogEvent interface.
func (m Message) Message() string {
return string(m)
}
// OpMessage defines a giving default type for containing data related to
// an operation detail.
type OpMessage struct {