Package ca.jimr.gae.profiler.MiniProfiler

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


      step.close();
    }
  }

  private List<Entity> getLeaderboard() {
    Step step = MiniProfiler.step("API.getLeaderboard");
    try {
      final Query query = new Query("Player");

      query.addSort("rating", SortDirection.DESCENDING);

      final DatastoreService datastore = DatastoreServiceFactory
          .getDatastoreService();
      final PreparedQuery pq = datastore.prepare(query);
      final List<Entity> entList = pq.asList(FetchOptions.Builder
          .withDefaults());
      return entList;
    } finally {
      step.close();
    }
  }
View Full Code Here


      step.close();
    }
  }

  private Long getMementoId(final Map<String, Object> parameters) {
    Step step = MiniProfiler.step("API.getOpenAndActiveTables");
    try {
      Object parameter = API.getParameter("mementoId", parameters);
      Long mementoId = -1L;

      if (parameter != null) {
        mementoId = Long.parseLong((String) parameter);
        ;
      }
      return mementoId;
    } finally {
      step.close();
    }
  }
View Full Code Here

    }
  }

  private PreparedQuery getMementos(final Long tableId, final long mementoId) {
    // TODO 0.1 need to try to go to memcache for this first somehow
    Step step = MiniProfiler.step("API.getMementos(" + tableId + ","
        + mementoId + ")");
    try {

      Filter tableIdFilter = new FilterPredicate("tableId",
          FilterOperator.EQUAL, tableId);

      Filter mementoIdFilter = new FilterPredicate("mementoId",
          FilterOperator.GREATER_THAN, mementoId);

      Filter tableIdAndMementoIdFilter = new CompositeFilter(
          CompositeFilterOperator.AND, Arrays.asList(tableIdFilter,
              mementoIdFilter));

      Query q = new Query("TableMemento")
          .setFilter(tableIdAndMementoIdFilter);
      DatastoreService datastore = DatastoreServiceFactory
          .getDatastoreService();

      PreparedQuery pq = datastore.prepare(q);
      return pq;
    } finally {
      step.close();
    }
  }
View Full Code Here

    }
  }

  private String getName(final ScriptableObject object)
      throws GameEngineException {
    Step step = MiniProfiler.step("API.getName");
    try {
      final Object sd = ge.invoke(object, "getName");

      if (sd == null
          || sd.getClass() == org.mozilla.javascript.Undefined.class)
        return null;
      else if (sd.getClass() == String.class)
        return (String) sd;

      else {
        return null;
      }
    } finally {
      step.close();
    }
  }
View Full Code Here

      step.close();
    }
  }

  private String getOpenAndActiveTables(String playerName) {
    Step step = MiniProfiler.step("API.getOpenAndActiveTables");
    try {
      Filter playerFilter = new FilterPredicate("players",
          FilterOperator.EQUAL, playerName);

      Filter activeSegmentFilter = new FilterPredicate("segment",
          FilterOperator.IN, ACTIVE_SEGMENTS);

      Filter openSegmentFilter = new FilterPredicate("segment",
          FilterOperator.IN, OPEN_SEGMENTS);

      Filter segmentFilter = new CompositeFilter(
          CompositeFilterOperator.OR, Arrays.asList(
              activeSegmentFilter, openSegmentFilter));

      Filter segmentAndPlayerFilter = new CompositeFilter(
          CompositeFilterOperator.AND, Arrays.asList(playerFilter,
              segmentFilter));

      Query q = new Query("Table").setFilter(segmentAndPlayerFilter);
      DatastoreService datastore = DatastoreServiceFactory
          .getDatastoreService();

      PreparedQuery pq = datastore.prepare(q);

      StringBuilder sb = tablesToJSON(pq);

      return sb.toString();
    } finally {
      step.close();
    }
  }
View Full Code Here

      step.close();
    }
  }

  private String getOpenTables() {
    Step step = MiniProfiler.step("API.getOpenTables");
    try {
      Filter segmentFilter = new FilterPredicate("segment",
          FilterOperator.IN, OPEN_SEGMENTS);

      Query q = new Query("Table").setFilter(segmentFilter);
      DatastoreService datastore = DatastoreServiceFactory
          .getDatastoreService();

      PreparedQuery pq = datastore.prepare(q);

      StringBuilder sb = tablesToJSON(pq);
      return sb.toString();
    } finally {
      step.close();
    }
  }
View Full Code Here

    }
  }

  private ScriptableObject getPlayer(final String username)
      throws GameEngineException {
    Step step = MiniProfiler.step("API.getPlayer");
    try {
      ScriptableObject player = null;
      if (username != null && !username.equals("")) {
        final HashMap<String, Object> hashMap = ge.persistence.get(
            "Player", username);
        // handle player being null
        if (!hashMap.isEmpty()) {
          player = (ScriptableObject) ge.invoke("Player",
              new String[] { username });
          final String json = (String) hashMap.get("json");
          update(player, ge.parse(json));
        }
      }
      return player;
    } finally {
      step.close();
    }
  }
View Full Code Here

   * @return Table.js object with additional property named json
   * @throws GameEngineException
   */
  private ScriptableObject getTable(final long tableId, final long mementoId)
      throws GameEngineException {
    Step step = MiniProfiler.step("API.getTable");
    try {
      final HashMap<String, Object> hashMap = ge.persistence.get("Table",
          tableId);

      final ScriptableObject table = createTable();

      String json = (String) hashMap.get("json");
      // convert the json string to an object
      Object jsonObject = ge.parse(json);
      restoreTable(table, jsonObject);

      Integer currentMementoId = (Integer) table.get("mementoId");
      if (currentMementoId == null) {
        currentMementoId = -1;
      }

      // if mementoId is greater then the tables mementoId
      if (mementoId < currentMementoId) {
        // get the mementos that are greater then mementoId
        PreparedQuery mementos = getMementos(tableId, mementoId);
        addMementos(table, mementos);
        // redo the json attribute
        json = stringify(table);
        // ScriptableObject.putProperty(table, "json", json2);
      }
      table.put("json", table, json);

      return table;
    } finally {
      step.close();
    }
  }
View Full Code Here

  // this one takes a ScriptableObject of disk objects
  protected ScriptableObject join(final ScriptableObject table,
      final ScriptableObject player, final String armyName)
      throws GameEngineException {
    Step step = MiniProfiler
        .step("API.join(ScriptableObject,ScriptableObject,ScriptableObject)");

    try {

      // Table.join returns an object that indicates success or failure
      // and failure messages
      ScriptableObject joinResult = (ScriptableObject) ge.invoke(table,
          "join", new Object[] { player, armyName });

      // don't save armies and disks
      ScriptableObject.deleteProperty(player, "armies");
      ScriptableObject.deleteProperty(player, "cart");
      ScriptableObject.deleteProperty(player, "disks");
      ScriptableObject.deleteProperty(player, "diskLocations");

      saveTable(table);

      // return joinResult
      return joinResult;
    } finally {
      step.close();
    }
  }
View Full Code Here

  private void fireMissiles(final ScriptableObject table,
      final String playerName, final String diskNumber,
      final String pointString, final String missileName)
      throws GameEngineException {

    Step step = MiniProfiler.step("API.fireMissiles");
    try {
      final ScriptableObject point = ge.execute("_=" + pointString);

      ScriptableObject missile = this.getDisk(missileName);

      ge.invoke(table, "fireMissiles", new Object[] { playerName,
          diskNumber, point, missile });
      saveTable(table);

    } catch (GameEngineException gee) {
      // GameEngineException
      mailUnitTest(createUnitTest(table));
      gee.printStackTrace();
      throw gee;
    } 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.