Class: N::Cluster::SHash
Overview
The SHash ‘endpoint’ resides in the App server
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cdrb ⇒ Object
drb for the cluster hash.
-
#ldrb ⇒ Object
drbobject for this hash (local).
-
#mon ⇒ Object
readonly
Returns the value of attribute mon.
Instance Method Summary collapse
-
#[](key) ⇒ Object
If the key is not found in the local hash, try the cluster hash.
- #[]=(key, value) ⇒ Object
-
#initialize(ldrb_uri = "druby://:9000", cdrb_uri = "druby://:8000") ⇒ SHash
constructor
ldrb = local drb uri cdrb = cluster drb uri.
- #old_set ⇒ Object
-
#server_sync(key, value) ⇒ Object
Called by the cluster.
Constructor Details
#initialize(ldrb_uri = "druby://:9000", cdrb_uri = "druby://:8000") ⇒ SHash
ldrb = local drb uri cdrb = cluster drb uri
126 127 128 129 130 131 132 |
# File 'lib/nitro/cluster.rb', line 126 def initialize(ldrb_uri = "druby://:9000", cdrb_uri = "druby://:8000") @mon = Monitor.new @ldrb_uri = ldrb_uri @ldrb = DRb.start_service(ldrb_uri, self) @cdrb = DRbObject.new(nil, cdrb_uri) @cdrb.join(ldrb_uri) end |
Instance Attribute Details
#cdrb ⇒ Object
drb for the cluster hash
121 122 123 |
# File 'lib/nitro/cluster.rb', line 121 def cdrb @cdrb end |
#ldrb ⇒ Object
drbobject for this hash (local)
118 119 120 |
# File 'lib/nitro/cluster.rb', line 118 def ldrb @ldrb end |
#mon ⇒ Object (readonly)
Returns the value of attribute mon.
115 116 117 |
# File 'lib/nitro/cluster.rb', line 115 def mon @mon end |
Instance Method Details
#[](key) ⇒ Object
If the key is not found in the local hash, try the cluster hash.
150 151 152 153 154 155 156 157 158 |
# File 'lib/nitro/cluster.rb', line 150 def [](key) @mon.synchronize { unless value = super value = @cdrb[key] old_set(key, value) end return value } end |
#[]=(key, value) ⇒ Object
138 139 140 141 142 143 144 145 |
# File 'lib/nitro/cluster.rb', line 138 def []=(key, value) # store the value in the local hash @mon.synchronize { puts "LOCAL #{key} = #{value}" old_set(key, value) @cdrb.cluster_sync(key, value, @ldrb_uri) } end |
#old_set ⇒ Object
134 |
# File 'lib/nitro/cluster.rb', line 134 alias_method :old_set, :[]= |
#server_sync(key, value) ⇒ Object
Called by the cluster
162 163 164 165 166 167 |
# File 'lib/nitro/cluster.rb', line 162 def server_sync(key, value) puts "SYNC #{key} = #{value}" @mon.synchronize { old_set(key, value) } end |