Don't hide pickling errors
[sinf2345framework.git] / EPFD.oz
blobab2781b12507a66dfe4c24728880ff2bc2a5a4cc
1 functor
2 import
3 DistFramework(session:Session)
4 export
5 Epfd
6 define
7 fun{Epfd LM ?Uri}
8 PP2P={LM getLayer('dist-layer:pp2p' $)}
9 BEP2P={LM getLayer('dist-layer:bep2p' $)}
10 Alarm={LM getLayer('dist-layer:alarm' $)}
11 UUID='epfd(8525f024-6543-4108-abb8-2621617504a9)'
12 SEND_DELAY=1000
13 CHECK_DELAY=5000
15 Uri='dist-layer:epfd'
16 class from Session
17 attr
18 sendAlarm
19 checkAlarm
20 pp2p
21 bep2p
23 oldMonitored
24 monitored
25 monitoring
26 meth init(SId Handler)
27 h:=Handler
28 sendAlarm:={Alarm init(UUID|sendAlarm|SId
29 {self facet(alarm:Send $)})}
30 checkAlarm:={Alarm init(UUID|checkAlarm|SId
31 {self facet(alarm:Check $)})}
32 pp2p:={PP2P init(UUID|pp2p|SId {self facet(pp2pDeliver:Deliver $)})}
33 bep2p:={BEP2P init(UUID|bep2p|SId {self facet(bep2pDeliver:Deliver $)})}
34 oldMonitored:={NewDictionary}
35 monitored:={NewDictionary}
36 monitoring:={NewDictionary}
37 {@sendAlarm setAlarmIn(SEND_DELAY unit)}
38 {@checkAlarm setAlarmIn(CHECK_DELAY unit)}
39 end
40 meth monitor(Remote)
41 @monitored.(Remote.id):=false#Remote
42 @oldMonitored.(Remote.id):=unit#Remote
43 {@pp2p pp2pSend(Remote monitor())}
44 end
45 meth Deliver(From Msg)
46 case Msg
47 of monitor() then
48 @monitoring.(From.id):=From
49 [] imAlive() then
50 @monitored.(From.id):=true#From
51 end
52 end
53 meth Check(_)
54 for X in {Dictionary.keys @monitored} do
55 if @oldMonitored.X.1 \= @monitored.X.1 then
56 if @monitored.X.1 then
57 {@h alive(@monitored.X.2)}
58 else
59 {@h crash(@monitored.X.2)}
60 end
61 @oldMonitored.X:=@monitored.X
62 end
63 @monitored.X:=false#(@monitored.X.2)
64 end
65 {@checkAlarm setAlarmIn(CHECK_DELAY unit)}
66 end
67 meth Send(_)
68 for X in {Dictionary.items @monitoring} do
69 {@bep2p bep2pSend(X imAlive)}
70 end
71 {@sendAlarm setAlarmIn(SEND_DELAY unit)}
72 end
73 end
74 end
75 end