gestão de dados partilhados em ambientes de computação móvel
gestão de dados partilhados em ambientes de computação móvel
gestão de dados partilhados em ambientes de computação móvel
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
216 APÊNDICE A. DOORS<br />
Funções do protocolo<br />
procedure syncViewSend(view_peer)<br />
(1) send (sync view,view_id,<br />
unknownM<strong>em</strong>bOps(view_peer))<br />
procedure syncViewReceive()<br />
(1) receive (sync view,view_peer,ops)<br />
(2) m<strong>em</strong>b.ops := m<strong>em</strong>b_ops ∪ ops<br />
(no protocolo local <strong>de</strong> mudança <strong>de</strong> vista)<br />
(3) if view_id = view_peer then<br />
(4) send (sync view,view_id,<br />
unknownM<strong>em</strong>bOps(view_peer))<br />
(5) end if<br />
procedure initBiEpi<strong>de</strong>mic( Ob js)<br />
(1) send (view_id)<br />
(2) nStep := 1; full := Ob js = U<br />
(3) send (nStep,full)<br />
(4) for ∀ o ∈ Ob js do<br />
(5) updateClock(o)<br />
(6) send (ask sync,o.id,o.l,o.a)<br />
(7) end for<br />
(8) send (end)<br />
procedure stepBiEpi<strong>de</strong>mic()<br />
(1) receive (view_peer)<br />
(2) if view_id = view_peer then<br />
(3) syncViewSend(view_peer); return;<br />
(4) end if<br />
(5) receive (nStep,full)<br />
(6) lastStep := lastStep(nStep)<br />
(7) send0 (view_id)<br />
(8) send0 (nStep+1,full)<br />
(9) Ob js = /0<br />
(10) forever do<br />
(11) receive msg<br />
(12) if msg.type = end then break end if<br />
(13) processOne( msg)<br />
(14) Ob js := Ob js ∪ {msg.id}<br />
(15) end forever<br />
(16) if full AND NOT lastStep then<br />
(17) for ∀ o ∈ U : o.id /∈ Ob js do<br />
(18) send (ask sync,o.id,o.l,o.a)<br />
(19) end for<br />
(20) end if<br />
(21) send0 (end)<br />
procedure processOne( msg)<br />
(1) case msg of<br />
(2) (ask sync,id,l,a):<br />
(3) if exists(id) then<br />
(4) o = getCoobject(id)<br />
(5) updateClock( o); updateAck( o, a)<br />
(6) send0 (sync,id,o.l,o.a,unknownOps(o,l))<br />
(7) else if r<strong>em</strong>oved(id) then<br />
(8) send0 (r<strong>em</strong>oved,id)<br />
(9) else<br />
(10) send0 (ask state,id)<br />
(11) end if<br />
(12) (sync,id,l,a,l_0,ops):<br />
(13) if exists(id) then<br />
(14) o = getCoobject(id)<br />
(15) o.ops := o.ops ∪ ops<br />
(16) updateLogged(o,l_0,l);updateClock(o);<br />
updateAck(o,a)<br />
(17) send0 (sync,id,o.l,o.a,l,unknownOps(o,l))<br />
(18) else<br />
(19) send0 (ask state,id)<br />
(20) end if<br />
(21) (r<strong>em</strong>oved,id):<br />
(22) U := U \ {getCoob ject(id)}<br />
(23) Del := Del ∪ {id}<br />
(24) (ask state,id):<br />
(25) if exists(id) then<br />
(26) o = getCoobject(id)<br />
(27) send0 (new state,id,o)<br />
(28) else<br />
(29) // do nothing<br />
(30) end if<br />
(31) (new state,id,o):<br />
(32) if exists(id) then<br />
(33) // error: do nothing<br />
(34) else<br />
(35) U := U ∪ {o}<br />
(36) end if<br />
Figura A.2: Funções do protocolo <strong>de</strong> sincronização bilateral (simplificado).