What is Megaphone?

What is Megaphone?
The Megaphone project is about enhancing open source chat software. Specifically, the goal is to allow ejabberd to support 1,000,000 simultaneous users. See The Plan page for more details on how I plan to solve this problem. See the About this Blog page for more details on why I created this blog.

Wednesday, January 25, 2012

megaphone II: Client Interface

Previously...
  • I started planning the megaphone module.
  • I did some more planning for the megaphone module.
  • I created the main loop for the megaphone module.

The main loop is all well and good but how do messages actually get to the megaphone process?  When a client is asking for data, the function needs to block until some data is available.  ejabberd also expects a certain interface, like having a function called "recv" for the BOSH stuff to call.  Here is my first go at the function:


recv(ConnectionID) ->
    megaphone ! { get_data, self(), ConnectionID },
    receive
        { ok, Result } ->
            { ok, Result };


        { error, Reason } ->
            { error, Reason };


        { shutdown } ->
            { error, shutdown }
    end.

The function to allow clients to send data does not have to worry about blocking and is much simpler:

send(ConnectionID, Data) ->
    megaphone ! { send_data, ConnectionID, Data }.

The function that megaphon_receiver uses to hand data off to ejabberd is also simple:

receive_packet(ConnectionID, Data) ->
    megaphone_sender ! {send, ConnectionID, Data}.

So much for the interface methods, next time I will go into the implementation of the main_loop methods.

No comments:

Post a Comment