Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Started cucub-server project from splitting old cucub-object repositoty

  • Loading branch information...
commit a375f67694062200a0f7fc12bc364c8901087c76 1 parent fc67510
@krakatoa krakatoa authored
View
8 Gemfile
@@ -3,12 +3,16 @@ source "http://rubygems.org"
# Example:
# gem "activesupport", ">= 2.3.5"
+gem "thor"
+gem "servolux"
+gem "ma-zmq"
+
# Add dependencies to develop your gem here.
# Include everything needed to run rake, tests, features, etc.
group :development do
gem "shoulda", ">= 0"
gem "rdoc", "~> 3.12"
- gem "bundler", "~> 1.0.0"
+ gem "bundler", "~> 1.1.3"
gem "jeweler", "~> 1.8.4"
- gem "rcov", ">= 0"
+ gem "simplecov", ">= 0"
end
View
50 Gemfile.lock
@@ -0,0 +1,50 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activesupport (3.2.8)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ eventmachine (1.0.0.beta.4)
+ ffi (1.1.5)
+ ffi-rzmq (0.9.3)
+ ffi
+ git (1.2.5)
+ i18n (0.6.1)
+ jeweler (1.8.4)
+ bundler (~> 1.0)
+ git (>= 1.2.5)
+ rake
+ rdoc
+ json (1.7.5)
+ ma-zmq (0.0.2)
+ eventmachine (= 1.0.0.beta.4)
+ ffi-rzmq (= 0.9.3)
+ multi_json (1.3.6)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ servolux (0.10.0)
+ shoulda (3.1.1)
+ shoulda-context (~> 1.0)
+ shoulda-matchers (~> 1.2)
+ shoulda-context (1.0.0)
+ shoulda-matchers (1.3.0)
+ activesupport (>= 3.0.0)
+ simplecov (0.6.4)
+ multi_json (~> 1.0)
+ simplecov-html (~> 0.5.3)
+ simplecov-html (0.5.3)
+ thor (0.15.2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ bundler (~> 1.1.3)
+ jeweler (~> 1.8.4)
+ ma-zmq
+ rdoc (~> 3.12)
+ servolux
+ shoulda
+ simplecov
+ thor
View
14 Rakefile
@@ -17,10 +17,12 @@ Jeweler::Tasks.new do |gem|
gem.name = "cucub-server"
gem.homepage = "http://github.com/krakatoa/cucub-server"
gem.license = "MIT"
- gem.summary = %Q{TODO: one-line summary of your gem}
- gem.description = %Q{TODO: longer description of your gem}
+ gem.summary = %Q{one-line summary of your gem}
+ gem.description = %Q{longer description of your gem}
gem.email = "krakatoa1987@gmail.com"
gem.authors = ["Fernando Alonso"]
+ gem.executables = ["cucub-server"]
+ gem.require_paths = ["lib"]
# dependencies defined in Gemfile
end
Jeweler::RubygemsDotOrgTasks.new
@@ -32,14 +34,6 @@ Rake::TestTask.new(:test) do |test|
test.verbose = true
end
-require 'rcov/rcovtask'
-Rcov::RcovTask.new do |test|
- test.libs << 'test'
- test.pattern = 'test/**/test_*.rb'
- test.verbose = true
- test.rcov_opts << '--exclude "gems/*"'
-end
-
task :default => :test
require 'rdoc/task'
View
1  VERSION
@@ -0,0 +1 @@
+0.0.1
View
6 bin/cucub-server
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby
+
+STDERR.sync = STDOUT.sync = true
+require File.expand_path('../../lib/cli.rb', __FILE__)
+
+Cucub::CLI.start
View
66 cucub-server.gemspec
@@ -0,0 +1,66 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = "cucub-server"
+ s.version = "0.0.1"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Fernando Alonso"]
+ s.date = "2012-09-02"
+ s.description = "longer description of your gem"
+ s.email = "krakatoa1987@gmail.com"
+ s.executables = ["cucub-server"]
+ s.extra_rdoc_files = [
+ "LICENSE.txt",
+ "README.rdoc"
+ ]
+ s.files = [
+ ".document",
+ "Gemfile",
+ "LICENSE.txt",
+ "README.rdoc",
+ "Rakefile",
+ "lib/cucub-server.rb",
+ "test/helper.rb",
+ "test/test_cucub-server.rb"
+ ]
+ s.homepage = "http://github.com/krakatoa/cucub-server"
+ s.licenses = ["MIT"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = "1.8.24"
+ s.summary = "one-line summary of your gem"
+
+ if s.respond_to? :specification_version then
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency(%q<servolux>, [">= 0"])
+ s.add_runtime_dependency(%q<ma-zmq>, [">= 0"])
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
+ s.add_development_dependency(%q<bundler>, ["~> 1.1.3"])
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
+ else
+ s.add_dependency(%q<servolux>, [">= 0"])
+ s.add_dependency(%q<ma-zmq>, [">= 0"])
+ s.add_dependency(%q<shoulda>, [">= 0"])
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
+ s.add_dependency(%q<bundler>, ["~> 1.1.3"])
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
+ s.add_dependency(%q<simplecov>, [">= 0"])
+ end
+ else
+ s.add_dependency(%q<servolux>, [">= 0"])
+ s.add_dependency(%q<ma-zmq>, [">= 0"])
+ s.add_dependency(%q<shoulda>, [">= 0"])
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
+ s.add_dependency(%q<bundler>, ["~> 1.1.3"])
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
+ s.add_dependency(%q<simplecov>, [">= 0"])
+ end
+end
+
View
120 lib/channel.rb
@@ -0,0 +1,120 @@
+module Cucub
+ module Channel
+=begin
+ def self.initialize
+ Cucub::Channel.local_push
+ end
+=end
+
+ def self.reply
+ # Es usado dentro del Reactor
+ return @reply if @reply.is_a? MaZMQ::Reply
+ @reply = MaZMQ::Reply.new
+ @reply.bind(:tcp, Cucub.address, 6441)
+
+ @reply.on_read { |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)
+
+ @reply.send_string("Cucub::Reply ok!")
+ }
+
+ @reply
+ end
+
+ def self.pull
+ # Es usado dentro del Reactor
+ return @pull if @pull.is_a? MaZMQ::Pull
+ @pull = MaZMQ::Pull.new
+ @pull.bind(:tcp, Cucub.address, 6442)
+
+####
+=begin
+ @pull.on_read { |msg|
+ Cucub::Queue.instance.push(msg)
+ }
+=end
+
+ @pull
+ end
+
+####
+=begin
+ def self.local_push
+ return @local_push if @local_push.is_a? Cucub::LiveProxy
+ @local_push = Cucub::LiveProxy.new
+ @local_push.channel = :local_push
+ @local_push.connect(Cucub.address)
+ @local_push.engage
+
+ @local_push
+ end
+=end
+
+#### # Reemplazar por broadcast para intercomunicar status updates !
+=begin
+ def self.ipc_set
+ # Es usado por un LiveProxy (dentro del Worker), para actualizar la info de conexion dentro del Reactor
+ return @ipc_set if @ipc_set.is_a? MaZMQ::Request
+ @ipc_set = MaZMQ::Request.new
+ @ipc_set.connect(:ipc, '/tmp/cucub.sock')
+
+ @ipc_set
+ end
+
+ def self.ipc_get
+ # Es usado dentro del Reactor
+
+ return @ipc_get if @ipc_get.is_a? MaZMQ::Reply
+ @ipc_get = MaZMQ::Reply.new
+ @ipc_get.bind(:ipc, '/tmp/cucub.sock')
+
+ @ipc_get.on_read { |msg|
+ msg = JSON.parse(msg)
+ proxy = Cucub::LiveProxy.select(msg['oid'])
+ proxy.send(msg['action'], *msg['params'])
+ @ipc_get.send_string 'Cucub ipc ok!'
+ }
+
+ @ipc_get
+ end
+=end
+
+ def self.shutdown!
+ if @reply
+ puts 'Closing reply channel.'
+ @reply.close
+ end
+
+ if @pull
+ puts 'Closing pull channel.'
+ @pull.close
+ end
+
+=begin
+ if @local_push
+ puts 'Closing local_push channel.'
+ @local_push.shutdown!
+ end
+
+ if @ipc_get
+ puts 'Closing ipc_get channel.'
+ @ipc_get.close
+ end
+
+ if @ipc_set
+ puts 'Closing ipc_set channel.'
+ @ipc_set.close
+ end
+=end
+
+ MaZMQ.terminate
+ end
+ end
+end
View
52 lib/cli.rb
@@ -0,0 +1,52 @@
+require 'thor'
+require 'thor/actions'
+
+require 'server'
+require 'object'
+
+# check reference
+# https://github.com/carlhuda/bundler/blob/master/lib/bundler/cli.rb
+
+module Cucub
+ class CLI < Thor
+ include Thor::Actions
+
+ #default_task :start
+
+ desc "start", "start cucub as a service"
+ method_option :host, :aliases => '-h', :default => '127.0.0.1', :type => :string
+ def start(boot_file)
+ opts = options.dup
+
+ # puts opts.inspect
+ # puts gem
+
+ # encapsular esto en una clase de Cucub::Server
+ # mover esto a una clase de cucub:server
+ logger = Logger.new($stderr)
+ logger.level = Logger::DEBUG
+
+ # encapsular esto en una clase de Cucub::Server
+ pid_file = File.expand_path('cucub.pid')
+
+ # before server
+ #driver = Driver.instance
+ #core = Antir::Core.instance
+ #core.oid = 1
+ server = Cucub.server('Cucub', :logger => logger, :pid_file => pid_file)
+
+ boot_file = "./#{boot_file}" unless boot_file.match(/^[\/.]/)
+ require boot_file
+
+ # after server
+
+ server.host = opts['host']
+
+ server.startup
+ end
+
+ def help(cli = nil)
+ puts "ping"
+ end
+ end
+end
View
3  lib/cucub-server.rb
@@ -0,0 +1,3 @@
+require 'server'
+require 'channel'
+require 'dispatcher'
View
75 lib/dispatcher.rb
@@ -0,0 +1,75 @@
+require 'singleton'
+require 'ma-zmq'
+
+module Cucub
+ class Dispatcher
+ include Singleton
+
+ def initialize
+ #@load_balancer = nil
+ end
+
+ def start(block=nil)
+ block ||= Proc.new {}
+ EM.epoll
+ EM.run do
+ #### @proxy_worker = Cucub::ProxyWorker::connection
+
+ ## TODO if list.size == 1 => oid unico
+
+####
+=begin
+ Cucub::LiveObject.list.each do |obj|
+ case obj.class.channel
+ when :reply
+ @reply = Cucub::Channel.reply
+ when :pull
+ @pull = Cucub::Channel.pull
+ when :subscribe
+ puts '?'
+ end
+ end
+=end
+ @ipc_get = Cucub::Channel.ipc_get
+
+####
+=begin
+ Cucub::LiveProxy.list.each do |proxy|
+ proxy.engage
+ end
+=end
+
+####
+=begin
+ @proxy_worker.each_job { |job|
+ if Cucub::LiveProxy.list.size > 0
+ msg = job.body
+ oid, channel = Cucub::ProxyWorker.read_oid(msg)
+ if channel == nil
+ proxy = Cucub::LiveProxy.select(oid)
+ else
+ proxy = Cucub::Channel.local_push
+ end
+
+ if proxy
+ if proxy.do(msg)
+ job.delete
+ else
+ job.release
+ end
+ end
+ end
+ }
+=end
+
+ block.call
+ end
+ end
+
+ def stop
+ #### Cucub::LiveProxy.shutdown!
+ Cucub::Channel.shutdown!
+ EM.stop
+ end
+ end
+end
View
60 lib/object.rb
@@ -0,0 +1,60 @@
+#require 'em-jack'
+#require 'json'
+
+require 'channel'
+require 'dispatcher'
+#require 'queue'
+#require 'live_object'
+#require 'live_proxy'
+
+#require 'worker'
+#require 'proxy_queue'
+#require 'proxy_worker'
+
+module Cucub
+ @@dispatcher = Cucub::Dispatcher.instance
+#####
+=begin
+ @@in_worker = false
+=end
+
+ def self.start!(address, block=Proc.new({}))
+ @@address = address
+ Cucub::Channel.initialize
+
+ # refactor !
+ # separar este codigo en init y start (?)
+ # mover codigo a cucub-server (?)
+#####
+=begin
+ workers_pool = Servolux::Prefork.new(:module => Cucub::Worker)
+ workers_pool.start 1
+ trap("INT") {
+ workers_pool.signal "INT"
+ workers_pool.reap
+ Cucub.shutdown!
+ exit
+ }
+=end
+ @@dispatcher.start(block)
+ end
+
+ def self.shutdown!
+ @@dispatcher.stop
+ end
+
+ def self.address
+ @@address
+ end
+
+#####
+=begin
+ def self.in_worker
+ @@in_worker = true
+ end
+
+ def self.in_worker?
+ @@in_worker
+ end
+=end
+end
View
48 lib/server.rb
@@ -0,0 +1,48 @@
+#require 'singleton'
+
+require 'servolux'
+require 'logger'
+
+module Cucub
+ #def self.initialize(&block)
+ # @@server.initialize_block = block
+ #end
+
+ def self.run(&block)
+ @@server.run_block = block
+ end
+
+ @@server = nil
+ def self.server(*args)
+ return @@server if @@server.is_a? Cucub::Server
+ @@server = Cucub::Server.new(*args)
+ @@server
+ end
+
+ class Server < Servolux::Server
+ attr_accessor :host
+
+ def run_block=(block)
+ @run_block = block
+ end
+
+ def run
+ Cucub.init
+ Cucub.start!(@host, @run_block)
+ Process.waitall
+ end
+
+ def prefork
+ workers_pool = Servolux::Pre
+ end
+
+ def before_stopping
+ Cucub.shutdown!
+ end
+ end
+end
+
+# daemon = Servolux::Daemon.new(:server => server)
+# daemon.startup
+# daemon.shutdown
+#Cucub.start!('10.0.0.4')
Please sign in to comment.
Something went wrong with that request. Please try again.