Exemple #1
0
    private void handleRequest(final CacheRequest request) {

      if (request.url == null) {
        request.notifyFailure(
            RequestFailureType.MALFORMED_URL,
            new NullPointerException("URL was null"),
            null,
            "URL was null");
        return;
      }

      switch (request.downloadType) {
        case NEVER:
          {
            final LinkedList<CacheEntry> result =
                dbManager.select(request.url, request.user.username, request.requestSession);

            if (result.size() == 0) {
              request.notifyFailure(
                  RequestFailureType.CACHE_MISS,
                  null,
                  null,
                  "Could not find this data in the cache");

            } else {
              final CacheEntry entry = mostRecentFromList(result);
              handleCacheEntryFound(entry, request);
            }

            break;
          }

        case IF_NECESSARY:
          {
            final LinkedList<CacheEntry> result =
                dbManager.select(request.url, request.user.username, request.requestSession);

            if (result.size() == 0) {
              queueDownload(request);

            } else {
              final CacheEntry entry = mostRecentFromList(result);
              handleCacheEntryFound(entry, request);
            }

            break;
          }

        case FORCE:
          queueDownload(request);
          break;
      }
    }
Exemple #2
0
 private void queueDownload(final CacheRequest request) {
   request.notifyDownloadNecessary();
   downloadQueue.add(request, CacheManager.this);
 }