ratonga 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ratonga.gemspec
4
+ gemspec
data/README ADDED
File without changes
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,49 @@
1
+ require 'drb'
2
+
3
+ module DRb
4
+ class DRbServer
5
+ alias :stop_service_orig :stop_service
6
+
7
+ def stop_service
8
+ stop_service_orig
9
+ @grp.list.each {|t| t.raise Interrupt if t.status.eql? 'sleep'}
10
+ end
11
+
12
+ def main_loop
13
+ Thread.start(@protocol.accept) do |client|
14
+ @grp.add Thread.current
15
+ Thread.current['DRb'] = { 'client' => client ,
16
+ 'server' => self }
17
+ DRb.mutex.synchronize do
18
+ client_uri = client.uri
19
+ @exported_uri << client_uri unless @exported_uri.include?(client_uri)
20
+ end
21
+ loop do
22
+ begin
23
+ succ = false
24
+ invoke_method = InvokeMethod.new(self, client)
25
+ succ, result = invoke_method.perform
26
+ if !succ && verbose
27
+ p result
28
+ result.backtrace.each do |x|
29
+ puts x
30
+ end
31
+ end
32
+ client.send_reply(succ, result) rescue nil
33
+ ensure
34
+ client.close unless succ
35
+ if Thread.current['DRb']['stop_service']
36
+ Thread.new { stop_service }
37
+ client.close if client.alive?
38
+ break
39
+ end
40
+ break unless succ
41
+ end
42
+ end
43
+ end
44
+ rescue Errno::EBADF
45
+ puts "Rescued from :#{$!}"
46
+ end
47
+ end
48
+ end
49
+
@@ -0,0 +1,63 @@
1
+ require "ratonga/version"
2
+ require 'uri'
3
+ require 'socket'
4
+ require 'drb'
5
+ require 'drb/patch'
6
+
7
+ module Ratonga
8
+ module DRbService
9
+ def uri
10
+ @service.uri
11
+ end
12
+
13
+ def port
14
+ URI.parse(uri).port
15
+ end
16
+
17
+ private
18
+ def start(port = nil)
19
+ if port.nil?
20
+ uri = nil
21
+ else
22
+ uri = "druby://#{Socket.gethostname}:#{port}"
23
+ if existing = DRb.fetch_server(uri)
24
+ puts "stops #{existing}"
25
+ existing.stop_service
26
+ end
27
+ raise if DRb.fetch_server(uri)
28
+ end
29
+ @service = DRb.start_service uri, self
30
+ end
31
+ end
32
+
33
+ class Server
34
+ include DRbService
35
+
36
+ def initialize(port = 3931)
37
+ @clients = {}
38
+ start(port)
39
+ end
40
+
41
+ def register(userid, uri)
42
+ puts "register: #{DRb.current_server}"
43
+ @clients[userid] = {uri: uri}
44
+ end
45
+ end
46
+
47
+ class Client
48
+ include DRbService
49
+
50
+ attr_reader :server, :userid
51
+
52
+ def initialize(userid = nil, port = nil)
53
+ @userid = userid
54
+ start(port)
55
+ connect
56
+ end
57
+
58
+ def connect(server_uri = 'druby://localhost:3931')
59
+ @server = DRbObject.new_with_uri server_uri
60
+ @server.register(userid, uri)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,31 @@
1
+ module Ratonga
2
+ module Login
3
+ module Server
4
+ def login(userid, password)
5
+ puts "login: #{DRb.current_server}"
6
+ if @clients[userid].nil?
7
+ false
8
+ else
9
+ client = DRbObject.new_with_uri @clients[userid][:uri]
10
+ client.login(password)
11
+ end
12
+ end
13
+ end
14
+
15
+ module Client
16
+ attr_writer :password
17
+
18
+ def login(password)
19
+ @password == password
20
+ end
21
+ end
22
+ end
23
+
24
+ class Server
25
+ include Login::Server
26
+ end
27
+
28
+ class Client
29
+ include Login::Client
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module Ratonga
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ratonga/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ratonga"
7
+ s.version = Ratonga::VERSION
8
+ s.authors = ["Chanik Yeon"]
9
+ s.email = ["chaniks@gmail.com"]
10
+ s.homepage = "https://github.com/chaniks/ratonga"
11
+ s.summary = %q{distributed client web service}
12
+ s.description = %q{distributed client web service}
13
+
14
+ s.rubyforge_project = "ratonga"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rspec", '~> 2.6'
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
@@ -0,0 +1,14 @@
1
+ require 'ratonga'
2
+ require 'ratonga/login'
3
+
4
+ describe Ratonga::Server do
5
+ describe "#login" do
6
+ it "should do something" do
7
+ puts "#{subject}"
8
+ sleep 1
9
+ client = Ratonga::Client.new('test');
10
+ client.password = 'test123'
11
+ subject.login('test', 'test123').should be_true
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,23 @@
1
+ require 'ratonga'
2
+
3
+ describe Ratonga::Server do
4
+
5
+ its(:uri) { should be_a String }
6
+ its(:uri) { should_not be_empty }
7
+ its(:port) { should be 3931 }
8
+
9
+ it "should start a drb service" do
10
+ DRb.fetch_server(subject.uri).should_not be nil
11
+ end
12
+ end
13
+
14
+ describe Ratonga::Client do
15
+ its(:uri) { should be_a String }
16
+ its(:uri) { should_not be_empty }
17
+ its(:port) { should be_an Integer }
18
+ its(:server) { should_not be nil }
19
+
20
+ it "should start a drb service" do
21
+ DRb.fetch_server(subject.uri).should_not be nil
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ratonga
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chanik Yeon
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &70247563162680 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.6'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70247563162680
25
+ description: distributed client web service
26
+ email:
27
+ - chaniks@gmail.com
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - .gitignore
33
+ - .rspec
34
+ - Gemfile
35
+ - README
36
+ - Rakefile
37
+ - lib/drb/patch.rb
38
+ - lib/ratonga.rb
39
+ - lib/ratonga/login.rb
40
+ - lib/ratonga/version.rb
41
+ - ratonga.gemspec
42
+ - spec/ratonga_login_spec.rb
43
+ - spec/ratonga_spec.rb
44
+ homepage: https://github.com/chaniks/ratonga
45
+ licenses: []
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project: ratonga
64
+ rubygems_version: 1.8.5
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: distributed client web service
68
+ test_files:
69
+ - spec/ratonga_login_spec.rb
70
+ - spec/ratonga_spec.rb