Git Product home page Git Product logo

buddychat's Introduction

buddychat

Akka FSM demo of an actor-based chat system

You're participating in a chatroom. You run BuddyChat. BuddyChat creates the manager of the chat. This manager will create all the participants, both automated and human. The one human participant it creates represents you and will provide you an interface to make it speak in the chat room. Whenever a participant speaks, the message goes to the chat manager who forwards the message on to the other participants.

ChatManager is created as a finite state machine (Akka FSM). ChatManager and the chat participants (BuddyActor, the automated participant, and UserActor, the interface to a human) are Akka actors. When a participant sends a Speak message to ChatManager, it's recorded by ChatManager then forwarded to the other participants. The chat history is passed among transitions as state data.

There's also the ability to enable and disable the chat room, toggling between ChatOnline and ChatOffline states. Going offline clears the chat history. While offline, ChatManager ignores Speak messages.

The last major detail is the ConsoleActor, which is used to asynchronously retrieve keyboard input, freeing up the UserActor to respond to incoming Speak messages.

Sample output from BuddyChat:

Please type something for your buddies and press enter!
Or, you can type:
stop, to disable chat
start, to restart it
or done, to exit this program!
chicken
buddy1: chicken sounds bad!
buddy3: I don't care about chicken
buddy2: I don't care about chicken
the sky
buddy1: the sky sounds bad!
buddy3: the sky sounds bad!
buddy2: the sky sounds good!
done
Shutting down...

-- Begin server chat log --
user: chicken
buddy1: chicken sounds bad!
buddy3: I don't care about chicken
buddy2: I don't care about chicken
user: the sky
buddy1: the sky sounds bad!
buddy3: the sky sounds bad!
buddy2: the sky sounds good!
-- End server chat log --
[INFO] [06/30/2013 02:24:39.345] [default-akka.actor.default-dispatcher-7] [akka://default/user/manager] Chat shutting down

buddychat's People

Contributors

sdanzig avatar

Watchers

 avatar  avatar

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.