Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Ara is a tiny class that’s allow you to use actors in Ruby
Ruby Scala Erlang
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
lib
test
.document
.gitignore
Gemfile
Gemfile.lock
LICENSE.txt
README.rdoc
Rakefile
VERSION
ara.gemspec

README.rdoc

ara

    \\
    (o>
    //\
____V_/\____
    //
   //

Ara is a tiny class that's allow you to use actors in Ruby

Documentation : rubydoc.info/github/glejeune/ara/master/frames

Why “ara”

Because of akka and my two parakeets ;)

Synopsys

require 'ara'

# Define an actor
class MyActor < Actor
  def receive(message)
    puts "MyActor receive message : #{message}"
    sleep rand(10)
    reply "Thanks @ #{Time.now}!"
  end

  private
  def pre_start
    # ...
  end

  def post_stop
    # ...
  end
end

# This method will receive the actor' replies after sending it an asynchronous message
def actor_response(r)
  puts "Actor reply : #{r}"
end

# Initialize and start the actor
myActor = Actor.actor_of(MyActor).start

# Send a simple message -- We do not expect any response
myActor | "Bonjour !"

# Send a synchronous message -- We wait for the response
response = myActor << "Hola !"

# Send an asynchronous message -- We don't wait for the response
myActor < "Hello !"

# main loop ;)
12.times do |_|
  puts "I'm the main... And I'm running"
  sleep 1
end

Create remote actor

Server :

# Server
require 'ara'

class SimpleMessage < Actor
  def receive(message)
    reply "@ #{Time.now} : Hello #{message}"
  end
end

Ara::Remote.server("localhost", 9292).register("simple_actor", Actors.actor_of(SimpleMessage)).start

Client :

# Client
require 'ara'

actor = Actors.actor_for("simple_actor", "localhost", 9292)
puts actor << "World"

Use scheduler

require 'ara'

class MySimpleActor < SimpleActor
  def receive( message )
    puts "Actor #{self} receive message : #{message}"
  end
end

my_actor = Actors.actor_of(MySimpleActor).start

my_scheduler = Scheduler.schedule(my_actor, "Hello World! (every 1 second)", 1, 1, Scheduler::SECOND)

sleep 10

my_scheduler.shutdown
puts "-- Scheduler has been shutdown! We wait 5 second to be sure ;)"

sleep 5

my_actor.stop

Changelog

0.0.3

  • Add pre_start and post_stop

  • Change logger

  • BindingOfCaller correction

  • Add Routing

0.0.2

  • Add Scheduler support

  • Add Remote actor support

0.0.1

  • Initial version

Contributing to ara

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet

  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it

  • Fork the project

  • Start a feature/bugfix branch

  • Commit and push until you are happy with your contribution

  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.

  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Copyright

Copyright © 2011 Gregoire Lejeune. See LICENSE.txt for further details.

binding_of_caller.rb

binding_of_caller.rb is part of the binding_of_caller project by James M. Lawrence

Copyright © 2011 James M. Lawrence. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.