Ejemplo n.º 1
0
 /**
  * Stop the time for this event. If the event haven't been started yet, the start and stop time
  * will be the same.
  */
 public void stop() {
   if (isActive()) {
     mStop = mClock.now();
   } else if (!isStarted()) {
     long now = mClock.now();
     mStart = now;
     mStop = now;
   }
   mStopped = true;
 }
 private Date newestDateToDelete() {
   GregorianCalendar calendar = new GregorianCalendar();
   calendar.setTime(clock.now());
   calendar.add(Calendar.DAY_OF_YEAR, -settings.getRequestLogCleanupMaxAgeDays());
   Date newestDateToDelete = calendar.getTime();
   return newestDateToDelete;
 }
Ejemplo n.º 3
0
  // This method is called via a global method defined in AuthImpl.register()
  @SuppressWarnings("unused")
  void finish(String hash) {
    TokenInfo info = new TokenInfo();
    String error = null;
    String errorDesc = "";
    String errorUri = "";

    // Iterate over keys and values in the string hash value to find relevant
    // information like the access token or an error message. The string will be
    // in the form of: #key1=val1&key2=val2&key3=val3 (etc.)
    int idx = 1;
    while (idx < hash.length() - 1) {
      // Grab the next key (between start and '=')
      int nextEq = hash.indexOf('=', idx);
      if (nextEq < 0) {
        break;
      }
      String key = hash.substring(idx, nextEq);

      // Grab the next value (between '=' and '&')
      int nextAmp = hash.indexOf('&', nextEq);
      nextAmp = nextAmp < 0 ? hash.length() : nextAmp;
      String val = hash.substring(nextEq + 1, nextAmp);

      // Start looking from here from now on.
      idx = nextAmp + 1;

      // Store relevant values to be used later.
      if (key.equals("access_token")) {
        info.accessToken = val;
      } else if (key.equals("expires_in")) {
        // expires_in is seconds, convert to milliseconds and add to now
        Double expiresIn = Double.valueOf(val) * 1000;
        info.expires = String.valueOf(clock.now() + expiresIn);
      } else if (key.equals("error")) {
        error = val;
      } else if (key.equals("error_description")) {
        errorDesc = " (" + val + ")";
      } else if (key.equals("error_uri")) {
        errorUri = "; see: " + val;
      }
    }

    if (error != null) {
      lastCallback.onFailure(
          new RuntimeException("Error from provider: " + error + errorDesc + errorUri));
    } else if (info.accessToken == null) {
      lastCallback.onFailure(new RuntimeException("Could not find access_token in hash " + hash));
    } else {
      setToken(lastRequest, info);
      lastCallback.onSuccess(info.accessToken);
    }
  }
  @Override
  public Response intercept(Chain chain) throws IOException {
    Request request = chain.request();

    monitor.onUpdate(request, null);

    Response response = null;
    Throwable throwable = null;
    try {
      response = chain.proceed(request);
    } catch (IOException | RuntimeException e) {
      throwable = e;
      throw e;
    } finally {
      monitor.onUpdate(request, new Result(clock.now(), response, throwable));
    }

    return response;
  }
Ejemplo n.º 5
0
 /**
  * Start the timer for this event. This method can be called multiple times, only the first time
  * will set the start time.
  */
 public void start() {
   if (!isStarted()) {
     mStart = mClock.now();
   }
   mStarted = true;
 }
Ejemplo n.º 6
0
 /**
  * Get the absolute duration of this event, this does not subtract duration of sub-events. If the
  * event is still active, the duration up till this point in time is returned, else it's the
  * duration from {@link #start()} till {@link #stop()}'
  *
  * @return The absolute duration of this event
  */
 public long getDurationAbsolute() {
   return (isActive() ? mClock.now() : mStop) - mStart;
 }
Ejemplo n.º 7
0
 /*
  * @param req The authentication request of which to request the expiration
  *        status.
  * @return The number of milliseconds until the token expires, or negative
  *         infinity if no token was found.
  */
 public double expiresIn(AuthRequest req) {
   String val = tokenStore.get(req.asString());
   return val == null
       ? Double.NEGATIVE_INFINITY
       : Double.valueOf(TokenInfo.fromString(val).expires) - clock.now();
 }
Ejemplo n.º 8
0
 /** Returns whether or not the token will be expiring within the next ten minutes. */
 boolean expiringSoon(TokenInfo info) {
   // TODO(jasonhall): Consider varying the definition of "soon" based on the
   // original expires_in value (e.g., "soon" = 1/10th of the total time before
   // it's expired).
   return Double.valueOf(info.expires) < (clock.now() + TEN_MINUTES);
 }
 public Instant now() {
   return clock.now();
 }