Giter Club home page Giter Club logo

lwes-erlang's Introduction

Light Weight Event System (LWES)

Click here for more information about lwes. For more information about using lwes from erlang read on.

Creating Events

There are 2 ways of creating events, the functional way

Event0 = lwes_event:new ("MyEvent"),
Event1 = lwes_event:set_uint16 (Event0, "MyUint16", 25),

or via records like

Event = #lwes_event {
          name = "MyEvent",
          attrs = [{uint16, "MyUint16", 25}]
        },

Emitting to a single channel

If you are using multicast, or only want to emit to a single channel you can open it as follows

{ok, Channel0} = lwes:open (emitter, {Ip, Port})
Channel1 = lwes:emit (Channel0, Event1).

Emit to several channels

If you aren't using multicast but would like to emit to several machines, or groups of machines you can with slightly different config,

% emit to 1 of a set in a round robin fashion
{ok, Channels0} = lwes:open (emitters, {1, [{Ip1,Port1},...{IpN,PortN}]})
Channels1 = lwes:emit (Channels0, Event1)
Channels2 = lwes:emit (Channels1, Event2)
...
lwes:close (ChannelsN)

% emit to 2 of a set in an m of n fashion (ie, emit to first 2 in list,
% then 2nd and 3rd, then 3rd and 4th, etc., wraps at end of list)
{ok, Channels0} = lwes:open (emitters, {2, [{Ip1,Port1},...{IpN,PortN}]})

Listening via callback

{ok, Channel} = lwes:open (listener, {Ip, Port})
lwes:listen (Channel, Fun, Type, Accum).

Fun is called for each event

Type is one of

rawcallback is given raw udp structure, use lwes_event:from_udp to turn into event
listcallback is given an #lwes_event record where the name is a binary, and the attributes is a proplist where keys are binaries, and values are either integers (for lwes int types), binaries (for lwes strings), true|false atoms (for lwes booleans), or 4-tuples (for lwes ip addresses)
taggedcallback is given an #lwes_event record where the name is a binary, and the attributes are 3-tuples with the first element the type of data, the second the key as a binary and the third the values as in the list format
dictcallback is given an #lwes_event record where the name is a binary, and the attributes are a dictionary with a binary key and value according to the type
jsonthis returns a proplist instead of an #lwes_event record. The valuse are mostly the same as list, but ip addresses are strings (as binary). This should means you can pass the returned value to mochijson2:encode (or other json encoders), and have the event as a json document

Closing channel

lwes:close (Channel)

lwes-erlang's People

Contributors

djnym avatar timrc-git avatar timwhalen avatar vimalearnest avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lwes-erlang's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.