Package ca.jimr.gae.profiler.MiniProfiler

Examples of ca.jimr.gae.profiler.MiniProfiler.Step


    }
  }

  private void saveTable(final ScriptableObject table)
      throws GameEngineException {
    Step step = MiniProfiler.step("API.saveTable");
    try {
      Object id = table.get("id");

      if (id == null) {
        Entity result = ge.persistence.save("Table");
        // id = result.getKey().getId();
        setId(table, result.getKey().getId());
        id = result.getKey().getId();
      }

      saveMementos(table);

      ScriptableObject.deleteProperty(table, "mementos");
      // System.out.print("mementosRemoved:" + mementosRemoved);

      HashMap<String, Object> properties = new HashMap<String, Object>();

      // json
      String json = stringify(table, ge.execute("[\"json\"]"));
      properties.put("json", json);

      // players
      properties.put("players",
          ((NativeArray) table.get("playerOrder")).toArray());

      // currentplayer
      properties.put("currentPlayer", ((ScriptableObject) table
          .get("memento")).get("currentPlayer"));

      // segment
      properties.put("segment",
          ((ScriptableObject) table.get("memento")).get("segment"));

      properties.put("mementoId", table.get("mementoId"));

      ge.persistence.save("Table", getId(table), properties);
      table.put("json", table, json);
    } finally {
      step.close();
    }
  }
View Full Code Here


  }

  private void setAttackee(final ScriptableObject table, final String user,
      final String attacker, final String attackee)
      throws GameEngineException {
    Step step = MiniProfiler.step("API.setAttackee");
    try {
      ge.invoke(table, "setAttackee", new Object[] { user, attacker,
          attackee });
      saveTable(table);

      // see if someone won
      if (((ScriptableObject) table.get("memento")).get("segment") == "FINISHED") {
        updateRatings(table);
      }
    } finally {
      step.close();
    }
  }
View Full Code Here

  }

  protected void setDefendee(final ScriptableObject table, final String user,
      final String defender, final String defendee)
      throws GameEngineException {
    Step step = MiniProfiler.step("API.setDefendee");
    try {
      ge.invoke(table, "setDefendee", new Object[] { user, defender,
          defendee });

      saveTable(table);

      // see if someone won
      if (((ScriptableObject) table.get("memento")).get("segment") == "FINISHED") {
        updateRatings(table);
      }
    } finally {
      step.close();
    }
  }
View Full Code Here

    }
  }

  private void setId(final ScriptableObject object, final long id)
      throws GameEngineException {
    Step step = MiniProfiler.step("API.setId");
    try {
      ge.invoke(object, "setId", new Object[] { id });
    } finally {
      step.close();
    }
  }
View Full Code Here

    }
  }

  private void setName(final ScriptableObject object, final String name)
      throws GameEngineException {
    Step step = MiniProfiler.step("API.setName");
    try {
      ge.invoke(object, "setName", new Object[] { name });
    } finally {
      step.close();
    }
  }
View Full Code Here

    }
  }

  private String stringify(final ScriptableObject object)
      throws GameEngineException {
    Step step = MiniProfiler.step("API.stringify(ScriptableObject)");
    try {
      return ge.stringify(object);
    } finally {
      step.close();
    }
  }
View Full Code Here

    }
  }

  private String stringify(final ScriptableObject object,
      ScriptableObject excludedKeys) throws GameEngineException {
    Step step = MiniProfiler
        .step("API.stringify(ScriptableObject,String[])");
    try {
      String json = null;
      if (object != null) {

        json = (String) ge.invoke(object, "stringify",
            new Object[] { excludedKeys });
      }
      return json;
    } finally {
      step.close();
    }
  }
View Full Code Here

      step.close();
    }
  }

  private StringBuilder tablesToJSON(PreparedQuery pq) {
    Step step = MiniProfiler.step("API.tablesToJSON");
    try {
      StringBuilder sb = new StringBuilder("[");

      for (Entity result : pq.asIterable()) {
        String json = ((Text) result.getProperty("json")).getValue();

        sb.append(json);
        sb.append(",");

      }
      if (pq.countEntities(FetchOptions.Builder.withDefaults()) > 0) {
        sb.replace(sb.length() - 1, sb.length(), "");
      }
      sb.append("]");
      return sb;
    } finally {
      step.close();
    }
  }
View Full Code Here

    }
  }

  private Object update(final ScriptableObject dest, final Object source)
      throws GameEngineException {
    Step step = MiniProfiler.step("API.update");
    try {
      return ge.invoke(dest, "update", new Object[] { source });
    } finally {
      step.close();
    }
  }
View Full Code Here

    }
  }

  protected void updateRatings(ScriptableObject table)
      throws GameEngineException {
    Step step = MiniProfiler.step("API.updateRatings");
    try {
      // loop over all the players in the table
      ScriptableObject players = (ScriptableObject) table.get("players");

      List<Object> playerNames = Arrays.asList(players.getIds());
      for (Object playerName : playerNames) {
        ScriptableObject player = getPlayer((String) playerName);
        Double adjustment = (Double) ge.invoke(table,
            "getRatingAdjustment", new Object[] { playerName });

        Object object = player.get("rating");
        if (object == null || !(object instanceof Number)) {
          object = new Double(0);
        }
        Double rating = ((Number) object).doubleValue();
        rating += adjustment;

        ge.invoke(player, "setRating", new Object[] { rating });
        savePlayer(player);
      }
    } finally {
      step.close();
    }
  }
View Full Code Here

TOP

Related Classes of ca.jimr.gae.profiler.MiniProfiler.Step

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.