Permalink
Browse files

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

  • Loading branch information...
krakatoa committed Sep 2, 2012
1 parent fc67510 commit a375f67694062200a0f7fc12bc364c8901087c76
Showing with 491 additions and 12 deletions.
  1. +6 −2 Gemfile
  2. +50 −0 Gemfile.lock
  3. +4 −10 Rakefile
  4. +1 −0 VERSION
  5. +6 −0 bin/cucub-server
  6. +66 −0 cucub-server.gemspec
  7. +120 −0 lib/channel.rb
  8. +52 −0 lib/cli.rb
  9. +3 −0 lib/cucub-server.rb
  10. +75 −0 lib/dispatcher.rb
  11. +60 −0 lib/object.rb
  12. +48 −0 lib/server.rb
View
@@ -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
@@ -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
@@ -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
@@ -0,0 +1 @@
+0.0.1
View
@@ -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
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,3 @@
+require 'server'
+require 'channel'
+require 'dispatcher'
Oops, something went wrong.

0 comments on commit a375f67

Please sign in to comment.