@Override public long addEntry(byte[] data) { String newPath; try { while (true) { try { if (ephemeral) { newPath = zoo.putEphemeralSequential(path + "/" + PREFIX, data); } else { newPath = zoo.putPersistentSequential(path + "/" + PREFIX, data); } String[] parts = newPath.split("/"); String last = parts[parts.length - 1]; return Long.parseLong(last.substring(PREFIX.length())); } catch (NoNodeException nne) { // the parent does not exist so try to create it zoo.putPersistentData(path, new byte[] {}, NodeExistsPolicy.SKIP); } } } catch (Exception ex) { throw new RuntimeException(ex); } }
@Override public void push(long tid, Repo<T> repo) throws StackOverflowException { verifyReserved(tid); String txpath = getTXPath(tid); try { String top = findTop(txpath); if (top != null && Long.parseLong(top.split("_")[1]) > 100) { throw new StackOverflowException("Repo stack size too large"); } zk.putPersistentSequential(txpath + "/repo_", serialize(repo)); } catch (StackOverflowException soe) { throw soe; } catch (Exception e) { throw new RuntimeException(e); } }
@Override public long addEntry(byte[] data) { String newPath; try { while (true) { try { if (ephemeral) { newPath = zoo.putEphemeralSequential(path + "/" + PREFIX, data); } else { newPath = zoo.putPersistentSequential(path + "/" + PREFIX, data); } String[] parts = newPath.split("/"); String last = parts[parts.length - 1]; return Long.parseLong(last.substring(PREFIX.length())); } catch (NoNodeException nne) { // the parent does not exist so try to create it zoo.putPersistentData(path, new byte[] {}, NodeExistsPolicy.SKIP); } } } catch (Exception ex) { throw new RuntimeException(ex); } }
@Override public void push(long tid, Repo<T> repo) throws StackOverflowException { verifyReserved(tid); String txpath = getTXPath(tid); try { String top = findTop(txpath); if (top != null && Long.parseLong(top.split("_")[1]) > 100) { throw new StackOverflowException("Repo stack size too large"); } zk.putPersistentSequential(txpath + "/repo_", serialize(repo)); } catch (StackOverflowException soe) { throw soe; } catch (Exception e) { throw new RuntimeException(e); } }