@Override public void close() { if (open.compareAndSet(true, false)) { if (notifier != null) { notifier.unsubscribe(ACCOUNT_METADATA_CHANGE_TOPIC, changeTopicListener); } if (scheduler != null) { shutDownExecutorService(scheduler, config.updaterShutDownTimeoutMs, TimeUnit.MILLISECONDS); } helixStore.stop(); } }
@Override public boolean publish(String topic, T message) { if (topic == null || message == null) { throw new IllegalArgumentException("topic or message cannot be null."); } Set<TopicListener<T>> listeners = topicToListenersMap.get(topic); if (listeners != null) { for (TopicListener listener : listeners) { listener.onMessage(topic, message); } } return true; }
@Override public AccountService getAccountService() { try { long startTimeMs = System.currentTimeMillis(); logger.info("Starting a HelixAccountService"); HelixPropertyStore<ZNRecord> helixStore = CommonUtils.createHelixPropertyStore(accountServiceConfig.zkClientConnectString, storeConfig, null); logger.info("HelixPropertyStore started with zkClientConnectString={}, zkClientSessionTimeoutMs={}, " + "zkClientConnectionTimeoutMs={}, rootPath={}", accountServiceConfig.zkClientConnectString, storeConfig.zkClientSessionTimeoutMs, storeConfig.zkClientConnectionTimeoutMs, storeConfig.rootPath); ScheduledExecutorService scheduler = accountServiceConfig.updaterPollingIntervalMs > 0 ? Utils.newScheduler(1, HELIX_ACCOUNT_UPDATER_PREFIX, false) : null; HelixAccountService helixAccountService = new HelixAccountService(helixStore, accountServiceMetrics, notifier, scheduler, accountServiceConfig); long spentTimeMs = System.currentTimeMillis() - startTimeMs; logger.info("HelixAccountService started, took {} ms", spentTimeMs); accountServiceMetrics.startupTimeInMs.update(spentTimeMs); return helixAccountService; } catch (Exception e) { throw new IllegalStateException("Could not instantiate HelixAccountService", e); } } }
/** * Constructor. * @param verifiableProperties The properties to get a {@link HelixAccountService} instance. Cannot be {@code null}. * @param metricRegistry The {@link MetricRegistry} for metrics tracking. Cannot be {@code null}. */ public HelixAccountServiceFactory(VerifiableProperties verifiableProperties, MetricRegistry metricRegistry) { this(new HelixPropertyStoreConfig(verifiableProperties), new HelixAccountServiceConfig(verifiableProperties), new AccountServiceMetrics(metricRegistry), new HelixNotifier(new HelixAccountServiceConfig(verifiableProperties).zkClientConnectString, new HelixPropertyStoreConfig(verifiableProperties))); }
notifier.subscribe(ACCOUNT_METADATA_CHANGE_TOPIC, changeTopicListener); } else { logger.warn("Notifier is null. Account updates cannot be notified to other entities. Local account cache may not "
} else if (notifier.publish(ACCOUNT_METADATA_CHANGE_TOPIC, FULL_ACCOUNT_METADATA_CHANGE_MESSAGE)) { logger.trace("Successfully published message for account metadata change"); } else {