@Override protected void handleEvent(NotificationContext event) { try { _handler.invoke(event); } catch (Exception e) { logger.warn("Exception in callback processing thread. Skipping callback", e); } } }
@Override protected void handleEvent(NotificationContext event) { try { _handler.invoke(event); } catch (Exception e) { logger.warn("Exception in callback processing thread. Skipping callback", e); } } }
public void enqueueTask(NotificationContext changeContext) throws Exception { //async mode only applicable to CALLBACK from ZK, During INIT and FINALIZE invoke the callback's immediately. if (_batchModeEnabled && changeContext.getType() == NotificationContext.Type.CALLBACK) { logger.debug("Enqueuing callback"); if (!isReady()) { logger.info( "CallbackHandler is not ready, ignore change callback from path: " + _path + ", for listener: " + _listener); } else { _batchCallbackProcessor.queueEvent(changeContext.getType(), changeContext); } } else { invoke(changeContext); } if (_monitor != null) { _monitor.increaseCallbackUnbatchedCounters(); } }
/** * 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); } }
public void enqueueTask(NotificationContext changeContext) throws Exception { //async mode only applicable to CALLBACK from ZK, During INIT and FINALIZE invoke the callback's immediately. if (_batchModeEnabled && changeContext.getType() == NotificationContext.Type.CALLBACK) { logger.debug("Enqueuing callback"); if (!isReady()) { logger.info( "CallbackHandler is not ready, ignore change callback from path: " + _path + ", for listener: " + _listener); } else { synchronized (this) { if (_batchCallbackProcessor != null) { _batchCallbackProcessor.queueEvent(changeContext.getType(), changeContext); } else { throw new HelixException("Failed to process callback in batch mode. Batch Callback Processor does not exist."); } } } } else { invoke(changeContext); } if (_monitor != null) { _monitor.increaseCallbackUnbatchedCounters(); } }
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); } }
/** * 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); } }