private TransactionRecover readTransaction(final File file) throws Exception { try (FileInputStream fis = new FileInputStream(file)) { byte[] content = new byte[(int) file.length()]; fis.read(content); return TransactionRecoverUtils.transformBean(content, serializer); } }
@Override public TransactionRecover findById(final String id) { try { Stat stat = new Stat(); byte[] contents = zooKeeper.getData(getRootPath(id), false, stat); return TransactionRecoverUtils.transformBean(contents, objectSerializer); } catch (Exception e) { throw new TransactionIoException(e); } }
@Override public List<TransactionRecover> listAll() { List<TransactionRecover> transactionRecovers = Lists.newArrayList(); List<String> zNodePaths; try { zNodePaths = zooKeeper.getChildren(rootPath, false); } catch (Exception e) { throw new TransactionIoException(e); } if (CollectionUtils.isNotEmpty(zNodePaths)) { transactionRecovers = zNodePaths.stream() .filter(StringUtils::isNoneBlank) .map(zNodePath -> { try { byte[] contents = zooKeeper.getData(getRootPath(zNodePath), false, new Stat()); return TransactionRecoverUtils.transformBean(contents, objectSerializer); } catch (KeeperException | InterruptedException | TransactionException e) { e.printStackTrace(); } return null; }).collect(Collectors.toList()); } return transactionRecovers; }
@Override public List<TransactionRecover> listAll() { try { List<TransactionRecover> transactions = Lists.newArrayList(); Set<byte[]> keys = jedisClient.keys((keyName + "*").getBytes()); for (final byte[] key : keys) { byte[] contents = jedisClient.get(key); if (contents != null) { transactions.add(TransactionRecoverUtils.transformBean(contents, objectSerializer)); } } return transactions; } catch (Exception e) { throw new TransactionIoException(e); } }
@Override public TransactionRecover findById(final String id) { try { final String redisKey = RedisHelper.buildRecoverKey(keyName, id); byte[] contents = jedisClient.get(redisKey.getBytes()); return TransactionRecoverUtils.transformBean(contents, objectSerializer); } catch (Exception e) { throw new TransactionIoException(e); } }