class Rubbis::State
Attributes
channels[R]
clock[R]
data[R]
expires[R]
list_watches[R]
log[R]
pchannels[R]
psubscribers[R]
ready_keys[R]
subscribers[R]
watches[R]
Public Class Methods
blocking_command?(cmd)
click to toggle source
# File lib/rubbis/state.rb, line 41 def self.blocking_command?(cmd) @blocking_commands ||= Set.new( BlockingCommands.public_instance_methods.map(&:to_s) ) @blocking_commands.include?(cmd) end
new(clock)
click to toggle source
# File lib/rubbis/state.rb, line 20 def initialize(clock) @clock = clock @data = {} @log = [] @expires = {} @watches = {} @list_watches = {} @ready_keys = [] @channels = Hash.new { |hash, key| hash[key] = Set.new } @subscribers = Hash.new { |hash, key| hash[key] = Set.new } @pchannels = Hash.new { |hash, key| hash[key] = Set.new } @psubscribers = Hash.new { |hash, key| hash[key] = Set.new } end
valid_command?(cmd)
click to toggle source
# File lib/rubbis/state.rb, line 34 def self.valid_command?(cmd) @valid_commands ||= Set.new( StateCommands.public_instance_methods.map(&:to_s) ) @valid_commands.include?(cmd) || blocking_command?(cmd) end
Public Instance Methods
apply_command(client, cmd)
click to toggle source
# File lib/rubbis/state.rb, line 60 def apply_command(client, cmd) unless State.valid_command?(cmd[0]) return Error.unknown_cmd(cmd[0]) end if State.blocking_command?(cmd[0]) cmd << client end public_send *cmd end
channel_count(client)
click to toggle source
# File lib/rubbis/state.rb, line 56 def channel_count(client) channels[client].length + pchannels[client].length end
deserialize(bytes)
click to toggle source
# File lib/rubbis/state.rb, line 52 def deserialize(bytes) @data, @expires = *Marshal.load(bytes) end
serialize()
click to toggle source
# File lib/rubbis/state.rb, line 48 def serialize Marshal.dump [@data, @expires] end
subscribers_for(channel)
click to toggle source
# File lib/rubbis/state.rb, line 72 def subscribers_for(channel) ( subscribers[channel].to_a + psubscribers.select {|pattern, _| File.fnmatch(pattern, channel) }.values.map(&:to_a).flatten ) end
Private Instance Methods
touch!(key)
click to toggle source
# File lib/rubbis/state.rb, line 402 def touch!(key) ws = watches.delete(key) || [] ws.each(&:call) end