17.01.2015 Views

Erlang and OTP in Action.pdf - Synrc

Erlang and OTP in Action.pdf - Synrc

Erlang and OTP in Action.pdf - Synrc

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

287<br />

This function pattern matches on the <strong>in</strong>itial l<strong>in</strong>e of the HTTP message <strong>in</strong> order to figure<br />

out what operation was performed <strong>and</strong> to capture the request URI <strong>in</strong>formation. It then<br />

performs the appropriate simple_cache function <strong>and</strong> creates a response message.<br />

We have now implemented all of the protocols we mentioned <strong>in</strong> the first part of this<br />

chapter. Our text <strong>in</strong>terface does not give us much freedom with regard to what we can store<br />

<strong>in</strong> the cache. It is pretty limited, which is f<strong>in</strong>e for stor<strong>in</strong>g certa<strong>in</strong> types of data. It has the<br />

benefit that it is pretty easy to implement <strong>and</strong> use. Our second protocol, the REST based<br />

protocol, puts the full power of HTTP at our disposal for transport<strong>in</strong>g data <strong>in</strong>to <strong>and</strong> out of our<br />

cache.<br />

11.3 – Summary<br />

The simple cache is now capable of talk<strong>in</strong>g with external clients through two different<br />

protocols, our custom text based protocol <strong>and</strong> the more structured RESTful <strong>in</strong>terface. Along<br />

the way we learned a very important technique/pattern for creat<strong>in</strong>g a concurrent TCP server,<br />

enough HTTP to be dangerous, <strong>and</strong> we rounded out our coverage of behaviors with the<br />

gen_fsm. This work has made it possible for the simple cache to be used <strong>in</strong> production<br />

environments outside of an <strong>Erlang</strong> shop which is certa<strong>in</strong>ly useful <strong>in</strong> today’s “right tool for the<br />

right job” multi-language <strong>and</strong> multi-platform production environments. In the next chapter,<br />

we will cover how to get <strong>Erlang</strong> to <strong>in</strong>teract directly with other languages like, C, Java to give<br />

you the skills for even tighter multi-language communication.<br />

©Mann<strong>in</strong>g Publications Co. Please post comments or corrections to the Author Onl<strong>in</strong>e forum:<br />

http://www.mann<strong>in</strong>g-s<strong>and</strong>box.com/forum.jspaforumID=454

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!