Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implemented Server::OuterInboundRouting class for handling Box messages

  • Loading branch information...
commit 2978c21716ff77abb1f390c29082b3a287465723 1 parent d18641a
@krakatoa krakatoa authored
View
2  lib/cucub-server.rb
@@ -3,6 +3,8 @@
require 'ostruct'
require_relative './server/channel'
+require_relative './server/outer_inbound_routing'
+
require_relative './stats_collector'
require_relative './router'
require_relative './dispatcher'
View
1  lib/dispatcher.rb
@@ -40,6 +40,7 @@ def start(block=nil)
=end
@box = Cucub::Server::Channel.box
+ Cucub::Server::OuterInboundRouting.handle(@box)
####
=begin
View
31 lib/server/channel.rb
@@ -21,31 +21,6 @@ def box_start
@socket.bind("tcp://#{Cucub::Server.instance.address}:6441")
@socket.register
- # TODO Do this setting on Dispatcher ?
- # TODO Decouple into a Different handler: OuterInboundRouting
- @socket.on_receive { |msg|
- # Chequear por llamada async / sync
-
- # Async - returns job id
- #### Cucub::Queue.instance.push(msg)
-
- # TODO Sync - returns object return
- # Usar EM Defer
- #Cucub::LiveObject.pass(msg)
-
- message = Cucub::Message.parse(msg)
- puts "received@server msg to: #{message.header.to.class_name}"
- # TODO check why this class_name is in capitals and the configurations.classes are in downcase
- destination = Cucub::Dispatcher.instance.router.random_with_least_assignments(message.header.to.class_name.downcase, Cucub::Server.instance.stats_collector.vm_stats)
-
- # TODO Route messages according class_name and object_uuid
-
- Cucub::Server::Channel.inner_inbound.send_string("#{destination.klass}##{destination.uid} #{msg}")
- Cucub::Server.instance.stats_collector.sent_msg_to(destination.uid, destination.klass, message.uuid)
-
- @socket.send_string("Cucub::Reply ok!")
- }
-
@socket
end
@@ -124,6 +99,12 @@ def self.channels
channels
end
+ def on_receive(&block)
+ @socket.on_receive { |msg|
+ block.call(msg)
+ }
+ end
+
def send_string(msg)
@socket.send_string(msg)
end
View
31 lib/server/outer_inbound_routing.rb
@@ -0,0 +1,31 @@
+module Cucub
+ class Server
+ class OuterInboundRouting
+ def self.handle(socket)
+ socket.on_receive do |msg|
+ # Chequear por llamada async / sync
+
+ # Async - returns job id
+ #### Cucub::Queue.instance.push(msg)
+
+ # TODO Sync - returns object return
+ # Usar EM Defer
+ #Cucub::LiveObject.pass(msg)
+
+ message = Cucub::Message.parse(msg)
+ puts "received@server msg to: #{message.header.to.class_name}"
+ # TODO check why this class_name is in capitals and the configurations.classes are in downcase
+ destination = Cucub::Dispatcher.instance.router.random_with_least_assignments(message.header.to.class_name.downcase, Cucub::Server.instance.stats_collector.vm_stats)
+
+ # TODO Route messages according class_name and object_uuid
+
+ Cucub::Server::Channel.inner_inbound.send_string("#{destination.klass}##{destination.uid} #{msg}")
+ Cucub::Server.instance.stats_collector.sent_msg_to(destination.uid, destination.klass, message.uuid)
+
+ socket.send_string("Cucub::Reply ok!")
+ end
+
+ end
+ end
+ end
+end
View
1  lib/stats_collector.rb
@@ -40,7 +40,6 @@ def mark_done(uid, klass, msg_uuid)
puts "#{vm.klass} #{uid}: #{vm.assigned} assigned; #{vm.done} done"
@pending.select{|key, value| value.include?(msg_uuid)}.values[0].delete(msg_uuid)
- puts "pending_for: #{@pending}"
end
def vm_stats
Please sign in to comment.
Something went wrong with that request. Please try again.