shooting_star 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/History.txt +42 -0
  2. data/Manifest.txt +38 -0
  3. data/README.txt +80 -0
  4. data/Rakefile +54 -0
  5. data/bin/shooting_star +70 -0
  6. data/ext/asteroid.c +262 -0
  7. data/ext/asteroid.h +4 -0
  8. data/ext/extconf.rb +9 -0
  9. data/lib/form_encoder.rb +23 -0
  10. data/lib/shooting_star/channel.rb +41 -0
  11. data/lib/shooting_star/config.rb +19 -0
  12. data/lib/shooting_star/server.rb +219 -0
  13. data/lib/shooting_star/shooter.rb +62 -0
  14. data/lib/shooting_star.rb +142 -0
  15. data/test/ext/asteroid_test.rb +60 -0
  16. data/test/lib/shooting_star_test.rb +55 -0
  17. data/test/lib/test_c10k_problem.c +47 -0
  18. data/test/test_helper.rb +33 -0
  19. data/test/test_shooting_star.rb +64 -0
  20. data/vendor/plugins/meteor_strike/README +50 -0
  21. data/vendor/plugins/meteor_strike/Rakefile +22 -0
  22. data/vendor/plugins/meteor_strike/generators/meteor/meteor_generator.rb +39 -0
  23. data/vendor/plugins/meteor_strike/generators/meteor/templates/controller.rb +25 -0
  24. data/vendor/plugins/meteor_strike/generators/meteor/templates/functional_test.rb +17 -0
  25. data/vendor/plugins/meteor_strike/generators/meteor/templates/migration.rb +13 -0
  26. data/vendor/plugins/meteor_strike/generators/meteor/templates/model.rb +15 -0
  27. data/vendor/plugins/meteor_strike/generators/meteor/templates/unit_test.rb +11 -0
  28. data/vendor/plugins/meteor_strike/generators/meteor/templates/view.rhtml +13 -0
  29. data/vendor/plugins/meteor_strike/init.rb +3 -0
  30. data/vendor/plugins/meteor_strike/lib/meteor_strike.rb +61 -0
  31. data/vendor/plugins/meteor_strike/test/meteor_strike_test.rb +15 -0
  32. metadata +100 -0
