nitro 0.11.0 → 0.12.0
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.
- data/ChangeLog +150 -0
- data/README +1 -1
- data/RELEASES +89 -0
- data/Rakefile +3 -3
- data/{AUTHORS → doc/AUTHORS} +0 -0
- data/{LICENSE → doc/LICENSE} +0 -0
- data/doc/bugs.txt +2 -1
- data/examples/README.windows +2 -2
- data/examples/blog/lib/blog/controller.rb +9 -8
- data/examples/blog/log/apache.error_log +71 -0
- data/{lib/xsl → examples/blog/root}/base.xsl +0 -0
- data/examples/blog/root/error.xhtml +56 -0
- data/examples/blog/root/index.xhtml +2 -2
- data/examples/blog/root/recent_posts.xhtml +1 -1
- data/examples/blog/root/style.xsl +4 -4
- data/examples/blog/run.rb +1 -2
- data/examples/no_xsl_blog/root/index.xhtml +2 -2
- data/examples/no_xsl_blog/root/recent_posts.xhtml +1 -1
- data/examples/why_wiki/run.rb +19 -19
- data/lib/nitro.rb +2 -21
- data/lib/nitro/adapters/webrick.rb +19 -3
- data/lib/nitro/context.rb +15 -1
- data/lib/nitro/controller.rb +84 -49
- data/lib/nitro/dispatcher.rb +30 -6
- data/lib/nitro/markup.rb +4 -2
- data/lib/nitro/render.rb +15 -11
- data/lib/nitro/routing.rb +33 -0
- data/lib/nitro/runner.rb +38 -3
- data/lib/nitro/scaffold.rb +7 -4
- data/lib/nitro/shaders.rb +11 -4
- data/lib/nitro/template.rb +140 -0
- data/lib/og.rb +25 -11
- data/lib/og/adapter.rb +141 -7
- data/lib/og/adapters/mysql.rb +41 -3
- data/lib/og/adapters/oracle.rb +4 -3
- data/lib/og/adapters/psql.rb +3 -3
- data/lib/og/adapters/sqlite.rb +3 -3
- data/lib/og/connection.rb +5 -1
- data/lib/og/database.rb +26 -12
- data/lib/og/enchant.rb +50 -16
- data/lib/og/meta.rb +15 -15
- data/lib/og/observer.rb +53 -0
- data/test/glue/tc_property_type_checking.rb +3 -0
- data/test/nitro/tc_controller.rb +1 -1
- data/test/nitro/tc_dispatcher.rb +1 -1
- data/test/nitro/tc_template.rb +32 -0
- data/test/og/tc_many_to_many.rb +62 -0
- data/test/og/tc_observer.rb +85 -0
- data/test/tc_og.rb +16 -2
- metadata +12 -14
- data/bin/cluster +0 -218
- data/examples/why_wiki/wiki.yml +0 -6
- data/examples/wiki.yml +0 -1
- data/lib/nitro/ui/select.rb +0 -40
- data/lib/nitro/ui/sitemap.rb +0 -183
- data/test/nitro/ui/tc_sitemap.rb +0 -37
data/test/nitro/tc_dispatcher.rb
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
require 'nitro/template'
|
7
|
+
|
8
|
+
class TC_Template < Test::Unit::TestCase # :nodoc: all
|
9
|
+
include N
|
10
|
+
|
11
|
+
def test_all
|
12
|
+
template = %q{
|
13
|
+
Hello #{user}
|
14
|
+
|
15
|
+
dont forget the following todo items:
|
16
|
+
|
17
|
+
<?r for item in items ?>
|
18
|
+
<li>#{item}</li>
|
19
|
+
<?r end ?>
|
20
|
+
}
|
21
|
+
|
22
|
+
user = 'gmosx'
|
23
|
+
items = %w{ nitro is really great }
|
24
|
+
out = ''
|
25
|
+
|
26
|
+
Template.process(template, :out, binding)
|
27
|
+
|
28
|
+
assert_match %r{\<li\>nitro\</li\>}, out
|
29
|
+
assert_match %r{\<li\>really\</li\>}, out
|
30
|
+
assert_match %r{Hello gmosx}, out
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
require 'og'
|
7
|
+
|
8
|
+
class TC_OgManyToMany < Test::Unit::TestCase # :nodoc: all
|
9
|
+
include N
|
10
|
+
|
11
|
+
class Attribute
|
12
|
+
property :name, String
|
13
|
+
|
14
|
+
def initialize(name = nil)
|
15
|
+
@name = name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class Klass
|
20
|
+
property :name, String
|
21
|
+
many_to_many :observed_attributes, Attribute, :linkback => :klass_observers
|
22
|
+
many_to_many :controlled_attributes, Attribute, :linkback => :klass_controllers
|
23
|
+
|
24
|
+
def initialize(name = nil)
|
25
|
+
@name = name
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_all
|
30
|
+
config = {
|
31
|
+
:adapter => 'psql',
|
32
|
+
:database => 'test',
|
33
|
+
:user => 'postgres',
|
34
|
+
:password => 'navelrulez',
|
35
|
+
:connection_count => 2
|
36
|
+
}
|
37
|
+
|
38
|
+
Og::Database.drop_db!(config)
|
39
|
+
og = Og::Database.new(config)
|
40
|
+
|
41
|
+
og.get_connection
|
42
|
+
|
43
|
+
k = Klass.create('klass1')
|
44
|
+
a1 = Attribute.create('attr1')
|
45
|
+
a2 = Attribute.create('attr2')
|
46
|
+
|
47
|
+
k.add_observed_attribute(a1)
|
48
|
+
k.add_observed_attribute(a2)
|
49
|
+
|
50
|
+
assert_equal 2, k.observed_attributes.size
|
51
|
+
assert_equal 1, a1.klass_observers.size
|
52
|
+
|
53
|
+
k.add_controlled_attribute(a1)
|
54
|
+
|
55
|
+
assert_equal 1, k.controlled_attributes.size
|
56
|
+
assert_equal 1, a1.klass_controllers.size
|
57
|
+
|
58
|
+
og.put_connection
|
59
|
+
og.shutdown
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
require 'og'
|
7
|
+
|
8
|
+
class TC_OgObserver < Test::Unit::TestCase # :nodoc: all
|
9
|
+
include N
|
10
|
+
|
11
|
+
class User
|
12
|
+
property :name
|
13
|
+
end
|
14
|
+
|
15
|
+
class Article
|
16
|
+
property :name, String
|
17
|
+
property :age, Fixnum
|
18
|
+
|
19
|
+
def initialize (name = nil, age = nil)
|
20
|
+
@name, @age = name, age
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Example of a simple class that acts as an observer.
|
25
|
+
|
26
|
+
class ArticleObserver
|
27
|
+
attr :count
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
@count = 0
|
31
|
+
end
|
32
|
+
|
33
|
+
def og_pre_insert(conn, obj)
|
34
|
+
@count += 1
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Rails style observer, baaah...
|
39
|
+
|
40
|
+
class MultiObserver < Og::Observer
|
41
|
+
observe Article, User
|
42
|
+
|
43
|
+
attr :count
|
44
|
+
|
45
|
+
def initialize
|
46
|
+
@count = 0
|
47
|
+
end
|
48
|
+
|
49
|
+
def og_pre_insert(conn, obj)
|
50
|
+
@count += 1
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def setup
|
55
|
+
end
|
56
|
+
|
57
|
+
def teardown
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_all
|
61
|
+
config = {
|
62
|
+
:adapter => 'psql',
|
63
|
+
:database => 'test',
|
64
|
+
:user => 'postgres',
|
65
|
+
:password => 'navelrulez',
|
66
|
+
:connection_count => 2
|
67
|
+
}
|
68
|
+
|
69
|
+
Og::Database.drop_db!(config)
|
70
|
+
og = Og::Database.new(config)
|
71
|
+
|
72
|
+
og.get_connection
|
73
|
+
|
74
|
+
ao = ArticleObserver.new
|
75
|
+
Article.add_observer(ao)
|
76
|
+
Article.create('Hello', 5)
|
77
|
+
|
78
|
+
assert_equal 1, ao.count
|
79
|
+
assert_equal 1, MultiObserver.instance.count
|
80
|
+
|
81
|
+
og.put_connection
|
82
|
+
og.shutdown
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
data/test/tc_og.rb
CHANGED
@@ -11,7 +11,7 @@ module Test # :nodoc: all
|
|
11
11
|
# bug: creates a table that fucks-up postgres if not
|
12
12
|
# correctly escaped.
|
13
13
|
class User
|
14
|
-
prop_accessor :name, String
|
14
|
+
prop_accessor :name, String, :unique => true
|
15
15
|
prop_accessor :banned, TrueClass
|
16
16
|
|
17
17
|
def initialize(name = nil)
|
@@ -212,6 +212,20 @@ class TC_N_OG < Test::Unit::TestCase
|
|
212
212
|
article = Article.new("Title", "Body")
|
213
213
|
article.save!
|
214
214
|
|
215
|
+
# advanced finder
|
216
|
+
|
217
|
+
users3 = User.find_by_banned(true)
|
218
|
+
assert users3.empty?
|
219
|
+
|
220
|
+
user3 = User.find_by_name('gmosx')
|
221
|
+
assert_equal 'gmosx', user3.name
|
222
|
+
|
223
|
+
user3.banned = true
|
224
|
+
user3.save
|
225
|
+
|
226
|
+
users3 = User.find_by_banned(true)
|
227
|
+
assert !users3.empty?
|
228
|
+
|
215
229
|
comment = Comment.new("This is a comment")
|
216
230
|
comment.article = article
|
217
231
|
comment.author = User["gmosx"]
|
@@ -330,7 +344,7 @@ class TC_N_OG < Test::Unit::TestCase
|
|
330
344
|
|
331
345
|
og = Og::Database.new(config)
|
332
346
|
|
333
|
-
user = User.new("
|
347
|
+
user = User.new("kokoriko")
|
334
348
|
user.save!
|
335
349
|
|
336
350
|
og.shutdown
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.6
|
|
3
3
|
specification_version: 1
|
4
4
|
name: nitro
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2005-
|
6
|
+
version: 0.12.0
|
7
|
+
date: 2005-03-07
|
8
8
|
summary: Nitro Web Engine
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -30,15 +30,12 @@ authors:
|
|
30
30
|
files:
|
31
31
|
- Rakefile
|
32
32
|
- ChangeLog
|
33
|
-
- LICENSE
|
34
|
-
- AUTHORS
|
35
33
|
- INSTALL
|
36
34
|
- RELEASES
|
37
35
|
- README
|
38
36
|
- install.rb
|
39
37
|
- bin/nitro
|
40
38
|
- bin/new_app.rb
|
41
|
-
- bin/cluster
|
42
39
|
- bin/proto
|
43
40
|
- bin/new_form.rb
|
44
41
|
- bin/proto/ctl
|
@@ -80,7 +77,6 @@ files:
|
|
80
77
|
- examples/blog
|
81
78
|
- examples/README.windows
|
82
79
|
- examples/og
|
83
|
-
- examples/wiki.yml
|
84
80
|
- examples/no_xsl_blog/log
|
85
81
|
- examples/no_xsl_blog/conf
|
86
82
|
- examples/no_xsl_blog/root
|
@@ -121,7 +117,6 @@ files:
|
|
121
117
|
- examples/no_xsl_blog/lib/blog/template.rb
|
122
118
|
- examples/no_xsl_blog/lib/blog/model.rb
|
123
119
|
- examples/no_xsl_blog/lib/blog/controller.rb
|
124
|
-
- examples/why_wiki/wiki.yml
|
125
120
|
- examples/why_wiki/run.rb
|
126
121
|
- examples/why_wiki/README
|
127
122
|
- examples/flash/log
|
@@ -158,6 +153,7 @@ files:
|
|
158
153
|
- examples/blog/conf/apache.conf
|
159
154
|
- examples/blog/conf/lhttpd.conf
|
160
155
|
- examples/blog/root/login.xhtml
|
156
|
+
- examples/blog/root/error.xhtml
|
161
157
|
- examples/blog/root/index.xhtml
|
162
158
|
- examples/blog/root/style.css
|
163
159
|
- examples/blog/root/entry_form.xhtml
|
@@ -165,6 +161,7 @@ files:
|
|
165
161
|
- examples/blog/root/fcgi.rb
|
166
162
|
- examples/blog/root/comments.xhtml
|
167
163
|
- examples/blog/root/style.xsl
|
164
|
+
- examples/blog/root/base.xsl
|
168
165
|
- examples/blog/root/recent_posts.xhtml
|
169
166
|
- examples/blog/root/view_entry.xhtml
|
170
167
|
- examples/blog/root/view_entry.xml
|
@@ -193,6 +190,8 @@ files:
|
|
193
190
|
- examples/og/README
|
194
191
|
- doc/ChangeLog.1
|
195
192
|
- doc/config.txt
|
193
|
+
- doc/LICENSE
|
194
|
+
- doc/AUTHORS
|
196
195
|
- doc/apache.txt
|
197
196
|
- doc/tutorial.txt
|
198
197
|
- doc/og_tutorial.txt
|
@@ -201,7 +200,6 @@ files:
|
|
201
200
|
- doc/og_config.txt
|
202
201
|
- lib/nitro
|
203
202
|
- lib/parts
|
204
|
-
- lib/xsl
|
205
203
|
- lib/glue.rb
|
206
204
|
- lib/nitro.rb
|
207
205
|
- lib/glue
|
@@ -210,6 +208,7 @@ files:
|
|
210
208
|
- lib/nitro/localization.rb
|
211
209
|
- lib/nitro/cookie.rb
|
212
210
|
- lib/nitro/session.rb
|
211
|
+
- lib/nitro/routing.rb
|
213
212
|
- lib/nitro/uri.rb
|
214
213
|
- lib/nitro/output.rb
|
215
214
|
- lib/nitro/runner.rb
|
@@ -217,6 +216,7 @@ files:
|
|
217
216
|
- lib/nitro/scaffold.rb
|
218
217
|
- lib/nitro/adapters
|
219
218
|
- lib/nitro/context.rb
|
219
|
+
- lib/nitro/template.rb
|
220
220
|
- lib/nitro/shaders.rb
|
221
221
|
- lib/nitro/buffering.rb
|
222
222
|
- lib/nitro/builders
|
@@ -245,16 +245,13 @@ files:
|
|
245
245
|
- lib/nitro/session/drb.rb
|
246
246
|
- lib/nitro/session/memory.rb
|
247
247
|
- lib/nitro/session/drbserver.rb
|
248
|
-
- lib/nitro/ui/sitemap.rb
|
249
248
|
- lib/nitro/ui/pager.rb
|
250
249
|
- lib/nitro/ui/date-select.rb
|
251
250
|
- lib/nitro/ui/tabs.rb
|
252
|
-
- lib/nitro/ui/select.rb
|
253
251
|
- lib/nitro/ui/popup.rb
|
254
252
|
- lib/parts/content.rb
|
255
253
|
- lib/parts/content
|
256
254
|
- lib/parts/README
|
257
|
-
- lib/xsl/base.xsl
|
258
255
|
- lib/glue/mixins.rb
|
259
256
|
- lib/glue/logger.rb
|
260
257
|
- lib/glue/pool.rb
|
@@ -275,6 +272,7 @@ files:
|
|
275
272
|
- lib/og/adapters
|
276
273
|
- lib/og/enchant.rb
|
277
274
|
- lib/og/connection.rb
|
275
|
+
- lib/og/observer.rb
|
278
276
|
- lib/og/database.rb
|
279
277
|
- lib/og/mock.rb
|
280
278
|
- lib/og/meta.rb
|
@@ -291,6 +289,7 @@ files:
|
|
291
289
|
- test/glue
|
292
290
|
- test/og
|
293
291
|
- test/nitro/tc_uri.rb
|
292
|
+
- test/nitro/tc_template.rb
|
294
293
|
- test/nitro/tc_controller.rb
|
295
294
|
- test/nitro/adapters
|
296
295
|
- test/nitro/tc_session.rb
|
@@ -306,7 +305,6 @@ files:
|
|
306
305
|
- test/nitro/builders/tc_xml.rb
|
307
306
|
- test/nitro/builders/tc_rss.rb
|
308
307
|
- test/nitro/ui/tc_pager.rb
|
309
|
-
- test/nitro/ui/tc_sitemap.rb
|
310
308
|
- test/root/blog
|
311
309
|
- test/root/blog/list.xhtml
|
312
310
|
- test/glue/tc_strings.rb
|
@@ -320,8 +318,10 @@ files:
|
|
320
318
|
- test/glue/tc_cache.rb
|
321
319
|
- test/glue/tc_numbers.rb
|
322
320
|
- test/og/tc_sqlite.rb
|
321
|
+
- test/og/tc_observer.rb
|
323
322
|
- test/og/tc_filesys.rb
|
324
323
|
- test/og/tc_meta.rb
|
324
|
+
- test/og/tc_many_to_many.rb
|
325
325
|
- test/og/tc_lifecycle.rb
|
326
326
|
- vendor/breakpoint_client.rb
|
327
327
|
- vendor/sexp_processor.rb
|
@@ -360,8 +360,6 @@ rdoc_options:
|
|
360
360
|
extra_rdoc_files:
|
361
361
|
- Rakefile
|
362
362
|
- ChangeLog
|
363
|
-
- LICENSE
|
364
|
-
- AUTHORS
|
365
363
|
- INSTALL
|
366
364
|
- RELEASES
|
367
365
|
- README
|
data/bin/cluster
DELETED
@@ -1,218 +0,0 @@
|
|
1
|
-
# * George Moschovitis <gm@navel.gr>
|
2
|
-
# (c) 2004-2005 Navel, all rights reserved.
|
3
|
-
# $Id: cluster.rb 249 2005-02-04 14:03:00Z gmosx $
|
4
|
-
|
5
|
-
# WARNING: This is old code, not updated to work in the
|
6
|
-
# latest nitro release. Will be fixed ASAP.
|
7
|
-
|
8
|
-
$:.unshift 'lib'
|
9
|
-
|
10
|
-
require 'drb'
|
11
|
-
require 'monitor'
|
12
|
-
|
13
|
-
require 'nitro/application'
|
14
|
-
require 'nitro/server'
|
15
|
-
require 'glue/cache'
|
16
|
-
require 'nitro/server/session'
|
17
|
-
|
18
|
-
module N
|
19
|
-
|
20
|
-
# A Cluster manages the state of a collection of servers. The cluster
|
21
|
-
# synchronizes the servers and distributes the state. An older version
|
22
|
-
# used a polling system, ie: the servers polled the cluster to
|
23
|
-
# obtain the state. This version uses a push system, ie when the
|
24
|
-
# state is changed a delta is pushed to the clients.
|
25
|
-
#
|
26
|
-
# TODO: use Sync instead of Monitor
|
27
|
-
|
28
|
-
class Cluster < N::Application
|
29
|
-
|
30
|
-
# The CHash 'endpoint' resides in the Cluster server
|
31
|
-
|
32
|
-
class CHash < Hash
|
33
|
-
attr :mon
|
34
|
-
|
35
|
-
# drbobject for this hash (local)
|
36
|
-
|
37
|
-
attr_accessor :ldrb
|
38
|
-
|
39
|
-
# the cluster, use a cluster to implement a set
|
40
|
-
# (one server per drb_uri)
|
41
|
-
|
42
|
-
attr_accessor :cluster
|
43
|
-
|
44
|
-
#
|
45
|
-
|
46
|
-
def initialize(ldrb_uri = "druby://:8000")
|
47
|
-
@mon = Monitor.new
|
48
|
-
@ldrb = DRb.start_service(ldrb_uri, self)
|
49
|
-
@cluster = {}
|
50
|
-
end
|
51
|
-
|
52
|
-
#
|
53
|
-
|
54
|
-
def join(sdrb_uri)
|
55
|
-
@mon.synchronize {
|
56
|
-
cluster[sdrb_uri] = DRbObject.new(nil, sdrb_uri)
|
57
|
-
}
|
58
|
-
end
|
59
|
-
|
60
|
-
alias_method :old_set, :[]=
|
61
|
-
|
62
|
-
# Not really usefull
|
63
|
-
|
64
|
-
def []=(key, value)
|
65
|
-
# store the value (useful on server restarts)
|
66
|
-
@mon.synchronize {
|
67
|
-
old_set(key, value)
|
68
|
-
|
69
|
-
puts "CLUSTER #{key} = #{value}"
|
70
|
-
|
71
|
-
cluster.each { |uri, sdrb|
|
72
|
-
begin
|
73
|
-
sdrb.server_sync(key, value)
|
74
|
-
rescue => ex
|
75
|
-
Logger.error "Server at #{uri} is down, removing from cluster"
|
76
|
-
cluster.delete(uri)
|
77
|
-
end
|
78
|
-
}
|
79
|
-
}
|
80
|
-
end
|
81
|
-
|
82
|
-
# Use this, avoids syncing the original server, and avoids a
|
83
|
-
# nasty deadlock.
|
84
|
-
#
|
85
|
-
def cluster_sync(key, value, server_uri)
|
86
|
-
# store the value (useful on server restarts)
|
87
|
-
@mon.synchronize {
|
88
|
-
old_set(key, value)
|
89
|
-
|
90
|
-
puts "CLUSTER #{key} = #{value}"
|
91
|
-
|
92
|
-
cluster.each { |uri, sdrb|
|
93
|
-
begin
|
94
|
-
sdrb.server_sync(key, value) unless uri == server_uri
|
95
|
-
rescue => ex
|
96
|
-
Logger.error "Server at #{uri} is down, removing from cluster"
|
97
|
-
cluster.delete(uri)
|
98
|
-
end
|
99
|
-
}
|
100
|
-
}
|
101
|
-
end
|
102
|
-
|
103
|
-
def [](key)
|
104
|
-
@mon.synchronize {
|
105
|
-
puts "LOOKUP #{key}"
|
106
|
-
return super
|
107
|
-
}
|
108
|
-
end
|
109
|
-
|
110
|
-
end
|
111
|
-
|
112
|
-
# The SHash 'endpoint' resides in the App server
|
113
|
-
|
114
|
-
class SHash < Hash
|
115
|
-
attr :mon
|
116
|
-
|
117
|
-
# drbobject for this hash (local)
|
118
|
-
attr_accessor :ldrb
|
119
|
-
|
120
|
-
# drb for the cluster hash
|
121
|
-
attr_accessor :cdrb
|
122
|
-
|
123
|
-
# ldrb = local drb uri
|
124
|
-
# cdrb = cluster drb uri
|
125
|
-
|
126
|
-
def initialize(ldrb_uri = "druby://:9000", cdrb_uri = "druby://:8000")
|
127
|
-
@mon = Monitor.new
|
128
|
-
@ldrb_uri = ldrb_uri
|
129
|
-
@ldrb = DRb.start_service(ldrb_uri, self)
|
130
|
-
@cdrb = DRbObject.new(nil, cdrb_uri)
|
131
|
-
@cdrb.join(ldrb_uri)
|
132
|
-
end
|
133
|
-
|
134
|
-
alias_method :old_set, :[]=
|
135
|
-
|
136
|
-
#
|
137
|
-
#
|
138
|
-
def []=(key, value)
|
139
|
-
# store the value in the local hash
|
140
|
-
@mon.synchronize {
|
141
|
-
puts "LOCAL #{key} = #{value}"
|
142
|
-
old_set(key, value)
|
143
|
-
@cdrb.cluster_sync(key, value, @ldrb_uri)
|
144
|
-
}
|
145
|
-
end
|
146
|
-
|
147
|
-
# If the key is not found in the local hash, try the
|
148
|
-
# cluster hash.
|
149
|
-
#
|
150
|
-
def [](key)
|
151
|
-
@mon.synchronize {
|
152
|
-
unless value = super
|
153
|
-
value = @cdrb[key]
|
154
|
-
old_set(key, value)
|
155
|
-
end
|
156
|
-
return value
|
157
|
-
}
|
158
|
-
end
|
159
|
-
|
160
|
-
# Called by the cluster
|
161
|
-
#
|
162
|
-
def server_sync(key, value)
|
163
|
-
puts "SYNC #{key} = #{value}"
|
164
|
-
@mon.synchronize {
|
165
|
-
old_set(key, value)
|
166
|
-
}
|
167
|
-
end
|
168
|
-
|
169
|
-
end
|
170
|
-
|
171
|
-
# Cluster Last Modified Hash
|
172
|
-
|
173
|
-
class Clm < CHash
|
174
|
-
def [](key)
|
175
|
-
@mon.synchronize {
|
176
|
-
unless value = super
|
177
|
-
puts "INIT #{key}"
|
178
|
-
value = Time.now.to_i
|
179
|
-
old_set(key, value)
|
180
|
-
end
|
181
|
-
return value
|
182
|
-
}
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
|
-
# = Slm Server Last Modified Hash
|
187
|
-
|
188
|
-
class Slm < SHash
|
189
|
-
def set!(key, lm = nil)
|
190
|
-
lm = Time.now.to_i unless lm
|
191
|
-
self[key] = lm
|
192
|
-
return lm
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
def initialize(name = "Cluster")
|
197
|
-
super
|
198
|
-
end
|
199
|
-
|
200
|
-
def run
|
201
|
-
N::Cluster::Clm.new
|
202
|
-
DRb.start_service("druby://:8001", N::SessionManager.new)
|
203
|
-
|
204
|
-
while true
|
205
|
-
sleep(5000)
|
206
|
-
end
|
207
|
-
|
208
|
-
super
|
209
|
-
end
|
210
|
-
|
211
|
-
end
|
212
|
-
|
213
|
-
end
|
214
|
-
|
215
|
-
if $0 == __FILE__
|
216
|
-
require 'logger'
|
217
|
-
N::Cluster.new.exec()
|
218
|
-
end
|