class Nestene::Actor::AutonStorage
Public Class Methods
new(auton_id, storage)
click to toggle source
# File lib/nestene/actor/auton_storage.rb, line 13 def initialize(auton_id, storage) @auton_id = auton_id @storage = storage end
Public Instance Methods
create(type)
click to toggle source
# File lib/nestene/actor/auton_storage.rb, line 23 def create type state = AutonState.new state.type = type instance = Nestene::class_from_string(type).new state.serialized = instance.to_structure @storage.store(@auton_id,state.to_structure) publish('state_update', @auton_id, state) rescue Exception => e abort e end
get()
click to toggle source
# File lib/nestene/actor/auton_storage.rb, line 34 def get structure = @storage.load(@auton_id) structure ? AutonState.from_structure(structure) : nil end
publish_initial_state()
click to toggle source
# File lib/nestene/actor/auton_storage.rb, line 18 def publish_initial_state state = get publish('state_update', @auton_id, state) if state end
shutdown()
click to toggle source
# File lib/nestene/actor/auton_storage.rb, line 39 def shutdown Celluloid::Actor.delete("storage:%s" % @auton_id) @storage.delete(@auton_id) publish('state_update', @auton_id, nil) terminate end
update(&block)
click to toggle source
# File lib/nestene/actor/auton_storage.rb, line 46 def update &block before = @storage.load(@auton_id) state = AutonState.from_structure(@storage.load(@auton_id)) result = block.call(state) after = state.to_structure @storage.store(@auton_id,after) publish('state_update', @auton_id, state) if before != after result rescue Exception => e abort e end