OSDN Git Service

* [shogi-server]
authorbeatles <beatles@b8c68f68-1e22-0410-b08e-880e1f8202b4>
Wed, 14 May 2008 01:22:33 +0000 (01:22 +0000)
committerbeatles <beatles@b8c68f68-1e22-0410-b08e-880e1f8202b4>
Wed, 14 May 2008 01:22:33 +0000 (01:22 +0000)
  - Floodgate's thread could cause an error when players.yaml was
    cleared by another program (mk_rate). This issue has been
    fixed.

changelog
shogi-server

index c8c14ea..2af377e 100644 (file)
--- a/changelog
+++ b/changelog
@@ -1,3 +1,10 @@
+2008-05-13 Daigo Moriwaki <daigo at debian dot org>
+
+       * [shogi-server]
+         - Floodgate's thread could cause an error when players.yaml was
+           cleared by another program (mk_rate). This issue has been 
+           fixed.
+
 2008-05-10 Daigo Moriwaki <daigo at debian dot org>
 
        * [shogi-server]
 2008-05-10 Daigo Moriwaki <daigo at debian dot org>
 
        * [shogi-server]
index 1f98f58..c98dcf7 100755 (executable)
@@ -135,15 +135,25 @@ class League
       end
     end
 
       end
     end
 
+    #
+    # trancaction=true means read only
+    #
+    def each_group(transaction=false)
+      @db.transaction(transaction) do
+        groups = @db["players"] || Hash.new
+        groups.each do |group, players|
+          yield group,players
+        end
+      end
+    end
+
     def load_player(player)
       return unless player.player_id
 
       hash = nil
     def load_player(player)
       return unless player.player_id
 
       hash = nil
-      @db.transaction(true) do
-        @db["players"].each do |group, players|
-          hash = players[player.player_id]
-          break if hash
-        end
+      each_group(true) do |group, players|
+        hash = players[player.player_id]
+        break if hash
       end
       return unless hash
 
       end
       return unless hash
 
@@ -160,25 +170,21 @@ class League
     def save(player)
       return unless player.player_id
 
     def save(player)
       return unless player.player_id
 
-      @db.transaction do
-        @db["players"].each do |group, players|
-          hash = players[player.player_id]
-          if hash
-            # write only this property. 
-            # the others are updated by ./mk_rate
-            hash['last_game_win'] = player.last_game_win
-            break
-          end
+      each_group do |group, players|
+        hash = players[player.player_id]
+        if hash
+          # write only this property. 
+          # the others are updated by ./mk_rate
+          hash['last_game_win'] = player.last_game_win
+          break
         end
       end
     end
 
     def get_players
       players = []
         end
       end
     end
 
     def get_players
       players = []
-      @db.transaction(true) do
-        @db["players"].each do |group, players_hash|
-          players << players_hash.keys
-        end
+      each_group(true) do |group, players_hash|
+        players << players_hash.keys
       end
       return players.flatten.collect do |player_id|
         p = BasicPlayer.new
       end
       return players.flatten.collect do |player_id|
         p = BasicPlayer.new
@@ -187,7 +193,7 @@ class League
         p
       end
     end
         p
       end
     end
-  end
+  end # class Persistent
 
   def initialize
     @mutex = Mutex.new # guard @players
 
   def initialize
     @mutex = Mutex.new # guard @players