﻿1
00:00:04,879 --> 00:00:07,740
welcome to section three working with

2
00:00:07,740 --> 00:00:11,009
akka basic tools in the previous section

3
00:00:11,009 --> 00:00:13,380
you learned the basic actor concepts in

4
00:00:13,380 --> 00:00:16,528
akka in this section we will take a look

5
00:00:16,528 --> 00:00:19,280
at the basic tools in occur such as

6
00:00:19,280 --> 00:00:23,160
actor f versus actor path versus actor

7
00:00:23,160 --> 00:00:27,868
selection routing replace actor behavior

8
00:00:27,868 --> 00:00:31,710
via become unbecoming

9
00:00:31,710 --> 00:00:35,939
via FSM let's start our first video

10
00:00:35,939 --> 00:00:38,759
actor ref versus actor path versus actor

11
00:00:38,759 --> 00:00:42,030
selection in this video we will discuss

12
00:00:42,030 --> 00:00:44,070
what's the difference between actor ref

13
00:00:44,070 --> 00:00:49,200
actor path and actor selection in the

14
00:00:49,200 --> 00:00:51,420
previous section when we discussed actor

15
00:00:51,420 --> 00:00:53,820
components we said that the actor ref is

16
00:00:53,820 --> 00:00:56,509
the interface of the actor instance

17
00:00:56,509 --> 00:00:59,039
actor F is a reference for a single

18
00:00:59,039 --> 00:01:01,439
actor it is created when an actor

19
00:01:01,439 --> 00:01:03,628
instance is created and is pointed to

20
00:01:03,628 --> 00:01:06,000
this instance when the actor is starts

21
00:01:06,000 --> 00:01:07,920
the instance still points to the same

22
00:01:07,920 --> 00:01:10,379
actor ref but when the actor shuts down

23
00:01:10,379 --> 00:01:12,328
the actor reference will point to a

24
00:01:12,328 --> 00:01:14,998
dead-letter and when you create a new

25
00:01:14,998 --> 00:01:15,810
instance

26
00:01:15,810 --> 00:01:18,468
acha will create a new actor reference

27
00:01:18,468 --> 00:01:21,659
this means actor references don't change

28
00:01:21,659 --> 00:01:24,989
during the actor life cycle we know

29
00:01:24,989 --> 00:01:26,728
actors are created in a strictly

30
00:01:26,728 --> 00:01:29,069
hierarchical fashion if we are thinking

31
00:01:29,069 --> 00:01:31,319
about an actor's tree like a file system

32
00:01:31,319 --> 00:01:33,899
and want to get a path for actor B it's

33
00:01:33,899 --> 00:01:38,700
a forward slash user /a /b this is a

34
00:01:38,700 --> 00:01:41,519
path for an actor actor path is a

35
00:01:41,519 --> 00:01:43,528
location of the actor on the actor

36
00:01:43,528 --> 00:01:46,019
system tree it's a sequence of actor

37
00:01:46,019 --> 00:01:48,179
names given by recursively following the

38
00:01:48,179 --> 00:01:49,978
supervision links between a child and

39
00:01:49,978 --> 00:01:52,078
parent down towards the roots of the

40
00:01:52,078 --> 00:01:55,319
actor system the difference between an

41
00:01:55,319 --> 00:01:57,629
actor path and actor ref is that the

42
00:01:57,629 --> 00:01:59,489
actor path represents a name of the

43
00:01:59,489 --> 00:02:01,409
actor which means you can create the

44
00:02:01,409 --> 00:02:03,899
actor terminate it and then create a new

45
00:02:03,899 --> 00:02:06,718
actor with the same path the newly

46
00:02:06,718 --> 00:02:08,758
created actor is a new instance of the

47
00:02:08,758 --> 00:02:10,500
actor which means it has a different

48
00:02:10,500 --> 00:02:13,949
actor reference actor selection is

49
00:02:13,949 --> 00:02:16,199
another representation of the actor like

50
00:02:16,199 --> 00:02:17,550
actor reference

51
00:02:17,550 --> 00:02:20,099
you can send messages to an actor via

52
00:02:20,099 --> 00:02:22,949
actor selection like actor F the main

53
00:02:22,949 --> 00:02:24,330
difference between them is that the

54
00:02:24,330 --> 00:02:26,099
actor selection is created from the

