Erlang's Gen_server Chapter

Source: Internet
Author: User

Erlang provides us with a ready-made implementation of such a server, which is gen_server, without having to write the server program on its own.

Here are a few things to do:

1. Determine the name of our callback module

2. Writing interface functions

3. Implementation of six callback methods

That means we just have to focus on the implementation of the callback module OK.

1:-module (XXXX) define module name

2: An interface function, a function that can be called.

Here you can define all the required methods as portals to function calls.

such as the common Start (), Stop (), and so on. Their role is to invoke Gen_server to complete the specified function.

3: Implement the callback function, altogether need to implement six.

Init ()/1----This method is called by the server when we call Gen_server:start_link

HANDLE_CALL/3----This method is called by the server when we call Gen_server:call

HANDLE_CAST/2----This method is called by the server when we call Gen_server:cast

HANDLE_INFO/2----Handle native messages sent to the server from outside, such as a pass-through PID! Message sent over

TERMINATE/2----method that is called when the server is terminated

CODE_CHANGE/2----Code hot-swap, function called when software upgrade code is replaced

Erlang's Gen_server Chapter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.