Java Code Examples for org.apache.zookeeper.KeeperException.Code#SESSIONEXPIRED

The following examples show how to use org.apache.zookeeper.KeeperException.Code#SESSIONEXPIRED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZooKeeperStateProvider.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void onComponentRemoved(final String componentId) throws IOException {
    try {
        ZKUtil.deleteRecursive(getZooKeeper(), getComponentPath(componentId));
    } catch (final KeeperException ke) {
        // Node doesn't exist so just ignore
        final Code exceptionCode = ke.code();
        if (Code.NONODE == exceptionCode) {
            return;
        }
        if (Code.SESSIONEXPIRED == exceptionCode) {
            invalidateClient();
            onComponentRemoved(componentId);
            return;
        }

        throw new IOException("Unable to remove state for component with ID '" + componentId + " with exception code " + exceptionCode, ke);
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new IOException("Failed to remove state for component with ID '" + componentId + "' from ZooKeeper due to being interrupted", e);
    }
}
 
Example 2
Source File: ZooKeeperStateProvider.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public void onComponentRemoved(final String componentId) throws IOException {
    try {
        ZKUtil.deleteRecursive(getZooKeeper(), getComponentPath(componentId));
    } catch (final KeeperException ke) {
        // Node doesn't exist so just ignore
        final Code exceptionCode = ke.code();
        if (Code.NONODE == exceptionCode) {
            return;
        }
        if (Code.SESSIONEXPIRED == exceptionCode) {
            invalidateClient();
            onComponentRemoved(componentId);
            return;
        }

        throw new IOException("Unable to remove state for component with ID '" + componentId + " with exception code " + exceptionCode, ke);
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new IOException("Failed to remove state for component with ID '" + componentId + "' from ZooKeeper due to being interrupted", e);
    }
}
 
Example 3
Source File: ZooKeeperStateProvider.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public StateMap getState(final String componentId) throws IOException {
    verifyEnabled();

    try {
        final Stat stat = new Stat();
        final String path = getComponentPath(componentId);
        final byte[] data = getZooKeeper().getData(path, false, stat);

        final StateMap stateMap = deserialize(data, stat.getVersion(), componentId);
        return stateMap;
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId + ", due to interruption", e);
    } catch (final KeeperException ke) {
        final Code exceptionCode = ke.code();
        if (Code.NONODE == exceptionCode) {
            return new StandardStateMap(null, -1L);
        }
        if (Code.SESSIONEXPIRED == exceptionCode) {
            invalidateClient();
            return getState(componentId);
        }

        throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId + " with exception code " + exceptionCode, ke);
    } catch (final IOException ioe) {
        // provide more context in the error message
        throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId, ioe);
    }
}
 
Example 4
Source File: WatchNodeExistance.java    From incubator-retired-blur with Apache License 2.0 5 votes vote down vote up
private void startDoubleCheckThread() {
  _doubleCheckThread = new Thread(new Runnable() {
    @Override
    public void run() {
      while (_running.get()) {
        try {
          synchronized (_running) {
            _running.wait(_delay);
          }
          if (!_running.get()) {
            return;
          }
          Stat stat = _zooKeeper.exists(_path, false);
          if (!isCorrect(stat)) {
            LOG.debug("Double check triggered for [" + _path + "]");
            synchronized (_lock) {
              _lock.notify();
            }
          }
        } catch (KeeperException e) {
          if (!_running.get()) {
            LOG.info("Error [{0}]", e.getMessage());
            return;
          }
          if (e.code() == Code.SESSIONEXPIRED) {
            LOG.warn("Session expired for [" + _path + "] [" + instance + "]");
            return;
          }
          LOG.error("Unknown error", e);
          throw new RuntimeException(e);
        } catch (InterruptedException e) {
          return;
        }
      }
    }
  });
  _doubleCheckThread.setName("Poll Watch Existance [" + _path + "][" + instance + "]");
  _doubleCheckThread.setDaemon(true);
  _doubleCheckThread.start();
}
 
