@Override public E next() throws IOException { makeRequestIfNeeded(); if (entries == null) { throw new NoSuchElementException(); } E entry = entries.get(idx++); prevKey = elementToPrevKey(entry); return entry; } }
@Override public BatchedEntries<CacheDirectiveEntry> makeRequest(Long prevKey) throws IOException { BatchedEntries<CacheDirectiveEntry> entries; try (TraceScope ignored = tracer.newScope("listCacheDirectives")) { entries = namenode.listCacheDirectives(prevKey, filter); } catch (IOException e) { if (e.getMessage().contains("Filtering by ID is unsupported")) { // Retry case for old servers, do the filtering client-side long id = filter.getId(); filter = removeIdFromFilter(filter); // Using id - 1 as prevId should get us a window containing the id // This is somewhat brittle, since it depends on directives being // returned in order of ascending ID. entries = namenode.listCacheDirectives(id - 1, filter); for (int i = 0; i < entries.size(); i++) { CacheDirectiveEntry entry = entries.get(i); if (entry.getInfo().getId().equals(id)) { return new SingleEntry(entry); } } throw new RemoteException(InvalidRequestException.class.getName(), "Did not find requested id " + id); } throw e; } Preconditions.checkNotNull(entries); return entries; }
@Override public ListCacheDirectivesResponseProto listCacheDirectives( RpcController controller, ListCacheDirectivesRequestProto request) throws ServiceException { try { CacheDirectiveInfo filter = PBHelper.convert(request.getFilter()); BatchedEntries<CacheDirectiveEntry> entries = server.listCacheDirectives(request.getPrevId(), filter); ListCacheDirectivesResponseProto.Builder builder = ListCacheDirectivesResponseProto.newBuilder(); builder.setHasMore(entries.hasMore()); for (int i=0, n=entries.size(); i<n; i++) { builder.addElements(PBHelper.convert(entries.get(i))); } return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public ListCacheDirectivesResponseProto listCacheDirectives( RpcController controller, ListCacheDirectivesRequestProto request) throws ServiceException { try { CacheDirectiveInfo filter = PBHelper.convert(request.getFilter()); BatchedEntries<CacheDirectiveEntry> entries = server.listCacheDirectives(request.getPrevId(), filter); ListCacheDirectivesResponseProto.Builder builder = ListCacheDirectivesResponseProto.newBuilder(); builder.setHasMore(entries.hasMore()); for (int i=0, n=entries.size(); i<n; i++) { builder.addElements(PBHelper.convert(entries.get(i))); } return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public ListCachePoolsResponseProto listCachePools(RpcController controller, ListCachePoolsRequestProto request) throws ServiceException { try { BatchedEntries<CachePoolEntry> entries = server.listCachePools(request.getPrevPoolName()); ListCachePoolsResponseProto.Builder responseBuilder = ListCachePoolsResponseProto.newBuilder(); responseBuilder.setHasMore(entries.hasMore()); for (int i=0, n=entries.size(); i<n; i++) { responseBuilder.addEntries(PBHelper.convert(entries.get(i))); } return responseBuilder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public ListEncryptionZonesResponseProto listEncryptionZones( RpcController controller, ListEncryptionZonesRequestProto req) throws ServiceException { try { BatchedEntries<EncryptionZone> entries = server .listEncryptionZones(req.getId()); ListEncryptionZonesResponseProto.Builder builder = ListEncryptionZonesResponseProto.newBuilder(); builder.setHasMore(entries.hasMore()); for (int i=0; i<entries.size(); i++) { builder.addZones(PBHelper.convert(entries.get(i))); } return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public ListEncryptionZonesResponseProto listEncryptionZones( RpcController controller, ListEncryptionZonesRequestProto req) throws ServiceException { try { BatchedEntries<EncryptionZone> entries = server .listEncryptionZones(req.getId()); ListEncryptionZonesResponseProto.Builder builder = ListEncryptionZonesResponseProto.newBuilder(); builder.setHasMore(entries.hasMore()); for (int i=0; i<entries.size(); i++) { builder.addZones(PBHelper.convert(entries.get(i))); } return builder.build(); } catch (IOException e) { throw new ServiceException(e); } }
@Override public ListCachePoolsResponseProto listCachePools(RpcController controller, ListCachePoolsRequestProto request) throws ServiceException { try { BatchedEntries<CachePoolEntry> entries = server.listCachePools(request.getPrevPoolName()); ListCachePoolsResponseProto.Builder responseBuilder = ListCachePoolsResponseProto.newBuilder(); responseBuilder.setHasMore(entries.hasMore()); for (int i=0, n=entries.size(); i<n; i++) { responseBuilder.addEntries(PBHelper.convert(entries.get(i))); } return responseBuilder.build(); } catch (IOException e) { throw new ServiceException(e); } }
private void makeRequest() throws IOException { idx = 0; entries = null; entries = makeRequest(prevKey); if (entries.size() == 0) { entries = null; } }
private void makeRequest() throws IOException { idx = 0; entries = null; entries = makeRequest(prevKey); if (entries.size() == 0) { entries = null; } }
@Override public E next() throws IOException { makeRequestIfNeeded(); if (entries == null) { throw new NoSuchElementException(); } E entry = entries.get(idx++); prevKey = elementToPrevKey(entry); return entry; } }
private void makeRequestIfNeeded() throws IOException { if (idx == -1) { makeRequest(); } else if ((entries != null) && (idx >= entries.size())) { if (!entries.hasMore()) { // Last time, we got fewer entries than requested. // So we should be at the end. entries = null; } else { makeRequest(); } } }
@Override public E next() throws IOException { makeRequestIfNeeded(); if (entries == null) { throw new NoSuchElementException(); } E entry = entries.get(idx++); prevKey = elementToPrevKey(entry); return entry; } }
@Override public E next() throws IOException { makeRequestIfNeeded(); if (entries == null) { throw new NoSuchElementException(); } E entry = entries.get(idx++); prevKey = elementToPrevKey(entry); return entry; } }
private void makeRequest() throws IOException { idx = 0; entries = null; entries = makeRequest(prevKey); if (entries.size() == 0) { entries = null; } }
private void makeRequestIfNeeded() throws IOException { if (idx == -1) { makeRequest(); } else if ((entries != null) && (idx >= entries.size())) { if (!entries.hasMore()) { // Last time, we got fewer entries than requested. // So we should be at the end. entries = null; } else { makeRequest(); } } }
private void makeRequestIfNeeded() throws IOException { if (idx == -1) { makeRequest(); } else if ((entries != null) && (idx >= entries.size())) { if (!entries.hasMore()) { // Last time, we got fewer entries than requested. // So we should be at the end. entries = null; } else { makeRequest(); } } }
@Override public E next() throws IOException { makeRequestIfNeeded(); if (entries == null) { throw new NoSuchElementException(); } E entry = entries.get(idx++); prevKey = elementToPrevKey(entry); return entry; } }