Another Erlang XML Project, Part 2 - Converted to gen_server
Joe Williams - - January 07, 2009A while back I wrote some code in Erlang to grab your public Amazon wishlist based off of your email address. Today I had the urge to rewrite it using OTP, specifically gen_server. The code is up on github. Switching it over to use gen_server is fairly trivial since the sequential code is already written. Basically all that needs to be done is to setup the handle_call method to send any email addresses over to the get_wishlist method for retrieval. Here’s what the handle_call looks like:
handle_call(Email_addr, _From, State) ->
%Reply back with the result from get_wishlist
Reply = get_wishlist(Email_addr),
{reply, Reply, State}.
The rest of the functions look pretty much as they did before so I won’t put them here. One other change I made was to start_link to have it also run inets:start() so we can make the http requests in the other functions.
Here’s how the thing works:
[zeusfaber@der-dieb ebin]$ erl
Erlang (BEAM) emulator version 5.6.5 [source] [64-bit] [smp:2] [async-threads:0] [hipe] [kernel-poll:false]Eshell V5.6.5 (abort with ^G)
1> c(’../src/amazon_wishlist_otp.erl’).
{ok,amazon_wishlist_otp}
2> amazon_wishlist_otp:start_link().
ok
3> gen_server:call(amazon_wishlist_otp, “SOMEADDR@SOMEPLACE.com”).
[[“Algorithms on Strings, Trees and Sequences: Computer Science and Computational Biology”,
“Algorithms: Sequential, Parallel, and Distributed”,
“Starting Forth: An Introduction to the Forth Language and Operating System for Beginners and Professionals (Prentice-Hall Software Series)”,
“Biobazaar: The Open Source Revolution and Biotechnology”,
“Nmap Network Scanning: The Official Nmap Project Guide to Network Discovery and Security Scanning”,
“American Nerd: The Story of My People”,
“FreeDarko presents The Macrophenomenal Pro Basketball Almanac: Styles, Stats, and Stars in Today’s Game”,
“CP Technologie USB TO SERIAL ADAPTER ( CP-US-03 )”,
“Made to Stick: Why Some Ideas Survive and Others Die”]]
Categories: Blogs Joe Williams
Comments
Nice job Joe. I just tested this and it works as expected. I’m emailing it to a co-worker now as an example of how to use xmerl in the real world.
-Andrew
Posted by AndrewStone on 13 Jan 2009 at 05:58Give Thanks you therefore much for the web logs enjoy! Observed to be a part of overmuch a talented radical of wedding professionals. Fantastic fashion to beginning off the another year! Thank you!
montreal erotic massage
Amazing posting because it shows that on that point is fantastic separate of residential area spirit out in that respect.
stubby holders
Add comment
Erlang on Twitter
» HornedKavu (Max Riveiro): RT @shwars: Вчера в докладе career.ru на #itedu были озвучены новые востреб.профессии на IT-рынке: Haskell-, Lisp- и Erlang-программист!
» phyrexianengine (Vasily K.): RT @shwars: Вчера в докладе career.ru на #itedu были озвучены новые востреб.профессии на IT-рынке: Haskell-, Lisp- и Erlang-программист!
» Erlang_ABNIC (Erlangga .A): @cjerikho829 selamat shooting ♈o kak.. Nitip salam buat kak @Bellaudya829.. ☺ Semangat (งˆヮˆ)ง
» dessyrosalia (♡pesek mancung♥ ): Erlang ke rumahku donk kangen nih
» si_erlang (Erlangga Adhitya): 75% dalane jahanam
» GeekDani (Dani Kim): @charsyam 그렇군용. :-) 여긴 서늘한데. 크크. Erlang Meetup 준비는 잘 하시나요. ㅋㅋ
» syahlafatimahA (LalaTik(ʃ⌣ƪ) ): Waaa?! Si erlang suka cherrybelle(?) wkwkwkwk ngakak aih xD
» yosukehara (Yosuke Hara): I’ll be a simple test for benchmarking JSX and Jiffy together. #erlang
» Debbyvheumen (Debby van Heumen): @elisaaa15 @kleingeld_ haha okee succes :) blijven jullie erlang
» ovatsus (Gustavo Guerra): RT @martintrojer: Just *blogged “Distributed Actors in Clojure” on http://t.co/WcKBpNBR #Clojure #Akka #Erlang #in
Statistics
Number of aggregated posts: 10498
Number of comments: 2115
Most recent article: May 15, 2012
Latest comments
» cheap soccer jerseys on Memory Models in Erlang vs Java: Nice discussion here,you are doing a great job. i was looking for this information. i found it on your page…
» mandesejohn on Couchbase Meetup at new HQ: Thanks for sharing experience. It should be really a great post. It should be knowledgeable and informative. Keep it up. flower delivery columbus ohio
» vermaseo on Scale means Skills: I’m surprised people are still commenting about this. George has been moved on to bigger and better things with the president for awhile now.ledikanten