Class: Archipelago::Hashish::DumpHashish

Inherits:
Object
  • Object
show all
Includes:
CachedHashish
Defined in:
lib/archipelago/hashish.rb

Overview

An Archipelago::Dump network backed CachedHashish.

Instance Method Summary collapse

Methods included from CachedHashish

#[], #[]=, #delete, #first, #forget, #get_deep_clone, #get_from_db, #include?, #initialize_cached_hashish, #last, #store_if_changed, #timestamp, #without_lock, #write_to_db

Methods included from Current::Synchronized

#lock_on, #mon_check_owner, #synchronize_on, #unlock_on

Constructor Details

#initialize(officer) ⇒ DumpHashish

Initialize a new DumpHashish with the given officer to find Dumps.



300
301
302
303
304
305
# File 'lib/archipelago/hashish.rb', line 300

def initialize(officer)
  super()
  initialize_cached_hashish
  @officer = officer
  @hash_by_key = {}
end

Instance Method Details

#changed?(serialized_key, serialized_value) ⇒ Boolean



306
307
308
# File 'lib/archipelago/hashish.rb', line 306

def changed?(serialized_key, serialized_value)
  return (old_hash = @hash_by_key[serialized_key]) && old_hash != Digest::SHA1.hexdigest(serialized_value)
end

#close!Object



317
318
# File 'lib/archipelago/hashish.rb', line 317

def close!
end

#db_include?(key) ⇒ Boolean



322
323
324
# File 'lib/archipelago/hashish.rb', line 322

def db_include?(key)
  return !@officer[officer_key(Marshal.dump(key), "content")].nil?
end

#do_delete_from_persistence(serialized_key) ⇒ Object



330
331
332
333
334
# File 'lib/archipelago/hashish.rb', line 330

def do_delete_from_persistence(serialized_key)
  @officer.delete(officer_key(serialized_key, "content"))
  @officer.delete(officer_key(serialized_key, "timestamp"))
  @hash_by_key[serialized_key] = Digest::SHA1.hexdigest(serialized_value)
end

#do_get_from_db(serialized_key) ⇒ Object



325
326
327
328
329
# File 'lib/archipelago/hashish.rb', line 325

def do_get_from_db(serialized_key)
  serialized_value = @officer[officer_key(serialized_key, "content")]
  @hash_by_key[serialized_key] = Digest::SHA1.hexdigest(serialized_value) if serialized_value
  return serialized_value
end

#do_get_timestamp_from_db(serialized_key) ⇒ Object



309
310
311
# File 'lib/archipelago/hashish.rb', line 309

def do_get_timestamp_from_db(serialized_key)
  return @officer[officer_key(serialized_key, "timestamp")]
end

#do_write_to_db(key, serialized_key, serialized_value, now) ⇒ Object



312
313
314
315
316
# File 'lib/archipelago/hashish.rb', line 312

def do_write_to_db(key, serialized_key, serialized_value, now)
  @officer[officer_key(serialized_key, "content")] = serialized_value
  @officer[officer_key(serialized_key, "timestamp")] = Marshal.dump(now)
  @hash_by_key[serialized_key] = Digest::SHA1.hexdigest(serialized_value)
end

#each(callable) ⇒ Object



335
336
337
# File 'lib/archipelago/hashish.rb', line 335

def each(callable)
  raise "You have to implement me!"
end

#officer_key(serialized_key, space) ⇒ Object



319
320
321
# File 'lib/archipelago/hashish.rb', line 319

def officer_key(serialized_key, space)
  Digest::SHA1.hexdigest("Archipelago::Hashish::DumpHashish:#{space}:#{serialized_key}")
end