@Override public TogglingLoadBalancer createLoadBalancer( ZKConnection zkConnection, ScheduledExecutorService executorService) { _log.info("Using d2ServicePath: " + _d2ServicePath); ZooKeeperPermanentStore<ClusterProperties> zkClusterRegistry = createPermanentStore( zkConnection, ZKFSUtil.clusterPath(_baseZKPath), new ClusterPropertiesJsonSerializer()); ZooKeeperPermanentStore<ServiceProperties> zkServiceRegistry = createPermanentStore( zkConnection, ZKFSUtil.servicePath(_baseZKPath, _d2ServicePath), new ServicePropertiesJsonSerializer()); ZooKeeperEphemeralStore<UriProperties> zkUriRegistry = createEphemeralStore( zkConnection, ZKFSUtil.uriPath(_baseZKPath), new UriPropertiesJsonSerializer(), new UriPropertiesMerger()); FileStore<ClusterProperties> fsClusterStore = createFileStore("clusters", new ClusterPropertiesJsonSerializer()); FileStore<ServiceProperties> fsServiceStore = createFileStore(_d2ServicePath, new ServicePropertiesJsonSerializer()); FileStore<UriProperties> fsUriStore = createFileStore("uris", new UriPropertiesJsonSerializer()); PropertyEventBus<ClusterProperties> clusterBus = new PropertyEventBusImpl<ClusterProperties>(executorService); PropertyEventBus<ServiceProperties> serviceBus = new PropertyEventBusImpl<ServiceProperties>(executorService); PropertyEventBus<UriProperties> uriBus = new PropertyEventBusImpl<UriProperties>(executorService); // This ensures the filesystem store receives the events from the event bus so that // it can keep a local backup. clusterBus.register(fsClusterStore); serviceBus.register(fsServiceStore); uriBus.register(fsUriStore); TogglingPublisher<ClusterProperties> clusterToggle = _factory.createClusterToggle(zkClusterRegistry, fsClusterStore, clusterBus); TogglingPublisher<ServiceProperties> serviceToggle = _factory.createServiceToggle(zkServiceRegistry, fsServiceStore, serviceBus); TogglingPublisher<UriProperties> uriToggle = _factory.createUriToggle(zkUriRegistry, fsUriStore, uriBus); SimpleLoadBalancerState state = new SimpleLoadBalancerState( executorService, uriBus, clusterBus, serviceBus, _clientFactories, _loadBalancerStrategyFactories, _sslContext, _sslParameters, _isSSLEnabled, _clientServicesConfig); SimpleLoadBalancer balancer = new SimpleLoadBalancer(state, _lbTimeout, _lbTimeoutUnit); TogglingLoadBalancer togLB = _factory.createBalancer(balancer, state, clusterToggle, serviceToggle, uriToggle); togLB.start( new Callback<None>() { @Override public void onError(Throwable e) { _log.warn( "Failed to run start on the TogglingLoadBalancer, may not have registered " + "SimpleLoadBalancer and State with JMX."); } @Override public void onSuccess(None result) { _log.info("Registered SimpleLoadBalancer and State with JMX."); } }); return togLB; }