Package com.linkedin.d2.balancer.util

Examples of com.linkedin.d2.balancer.util.TogglingLoadBalancer


      LOG.info("ZK flag file: {}", _zkFlagFile.getAbsolutePath());
      LOG.info("ZK currently suppressed by flag file: {}", suppressZK());
    }

    _zkConnection = new ZKConnection(_connectString, _sessionTimeout, _shutdownAsynchronously, _isSymlinkAware);
    final TogglingLoadBalancer balancer = _loadBalancerFactory.createLoadBalancer(_zkConnection, _executor);

    // _currentLoadBalancer will never be null except the first time this method is called.
    // In this case we want the not-yet-started load balancer to service client requests.  In
    // all other cases, we service requests from the old LoadBalancer until the new one is started
    if (_currentLoadBalancer == null)
    {
      _currentLoadBalancer = balancer;
    }

    Callback<None> wrapped = new Callback<None>()
    {
      @Override
      public void onSuccess(None none)
      {
        _currentLoadBalancer = balancer;
        callback.onSuccess(none);
      }

      @Override
      public void onError(Throwable e)
      {
        callback.onError(e);
      }
    };
    if (!_startupCallback.compareAndSet(null, wrapped))
    {
      throw new IllegalStateException("Startup already in progress");
    }
    _executor.execute(new PropertyEventThread.PropertyEvent("startup")
    {

      @Override
      public void innerRun()
      {
        _zkConnection.addStateListener(new ZKListener(balancer));
        try
        {
          _zkConnection.start();
        }
        catch (Exception e)
        {
          LOG.error("Failed to start ZooKeeper (bad configuration?), enabling backup stores", e);
          Callback<None> startupCallback = _startupCallback.getAndSet(null);
          // TODO this should never be null
          balancer.enableBackup(startupCallback);
          return;
        }

        LOG.info("Started ZooKeeper");
        _executor.schedule(new Runnable()
        {
          @Override
          public void run()
          {
            Callback<None> startupCallback = _startupCallback.getAndSet(null);
            if (startupCallback != null)
            {
              // Noone has enabled the stores yet either way
              LOG.error("No response from ZooKeeper within {}ms, enabling backup stores", _initialZKTimeout);
              balancer.enableBackup(startupCallback);
            }
          }
        }, _initialZKTimeout, TimeUnit.MILLISECONDS);
      }
    });
View Full Code Here



    // create the load balancer
    SimpleLoadBalancer loadBalancer = new SimpleLoadBalancer(state);

    final TransportClient tc = loadBalancer.getClient(new URIRequest("d2://browsemaps/52"),
                                                      new RequestContext());
    final Client c = new TransportClientAdapter(tc);
    c.restRequest(null);
  }
View Full Code Here

  public static void testBuildAllPartitionsRequest(RestliRequestOptions options) throws ServiceUnavailableException, URISyntaxException, RestException
  {

    final int PARTITION_NUM = 10;

    ConsistentHashKeyMapper mapper = getKeyToHostMapper(PARTITION_NUM);

    AllPartitionsRequestBuilder<CollectionResponse<Greeting>> searchRB = new AllPartitionsRequestBuilder<CollectionResponse<Greeting>>(mapper);
    FindRequestBuilder<Long, Greeting> findRB = new FindRequestBuilder<Long, Greeting>(TEST_URI,
                                                                                       Greeting.class,
                                                                                       _COLL_SPEC,
View Full Code Here

  @Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "restliRequestOptions")
  public static void testSendAllPartitionsRequests(RestliRequestOptions options) throws ServiceUnavailableException, URISyntaxException, RestException, InterruptedException
  {
    final int PARTITION_NUM = 10;
    ConsistentHashKeyMapper mapper = getKeyToHostMapper(PARTITION_NUM);
    AllPartitionsRequestBuilder<Greeting> searchRB = new AllPartitionsRequestBuilder<Greeting>(mapper);
    ActionRequestBuilder<Long, Greeting> builder = new ActionRequestBuilder<Long, Greeting>(TEST_URI,
                                                                                            Greeting.class,
                                                                                            _COLL_SPEC,
                                                                                            options);
View Full Code Here

    {
      final ConsistentHashRing<URI> ring = new ConsistentHashRing<URI>(map);
      rings.add(ring);
    }

    return new ConsistentHashKeyMapper(new StaticRingProvider(rings), new TestPartitionInfoProvider());
  }
View Full Code Here

    {
      final ConsistentHashRing<URI> ring = new ConsistentHashRing<URI>(map);
      rings.add(ring);
    }

    return new ConsistentHashKeyMapper(new StaticRingProvider(rings), new TestPartitionInfoProvider());
  }
View Full Code Here

  private ZKFSLoadBalancer.TogglingLoadBalancerFactory createLoadBalancerFactory(D2ClientConfig config)
  {
    final ZKFSTogglingLoadBalancerFactoryImpl.ComponentFactory loadBalancerComponentFactory;
    if (config.componentFactory == null)
    {
      loadBalancerComponentFactory = new ZKFSComponentFactory();
    }
    else
    {
      loadBalancerComponentFactory = config.componentFactory;
    }
View Full Code Here

{

  @Override
  public LoadBalancerWithFacilities create(D2ClientConfig config)
  {
    return  new ZKFSLoadBalancer(config.zkHosts,
                                    (int) config.zkSessionTimeoutInMs,
                                    (int) config.zkStartupTimeoutInMs,
                                    createLoadBalancerFactory(config),
                                    config.flagFile,
                                    config.basePath,
View Full Code Here

    }

    final Map<String, LoadBalancerStrategyFactory<? extends LoadBalancerStrategy>> loadBalancerStrategyFactories =
        createDefaultLoadBalancerStrategyFactories();

    return new ZKFSTogglingLoadBalancerFactoryImpl(loadBalancerComponentFactory,
                                                   config.lbWaitTimeout,
                                                   config.lbWaitUnit,
                                                   config.basePath,
                                                   config.fsBasePath,
                                                   config.clientFactories,
View Full Code Here

      Map<String, Object> untyped = JacksonUtil.getObjectMapper().readValue(new String(bytes, "UTF-8"), HashMap.class);
      return fromMap(untyped);
    }
    catch (Exception e)
    {
      throw new PropertySerializationException(e);
    }
  }
View Full Code Here

TOP

Related Classes of com.linkedin.d2.balancer.util.TogglingLoadBalancer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.