@Override public void unhandledError(String message, Throwable ex) { LOG.error("Unrecoverable error: " + message, ex); try { close(); } catch (IOException ioe) { LOG.warn("Exception when closing.", ioe); } } };
public boolean doZkClientAction(ZkClientAction action) throws IOException { return doZkClientAction(action, false); }
/** * On master change. * * @param currentData the current data */ protected void onMasterChange(ChildData currentData) { ControlNodeInfo controlServerInfo = extractControlServerInfo(currentData); for (ControlNodeListener listener : listeners) { listener.onControlNodeChange(controlServerInfo); } }
@Override public void nodeChanged() throws Exception { ChildData currentData = controlCache.getCurrentData(); if (currentData == null) { LOG.warn("Control service node died!"); onNoMaster(); } else { LOG.warn("Control service node changed!"); onMasterChange(currentData); } } });
/** * Start. * * @throws Exception the exception */ public void start() throws Exception { //NOSONAR LOG.info("Starting node tracker"); zkClient.getUnhandledErrorListenable().addListener(errorsListener); if (createZkNode()) { controlCache = new NodeCache(zkClient, CONTROL_SERVER_NODE_PATH); controlCache.getListenable().addListener(new NodeCacheListener() { @Override public void nodeChanged() throws Exception { ChildData currentData = controlCache.getCurrentData(); if (currentData == null) { LOG.warn("Control service node died!"); onNoMaster(); } else { LOG.warn("Control service node changed!"); onMasterChange(currentData); } } }); controlCache.start(); } else { LOG.warn("Failed to create ZK node!"); } }
@Override public void start() throws Exception { super.start(); endpointCache.getListenable().addListener(new PathChildrenCacheListener() { @Override
/** * Do Zookeeper client action. * * @param action the Zookeeper client action * @param throwIoException define throw or not IOException * @return boolean 'true' if doWithZkClient method works without exceptions * @throws IOException the IOException */ public boolean doZkClientAction(ZkClientAction action, boolean throwIoException) throws IOException { try { action.doWithZkClient(zkClient); return true; } catch (Exception ex) { LOG.error("Unknown Error", ex); close(); if (throwIoException) { throw new IOException(ex); } else { return false; } } }
@Override public ControlNodeInfo getControlServerInfo() { if (controlCache != null && controlCache.getCurrentData() != null) { return extractControlServerInfo(controlCache.getCurrentData()); } else { return null; } }
@Override public void close() throws IOException { endpointCache.close(); bootstrapCache.close(); super.close(); } }