Package com.hbasebook.hush.model

Examples of com.hbasebook.hush.model.ShortUrl


      // otherwise assume it is a short Id
      ResourceManager rm = ResourceManager.getInstance();
      boolean isQrCode = uri.endsWith(QR_EXTENSION);
      String shortId = isQrCode ? uri.substring(1, uri.length() -
        QR_EXTENSION.length()) : uri.substring(1);
      ShortUrl surl = rm.getUrlManager().getShortUrl(shortId);
      if (surl == null) {
        // if the short Id was bogus show a "shush" (our fail whale)
        httpResponse.sendError(404);
      } else if (isQrCode) {
        // show QRCode if requested
        sendQRCode(httpResponse, surl.getLongUrl());
      } else {
        // increment counters and redirect!
        rm.getCounters().incrementUsage(shortId, new RequestInfo(httpRequest));
        String refShortId = surl.getRefShortId();
        if (refShortId != null) {
          // increment the aggregate link
          rm.getCounters().incrementUsage(refShortId,
            new RequestInfo(httpRequest));
        }
        httpResponse.sendRedirect(surl.getLongUrl());
      }
    }
  }
View Full Code Here


  private void initializeAdminStats() throws IOException {
    Map<RequestInfo.InfoName, String> props =
      new HashMap<RequestInfo.InfoName, String>();
    props.put(RequestInfo.InfoName.RemoteAddr, getRandomIp());
    RequestInfo info = new RequestInfo(props);
    ShortUrl shortUrl = rm.getUrlManager().shorten(
      new URL("http://hbasebook.com"), "admin", info);
    Calendar startDate = Calendar.getInstance();
    startDate.set(2011, 1, 1);
    Calendar endDate = Calendar.getInstance();
    endDate.setTime(new Date());
    while (startDate.before(endDate)) {
      props.put(RequestInfo.InfoName.RemoteAddr, getRandomIp());
      int count = RANDOM.nextInt(200);
      rm.getCounters().incrementUsage(shortUrl.getId(), info,
        count, startDate.getTime());
      if (shortUrl.getRefShortId() != null) {
        rm.getCounters().incrementUsage(shortUrl.getRefShortId(), info,
          count, startDate.getTime());
      }
      startDate.add(Calendar.DATE, 1);
    }
    LOG.info("Admin statistics initialized.");
View Full Code Here

    String shortId = generateShortId();
    String domain = rm.getDomainManager().shorten(url.getHost());
    String urlString = url.toString();
    String refShortId = getReferenceShortId(domain, urlString, username);

    ShortUrl shortUrl;
    if (refShortId != null && UserManager.isAnonymous(username)) {
      // no need to create a new link, just look up an existing one
      shortUrl = getShortUrl(refShortId);
      createUserShortUrl(username, refShortId);
    } else {
      shortUrl = new ShortUrl(shortId, domain, urlString, refShortId, username);
      createShortUrl(shortUrl);
      createUserShortUrl(username, shortId);
      rm.getCounters().incrementUsage(shortId, info, 0L);
    }
    return shortUrl;
View Full Code Here

      LongUrlTable.URL, null, put);
    String shortId = null;
    // check if we added a new URL, if so assign an Id subsequently
    if (hasPut) {
      shortId = generateShortId();
      createShortUrl(new ShortUrl(shortId, domain, url, null, username));
      put.add(LongUrlTable.DATA_FAMILY, LongUrlTable.SHORT_ID,
        Bytes.toBytes(shortId));
      table.put(put);
      table.flushCommits();
    }
View Full Code Here

      ShortUrlTable.USER_ID));
    long clicks = Bytes.toLong(result.getValue(ShortUrlTable.DATA_FAMILY,
      ShortUrlTable.CLICKS));

    rm.putTable(table);
    return new ShortUrl(shortId, domain, url, refShortId, user, clicks);
  }
View Full Code Here

TOP

Related Classes of com.hbasebook.hush.model.ShortUrl

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.