@Test public void fetchTop() throws FailStoreException { List<Pair<String, Job>> pairs = failStore.fetchTop(5, Job.class); if (CollectionUtils.isNotEmpty(pairs)) { for (Pair<String, Job> pair : pairs) { System.out.println(JSON.toJSONString(pair)); } } }
@Override public <T> List<Pair<String, T>> fetchTop(int size, Type type) throws FailStoreException { RocksIterator iterator = null; try { List<Pair<String, T>> list = new ArrayList<Pair<String, T>>(size); iterator = db.newIterator(); for (iterator.seekToFirst(); iterator.isValid(); iterator.next()) { iterator.status(); String key = new String(iterator.key(), "UTF-8"); T value = JSON.parse(new String(iterator.value(), "UTF-8"), type); Pair<String, T> pair = new Pair<String, T>(key, value); list.add(pair); if (list.size() >= size) { break; } } return list; } catch (Exception e) { throw new FailStoreException(e); } finally { if (iterator != null) { iterator.dispose(); } } }
RocksdbFailStore extends AbstractFailStore { @Override public <T> List<Pair<String, T>> fetchTop(int size, Type type) throws FailStoreException { RocksIterator iterator = null; try { List<Pair<String, T>> list = new ArrayList<Pair<String, T>>(size); iterator = db.newIterator(); for (iterator.seekToFirst(); iterator.isValid(); iterator.next()) { iterator.status(); String key = new String(iterator.key(), "UTF-8"); T value = JSON.parse(new String(iterator.value(), "UTF-8"), type); Pair<String, T> pair = new Pair<String, T>(key, value); list.add(pair); if (list.size() >= size) { break; } } return list; } catch (Exception e) { throw new FailStoreException(e); } finally { if (iterator != null) { iterator.dispose(); } } } }
RocksdbFailStore extends AbstractFailStore { @Override public <T> List<Pair<String, T>> fetchTop(int size, Type type) throws FailStoreException { RocksIterator iterator = null; try { List<Pair<String, T>> list = new ArrayList<Pair<String, T>>(size); iterator = db.newIterator(); for (iterator.seekToFirst(); iterator.isValid(); iterator.next()) { iterator.status(); String key = new String(iterator.key(), "UTF-8"); T value = JSON.parse(new String(iterator.value(), "UTF-8"), type); Pair<String, T> pair = new Pair<String, T>(key, value); list.add(pair); if (list.size() >= size) { break; } } return list; } catch (Exception e) { throw new FailStoreException(e); } finally { if (iterator != null) { iterator.dispose(); } } } RocksdbFailStore(File dbPath, boolean needLock); }
RocksdbFailStore extends AbstractFailStore { @Override public <T> List<Pair<String, T>> fetchTop(int size, Type type) throws FailStoreException { RocksIterator iterator = null; try { List<Pair<String, T>> list = new ArrayList<Pair<String, T>>(size); iterator = db.newIterator(); for (iterator.seekToFirst(); iterator.isValid(); iterator.next()) { iterator.status(); String key = new String(iterator.key(), "UTF-8"); T value = JSON.parse(new String(iterator.value(), "UTF-8"), type); Pair<String, T> pair = new Pair<String, T>(key, value); list.add(pair); if (list.size() >= size) { break; } } return list; } catch (Exception e) { throw new FailStoreException(e); } finally { if (iterator != null) { iterator.dispose(); } } } RocksdbFailStore(File dbPath, boolean needLock); @Override void open(); @Override void put(String key, Object value); @Override void delete(String key); @Override void delete(List<String> keys); @Override List<Pair<String, T>> fetchTop(int size, Type type); @Override void close(); @Override void destroy(); }
RocksdbFailStore extends AbstractFailStore { @Override public <T> List<Pair<String, T>> fetchTop(int size, Type type) throws FailStoreException { RocksIterator iterator = null; try { List<Pair<String, T>> list = new ArrayList<Pair<String, T>>(size); iterator = db.newIterator(); for (iterator.seekToFirst(); iterator.isValid(); iterator.next()) { iterator.status(); String key = new String(iterator.key(), "UTF-8"); T value = JSON.parse(new String(iterator.value(), "UTF-8"), type); Pair<String, T> pair = new Pair<String, T>(key, value); list.add(pair); if (list.size() >= size) { break; } } return list; } catch (Exception e) { throw new FailStoreException(e); } finally { if (iterator != null) { iterator.dispose(); } } } RocksdbFailStore(File dbPath, boolean needLock); @Override void open(); @Override void put(String key, Object value); @Override void delete(String key); @Override void delete(List<String> keys); @Override List<Pair<String, T>> fetchTop(int size, Type type); @Override void close(); @Override void destroy(); static final String name; }