@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); } }
/** * Clone a new Notification context from existing one. Map contents are * not recursively deep copied. * * @return new copy of NotificationContext */ public NotificationContext clone() { NotificationContext copy = new NotificationContext(_manager); copy.setType(_type); copy.setChangeType(_changeType); copy.setPathChanged(_pathChanged); copy.setEventName(_eventName); copy.setCreationTime(_creationTime); copy._map.putAll(_map); return copy; }
/** * Clone a new Notification context from existing one. Map contents are * not recursively deep copied. * * @return new copy of NotificationContext */ public NotificationContext clone() { NotificationContext copy = new NotificationContext(_manager); copy.setType(_type); copy.setChangeType(_changeType); copy.setPathChanged(_pathChanged); copy.setEventName(_eventName); copy.setCreationTime(_creationTime); copy._map.putAll(_map); return copy; }
/** * Invoke the listener for the last time so that the listener could clean up resources */ public void reset() { logger.info("Resetting CallbackHandler: " + this.toString()); try { _ready = false; if (_batchCallbackProcessor != null) { _batchCallbackProcessor.shutdown(); } NotificationContext changeContext = new NotificationContext(_manager); changeContext.setType(NotificationContext.Type.FINALIZE); changeContext.setChangeType(_changeType); invoke(changeContext); } catch (Exception e) { String msg = "Exception while resetting the listener:" + _listener; ZKExceptionHandler.getInstance().handle(msg, e); } }
private void forceRebalance(HelixManager manager, ClusterEventType eventType) { NotificationContext changeContext = new NotificationContext(manager); changeContext.setType(NotificationContext.Type.CALLBACK); String uid = UUID.randomUUID().toString().substring(0, 8); ClusterEvent event = new ClusterEvent(_clusterName, eventType, uid); event.addAttribute(AttributeName.helixmanager.name(), changeContext.getManager()); event.addAttribute(AttributeName.changeContext.name(), changeContext); event.addAttribute(AttributeName.eventData.name(), new ArrayList<>()); event.addAttribute(AttributeName.AsyncFIFOWorkerPool.name(), _asyncFIFOWorkerPool); _taskEventQueue.put(event); _eventQueue.put(event.clone(uid)); logger.info(String .format("Controller rebalance event triggered with event type: %s for cluster %s", eventType, _clusterName)); }
@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); } }
void reset(boolean isShutdown) { logger.info("Resetting CallbackHandler: {}. Is resetting for shutdown: {}.", this.toString(), isShutdown); try { _ready = false; synchronized (this) { if (_batchCallbackProcessor != null) { if (isShutdown) { _batchCallbackProcessor.shutdown(); _batchCallbackProcessor = null; } else { _batchCallbackProcessor.resetEventQueue(); } } } NotificationContext changeContext = new NotificationContext(_manager); changeContext.setType(NotificationContext.Type.FINALIZE); changeContext.setChangeType(_changeType); invoke(changeContext); } catch (Exception e) { String msg = "Exception while resetting the listener:" + _listener; ZKExceptionHandler.getInstance().handle(msg, e); } }
@Override public void run() { try { if (_clusterEventType.equals(ClusterEventType.PeriodicalRebalance)) { _cache.requireFullRefresh(); _taskCache.requireFullRefresh(); _cache.refresh(_manager.getHelixDataAccessor()); if (_cache.getLiveInstances() != null) { NotificationContext changeContext = new NotificationContext(_manager); changeContext.setType(NotificationContext.Type.CALLBACK); synchronized (_manager) { checkLiveInstancesObservation(new ArrayList<>(_cache.getLiveInstances().values()), changeContext); } } } forceRebalance(_manager, _clusterEventType); } catch (Throwable ex) { logger.error("Time task failed. Rebalance task type: " + _clusterEventType + ", cluster: " + _clusterName, ex); } } }
@Override public void run() { try { if (_clusterEventType.equals(ClusterEventType.PeriodicalRebalance)) { _cache.requireFullRefresh(); _taskCache.requireFullRefresh(); _cache.refresh(_manager.getHelixDataAccessor()); if (_cache.getLiveInstances() != null) { NotificationContext changeContext = new NotificationContext(_manager); changeContext.setType(NotificationContext.Type.CALLBACK); synchronized (_manager) { checkLiveInstancesObservation(new ArrayList<>(_cache.getLiveInstances().values()), changeContext); } } } forceRebalance(_manager, _clusterEventType); } catch (Throwable ex) { logger.error("Time task failed. Rebalance task type: " + _clusterEventType + ", cluster: " + _clusterName); } } }
/** * 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); } }
/** * 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); } }
private void forceRebalance(HelixManager manager, ClusterEventType eventType) { NotificationContext changeContext = new NotificationContext(manager); changeContext.setType(NotificationContext.Type.CALLBACK); ClusterEvent event = new ClusterEvent(_clusterName, eventType); event.addAttribute(AttributeName.helixmanager.name(), changeContext.getManager()); event.addAttribute(AttributeName.changeContext.name(), changeContext); event.addAttribute(AttributeName.eventData.name(), new ArrayList<>()); event.addAttribute(AttributeName.AsyncFIFOWorkerPool.name(), _asyncFIFOWorkerPool); _taskEventQueue.put(event); _eventQueue.put(event); logger.info("Controller rebalance event triggered with event type: " + eventType); }
/** * Shutdown current RoutingTableProvider. Once it is shutdown, it should never be reused. */ public void shutdown() { if (_periodicRefreshExecutor != null) { _periodicRefreshExecutor.purge(); _periodicRefreshExecutor.shutdown(); } _routerUpdater.shutdown(); _monitor.unregister(); if (_helixManager != null) { PropertyKey.Builder keyBuilder = _helixManager.getHelixDataAccessor().keyBuilder(); switch (_sourceDataType) { case EXTERNALVIEW: _helixManager.removeListener(keyBuilder.externalViews(), this); break; case TARGETEXTERNALVIEW: _helixManager.removeListener(keyBuilder.targetExternalViews(), this); break; case CURRENTSTATES: NotificationContext context = new NotificationContext(_helixManager); context.setType(NotificationContext.Type.FINALIZE); updateCurrentStatesListeners(Collections.<LiveInstance> emptyList(), context); break; default: break; } } }
/** * Shutdown current RoutingTableProvider. Once it is shutdown, it should never be reused. */ public void shutdown() { if (_periodicRefreshExecutor != null) { _periodicRefreshExecutor.purge(); _periodicRefreshExecutor.shutdown(); } _routerUpdater.shutdown(); _monitor.unregister(); if (_helixManager != null) { PropertyKey.Builder keyBuilder = _helixManager.getHelixDataAccessor().keyBuilder(); switch (_sourceDataType) { case EXTERNALVIEW: _helixManager.removeListener(keyBuilder.externalViews(), this); break; case TARGETEXTERNALVIEW: _helixManager.removeListener(keyBuilder.targetExternalViews(), this); break; case CURRENTSTATES: NotificationContext context = new NotificationContext(_helixManager); context.setType(NotificationContext.Type.FINALIZE); updateCurrentStatesListeners(Collections.<LiveInstance> emptyList(), context); break; default: break; } } }
periodicRefreshContext.setType(NotificationContext.Type.PERIODIC_REFRESH);
periodicRefreshContext.setType(NotificationContext.Type.PERIODIC_REFRESH);
new DistributedLeaderElection(manager, controller0, timerTasks); NotificationContext context = new NotificationContext(manager); context.setType(NotificationContext.Type.INIT); election.onControllerChange(context); election = new DistributedLeaderElection(manager, controller1, timerTasks); context = new NotificationContext(manager); context.setType(NotificationContext.Type.INIT); election.onControllerChange(context);
new DistributedLeaderElection(manager, controller0, timerTasks); NotificationContext context = new NotificationContext(manager); context.setType(NotificationContext.Type.CALLBACK); election.onControllerChange(context); election = new DistributedLeaderElection(manager, controller1, timerTasks); context = new NotificationContext(manager); context.setType(NotificationContext.Type.CALLBACK); election.onControllerChange(context);