55
00:02:26,099 --> 00:02:29,400
actor path or actor name this means that

56
00:02:29,400 --> 00:02:31,500
the actor selection stays valid even

57
00:02:31,500 --> 00:02:33,300
when an actor dies and another instance

58
00:02:33,300 --> 00:02:36,300
is created so you can't watch the actor

59
00:02:36,300 --> 00:02:38,069
selection like actor reference because

60
00:02:38,069 --> 00:02:39,960
actor selection doesn't represent a

61
00:02:39,960 --> 00:02:43,439
single instance it represents a path now

62
00:02:43,439 --> 00:02:45,060
let's play with an actor reference and

63
00:02:45,060 --> 00:02:48,629
actor selection we have a counter actor

64
00:02:48,629 --> 00:02:51,240
that handles two messages increment and

65
00:02:51,240 --> 00:02:55,349
decrement and has a count variable now

66
00:02:55,349 --> 00:02:57,409
let's create an instance from a counter

67
00:02:57,409 --> 00:03:00,210
then let's print an act of reference for

68
00:03:00,210 --> 00:03:04,259
our instance after that let's create an

69
00:03:04,259 --> 00:03:06,780
actor selection we will use the actor

70
00:03:06,780 --> 00:03:08,759
selection method that takes a path or

71
00:03:08,759 --> 00:03:11,939
name we will give it our actor name and

72
00:03:11,939 --> 00:03:15,050
print the actor selection for our actor

73
00:03:15,050 --> 00:03:18,150
then let's kill our counter instance and

74
00:03:18,150 --> 00:03:20,039
create a new one and a new actor

75
00:03:20,039 --> 00:03:23,849
selection we'll print a new actor

76
00:03:23,849 --> 00:03:28,219
reference and actor selection let's run

77
00:03:28,219 --> 00:03:30,810
yeah it's not the same actor reference

78
00:03:30,810 --> 00:03:33,840
but it's the same actor selection we

79
00:03:33,840 --> 00:03:35,759
said we can't watch the actor selection

80
00:03:35,759 --> 00:03:37,650
but what if we don't have an actor

81
00:03:37,650 --> 00:03:39,689
reference and we know just a name for

82
00:03:39,689 --> 00:03:43,319
the actor how can we watch it it's

83
00:03:43,319 --> 00:03:46,229
simple by default every actor can handle

84
00:03:46,229 --> 00:03:48,479
a message called identify and reply to

85
00:03:48,479 --> 00:03:51,479
this message with the actor reference so

86
00:03:51,479 --> 00:03:53,340
you can easily convert active selection

87
00:03:53,340 --> 00:03:55,830
to act a reference and avoid using actor

88
00:03:55,830 --> 00:03:59,340
selection so let's create a watch actor

89
00:03:59,340 --> 00:04:01,050
that will have a selection value for the

90
00:04:01,050 --> 00:04:04,110
counter actor we will send an identify

91
00:04:04,110 --> 00:04:07,020
message for this selection an identify

92
00:04:07,020 --> 00:04:09,300
message contains the message ID that

93
00:04:09,300 --> 00:04:13,229
will return a response on the receive

94
00:04:13,229 --> 00:04:14,909
method we will handle the response of

95
00:04:14,909 --> 00:04:16,769
identify

96
00:04:16,769 --> 00:04:19,348
acta identify contains a correlated ID

97
00:04:19,348 --> 00:04:21,750
which is the message ID and an optional

98
00:04:21,750 --> 00:04:25,949
value for actor ref when the actor is

99
00:04:25,949 --> 00:04:28,079
live it will have some value for actor F

100
00:04:28,079 --> 00:04:30,329
and when the actor does not exist the

101
00:04:30,329 --> 00:04:38,990
value will be none

102
00:04:38,990 --> 00:04:41,089
you

103
00:04:41,089 --> 00:04:44,379
now let's create two instance forms

104
00:04:44,379 --> 00:04:51,069
counter and watcher let's run

105
00:04:51,069 --> 00:04:53,959
great that's the act of reference for

106
00:04:53,959 --> 00:04:56,839
the current running counter instance to

107
00:04:56,839 --> 00:04:59,000
summarize we discussed the difference

108
00:04:59,000 --> 00:05:01,430
between actor reference actor path and

109
00:05:01,430 --> 00:05:03,045
actor selection


