コード例 #1
0
ファイル: CacheManager.java プロジェクト: jmsloat/RedReader
    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;
      }
    }
コード例 #2
0
ファイル: CacheManager.java プロジェクト: jmsloat/RedReader
 private void queueDownload(final CacheRequest request) {
   request.notifyDownloadNecessary();
   downloadQueue.add(request, CacheManager.this);
 }