[Erlang Study Notes] Erlang behaviour Summary

Source: Internet
Author: User

The Behaviour framework (gen_server, gen_fsm, gen_event, and supervisor) using Erlang saves a lot of unnecessary code when dealing with many situations, you can build a project by adding a custom logic to the framework.


Gen_server: Provides the processing of requests and callbacks between the client and the server.

Client -- request --> server -- Response --> Client

Specific description: gen_server in Erlang behaviour Summary



Gen_fsm: Provides event status conversion and action trigger processing.

 {State1 * event} ----> {Action, state2}

Statename (event, statedata)->

% Action here,

{Next_state, statename ', statedata '}.



Gen_event: event manager processes events. Custom event manager receives the event for custom processing.

Event_manager (event)->

% Deal with the event.

{OK }.


Here are some differences between gen_event and gen_fsm:

Gen_fsm refers to the conversion of an external State (custom State). A State changes because of an event. When an action is triggered, it enters the next state, which can be a loop.

Similar to the conversion of water and ice: the state of water is liquid, and a "cooling" event occurs. The water is converted to ice and the liquid is converted to solid state, solid ice encountered a "heated" event and turned back to liquid water.

Gen_event can be interpreted as one-way event processing. The event manager will process the event.



Supervisor: provides startup, stop, and monitoring operations for sub-processes. It can be said that it is an exception handling framework, but similar to the aspect, it can interfere with every process of the project (start or stop any sub-process ). If the sub-process needs to be restarted, the supervisor determines how to restart the sub-process based on the restart policy and the maximum restart frequency.



With these behaviour, it is not necessary to encapsulate components that release similar functions.

Based on Erlang behavoiur, it is easy to build highly feasible projects.


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.