Example usage for org.apache.zookeeper KeeperException.SessionExpiredException getMessage

List of usage examples for org.apache.zookeeper KeeperException.SessionExpiredException getMessage

Introduction

In this page you can find the example usage for org.apache.zookeeper KeeperException.SessionExpiredException getMessage.

Prototype

@Override
    public String getMessage() 

Source Link

Usage

From source file:nl.gridline.zieook.workflow.scheduler.DistributedQueue.java

License:Apache License

/**
 * Returns a Map of the children, ordered by id.
 * @param watcher optional watcher on getChildren() operation.
 * @return map from id to child name for all children
 *//*from   w ww. j a  v a2  s.  c  o  m*/
private TreeMap<String, String> orderedChildren(Watcher watcher) throws KeeperException, InterruptedException {
    TreeMap<String, String> orderedChildren = new TreeMap<String, String>();

    List<String> childNames = null;
    try {
        childNames = zookeeper.getChildren(dir, watcher);
    } catch (KeeperException.NoNodeException e) {
        throw e;
    } catch (KeeperException.SessionExpiredException e1) {
        LOG.error("Session expired; {}", e1.getMessage());
        Thread.sleep(4000); // sleep a while, otherwise this method goes crazy
        return orderedChildren;
    }

    for (String childName : childNames) {
        try {
            // Check format
            if (!childName.regionMatches(0, PREFIX, 0, PREFIX.length())) {
                LOG.warn("Found child node with improper name: " + childName);
                continue;
            }
            String suffix = childName.substring(PREFIX.length());
            // Long childId = new Long(suffix);
            orderedChildren.put(suffix, childName);
        } catch (NumberFormatException e) {
            LOG.warn("Found child node with improper format : " + childName + " " + e, e);
        }
    }

    return orderedChildren;
}