Class: GameMachine::Commands::DatastoreCommands

Inherits:
Object
  • Object
show all
Defined in:
server/lib/game_machine/commands/datastore_commands.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDatastoreCommands


6
7
8
# File 'server/lib/game_machine/commands/datastore_commands.rb', line 6

def initialize
  @store = DbLib::Store.get_instance
end

Instance Attribute Details

#storeObject (readonly)

Returns the value of attribute store


5
6
7
# File 'server/lib/game_machine/commands/datastore_commands.rb', line 5

def store
  @store
end

Instance Method Details

#call_dbproc(name, current_entity_id, update_entity, blocking = true) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
25
# File 'server/lib/game_machine/commands/datastore_commands.rb', line 14

def call_dbproc(name,current_entity_id,update_entity,blocking=true)
  ref = ObjectDb.find_distributed(current_entity_id)
  message = MessageLib::ObjectdbUpdate.new.
    set_current_entity_id(current_entity_id).
    set_update_method(name).
    set_update_entity(update_entity)
  if blocking
    ref.ask(message, 100)
  else
    ref.tell(message)
  end
end

#define_dbproc(name, &blk) ⇒ Object


10
11
12
# File 'server/lib/game_machine/commands/datastore_commands.rb', line 10

def define_dbproc(name,&blk)
  ObjectDb.dbprocs[name] = blk
end

#delete(entity_id) ⇒ Object


49
50
51
52
# File 'server/lib/game_machine/commands/datastore_commands.rb', line 49

def delete(entity_id)
  ref = Actor::Base.find_distributed(entity_id,'object_store')
  ref.tell(MessageLib::ObjectdbDel.new.set_entity_id(entity_id))
end

#delete!(entity_id) ⇒ Object


35
36
37
# File 'server/lib/game_machine/commands/datastore_commands.rb', line 35

def delete!(entity_id)
  store.delete(entity_id)
end

#get(entity_id, timeout = 1000) ⇒ Object


44
45
46
47
# File 'server/lib/game_machine/commands/datastore_commands.rb', line 44

def get(entity_id,timeout=1000)
  ref = Actor::Base.find_distributed(entity_id,'object_store')
  ref.ask(MessageLib::ObjectdbGet.new.set_entity_id(entity_id), timeout)
end

#get!(entity_id) ⇒ Object


31
32
33
# File 'server/lib/game_machine/commands/datastore_commands.rb', line 31

def get!(entity_id)
  store.get(entity_id)
end

#put(entity) ⇒ Object


39
40
41
42
# File 'server/lib/game_machine/commands/datastore_commands.rb', line 39

def put(entity)
  ref = Actor::Base.find_distributed(entity.get_id,'object_store')
  ref.tell(MessageLib::ObjectdbPut.new.set_entity(entity))
end

#put!(entity) ⇒ Object


27
28
29
# File 'server/lib/game_machine/commands/datastore_commands.rb', line 27

def put!(entity)
  store.set(entity.id,entity)
end