Package ca.jimr.gae.profiler.MiniProfiler

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


  }

  private static JsonToken createToken(final String disks, final String user,
      final float cost, String description) throws InvalidKeyException {

    Step step = MiniProfiler.step("API.createToken");
    try {

      // Current time and signing algorithm
      final Calendar cal = Calendar.getInstance();
      final HmacSHA256Signer signer = new HmacSHA256Signer(ISSUER, null,
          SIGNING_KEY.getBytes());

      // Configure JSON token
      final JsonToken token = new JsonToken(signer);
      token.setAudience("Google");
      token.setParam("typ", "google/payments/inapp/item/v1");
      token.setIssuedAt(new Instant(cal.getTimeInMillis()));
      token.setExpiration(new Instant(cal.getTimeInMillis() + 60000L));

      // Configure request object
      final JsonObject request = new JsonObject();
      request.addProperty("name", "Battle Disks");
      request.addProperty("description", description);
      request.addProperty("price", cost);
      request.addProperty("currencyCode", "USD");
      request.addProperty("sellerData", user);

      final JsonObject payload = token.getPayloadAsJsonObject();
      payload.add("request", request);

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


      step.close();
    }
  }

  private static String createUnitTest(final ScriptableObject table) {
    Step step = MiniProfiler.step("API.createUnitTest");
    try {
      // recordReplay
      if (table == null) {
        return "";
      }

      final StringBuilder unitTest = new StringBuilder("@Test \n");
      unitTest.append("public void replay").append(table.get("id"))
          .append("Round").append(table.get("round"))
          .append("() throws GameEngineException {\n");

      unitTest.append("API api = new API();\n");

      unitTest.append("ScriptableObject table=");

      final NativeArray actions = (NativeArray) table.get("actions");
      for (final Object a : actions) {
        unitTest.append("api.").append(
            ((ScriptableObject) a).get("method"));

        if (((ScriptableObject) a).get("method") != "createTable") {
          unitTest.append("(table,");
        }
        final NativeArray args = (NativeArray) ((ScriptableObject) a)
            .get("arguments");
        for (final Object argO : args.toArray()) {
          // test.append("\"");
          StringBuilder arg = toString(argO);
          // if string does not start with a quote
          if (!arg.toString().startsWith("\"")) {
            final String replaceAll = arg.toString().replace("\"",
                "\\\"");
            arg = new StringBuilder("\"");
            arg.append(replaceAll);
            arg.append("\"");
          }
          unitTest.append(arg);
          // test.append("\"");
          unitTest.append(",");
        }
        if (args.getIds().length > 0) {
          unitTest.replace(unitTest.length() - 1, unitTest.length(),
              "");
        }
        unitTest.append(");\n");

      }

      unitTest.append("}");

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

      step.close();
    }
  }

  private static String deserialize(final String tokenString) {
    Step step = MiniProfiler.step("API.deserialize");
    try {

      final String[] pieces = splitTokenString(tokenString);
      final String jwtPayloadSegment = pieces[1];
      final JsonParser parser = new JsonParser();
      final String newStringUtf8 = StringUtils.newStringUtf8(Base64
          .decodeBase64(jwtPayloadSegment.getBytes()));
      final JsonElement payload = parser.parse(newStringUtf8);

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

    }
  }

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

      return getLong(sd);

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

      step.close();
    }
  }

  private static Integer getInteger(final Object o) {
    Step step = MiniProfiler.step("API.getInteger");
    try {
      if (o instanceof Integer) {
        return (Integer) o;
      } else if (o instanceof Double) {
        return (int) (double) (Double) o;
      }
      return null;
    } finally {
      step.close();
    }
  }
View Full Code Here

      step.close();
    }
  }

  private static Long getLong(final Object o) {
    Step step = MiniProfiler.step("API.getLong");
    try {
      if (o instanceof Long) {
        return (Long) o;
      } else if (o instanceof Double) {
        return (long) ((Double) o).longValue();
      } else if (o instanceof String) {
        return Long.parseLong((String) o);
      }
      return null;
    } finally {
      step.close();
    }
  }
View Full Code Here

    }
  }

  private static Object getParameter(final String name,
      final Map<String, Object> parameters) {
    Step step = MiniProfiler.step("API.getParameter");
    try {
      String s = null;
      final Object object = parameters.get(name);
      if (object instanceof Blob) {
        return object;
      } else if (object instanceof BlobKey) {
        return ((BlobKey) object).getKeyString();
      } else if (object != null && object instanceof Object[]) {
        if (((Object[]) object).length > 0) {
          s = (String) ((Object[]) object)[0];
          s = s.replace("!", "");
        }
      }
      return s;
    } finally {
      step.close();
    }
  }
View Full Code Here

      step.close();
    }
  }

  private static Long getTableId(final Map<String, Object> parameters) {
    Step step = MiniProfiler.step("API.getTableId");
    try {
      final String s = (String) getParameter("id", parameters);

      Long parseLong = null;
      if (s != null && !s.equals("") && !s.equals("null")) {
        parseLong = Long.parseLong(s.replace("!", "").replace("#", ""));
      }
      return parseLong;
    } finally {
      step.close();
    }
  }
View Full Code Here

      step.close();
    }
  }

  protected static String getUser(final HttpServletRequest req) {
    Step step = MiniProfiler.step("API.getUser");
    try {
      final User currentUser = UserServiceFactory.getUserService()
          .getCurrentUser();
      return currentUser != null ? currentUser.getEmail() : null;
    } finally {
      step.close();
    }
  }
View Full Code Here

    }
  }

  private static ZipInputStream getZipFile(final BlobKey csvBlobKey)
      throws FileNotFoundException, IOException {
    Step step = MiniProfiler.step("API.getZipFile");

    try {

      final BlobstoreService blobstoreService = BlobstoreServiceFactory
          .getBlobstoreService();

      BlobInfo info = new BlobInfoFactory().loadBlobInfo(csvBlobKey);

      byte[] bytes = blobstoreService.fetchData(csvBlobKey, 0,
          info.getSize());

      final ZipInputStream zipIn = new ZipInputStream(
          new ByteArrayInputStream(bytes));

      return zipIn;
    } 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.