SlideShare a Scribd company logo
1 of 15
Download to read offline
Aleph
A framework for asynchronous communication


    http://github.com/ztellman/aleph
Supports many protocols
Client and server support for:
•   HTTP

•   WebSockets

•   TCP

•   Serialized Objects

•   More in the near future...
Channels


• event-driven queues
• not immutable; once a message is consumed, it’s gone
• rich set of operators
> (def ch (channel))
<== []
> (enqueue ch 1)
true
> (enqueue ch 2 3)
true
> (def ch (channel))
<== []
> (enqueue ch 1)
true
> (enqueue ch 2 3)
true




> (receive ch #(println "received" %))
received 1
true
> (def ch (channel))
<== []
> (receive ch #(println "callback a:" %))
true
> (receive ch #(println "callback b:" %))
true
> (enqueue ch 1)
callback a: 1
callback b: 1
true
> (def ch (channel 1 2))
<== [1 2]
> (receive-all ch #(println %))
1
2
true
> (enqueue ch 3)
3
true
enqueue/receive-all = publish/subscribe
Bidirectional communication
Bidirectional communication




> (channel-pair)
[ <== [], <== [] ]
A simple echo server




(defn setup-echo [ch]
  (receive-all ch #(enqueue ch %))

 or

(defn setup-echo [ch]
  (siphon ch ch))
A restatement of the problem

• We want the latest changelist from the server
• If a new changelist is available, respond
  immediately
• Otherwise, delay the response until a new
  changelist comes in
(def latest (ref nil))
(def changelists (channel))
(def latest (ref nil))
(def changelists (channel))

(receive-all changelists
  (fn [changelist]
    (dosync
      (ref-set latest changelist))))
(def latest (ref nil))
(def changelists (channel))

(receive-all changelists
  (fn [changelist]
    (dosync
      (ref-set latest changelist))))

(defn request-handler [response-channel request]
  (let [last-serial (-> request :body :last-serial)

        src (dosync

            (if (and @latest (> (:serial latest) last-serial))

 
             (channel @latest)

 
             (take* 1 changelists)))]
    (siphon
      (map* create-http-response src)
      response-channel)))

More Related Content

Viewers also liked

blogサービスの全文検索の話 - #groonga を囲む夕べ
blogサービスの全文検索の話 - #groonga を囲む夕べblogサービスの全文検索の話 - #groonga を囲む夕べ
blogサービスの全文検索の話 - #groonga を囲む夕べ
Masahiro Nagano
 
Ruby1.9のfiberのかっこいい使い方
Ruby1.9のfiberのかっこいい使い方Ruby1.9のfiberのかっこいい使い方
Ruby1.9のfiberのかっこいい使い方
Kindai University
 
Code as data as code.
Code as data as code.Code as data as code.
Code as data as code.
Mike Fogus
 
ARC環境で メモリリークを起こす 7つの方法
ARC環境で メモリリークを起こす 7つの方法ARC環境で メモリリークを起こす 7つの方法
ARC環境で メモリリークを起こす 7つの方法
ushiostarfish _
 
Mobage を支える Ruby の技術 ~ 複数DB編 ~
Mobage を支える Ruby の技術 ~ 複数DB編 ~Mobage を支える Ruby の技術 ~ 複数DB編 ~
Mobage を支える Ruby の技術 ~ 複数DB編 ~
Naotoshi Seo
 

Viewers also liked (19)

Next Generation Web Application Architecture
Next Generation Web Application ArchitectureNext Generation Web Application Architecture
Next Generation Web Application Architecture
 
new Objctive-C literal syntax
new Objctive-C literal syntaxnew Objctive-C literal syntax
new Objctive-C literal syntax
 
blogサービスの全文検索の話 - #groonga を囲む夕べ
blogサービスの全文検索の話 - #groonga を囲む夕べblogサービスの全文検索の話 - #groonga を囲む夕べ
blogサービスの全文検索の話 - #groonga を囲む夕べ
 
Rubyはとても「人間的」
Rubyはとても「人間的」Rubyはとても「人間的」
Rubyはとても「人間的」
 
Ruby1.9のfiberのかっこいい使い方
Ruby1.9のfiberのかっこいい使い方Ruby1.9のfiberのかっこいい使い方
Ruby1.9のfiberのかっこいい使い方
 
本格的に始めるzsh
本格的に始めるzsh本格的に始めるzsh
本格的に始めるzsh
 
いまさら聞けないDocker - 第5回コンテナ型仮想化の情報交換会@大阪
いまさら聞けないDocker - 第5回コンテナ型仮想化の情報交換会@大阪いまさら聞けないDocker - 第5回コンテナ型仮想化の情報交換会@大阪
いまさら聞けないDocker - 第5回コンテナ型仮想化の情報交換会@大阪
 
プログラマとして仕事をするために勉強すること
プログラマとして仕事をするために勉強することプログラマとして仕事をするために勉強すること
プログラマとして仕事をするために勉強すること
 
Project Lambdaの基礎
Project Lambdaの基礎Project Lambdaの基礎
Project Lambdaの基礎
 
Code as data as code.
Code as data as code.Code as data as code.
Code as data as code.
 
受託開発時におけるAWSクラウド活用術
受託開発時におけるAWSクラウド活用術受託開発時におけるAWSクラウド活用術
受託開発時におけるAWSクラウド活用術
 
ARC環境で メモリリークを起こす 7つの方法
ARC環境で メモリリークを起こす 7つの方法ARC環境で メモリリークを起こす 7つの方法
ARC環境で メモリリークを起こす 7つの方法
 
ES6 at PayPal
ES6 at PayPalES6 at PayPal
ES6 at PayPal
 
Eclipse活用術
Eclipse活用術Eclipse活用術
Eclipse活用術
 
Storm Anatomy
Storm AnatomyStorm Anatomy
Storm Anatomy
 
Closure CompilerのES6対応 あるいはES6時代のAltJS生存戦略
Closure CompilerのES6対応 あるいはES6時代のAltJS生存戦略Closure CompilerのES6対応 あるいはES6時代のAltJS生存戦略
Closure CompilerのES6対応 あるいはES6時代のAltJS生存戦略
 
Mobage を支える Ruby の技術 ~ 複数DB編 ~
Mobage を支える Ruby の技術 ~ 複数DB編 ~Mobage を支える Ruby の技術 ~ 複数DB編 ~
Mobage を支える Ruby の技術 ~ 複数DB編 ~
 
ChefConf 2013: Beginner Chef Antipatterns
ChefConf 2013: Beginner Chef AntipatternsChefConf 2013: Beginner Chef Antipatterns
ChefConf 2013: Beginner Chef Antipatterns
 
Scala 初めての人が Heroku で Web アプリを公開するまで
Scala 初めての人が Heroku で Web アプリを公開するまでScala 初めての人が Heroku で Web アプリを公開するまで
Scala 初めての人が Heroku で Web アプリを公開するまで
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

Aleph: a Framework for Asynchronous Communication

  • 1. Aleph A framework for asynchronous communication http://github.com/ztellman/aleph
  • 2. Supports many protocols Client and server support for: • HTTP • WebSockets • TCP • Serialized Objects • More in the near future...
  • 3. Channels • event-driven queues • not immutable; once a message is consumed, it’s gone • rich set of operators
  • 4. > (def ch (channel)) <== [] > (enqueue ch 1) true > (enqueue ch 2 3) true
  • 5. > (def ch (channel)) <== [] > (enqueue ch 1) true > (enqueue ch 2 3) true > (receive ch #(println "received" %)) received 1 true
  • 6. > (def ch (channel)) <== [] > (receive ch #(println "callback a:" %)) true > (receive ch #(println "callback b:" %)) true > (enqueue ch 1) callback a: 1 callback b: 1 true
  • 7. > (def ch (channel 1 2)) <== [1 2] > (receive-all ch #(println %)) 1 2 true > (enqueue ch 3) 3 true
  • 11. A simple echo server (defn setup-echo [ch] (receive-all ch #(enqueue ch %)) or (defn setup-echo [ch] (siphon ch ch))
  • 12. A restatement of the problem • We want the latest changelist from the server • If a new changelist is available, respond immediately • Otherwise, delay the response until a new changelist comes in
  • 13. (def latest (ref nil)) (def changelists (channel))
  • 14. (def latest (ref nil)) (def changelists (channel)) (receive-all changelists   (fn [changelist]     (dosync       (ref-set latest changelist))))
  • 15. (def latest (ref nil)) (def changelists (channel)) (receive-all changelists   (fn [changelist]     (dosync       (ref-set latest changelist)))) (defn request-handler [response-channel request]   (let [last-serial (-> request :body :last-serial) src (dosync (if (and @latest (> (:serial latest) last-serial)) (channel @latest) (take* 1 changelists)))]     (siphon (map* create-http-response src) response-channel)))