(* Title: Publisher_Subscriber.thy Author: Diego Marmsoler *) section "A Theory of Publisher-Subscriber Architectures" text\ In the following, we formalize the specification of the publisher subscriber pattern as described in~\cite{Marmsoler2018c}. \ theory Publisher_Subscriber imports Singleton begin subsection "Subscriptions" datatype 'evt subscription = sub 'evt | unsub 'evt subsection "Publisher-Subscriber Architectures" locale publisher_subscriber = pb: singleton pbactive pbcmp + sb: dynamic_component sbcmp sbactive for pbactive :: "'pid \ cnf \ bool" ("\_\\<^bsub>_\<^esub>" [0,110]60) and pbcmp :: "'pid \ cnf \ 'PB" ("\\<^bsub>_\<^esub>(_)" [0,110]60) and sbactive :: "'sid \ cnf \ bool" ("\_\\<^bsub>_\<^esub>" [0,110]60) and sbcmp :: "'sid \ cnf \ 'SB" ("\\<^bsub>_\<^esub>(_)" [0,110]60) + fixes pbsb :: "'PB \ ('evt set) subscription set" and pbnt :: "'PB \ ('evt \ 'msg)" and sbnt :: "'SB \ ('evt \ 'msg) set" and sbsb :: "'SB \ ('evt set) subscription" assumes conn1: "\k pid. \pid\\<^bsub>k\<^esub> \ pbsb (\\<^bsub>pid\<^esub>(k)) = (\sid\{sid. \sid\\<^bsub>k\<^esub>}. {sbsb (\\<^bsub>sid\<^esub>(k))})" and conn2: "\t n n'' sid pid E e m. \t \ arch; \pid\\<^bsub>t n\<^esub>; \sid\\<^bsub>t n\<^esub>; sub E = sbsb (\\<^bsub>sid\<^esub>(t n)); n''\ n; e \ E; \n' E'. n' \ n \ n' \ n'' \ \sid\\<^bsub>t n'\<^esub> \ unsub E' = sbsb (\\<^bsub>sid\<^esub>(t n')) \ e \ E'; (e, m) = pbnt (\\<^bsub>pid\<^esub>(t n'')); \sid\\<^bsub>t n''\<^esub>\ \ pbnt (\\<^bsub>pid\<^esub>(t n'')) \ sbnt (\\<^bsub>sid\<^esub>(t n''))" begin subsubsection "Calculus Interpretation" text \ \noindent @{thm[source] pb.baIA}: @{thm pb.baIA [no_vars]} \ text \ \noindent @{thm[source] sb.baIA}: @{thm sb.baIA [no_vars]} \ subsubsection "Results from Singleton" abbreviation the_pb :: "'pid" where "the_pb \ pb.the_singleton" text \ \noindent @{thm[source] pb.ts_prop(1)}: @{thm pb.ts_prop(1) [no_vars]} \ text \ \noindent @{thm[source] pb.ts_prop(2)}: @{thm pb.ts_prop(2) [no_vars]} \ subsubsection "Architectural Guarantees" text \ The following theorem ensures that a subscriber indeed receives all messages associated with an event for which he is subscribed. \ theorem msgDelivery: fixes t n n'' and sid::'sid and E e m assumes "t \ arch" and "\sid\\<^bsub>t n\<^esub>" and "sub E = sbsb (\\<^bsub>sid\<^esub>(t n))" and "n'' \ n" and "\n' E'. n' \ n \ n' \ n'' \ \sid\\<^bsub>t n'\<^esub> \ unsub E' = sbsb(\\<^bsub>sid\<^esub>(t n')) \ e \ E'" and "e \ E" and "(e,m) = pbnt (\\<^bsub>the_pb\<^esub>(t n''))" and "\sid\\<^bsub>t n''\<^esub>" shows "(e,m) \ sbnt (\\<^bsub>sid\<^esub>(t n''))" using assms conn2 pb.ts_prop(2) by simp text \ Since a publisher is actually a singleton, we can provide an alternative version of constraint @{thm[source] conn1}. \ lemma conn1A: fixes k shows "pbsb (\\<^bsub>the_pb\<^esub>(k)) = (\sid\{sid. \sid\\<^bsub>k\<^esub>}. {sbsb (\\<^bsub>sid\<^esub>(k))})" using conn1[OF pb.ts_prop(2)] . end end