Search in sources :

Example 1 with Pair

use of com.nokia.dempsy.util.Pair in project Dempsy by Dempsy.

the class LocalClusterSessionFactory method doormdir.

private static synchronized Pair<Entry, Entry> doormdir(String path) throws ClusterInfoException {
    Entry ths = entries.get(path);
    if (ths == null)
        throw new ClusterInfoException("rmdir of non existant node \"" + path + "\"");
    Entry parent = entries.get(parent(path));
    entries.remove(path);
    if (parent != null) {
        int lastSlash = path.lastIndexOf('/');
        parent.children.remove(path.substring(lastSlash + 1));
    }
    return new Pair<Entry, Entry>(ths, parent);
}
Also used : ClusterInfoException(com.nokia.dempsy.cluster.ClusterInfoException) Pair(com.nokia.dempsy.util.Pair)

Example 2 with Pair

use of com.nokia.dempsy.util.Pair in project Dempsy by Dempsy.

the class LocalClusterSessionFactory method doomkdir.

private static synchronized Pair<Entry, String> doomkdir(String path, Object data, DirMode mode) throws ClusterInfoException {
    if (oexists(path, null))
        return new Pair<Entry, String>(null, null);
    String parentPath = parent(path);
    Entry parent = entries.get(parentPath);
    if (parent == null) {
        throw new ClusterInfoException("No Parent for \"" + path + "\" which is expected to be \"" + parent(path) + "\"");
    }
    long seq = -1;
    if (mode.isSequential()) {
        AtomicLong cseq = parent.childSequences.get(path);
        if (cseq == null)
            parent.childSequences.put(path, cseq = new AtomicLong(0));
        seq = cseq.getAndIncrement();
    }
    String pathToUse = seq >= 0 ? (path + seq) : path;
    entries.put(pathToUse, new Entry(data));
    // find the relative path
    int lastSlash = pathToUse.lastIndexOf('/');
    parent.children.add(pathToUse.substring(lastSlash + 1));
    return new Pair<Entry, String>(parent, pathToUse);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ClusterInfoException(com.nokia.dempsy.cluster.ClusterInfoException) SafeString(com.nokia.dempsy.internal.util.SafeString) Pair(com.nokia.dempsy.util.Pair)

Aggregations

ClusterInfoException (com.nokia.dempsy.cluster.ClusterInfoException)2 Pair (com.nokia.dempsy.util.Pair)2 SafeString (com.nokia.dempsy.internal.util.SafeString)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1