@@ -0,0 +1,50 @@
1
+ MeteorStrike
2
+ ============
3
+ by Genki Takiuchi <takiuchi@drecom.co.jp>
4
+
5
+ This plugin provides an implementation of comet client corresponding to
6
+ comet server named ShootingStar.
7
+
8
+ INSTALL:
9
+ You need to configure this plugin by database.yml like this;
10
+
11
+ development:
12
+ database: db/development.sqlite3
13
+ timeout: 5000
14
+ shooting_star:
15
+ server: 127.0.0.1:8080
16
+ shooter: druby://localhost:7123
17
+
18
+ server is the host serving comet which is accessed from client browser.
19
+ shooter is the URI serving druby object which is accessed from Rails
20
+ application.
21
+
22
+ In order to keep security, shooter should be private address.
23
+
24
+ USAGE:
25
+ In the view rhtml file, you can connect to the server by calling one helper
26
+ method below:
27
+
28
+ <%=
29
+ meteor_strike 'channel/name',
30
+ :uid => user_identifier,
31
+ :tag => [tag1, tag2],
32
+ :event => %Q{
33
+ switch(params.event){
34
+ case 'enter':
35
+ /* params.uid is entered to the channel with params.tag */
36
+ break;
37
+ case 'leave':
38
+ /* params.uid is left from the channel with params.tag */
39
+ break;
40
+ case 'update':
41
+ /* params.uid is updated status in the channel */
42
+ break;
43
+ }
44
+ }
45
+ %>
46
+
47
+ Second parameter is optional.
48
+ :uid should be unique number or string which identifing user.
49
+ :tag acts as sub-channel.
50
+ :event is a javascript handling events from server.
@@ -0,0 +1,22 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the meteor_strike plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the meteor_strike plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'MeteorStrike'
19
+ rdoc.options << '--line-numbers' << '--inline-source'
20
+ rdoc.rdoc_files.include('README')
21
+ rdoc.rdoc_files.include('lib/**/*.rb')
22
+ end
@@ -0,0 +1,39 @@
1
+ class MeteorGenerator < Rails::Generator::NamedBase
2
+ def initialize(runtime_args, runtime_options)
3
+ base_name = 'meteor'
4
+ runtime_args.unshift(base_name)
5
+ super
6
+ end
7
+
8
+ def manifest
9
+ controller_class = "#{class_name}Controller"
10
+ controller_file = "#{file_name}_controller"
11
+ record do |m|
12
+ m.class_collisions(controller_class, "#{controller_class}Test")
13
+ m.class_collisions(class_name, "#{class_name}Test")
14
+
15
+ m.directory File.join('app/controllers', class_path)
16
+ m.directory File.join('test/functional', class_path)
17
+ m.directory File.join('app/views', class_path, file_name)
18
+ m.directory File.join('app/models', class_path)
19
+ m.directory File.join('test/unit', class_path)
20
+
21
+ m.template 'controller.rb',
22
+ File.join('app/controllers', class_path, "#{controller_file}.rb")
23
+ m.template 'functional_test.rb',
24
+ File.join('test/functional', class_path, "#{controller_file}_test.rb")
25
+
26
+ m.file 'view.rhtml',
27
+ File.join('app/views', class_path, "#{file_name}/strike.rhtml")
28
+
29
+ m.template 'model.rb',
30
+ File.join('app/models', class_path, "#{file_name}.rb")
31
+ m.template 'unit_test.rb',
32
+ File.join('test/unit', class_path, "#{file_name}_test.rb")
33
+
34
+ m.migration_template 'migration.rb',
35
+ File.join('db/migrate', class_path),
36
+ :migration_file_name => 'create_meteors'
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,25 @@
1
+ class MeteorController < ApplicationController
2
+ layout nil
3
+
4
+ def strike
5
+ @channel = params[:channel].split('/').map{|i| CGI.escape(i)}.join('/')
6
+ if params[:event].blank?
7
+ meteor = Meteor.find(params[:id])
8
+ @javascript = meteor.javascript
9
+ else
10
+ @javascript = %Q[setTimeout(function(){
11
+ meteorStrike.event[#{@channel.to_json}](#{params.to_json});}, 0);]
12
+ end
13
+ Meteor.shooter.executed(params[:sig], params[:id])
14
+ end
15
+
16
+ def update
17
+ tags = (params[:tag] || '').split(',').map{|i| CGI.unescape(i)}
18
+ Meteor.shooter.update(params[:sig], params[:uid], tags)
19
+ render :nothing => true
20
+ end
21
+
22
+ def sweep
23
+ Meteor.shooter.sweep
24
+ end
25
+ end
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require 'meteor_controller'
3
+
4
+ # Re-raise errors caught by the controller.
5
+ class MeteorController; def rescue_action(e) raise e end; end
6
+
7
+ class MeteorControllerTest < Test::Unit::TestCase
8
+ def setup
9
+ @controller = MeteorController.new
10
+ @request = ActionController::TestRequest.new
11
+ @response = ActionController::TestResponse.new
12
+ end
13
+
14
+ def test_truth
15
+ assert true
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ class CreateMeteors < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :meteors do |t|
4
+ t.column :javascript, :text
5
+ t.column :limit, :integer
6
+ t.column :created_at, :datetime
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :meteors
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ require 'drb/drb'
2
+
3
+ class Meteor < ActiveRecord::Base
4
+ def self.shooter
5
+ @@shooter ||= DRbObject.new_with_uri(
6
+ configurations[RAILS_ENV]['shooting_star']['shooter'])
7
+ end
8
+
9
+ def self.shoot(channel, javascript, tag = [])
10
+ meteor = Meteor.new(:javascript => javascript)
11
+ returning(meteor.save) do |succeeded|
12
+ shooter.shoot(channel, meteor.id, tag) if succeeded
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class MeteorTest < Test::Unit::TestCase
4
+ def test_creation
5
+ initial_count = Meteor.count
6
+ assert Meteor.create(:javascript => %Q{
7
+ alert(1);
8
+ })
9
+ assert_equal initial_count + 1, Meteor.count
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ <html>
2
+ <head>
3
+ <%= javascript_tag %Q{
4
+ (function(){
5
+ var channel = #{@channel.to_json};
6
+ var javascript = #{@javascript.to_json};
7
+ var meteorStrike = parent.parent.meteorStrike;
8
+ if(meteorStrike) meteorStrike.execute(javascript);
9
+ else alert('Connection is not established to the ShootingStar server.');
10
+ })();
11
+ }%>
12
+ </head>
13
+ </html>
@@ -0,0 +1,3 @@
1
+ require 'meteor_strike'
2
+
3
+ ActionView::Base.send(:include, MeteorStrike::Helper)
@@ -0,0 +1,61 @@
1
+ require 'uri'
2
+ require 'md5'
3
+
4
+ module MeteorStrike
5
+ module Helper
6
+ def meteor_strike(channel, options = {})
7
+ config = ActiveRecord::Base.configurations[RAILS_ENV]
8
+ shooting_star_uri = "#{config['shooting_star']['server']}/#{channel}"
9
+ uri = url_for(:only_path => false).split('/')[0..2].join('/')
10
+ uid = options[:uid] ? CGI.escape(options[:uid].to_s) : ''
11
+ tags = options[:tag] || []
12
+ tag = tags.map{|i| CGI.escape(i.to_s)}.join(',')
13
+ base_uri = "http://#{shooting_star_uri}?execute=#{uri}/meteor/strike"
14
+ update_uri = "#{uri}/meteor/update"
15
+ sig = Meteor.shooter.signature
16
+ <<-"EOH"
17
+ <script type="text/javascript">
18
+ //<[CDATA[
19
+ var meteorStrike;
20
+ Event.observe(window, 'load', function(){
21
+ var channel = #{channel.to_json};
22
+ var UID = #{uid.to_json}, TAGS = #{tags.to_json};
23
+ var encodeTags = function(tags){
24
+ var encode = function(i){return encodeURIComponent(i)};
25
+ return $A(tags).uniq().map(encode).join(',');
26
+ };
27
+ meteorStrike = meteorStrike || new Object;
28
+ meteorStrike.execute = function(js){eval(js)};
29
+ meteorStrike.event = meteorStrike.event || $H();
30
+ meteorStrike.event[channel] = function(params){#{options[:event]}};
31
+ meteorStrike.update = function(uid, tags){
32
+ new Ajax.Request([#{update_uri.to_json},
33
+ '?channel=', channel,
34
+ '&uid=', uid || UID,
35
+ '&tag=', encodeTags(tags || TAGS),
36
+ '&sig=', #{sig.to_json}].join(''));
37
+ UID = uid, TAGS = tags;
38
+ };
39
+ meteorStrike.tuneIn = function(tags){
40
+ meteorStrike.update(UID, TAGS.concat(tags).uniq());
41
+ };
42
+ meteorStrike.tuneOut = function(tags){
43
+ meteorStrike.update(UID, Array.prototype.without.apply(TAGS, tags));
44
+ };
45
+ setTimeout(function(){
46
+ var iframe = document.createElement('iframe');
47
+ iframe.src = "#{base_uri}&uid=#{uid}&tag=#{tag}&sig=#{sig}";
48
+ iframe.frameborder = "0";
49
+ iframe.width = "0";
50
+ iframe.height = "0";
51
+ iframe.style.border = '0px';
52
+ document.body.appendChild(iframe);
53
+ setTimeout(function(){#{options[:connected]}}, 0);
54
+ }, 0);
55
+ });
56
+ //]]>
57
+ </script>
58
+ EOH
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,15 @@
1
+ require 'test/unit'
2
+ require File.join(File.dirname(__FILE__), '../lib/meteor_strike')
3
+ begin
4
+ require 'rubygems'
5
+ require 'redgreen'
6
+ rescue
7
+ end
8
+
9
+ class MeteorStrikeTest < Test::Unit::TestCase
10
+ include MeteorStrike::Helper
11
+
12
+ def test_meteor_strike
13
+ assert respond_to?(:meteor_strike)
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: shooting_star
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.0.3
7
+ date: 2007-03-23 00:00:00 +09:00
8
+ summary: Our goal is development of practical comet server which will be achieving over 100,000 simultaneous connections per host. On this purpose, we abandon portability and use system calls depending on particular OS such as epoll and kqueue.
9
+ require_paths:
10
+ - lib
11
+ - ext
12
+ email: takiuchi@drecom.co.jp
13
+ homepage: " by Genki Takiuchi <takiuchi@drecom.co.jp>"
14
+ rubyforge_project: shooting-star
15
+ description: "Our goal is development of practical comet server which will be achieving over 100,000 simultaneous connections per host. On this purpose, we abandon portability and use system calls depending on particular OS such as epoll and kqueue. == FEATURES/PROBLEMS: * Comet server * Comet client implementation (Rails plugin) == SYNOPSYS:"
16
+ autorequire:
17
+ default_executable:
18
+ bindir: bin
19
+ has_rdoc: true
20
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
21
+ requirements:
22
+ - - ">"
23
+ - !ruby/object:Gem::Version
24
+ version: 0.0.0
25
+ version:
26
+ platform: ruby
27
+ signing_key:
28
+ cert_chain:
29
+ post_install_message:
30
+ authors:
31
+ - Genki Takiuchi
32
+ files:
33
+ - History.txt
34
+ - Manifest.txt
35
+ - README.txt
36
+ - Rakefile
37
+ - bin/shooting_star
38
+ - lib/shooting_star.rb
39
+ - lib/shooting_star/server.rb
40
+ - lib/shooting_star/shooter.rb
41
+ - lib/shooting_star/channel.rb
42
+ - lib/shooting_star/config.rb
43
+ - lib/form_encoder.rb
44
+ - ext/asteroid.c
45
+ - ext/extconf.rb
46
+ - ext/asteroid.h
47
+ - test/test_helper.rb
48
+ - test/lib/shooting_star_test.rb
49
+ - test/lib/test_c10k_problem.c
50
+ - test/ext/asteroid_test.rb
51
+ - vendor
52
+ - vendor/plugins
53
+ - vendor/plugins/meteor_strike
54
+ - vendor/plugins/meteor_strike/README
55
+ - vendor/plugins/meteor_strike/Rakefile
56
+ - vendor/plugins/meteor_strike/init.rb
57
+ - vendor/plugins/meteor_strike/lib
58
+ - vendor/plugins/meteor_strike/lib/meteor_strike.rb
59
+ - vendor/plugins/meteor_strike/test
60
+ - vendor/plugins/meteor_strike/test/meteor_strike_test.rb
61
+ - vendor/plugins/meteor_strike/generators
62
+ - vendor/plugins/meteor_strike/generators/meteor
63
+ - vendor/plugins/meteor_strike/generators/meteor/meteor_generator.rb
64
+ - vendor/plugins/meteor_strike/generators/meteor/templates
65
+ - vendor/plugins/meteor_strike/generators/meteor/templates/controller.rb
66
+ - vendor/plugins/meteor_strike/generators/meteor/templates/model.rb
67
+ - vendor/plugins/meteor_strike/generators/meteor/templates/view.rhtml
68
+ - vendor/plugins/meteor_strike/generators/meteor/templates/migration.rb
69
+ - vendor/plugins/meteor_strike/generators/meteor/templates/unit_test.rb
70
+ - vendor/plugins/meteor_strike/generators/meteor/templates/functional_test.rb
71
+ test_files:
72
+ - test/test_helper.rb
73
+ - test/test_shooting_star.rb
74
+ rdoc_options:
75
+ - -S
76
+ - --template
77
+ - kilmer
78
+ - --main
79
+ - README.txt
80
+ - --exclude
81
+ - ext/asteroid
82
+ - README.txt
83
+ extra_rdoc_files: []
84
+
85
+ executables:
86
+ - shooting_star
87
+ extensions:
88
+ - ext/extconf.rb
89
+ requirements: []
90
+
91
+ dependencies:
92
+ - !ruby/object:Gem::Dependency
93
+ name: hoe
94
+ version_requirement:
95
+ version_requirements: !ruby/object:Gem::Version::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 1.2.0
100
+ version: