shooting_star 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,4 +1,15 @@
1
- *** 2.0.1 / 2007-05-16
1
+ *** 2.0.2 / 2007-06-09
2
+ + 1 major enhancement:
3
+ + Added chat generator.
4
+
5
+ + 1 minor enhancement:
6
+ + Default client configuration.
7
+ + Changed reconnecting interval from 1 sec to 3 sec.
8
+
9
+ + 1 minor bugfix:
10
+ + Suppressed invalid access to closed channel.
11
+
12
+ *** 2.0.1 / 2007-05-20
2
13
  + 1 minor enhancement:
3
14
  + Added dependencies of gems.
4
15
  + 2 minor bug fix:
data/Manifest.txt CHANGED
@@ -37,3 +37,15 @@ vendor/plugins/meteor_strike/generators/meteor/templates/view.rhtml
37
37
  vendor/plugins/meteor_strike/generators/meteor/templates/migration.rb
38
38
  vendor/plugins/meteor_strike/generators/meteor/templates/unit_test.rb
39
39
  vendor/plugins/meteor_strike/generators/meteor/templates/functional_test.rb
40
+ vendor/plugins/meteor_strike/generators/chat
41
+ vendor/plugins/meteor_strike/generators/chat/chat_generator.rb
42
+ vendor/plugins/meteor_strike/generators/chat/templates
43
+ vendor/plugins/meteor_strike/generators/chat/templates/controller.rb
44
+ vendor/plugins/meteor_strike/generators/chat/templates/model.rb
45
+ vendor/plugins/meteor_strike/generators/chat/templates/helper.rb
46
+ vendor/plugins/meteor_strike/generators/chat/templates/layout.rhtml
47
+ vendor/plugins/meteor_strike/generators/chat/templates/index.rhtml
48
+ vendor/plugins/meteor_strike/generators/chat/templates/show.rhtml
49
+ vendor/plugins/meteor_strike/generators/chat/templates/migration.rb
50
+ vendor/plugins/meteor_strike/generators/chat/templates/unit_test.rb
51
+ vendor/plugins/meteor_strike/generators/chat/templates/functional_test.rb
@@ -56,10 +56,7 @@ module ShootingStar
56
56
  unless @params['__t__']
57
57
  make_connection(path)
58
58
  else
59
- unless Channel[@channel]
60
- Channel.new(@channel)
61
- log "Channel opened: #{@channel}"
62
- end
59
+ prepare_channel(@channel)
63
60
  unless @@servers[@signature] || @params['__t__'] == 'rc'
64
61
  notify(:event => :enter, :uid => @uid, :tag => @tag)
65
62
  log "Connected: #{@uid}"
@@ -71,6 +68,8 @@ module ShootingStar
71
68
  @@servers[@signature] = self
72
69
  wait_for
73
70
  end
71
+ rescue MethodNotAcceptable
72
+ write_and_close
74
73
  rescue Exception => e
75
74
  log "ERROR: #{e.message}\n#{e.backtrace.join("\n")}\n#{data}"
76
75
  write_and_close
@@ -166,12 +165,21 @@ module ShootingStar
166
165
  # the execution buffer, they'll be flushed and return on the spot.
167
166
  def wait_for
168
167
  log "Wait for: #{@channel}:#{@uid}:#{@tag.join(',')}:#{@signature}"
169
- if Channel[@channel].join(self)
168
+ if prepare_channel(@channel).join(self)
170
169
  log "Flushed: #{@channel}:#{@uid}:#{@tag.join(',')}:#{@signature}"
171
170
  end
172
171
  @waiting = true
173
172
  end
174
173
 
174
+ # prepare channel object.
175
+ def prepare_channel(channel)
176
+ unless Channel[channel]
177
+ Channel.new(channel)
178
+ log "Channel opened: #{channel}"
179
+ end
180
+ Channel[channel]
181
+ end
182
+
175
183
  # add execution line to the buffer.
176
184
  def execute(id, params)
177
185
  sweep_timeout = ShootingStar::CONFIG.sweep_timeout
@@ -198,7 +206,6 @@ module ShootingStar
198
206
  assets = URI.parse(@params['execute'])
199
207
  assets.path = '/javascripts/prototype.js'
200
208
  assets.query = assets.fragment = nil
201
-
202
209
  send_data "HTTP/1.1 200 OK\nContent-Type: text/html\n\n" +
203
210
  <<-"EOH"
204
211
  <html><head><script type="text/javascript" src="#{assets}"></script>
@@ -210,7 +217,7 @@ module ShootingStar
210
217
  var request = new Ajax.Request(#{path.to_json},
211
218
  {evalScript: true, onComplete: function(xhr){
212
219
  setTimeout(function(){connect(true)},
213
- xhr.getResponseHeader('Content-Type') ? 0 : 1000);
220
+ xhr.getResponseHeader('Content-Type') ? 0 : 3000);
214
221
  }, postBody: body.toQueryString()});
215
222
  var disconnect = function()
216
223
  { request.options.onComplete = function(){};
data/lib/shooting_star.rb CHANGED
@@ -7,7 +7,7 @@ require 'shooting_star/config'
7
7
  require 'shooting_star/shooter'
8
8
 
9
9
  module ShootingStar
10
- VERSION = '2.0.1'
10
+ VERSION = '2.0.2'
11
11
  CONFIG = Config.new(
12
12
  :config => 'config/shooting_star.yml',
13
13
  :pid_file => 'log/shooting_star.pid',
@@ -0,0 +1,45 @@
1
+ class ChatGenerator < Rails::Generator::NamedBase
2
+ def initialize(runtime_args, runtime_options)
3
+ base_name = runtime_args.shift || 'chat'
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.template 'helper.rb',
27
+ File.join('app/helpers', class_path, "#{file_name}_helper.rb")
28
+
29
+ m.template 'layout.rhtml',
30
+ File.join('app/views', class_path, "layouts/#{file_name}.rhtml")
31
+ m.template 'index.rhtml',
32
+ File.join('app/views', class_path, "#{file_name}/index.rhtml")
33
+ m.template 'show.rhtml',
34
+ File.join('app/views', class_path, "#{file_name}/show.rhtml")
35
+
36
+ m.template 'model.rb',
37
+ File.join('app/models', class_path, "#{file_name}.rb")
38
+ m.template 'unit_test.rb',
39
+ File.join('test/unit', class_path, "#{file_name}_test.rb")
40
+
41
+ m.migration_template 'migration.rb', 'db/migrate',
42
+ :migration_file_name => "create_#{file_name.pluralize}"
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,24 @@
1
+ class <%= class_name %>Controller < ApplicationController
2
+ layout '<%= file_name %>', :only => :index
3
+
4
+ def index
5
+ @chats = <%= class_name %>.find(:all).reverse
6
+ end
7
+
8
+ def show
9
+ @chat = <%= class_name %>.find(params[:id])
10
+ end
11
+
12
+ def talk
13
+ @chat = <%= class_name %>.create!(params[:chat])
14
+ content = render_component_as_string :action => 'show', :id => @chat.id
15
+ javascript = render_to_string :update do |page|
16
+ page.insert_html :top, 'chat-list', content
17
+ end
18
+ Meteor.shoot '<%= file_name %>', javascript
19
+ render :update do |page|
20
+ page[:chat_message].clear
21
+ page[:chat_message].focus
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require '<%= file_name %>_controller'
3
+
4
+ # Re-raise errors caught by the controller.
5
+ class <%= class_name %>Controller; def rescue_action(e) raise e end; end
6
+
7
+ class <%= class_name %>ControllerTest < Test::Unit::TestCase
8
+ def setup
9
+ @controller = <%= class_name %>Controller.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,2 @@
1
+ module MeteorHelper
2
+ end
@@ -0,0 +1,11 @@
1
+ <%% form_remote_for(:chat, :url => {:action => 'talk'}) do |f| %>
2
+ <%%= f.text_field :name %>
3
+ <%%= submit_tag 'Talk' %><br />
4
+ <%%= f.text_area :message, :rows => 3 %>
5
+ <%% end %>
6
+ <ul id="chat-list">
7
+ <%% for chat in @chats %>
8
+ <%%= render_component :action => 'show', :id => chat.id %>
9
+ <%% end %>
10
+ </ul>
11
+ <%%= meteor_strike '<%= file_name %>' %>
@@ -0,0 +1,12 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
6
+ <title><%= class_name %>: <%%= controller.action_name %></title>
7
+ <%%= javascript_include_tag :defaults %>
8
+ </head>
9
+ <body>
10
+ <%%= yield %>
11
+ </body>
12
+ </html>
@@ -0,0 +1,13 @@
1
+ class Create<%= class_name.pluralize %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table '<%= file_name.pluralize %>' do |t|
4
+ t.column :name, :string
5
+ t.column :message, :text
6
+ t.column :created_at, :datetime
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table '<%= file_name.pluralize %>'
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+ validates_presence_of :name, :message
3
+ end
@@ -0,0 +1,5 @@
1
+ <li>
2
+ <span><%%=h @chat.name %></span>
3
+ <span><%%=h @chat.message %></span>
4
+ </li>
5
+
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class <%= class_name %>Test < Test::Unit::TestCase
4
+ def test_truth
5
+ assert true
6
+ end
7
+ end
@@ -34,9 +34,8 @@ class MeteorGenerator < Rails::Generator::NamedBase
34
34
  m.template 'unit_test.rb',
35
35
  File.join('test/unit', class_path, "#{file_name}_test.rb")
36
36
 
37
- m.migration_template 'migration.rb',
38
- File.join('db/migrate', class_path),
39
- :migration_file_name => 'create_meteors'
37
+ m.migration_template 'migration.rb', 'db/migrate',
38
+ :migration_file_name => "create_#{file_name.pluralize}"
40
39
  end
41
40
  end
42
41
  end
@@ -6,6 +6,7 @@ class Meteor < ActiveRecord::Base
6
6
  LISTINGS = [:listeners, :listeners_with, :channels, :signatures]
7
7
 
8
8
  def initialize(config)
9
+ config['shooting_star'] ||= {'shooter' => 'druby://localhost:7123'}
9
10
  uris = config['shooting_star']['shooter']
10
11
  @shooters = [uris].flatten.map{|uri| DRbObject.new_with_uri(uri)}
11
12
  end
@@ -20,6 +20,9 @@ module MeteorStrike
20
20
  end
21
21
  @meteor_strike += 1
22
22
  config = ActiveRecord::Base.configurations[RAILS_ENV]['shooting_star']
23
+ config ||= {}
24
+ config['server'] ||= 'localhost:8080'
25
+ config['shooter'] ||= 'druby://localhost:7123'
23
26
  server = config['server'].kind_of?(Array) ?
24
27
  config['server'][rand(config['server'].length)] : config['server']
25
28
  shooting_star_uri = "#{server}/#{channel}"
@@ -56,6 +59,7 @@ module MeteorStrike
56
59
  };
57
60
  var ms = meteorStrike[channel] = meteorStrike[channel] || new Object;
58
61
  ms.getTags = function(){return TAGS};
62
+ ms.getUid = function(){return UID};
59
63
  ms.execute = function(js){eval(js)};
60
64
  ms.event = function(params){#{options[:event]}};
61
65
  ms.update = function(uid, tags){
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.3
2
+ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: shooting_star
5
5
  version: !ruby/object:Gem::Version
6
- version: 2.0.1
7
- date: 2007-05-20 00:00:00 +09:00
6
+ version: 2.0.2
7
+ date: 2007-06-08 00:00:00 +09:00
8
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
9
  require_paths:
10
10
  - lib
@@ -69,6 +69,18 @@ files:
69
69
  - vendor/plugins/meteor_strike/generators/meteor/templates/migration.rb
70
70
  - vendor/plugins/meteor_strike/generators/meteor/templates/unit_test.rb
71
71
  - vendor/plugins/meteor_strike/generators/meteor/templates/functional_test.rb
72
+ - vendor/plugins/meteor_strike/generators/chat
73
+ - vendor/plugins/meteor_strike/generators/chat/chat_generator.rb
74
+ - vendor/plugins/meteor_strike/generators/chat/templates
75
+ - vendor/plugins/meteor_strike/generators/chat/templates/controller.rb
76
+ - vendor/plugins/meteor_strike/generators/chat/templates/model.rb
77
+ - vendor/plugins/meteor_strike/generators/chat/templates/helper.rb
78
+ - vendor/plugins/meteor_strike/generators/chat/templates/layout.rhtml
79
+ - vendor/plugins/meteor_strike/generators/chat/templates/index.rhtml
80
+ - vendor/plugins/meteor_strike/generators/chat/templates/show.rhtml
81
+ - vendor/plugins/meteor_strike/generators/chat/templates/migration.rb
82
+ - vendor/plugins/meteor_strike/generators/chat/templates/unit_test.rb
83
+ - vendor/plugins/meteor_strike/generators/chat/templates/functional_test.rb
72
84
  test_files:
73
85
  - test/test_helper.rb
74
86
  - test/test_shooting_star.rb