-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/update-celuloid-0.17
- Loading branch information
Showing
11 changed files
with
107 additions
and
165 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,72 @@ | ||
# <<<<<<< HEAD | ||
# require 'bundler/setup' | ||
# require 'celluloid_pubsub' | ||
# require 'logger' | ||
# | ||
# debug_enabled = ENV['DEBUG'].present? && ENV['DEBUG'].to_s == 'true' | ||
# | ||
# if debug_enabled == true | ||
# log_file_path = File.join(File.expand_path(File.dirname(__FILE__)), 'log', 'celluloid_pubsub.log') | ||
# puts log_file_path | ||
# puts CelluloidPubsub::BaseActor.celluloid_version | ||
# puts CelluloidPubsub::BaseActor.version_less_than_sixten? | ||
# FileUtils.rm(log_file_path) if File.exist?(log_file_path) | ||
# FileUtils.mkdir_p(File.dirname(log_file_path)) | ||
# log_file = File.open(log_file_path, 'w') | ||
# log_file.sync = true | ||
# $CELLULOID_DEBUG = true | ||
# Celluloid.logger = ::Logger.new(log_file_path) | ||
# end | ||
# | ||
# # actor that subscribes to a channel | ||
# class Subscriber < CelluloidPubsub::BaseActor | ||
# | ||
# def initialize(options = {}) | ||
# @client = CelluloidPubsub::Client.connect({ actor: Actor.current, channel: 'test_channel' }.merge(options)) | ||
# end | ||
# | ||
# def on_message(message) | ||
# if @client.succesfull_subscription?(message) | ||
# puts "subscriber got successful subscription #{message.inspect}" | ||
# @client.publish('test_channel2', 'data' => ' subscriber got successfull subscription') # the message needs to be a Hash | ||
# else | ||
# puts "subscriber got message #{message.inspect}" | ||
# @client.unsubscribe('test_channel') | ||
# end | ||
# end | ||
# | ||
# def on_close(code, reason) | ||
# puts "websocket connection closed: #{code.inspect}, #{reason.inspect}" | ||
# terminate | ||
# end | ||
# end | ||
# | ||
# # actor that publishes a message in a channel | ||
# class Publisher < CelluloidPubsub::BaseActor | ||
# | ||
# def initialize(options = {}) | ||
# @client = CelluloidPubsub::Client.connect({ actor: Actor.current, channel: 'test_channel2' }.merge(options)) | ||
# @client.publish('test_channel', 'data' => 'my_message') # the message needs to be a Hash | ||
# end | ||
# | ||
# def on_message(message) | ||
# puts " publisher got #{message.inspect}" | ||
# @client.unsubscribe('test_channel2') | ||
# end | ||
# | ||
# def on_close(code, reason) | ||
# puts "websocket connection closed: #{code.inspect}, #{reason.inspect}" | ||
# terminate | ||
# end | ||
# end | ||
# | ||
# CelluloidPubsub::BaseActor.setup_actor_supervision(CelluloidPubsub::WebServer, actor_name: :web_server, args: {enable_debug: debug_enabled }) | ||
# CelluloidPubsub::BaseActor.setup_actor_supervision(Subscriber, actor_name: :subscriber, args: {enable_debug: debug_enabled }) | ||
# CelluloidPubsub::BaseActor.setup_actor_supervision(Publisher, actor_name: :publisher, args: {enable_debug: debug_enabled }) | ||
# | ||
# sleep | ||
# ======= | ||
ENV['USE_REDIS'] = 'false' | ||
require_relative './shared_classes' | ||
require 'bundler/setup' | ||
require 'celluloid_pubsub' | ||
require 'logger' | ||
|
||
debug_enabled = ENV['DEBUG'].present? && ENV['DEBUG'].to_s == 'true' | ||
log_file_path = File.join(File.expand_path(File.dirname(__FILE__)), 'log', 'celluloid_pubsub.log') | ||
|
||
# actor that subscribes to a channel | ||
class FirstActor | ||
include Celluloid | ||
|
||
def initialize(options = {}) | ||
@client = CelluloidPubsub::Client.new({ actor: Actor.current, channel: 'test_channel' }.merge(options)) | ||
end | ||
|
||
def on_message(message) | ||
if @client.succesfull_subscription?(message) | ||
puts "subscriber got successful subscription #{message.inspect}" | ||
@client.publish('test_channel2', 'data' => ' subscriber got successfull subscription') # the message needs to be a Hash | ||
else | ||
puts "subscriber got message #{message.inspect}" | ||
end | ||
end | ||
|
||
def on_close(code, reason) | ||
puts "websocket connection closed: #{code.inspect}, #{reason.inspect}" | ||
terminate | ||
end | ||
|
||
|
||
end | ||
|
||
# actor that publishes a message in a channel | ||
class SecondActor | ||
include Celluloid | ||
|
||
def initialize(options = {}) | ||
@client = CelluloidPubsub::Client.new({ actor: Actor.current, channel: 'test_channel2' }.merge(options)) | ||
end | ||
|
||
def on_message(message) | ||
if @client.succesfull_subscription?(message) | ||
puts "publisher got successful subscription #{message.inspect}" | ||
@client.publish('test_channel', 'data' => ' my_message') # the message needs to be a Hash | ||
else | ||
puts "publisher got message #{message.inspect}" | ||
end | ||
end | ||
|
||
def on_close(code, reason) | ||
puts "websocket connection closed: #{code.inspect}, #{reason.inspect}" | ||
terminate | ||
end | ||
|
||
end | ||
|
||
|
||
# please don't use the BaseActor class to supervise actors. This is subject to change . This class is used only to test backward compatibility. | ||
# For more information on how to supervise actors please see Celluloid wiki. | ||
CelluloidPubsub::BaseActor.setup_actor_supervision(CelluloidPubsub::WebServer, actor_name: :web_server, args: {enable_debug: debug_enabled, adapter: nil,log_file_path: log_file_path }) | ||
CelluloidPubsub::BaseActor.setup_actor_supervision(FirstActor, actor_name: :first_actor, args: {enable_debug: debug_enabled }) | ||
CelluloidPubsub::BaseActor.setup_actor_supervision(SecondActor, actor_name: :second_actor, args: {enable_debug: debug_enabled }) | ||
|
||
signal_received = false | ||
|
||
Signal.trap('INT') do | ||
puts "\nAn interrupt signal has been triggered!" | ||
signal_received = true | ||
end | ||
|
||
puts 'Exited succesfully! =)' | ||
sleep 0.1 until signal_received |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require 'reel/spy' | ||
Reel::Spy::Colors.class_eval do | ||
alias_method :original_colorize, :colorize | ||
|
||
def colorize(n, str) | ||
force_utf8_encoding(str) | ||
end | ||
|
||
# Returns utf8 encoding of the msg | ||
# @param [String] msg | ||
# @return [String] ReturnsReturns utf8 encoding of the msg | ||
def force_utf8_encoding(msg) | ||
msg.respond_to?(:force_encoding) && msg.encoding.name != 'UTF-8' ? msg.force_encoding('UTF-8') : msg | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
This file contains 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