Created
February 1, 2012 09:57
-
-
Save bakkdoor/1716281 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/projects/fancy/dcell[master] $ rbx node1.rb | |
The Time is: Wed Feb 01 11:00:54 +0100 2012 | |
D, [2012-02-01T11:00:59.694176 #56469] DEBUG -- : ZMQ error: got read event without associated reader | |
I, [2012-02-01T11:00:59.695723 #56469] INFO -- : Connected to node2 | |
"0 hello world!" | |
"1 hello world!" | |
"2 hello world!" | |
"3 hello world!" | |
"4 hello world!" | |
"5 hello world!" | |
"6 hello world!" | |
"7 hello world!" | |
"8 hello world!" | |
"9 hello world!" | |
"0 hello world!" | |
"1 hello world!" | |
"2 hello world!" | |
"3 hello world!" | |
"4 hello world!" | |
"5 hello world!" | |
"6 hello world!" | |
"7 hello world!" | |
W, [2012-02-01T11:01:13.930082 #56469] WARN -- : Communication with node2 interrupted |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require("./time.rb") | |
require "rubygems" | |
require "dcell" | |
DCell.start :id => "node1", :addr => "tcp://127.0.0.1:4567" | |
class TimeServer | |
include Celluloid | |
def time | |
"The Time is: #{Time.now}" | |
end | |
def print(str) | |
puts str.inspect | |
end | |
end | |
TimeServer.supervise_as :time_server | |
puts Celluloid::Actor[:time_server].time | |
DCell::Global[:time_server] = Celluloid::Actor[:time_server] | |
loop do | |
sleep 2 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~/projects/fancy/dcell[master] $ rbx node2.rb | |
I, [2012-02-01T11:00:59.690299 #56475] INFO -- : Connected to node1 | |
~/projects/fancy/dcell[master] $ rbx node2.rb | |
I, [2012-02-01T11:01:03.927943 #56492] INFO -- : Connected to node1 | |
W, [2012-02-01T11:01:14.699166 #56492] WARN -- : Communication with node1 interrupted |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "./time.rb" | |
require "rubygems" | |
require "dcell" | |
DCell.start :id => "node2", :addr => "tcp://127.0.0.1:4568" | |
node = DCell::Node["node1"] | |
ts = node[:time_server] | |
10.times do |i| | |
ts.print "#{i} hello world!" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "time" | |
class Time | |
def self.new(year = nil, month=nil, day=nil, hour=nil, min=nil, sec=nil, utc_offset=nil) | |
return Time.now unless year | |
str = "%d-%d-%d %d:%d:%d %s" % [year.to_i, month.to_i, day.to_i, hour.to_i, min.to_i, sec.to_i, utc_offset] | |
return Time.parse(str) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment