@Override public void handleDataDeleted(String dataPath) { if (logger.isDebugEnabled()) { logger.debug("Data change callback: path deleted: " + dataPath); } try { updateNotificationTime(System.nanoTime()); if (dataPath != null && dataPath.startsWith(_path)) { logger.info(_manager.getInstanceName() + " unsubscribe data-change. path: " + dataPath + ", listener: " + _listener); _zkClient.unsubscribeDataChanges(dataPath, this); // only needed for bucketized parent, but OK if we don't have child-change // watch on the bucketized parent path logger.info(_manager.getInstanceName() + " unsubscribe child-change. path: " + dataPath + ", listener: " + _listener); _zkClient.unsubscribeChildChanges(dataPath, this); // No need to invoke() since this event will handled by child-change on parent-node } } catch (Exception e) { String msg = "exception in handling data-delete-change. path: " + dataPath + ", listener: " + _listener; ZKExceptionHandler.getInstance().handle(msg, e); } }
@Override public void handleDataDeleted(String dataPath) { if (logger.isDebugEnabled()) { logger.debug("Data change callback: path deleted: " + dataPath); } try { updateNotificationTime(System.nanoTime()); if (dataPath != null && dataPath.startsWith(_path)) { logger.info(_manager.getInstanceName() + " unsubscribe data-change. path: " + dataPath + ", listener: " + _listener); _zkClient.unsubscribeDataChanges(dataPath, this); // only needed for bucketized parent, but OK if we don't have child-change // watch on the bucketized parent path logger.info(_manager.getInstanceName() + " unsubscribe child-change. path: " + dataPath + ", listener: " + _listener); _zkClient.unsubscribeChildChanges(dataPath, this); // No need to invoke() since this event will handled by child-change on parent-node } } catch (Exception e) { String msg = "exception in handling data-delete-change. path: " + dataPath + ", listener: " + _listener; ZKExceptionHandler.getInstance().handle(msg, e); } }
@Override public void handleDataChange(String dataPath, Object data) { if (logger.isDebugEnabled()) { logger.debug("Data change callback: paths changed: " + dataPath); } try { updateNotificationTime(System.nanoTime()); if (dataPath != null && dataPath.startsWith(_path)) { NotificationContext changeContext = new NotificationContext(_manager); changeContext.setType(NotificationContext.Type.CALLBACK); changeContext.setPathChanged(dataPath); changeContext.setChangeType(_changeType); enqueueTask(changeContext); } } catch (Exception e) { String msg = "exception in handling data-change. path: " + dataPath + ", listener: " + _listener; ZKExceptionHandler.getInstance().handle(msg, e); } }
@Override public void handleDataChange(String dataPath, Object data) { if (logger.isDebugEnabled()) { logger.debug("Data change callback: paths changed: " + dataPath); } try { updateNotificationTime(System.nanoTime()); if (dataPath != null && dataPath.startsWith(_path)) { NotificationContext changeContext = new NotificationContext(_manager); changeContext.setType(NotificationContext.Type.CALLBACK); changeContext.setPathChanged(dataPath); changeContext.setChangeType(_changeType); enqueueTask(changeContext); } } catch (Exception e) { String msg = "exception in handling data-change. path: " + dataPath + ", listener: " + _listener; ZKExceptionHandler.getInstance().handle(msg, e); } }
@Override public void handleChildChange(String parentPath, List<String> currentChilds) { if (logger.isDebugEnabled()) { logger.debug("Data change callback: child changed, path: {} , current child count: {}", parentPath, currentChilds == null ? 0 : currentChilds.size()); } try { updateNotificationTime(System.nanoTime()); if (parentPath != null && parentPath.startsWith(_path)) { if (currentChilds == null && parentPath.equals(_path)) { // _path has been removed, remove this listener // removeListener will call handler.reset(), which in turn call invoke() on FINALIZE type _manager.removeListener(_propertyKey, _listener); } else { NotificationContext changeContext = new NotificationContext(_manager); changeContext.setType(NotificationContext.Type.CALLBACK); changeContext.setPathChanged(parentPath); changeContext.setChangeType(_changeType); subscribeForChanges(changeContext.getType(), _path, _watchChild); enqueueTask(changeContext); } } } catch (Exception e) { String msg = "exception in handling child-change. instance: " + _manager.getInstanceName() + ", parentPath: " + parentPath + ", listener: " + _listener; ZKExceptionHandler.getInstance().handle(msg, e); } }
@Override public void handleChildChange(String parentPath, List<String> currentChilds) { if (logger.isDebugEnabled()) { logger.debug("Data change callback: child changed, path: {} , current child count: {}", parentPath, currentChilds == null ? 0 : currentChilds.size()); } try { updateNotificationTime(System.nanoTime()); if (parentPath != null && parentPath.startsWith(_path)) { if (currentChilds == null && parentPath.equals(_path)) { // _path has been removed, remove this listener // removeListener will call handler.reset(), which in turn call invoke() on FINALIZE type _manager.removeListener(_propertyKey, _listener); } else { NotificationContext changeContext = new NotificationContext(_manager); changeContext.setType(NotificationContext.Type.CALLBACK); changeContext.setPathChanged(parentPath); changeContext.setChangeType(_changeType); subscribeForChanges(changeContext.getType(), _path, _watchChild); enqueueTask(changeContext); } } } catch (Exception e) { String msg = "exception in handling child-change. instance: " + _manager.getInstanceName() + ", parentPath: " + parentPath + ", listener: " + _listener; ZKExceptionHandler.getInstance().handle(msg, e); } }
/** * Invoke the listener so that it sets up the initial values from the zookeeper if any * exists */ public void init() { logger.info("initializing CallbackHandler: " + this.toString() + " content: " + getContent()); if (_batchModeEnabled) { synchronized (this) { if (_batchCallbackProcessor != null) { _batchCallbackProcessor.resetEventQueue(); } else { _batchCallbackProcessor = new CallbackProcessor(this); _batchCallbackProcessor.start(); } } } updateNotificationTime(System.nanoTime()); try { NotificationContext changeContext = new NotificationContext(_manager); changeContext.setType(NotificationContext.Type.INIT); changeContext.setChangeType(_changeType); _ready = true; invoke(changeContext); } catch (Exception e) { String msg = "Exception while invoking init callback for listener:" + _listener; ZKExceptionHandler.getInstance().handle(msg, e); } }
/** * Invoke the listener so that it sets up the initial values from the zookeeper if any * exists */ public void init() { logger.info("initializing CallbackHandler: " + this.toString() + " content: " + getContent()); if (_batchModeEnabled) { if (_batchCallbackProcessor != null) { _batchCallbackProcessor.shutdown(); } _batchCallbackProcessor = new CallbackProcessor(this); _batchCallbackProcessor.start(); } updateNotificationTime(System.nanoTime()); try { NotificationContext changeContext = new NotificationContext(_manager); changeContext.setType(NotificationContext.Type.INIT); changeContext.setChangeType(_changeType); _ready = true; invoke(changeContext); } catch (Exception e) { String msg = "Exception while invoking init callback for listener:" + _listener; ZKExceptionHandler.getInstance().handle(msg, e); } }