/** * Obtains an ancestor of the current Fqn. Literally performs <code>elements.subList(0, generation)</code> such that * if <code> generation == Fqn.size() </code> then the return value is the Fqn itself (current generation), and if * <code> generation == Fqn.size() - 1 </code> then the return value is the same as <code> Fqn.getParent() </code> * i.e., just one generation behind the current generation. <code> generation == 0 </code> would return Fqn.ROOT. * * @param generation the generation of the ancestor to retrieve * @return an ancestor of the current Fqn */ public Fqn<E> getAncestor(int generation) { if (generation == 0) return root(); return getSubFqn(0, generation); }
/** * Returns the parent of this Fqn. The parent of the root node is {@link #ROOT}. Examples: * <pre> * Fqn<String> f1 = Fqn.fromString("/a"); * Fqn<String> f2 = Fqn.fromString("/a/b"); * assertEquals(f1, f2.getParent()); * assertEquals(Fqn.ROOT, f1.getParent().getParent()); * assertEquals(Fqn.ROOT, Fqn.ROOT.getParent()); * </pre> * * @return the parent Fqn */ public Fqn<E> getParent() { switch (elements.length) { case 0: case 1: return root(); default: return getSubFqn(0, elements.length - 1); } }
/** * Creates a new Fqn whose ancestor has been replaced with the new ancestor passed in. * * @param oldAncestor old ancestor to replace * @param newAncestor nw ancestor to replace with * @return a new Fqn with ancestors replaced. */ public Fqn<E> replaceAncestor(Fqn<E> oldAncestor, Fqn<E> newAncestor) { if (!isChildOf(oldAncestor)) throw new IllegalArgumentException("Old ancestor must be an ancestor of the current Fqn!"); Fqn<E> subFqn = this.getSubFqn(oldAncestor.size(), size()); return Fqn.fromRelativeFqn(newAncestor, subFqn); } }
public Fqn getActualFqn(Fqn fqn) { if (!isBackupFqn(fqn)) return fqn; if (fqn.equals(BUDDY_BACKUP_SUBTREE_FQN)) return Fqn.ROOT; // remove the first 2 (or 3 in the case of a dead backup region) elements boolean isDead = isDeadBackupFqn(fqn); int fqnSz = fqn.size(); if (isDead && fqnSz == 2) return Fqn.ROOT; return fqn.getSubFqn(isDead ? 3 : 2, fqnSz); }
public void setContextClassLoaderAsCurrent(Fqn fqn) { if (fqn.isChildOf(BuddyManager.BUDDY_BACKUP_SUBTREE_FQN)) { if (fqn.size() <= 2) { fqn = Fqn.ROOT; } else { fqn = fqn.getSubFqn(2, fqn.size()); } } Region region = getRegion(fqn, false); ClassLoader regionCL = (region == null) ? null : region.getClassLoader(); if (regionCL != null) { Thread.currentThread().setContextClassLoader(regionCL); } }
/** * Returns the buddy backp root portion of a given Fqn, provided it is a backup Fqn. If it is not a backup Fqn, Fqn.ROOT is returned. * * @param fqn fqn * @return a backup root from an Fqn */ public Fqn getBackupRootFromFqn(Fqn fqn) { if (isBackupFqn(fqn) && fqn.size() > 1) { return fqn.getSubFqn(0, isDeadBackupFqn(fqn) ? 3 : 2); } else { return Fqn.root(); } }
if (nextFqn.size() > largestFqnLength) nextFqn = nextFqn.getSubFqn(0, largestFqnLength);