Ejemplo n.º 1
0
 // ignoring since this never ends ... useful for testing
 // https://github.com/Netflix/Hystrix/issues/236
 @Ignore
 @Test
 public void testSuccessClosesCircuitWhenBusy() throws InterruptedException {
   HystrixPlugins.getInstance().registerCommandExecutionHook(new MyHystrixCommandExecutionHook());
   try {
     performLoad(200, 0, 40);
     performLoad(250, 100, 40);
     performLoad(600, 0, 40);
   } finally {
     Hystrix.reset();
   }
 }
  @Override
  protected MetricRegistry getMetricRegistry() {

    METRIC_REGISTRY.register(name("jvm", "gc"), new GarbageCollectorMetricSet());
    METRIC_REGISTRY.register(name("jvm", "memory"), new MemoryUsageGaugeSet());
    METRIC_REGISTRY.register(name("jvm", "thread-states"), new ThreadStatesGaugeSet());

    HystrixCodaHaleMetricsPublisher hystrixCodaHaleMetricsPublisher =
        new HystrixCodaHaleMetricsPublisher(METRIC_REGISTRY);
    HystrixPlugins.getInstance().registerMetricsPublisher(hystrixCodaHaleMetricsPublisher);

    return METRIC_REGISTRY;
  }
  /**
   * Get or create the {@link HystrixCommandMetrics} instance for a given {@link HystrixCommandKey}.
   *
   * <p>This is thread-safe and ensures only 1 {@link HystrixCommandMetrics} per {@link
   * HystrixCommandKey}.
   *
   * @param key {@link HystrixCommandKey} of {@link HystrixCommand} instance requesting the {@link
   *     HystrixCommandMetrics}
   * @param commandGroup Pass-thru to {@link HystrixCommandMetrics} instance on first time when
   *     constructed
   * @param properties Pass-thru to {@link HystrixCommandMetrics} instance on first time when
   *     constructed
   * @return {@link HystrixCommandMetrics}
   */
  public static HystrixCommandMetrics getInstance(
      HystrixCommandKey key,
      HystrixCommandGroupKey commandGroup,
      HystrixThreadPoolKey threadPoolKey,
      HystrixCommandProperties properties) {
    // attempt to retrieve from cache first
    HystrixCommandMetrics commandMetrics = metrics.get(key.name());
    if (commandMetrics != null) {
      return commandMetrics;
    }
    // it doesn't exist so we need to create it

    // now check to see if we need to create a synthetic threadPoolKey
    HystrixThreadPoolKey nonNullThreadPoolKey;
    if (threadPoolKey == null) {
      nonNullThreadPoolKey = HystrixThreadPoolKey.Factory.asKey(commandGroup.name());
    } else {
      nonNullThreadPoolKey = threadPoolKey;
    }
    commandMetrics =
        new HystrixCommandMetrics(
            key,
            commandGroup,
            nonNullThreadPoolKey,
            properties,
            HystrixPlugins.getInstance().getEventNotifier());
    // attempt to store it (race other threads)
    HystrixCommandMetrics existing = metrics.putIfAbsent(key.name(), commandMetrics);
    if (existing == null) {
      // we won the thread-race to store the instance we created
      return commandMetrics;
    } else {
      // we lost so return 'existing' and let the one we created be garbage collected
      return existing;
    }
  }
Ejemplo n.º 4
0
 @Override
 public Scheduler getScheduler(Func0<Boolean> shouldInterruptThread) {
   return new HystrixContextScheduler(
       HystrixPlugins.getInstance().getConcurrencyStrategy(), this, shouldInterruptThread);
 }
Ejemplo n.º 5
0
 @Override
 public Scheduler getScheduler() {
   return new HystrixContextScheduler(
       HystrixPlugins.getInstance().getConcurrencyStrategy(), this);
 }
Ejemplo n.º 6
0
 /**
  * {@link HystrixRequestLog} for current request as defined by {@link HystrixRequestContext}.
  *
  * <p>NOTE: This uses the default {@link HystrixConcurrencyStrategy} or global override. If an
  * injected strategy is being used by commands you must instead use {@link
  * #getCurrentRequest(HystrixConcurrencyStrategy)}.
  *
  * @return {@link HystrixRequestLog}
  */
 public static HystrixRequestLog getCurrentRequest() {
   return currentRequestLog.get(HystrixPlugins.getInstance().getConcurrencyStrategy());
 }