Example 5
Source File: ZooKeeperStateProvider.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public StateMap getState(final String componentId) throws IOException {
    verifyEnabled();

    try {
        final Stat stat = new Stat();
        final String path = getComponentPath(componentId);
        final byte[] data = getZooKeeper().getData(path, false, stat);

        final StateMap stateMap = deserialize(data, stat.getVersion(), componentId);
        return stateMap;
    } catch (final InterruptedException e) {
        Thread.currentThread().interrupt();
        throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId + ", due to interruption", e);
    } catch (final KeeperException ke) {
        final Code exceptionCode = ke.code();
        if (Code.NONODE == exceptionCode) {
            return new StandardStateMap(null, -1L);
        }
        if (Code.SESSIONEXPIRED == exceptionCode) {
            invalidateClient();
            return getState(componentId);
        }

        throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId + " with exception code " + exceptionCode, ke);
    } catch (final IOException ioe) {
        // provide more context in the error message
        throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId, ioe);
    }
}
 
Example 6
Source File: ActiveStandbyElector.java    From hadoop with Apache License 2.0 4 votes vote down vote up
private static boolean isSessionExpired(Code code) {
  return (code == Code.SESSIONEXPIRED);
}
 
Example 7
Source File: ActiveStandbyElector.java    From big-c with Apache License 2.0 4 votes vote down vote up
private static boolean isSessionExpired(Code code) {
  return (code == Code.SESSIONEXPIRED);
}
 
Example 8
Source File: WatchNodeData.java    From incubator-retired-blur with Apache License 2.0 4 votes vote down vote up
private void startDoubleCheckThread() {
  _doubleCheckThread = new Thread(new Runnable() {

    @Override
    public void run() {
      while (_running.get()) {
        try {
          synchronized (_running) {
            _running.wait(_delay);
          }
          if (!_running.get()) {
            return;
          }
          Stat stat = _zooKeeper.exists(_path, false);
          if (stat == null) {
            LOG.debug("Path [{0}] not found.", _path);
            synchronized (_lock) {
              _lock.notify();
            }
            return;
          }

          byte[] data = _zooKeeper.getData(_path, false, stat);
          if (!isCorrect(data)) {
            LOG.debug("Double check triggered for [" + _path + "]");
            synchronized (_lock) {
              _lock.notify();
            }
          }
        } catch (KeeperException e) {
          if (!_running.get()) {
            LOG.info("Error [{0}]", e.getMessage());
            return;
          }
          if (e.code() == Code.SESSIONEXPIRED) {
            LOG.warn("Session expired for [" + _path + "] [" + instance + "]");
            return;
          }
          LOG.error("Unknown error", e);
          throw new RuntimeException(e);
        } catch (InterruptedException e) {
          return;
        }
      }
    }
  });
  _doubleCheckThread.setName("Poll Watch Data [" + _path + "][" + instance + "]");
  _doubleCheckThread.setDaemon(true);
  _doubleCheckThread.start();
}
 
Example 9
Source File: WatchChildren.java    From incubator-retired-blur with Apache License 2.0 4 votes vote down vote up
private void startDoubleCheckThread() {
  _doubleCheckThread = new Thread(new Runnable() {
    @Override
    public void run() {
      while (_running.get()) {
        try {
          synchronized (_running) {
            _running.wait(_delay);
          }
          if (!_running.get()) {
            return;
          }
          if (_zooKeeper.exists(_path, false) == null) {
            LOG.debug("Path for watching not found [{0}], no longer double checking.", _path);
            return;
          }
          List<String> children = _zooKeeper.getChildren(_path, false);
          if (!isCorrect(children)) {
            LOG.error("Double check triggered for [" + _path + "] [" + instance + "]");
            synchronized (_lock) {
              _lock.notify();
            }
          }
        } catch (KeeperException e) {
          if (!_running.get()) {
            LOG.info("Error [{0}]", e.getMessage());
            return;
          }
          if (e.code() == Code.SESSIONEXPIRED) {
            LOG.warn("Session expired for [" + _path + "] [" + instance + "]");
            return;
          }
          LOG.error("Unknown error", e);
          throw new RuntimeException(e);
        } catch (InterruptedException e) {
          return;
        }
      }
    }
  });
  _doubleCheckThread.setName("Poll Watch Children [" + _path + "][" + instance + "]");
  _doubleCheckThread.setDaemon(true);
  _doubleCheckThread.start();
}