• Save
Actors in Java
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Actors in Java

  • 267 views
Uploaded on

My slides from JavaDay 2011 Kyiv

My slides from JavaDay 2011 Kyiv

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
267
On Slideshare
267
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. АКТЁРЫ В JVMПростая архитектура дляконкурентных отказоустойчивыхмасштабируемых Java-приложений
  • 2. Данные
  • 3. Данные
  • 4. Данные
  • 5. Данные
  • 6. Данные
  • 7. Данные
  • 8. Данные
  • 9. Данные
  • 10. Данные
  • 11. Данные
  • 12. Данные
  • 13. Данные
  • 14. CalculateGet Lock Modify ДанныеRelease Lock
  • 15. Get Lock A Modify A IF (cond) Get Lock B A Modify B B Release Release Lock A Lock B
  • 16. Get Lock A Modify AGet Lock A Get Lock B Modify A Modify B Release Lock A Release Lock B Release Lock A
  • 17. 2 1 Get Lock BGet Lock A 2 1 Modify B Modify A 2 Get Lock A 1 1 IF (cond) Get Lock B 2 Modify B 1 Modify B 2 Release A 1 1Release A Release B 2 Release B
  • 18. 1 1 2Get Lock A Get Lock A Get Lock B 1 1 2 Modify A Modify A Modify B 1 1 2Get Lock B Get Lock B Get Lock A 1 1 2 Modify B Modify B Modify B 2 1 1 Release ARelease B Release B 2 2 1 Release BGet Lock B Release A 1 Get Lock A 2 2 Modify B Get Lock B 1 Modify A 1 2Release A Modify B 1 Get Lock B 2 2Get Lock A Get Lock A 1 2 2 Modify B Modify B Modify B 1 2 2 Release BRelease A Release A 2 2 1Release B Release B Release A
  • 19. 1 1 2 2Get Lock A Get Lock A Get Lock B Get Lock B 1 1 2 2 Modify A Modify A Modify B Modify B 1 1 2 1Get Lock B Get Lock B Get Lock A Get Lock A 1 1 2 1 Modify B Modify B Modify B Modify A 2 1 1 Release A 1Release B Release B Get Lock B 2 2 1 Release B 2Get Lock B Release A 1 Get Lock A Get Lock A 2 2 Modify B Get Lock B 1 Modify A 1 2Release A Modify B 1 Get Lock B 2 2Get Lock A Get Lock A 1 2 2 Modify B Modify B Modify B 1 2 2 Release BRelease A Release A 2 2 1Release B Release B Release A
  • 20. От чего избавиться?Что улучшить?
  • 21. Взаимные блокировкиПоследовательный доступ
  • 22. Разделяемая памятьСинхронные вызовыОчередь событий
  • 23. Актер =состояние + поведение + почтовый ящик
  • 24. A
  • 25. A AA A AA AAAA A A A A AA A A A A AA AA AA A AA AA A AA A AA AA AA A AA A
  • 26. A
  • 27. A Данные
  • 28. A ДанныеA A
  • 29. A ДанныеA AA
  • 30. A A
  • 31. A A
  • 32. A A AAA A A
  • 33. A A AAA A A AA A A
  • 34. AA
  • 35. AAction ActionActionAction
  • 36. AAction F ActionGet! F ActionAction F
  • 37. AAction F ActionAction ActionAction FGet! F
  • 38. Данные
  • 39. A4 A8
  • 40. A4 A8
  • 41. Call! Action ActionAction ReturnAction
  • 42. Action ActionAction ActionReturn Return
  • 43. AДанные Данные копия A Данные копия 2
  • 44. AA A A A A →
  • 45. ?
  • 46. AStart
  • 47. A Login A AStart Register A Email Dispatcher
  • 48. ALogin
  • 49. A Login A Login ALogin A Login A Login
  • 50. A Sender A Sender A Email ADispatcher Sender A Sender
  • 51. A A UserSession1 User1 ALogin
  • 52. A A UserSession1 User1 A ALogin UserSession2 A User2
  • 53. A A UserSession1 User1 A ALogin UserSession2 A A UserSession3 User2
  • 54. A A AUserSession1 A
  • 55. A AUserSession1 Document1
  • 56. A AUserSession1 Document1 A Document7
  • 57. A AUserSession3 Document4 A AUserSession1 Document1 A AUserSession5 Document7
  • 58. A A A Login Session User A AStart Register A Document A Email Dispatcher
  • 59. A ASession User A Document
  • 60. ASession1
  • 61. ASession1 ADocument1
  • 62. A Session1 A Document1A A A AUser User User User
  • 63. A Document1 A A A AUser1 User2 User3 User4
  • 64. A Document1 A A A A User1 User2 User3 User4 A A A A A ASession1 Session2 Session3 Session4 Session5 Session6
  • 65. A ДанныеDocument1
  • 66. A ДанныеDocument1
  • 67. A Данные
  • 68. A ДанныеGET Данные Копия Данные Копия
  • 69. A ДанныеUPDATE
  • 70. Actor
  • 71. A UserSession1 User1 A ALogin UserSession2 A A UserSession3 User2
  • 72. To:Session1 A A Login UserSession2 A A UserSession3 User2
  • 73. To:Session1 A A Login UserSession2 A A UserSession3 User2
  • 74. To:Session1 A A UserSession1 User1 A A Login UserSession2 A A UserSession3 User2
  • 75. GET A Данные Данные Копия Данные Копия
  • 76. A A UserSession1 User1 A ALogin UserSession2 A UserSession3 User2
  • 77. A A UserSession1 User1 ALogin UserSession2 UserSession3 User2
  • 78. A A UserSession1 User1 ALogin
  • 79. A
  • 80. A
  • 81. AAAA
  • 82. F AF AF AF A
  • 83. F A F AF F A F A
  • 84. F A F AF F A F A
  • 85. F A F AF F A F A
  • 86. akka.io
  • 87. import akka.actor.Actorimport akka.event.EventHandlerpublic class HelloActor extends Actor { def receive = { case "hello" => HelloService().hi case s: String => HelloService().sayHello(s) case _ => EventHandler.info(this, "unknown message") }}
  • 88. //Startval actorRef = Actor.actorOf[MyActor]actorRef.start()//Send messageactorRef ! "hello"actorRef ! new Date()//Obtain actorsval actors = Actor.registry.actorsFor(classOf[HelloActor])
  • 89. //Askval response = actorRef ? "hello"//Get resultval result = response.getActor.become( newRecieveFunction )
  • 90. import akka.actor.UntypedActor;import akka.event.EventHandler;public class HelloActor extends UntypedActor { public void onReceive(Object message) { if (message instanceof String) { HelloService.getInstance().sayHello(message); } }}
  • 91. //StartActorRef ref = Actors.actorOf(HelloActor.class);ref.start();//Send messageref.tell("hello");ref.tell(new Date());//Obtain actorsActorRef[] actors = Actors.registry().actorsFor(HelloActor.class);
  • 92. //AskFuture response = actorRef.ask("hello");…//Get resultString result = response.get();//Hello, synchronous call! Long time no see.String syncResult = actorRef.ask("hello").get();
  • 93. • Actors• Typed Actors• Supervisors• Routing• Futures• STM• FSM• TestKit
  • 94. class SomeSpec extends … TestKit { "A Worker" must { "send timely replies" in { val worker = actorOf(...) within (500 millis) { worker ! "some work" } } }}
  • 95. Виктор Тесленкоvictor@teslenko.com.uatwitter: @vir