Posts

Showing posts with the label erlang

Process Communication in Erlang

Image
Hi there! In erlang, no process talks directly to each other. You can think of it as a process in erlang has locked itself up in a room. And it is very workaholic. It loves doing its own work. What about Concurrency and inter process communication? Your one process can mail other process with required details and ask it to work on the data. (Erlang processes are workaholic). You just need the address of the process (the Process ID or the PID for this). Lets take a very simple example, where in the erlang process prints the sound of the animal. ==================== -module(animal_sound). -compile(export_all). sound()-> receive dog -> io:format("bhuw bhuw"); cat -> io:format("Meow"); _ -> io:format("Whisperings!") end. ==================== Save as animal_sound.erl, compile and run. Note : compile(export_all) can be used when you want all your functions to be visible to the outside world. Else you can export onl...

PLSQL Procedure in Erlang

Image
Functions/Procedures from Erlang: Prepare your DB: drop table employee; CREATE TABLE EMPLOYEE ( "NR" NUMBER, "FIRSTNAME" VARCHAR2(20), "LASTNAME" VARCHAR2(20), "GENDER" CHAR(1), "EXPERIENCE" NUMBER ) ; ALTER TABLE EMPLOYEE ADD PRIMARY KEY ("NR"); DROP SEQUENCE EMPLOYEE_SEQ; CREATE SEQUENCE EMPLOYEE_SEQ INCREMENT BY 1 START WITH 1 MAXVALUE 9999999999999999999999999999 MINVALUE 1 CACHE 20; create or replace TRIGGER EMPLOYEE_SEQ_TRG BEFORE INSERT ON EMPLOYEE FOR EACH ROW BEGIN <<COLUMN_SEQUENCES>> BEGIN IF INSERTING AND :NEW.NR IS NULL THEN SELECT EMPLOYEE_SEQ.NEXTVAL INTO :NEW.NR FROM SYS.DUAL; END IF; END COLUMN_SEQUENCES; END; insert into EMPLOYEE(FIRSTNAME, LASTNAME, GENDER, EXPERIENCE) values ('Richa','Vaidya','F',4); select * from EMPLOYEE; and check the output. Lets create a procedure for inserting: ...

Erlang OTP

Joe Erlang had fault tolerance in his mind when he designed and implemented Erlang. He was the chief architect of the project which built Erlang/OTP. Features of Erlang: Concurrent Scalable Soft-Real Time Distributed Fault Tolerant Where all is Erlang used? Telecom Banking E-Commerce Instant Messaging Computer Telephony What is OTP? OTP is set of Erlang libraries and design principles providing middle-ware to develop these systems. It includes its own distributed database applications to interface towards other languages debugging release handling tools Ericsson managed to get the nine 9's reliability in one of its product (99.9999999% reliability). Erlang is based on the following ideas: Share Nothing Pure message passing Crash detection. Let it crash and recover principle Erlang processes are very lightweight. Erlang can have hundreds of thousands of processes. Garbage collection is also good. It can have thousands of independent heaps and all are...

Writing your own ejabberd Module

Coming soon: What is ejabberd? What is erlang? Installation details. I will start with writing the ejabberd module first. Once you have done all the installations: sudo make sudo make install sudo ejabberdctl start sudo ejabberdctl stop You can check the status using: sudo ejabberdctl status You can locate logs at: (With default installation) /var/log/ejabberd All config related changes will be mainly done at: /etc/ejabberd/ejabberd.yml You will need a basic understanding of erlang. You can take a short crash course at: http://www.erlang.org/course/course.html This is a good reference. Go to your ejabberd-15.07/src directory. This is where you will write the hook for your ejabberd server. Create a file, say mod_changeBody.erl. Your module name and file name should be same. Add the following basic contents into your erl file: -module(mod_changeBody). -behavior(gen_mod). -include("ejabberd.hrl"). -include("logger.hrl"). -expo...