com.netflix.hystrix.Hystrix类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(280)

本文整理了Java中com.netflix.hystrix.Hystrix类的一些代码示例,展示了Hystrix类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hystrix类的具体详情如下:
包路径:com.netflix.hystrix.Hystrix
类名称:Hystrix

Hystrix介绍

[英]Lifecycle management of Hystrix.
[中]Hystrix的生命周期管理。

代码示例

代码示例来源:origin: PipelineAI/pipeline

@Override
protected void before() {
  this.context = HystrixRequestContext.initializeContext();
  Hystrix.reset();
}

代码示例来源:origin: PipelineAI/pipeline

/**
 * Reset state and release resources in use (such as thread-pools).
 * <p>
 * NOTE: This can result in race conditions if HystrixCommands are concurrently being executed.
 * </p>
 */
public static void reset() {
  // shutdown thread-pools
  HystrixThreadPool.Factory.shutdown();
  _reset();
}

代码示例来源:origin: PipelineAI/pipeline

/* package */static void endCurrentThreadExecutingCommand() {
  endCurrentThreadExecutingCommand(currentCommand.get());
}

代码示例来源:origin: PipelineAI/pipeline

@Override
protected Boolean run() {
  assertEquals("SemaphoreIsolatedCommandName", Hystrix.getCurrentThreadExecutingCommand().name());
  System.out.println("Semaphore Thread : " + Thread.currentThread().getName());
  //should be a single execution on the caller thread (since it's busy here)
  assertEquals(1, Hystrix.getCommandCount());
  return Hystrix.getCurrentThreadExecutingCommand() != null;
}

代码示例来源:origin: PipelineAI/pipeline

@Override
  public Observable<R> call() {
    executionResult = executionResult.setExecutionOccurred();
    if (!commandState.compareAndSet(CommandState.OBSERVABLE_CHAIN_CREATED, CommandState.USER_CODE_EXECUTED)) {
      return Observable.error(new IllegalStateException("execution attempted while in state : " + commandState.get().name()));
    }
    metrics.markCommandStart(commandKey, threadPoolKey, ExecutionIsolationStrategy.SEMAPHORE);
    // semaphore isolated
    // store the command that is being run
    endCurrentThreadExecutingCommand = Hystrix.startCurrentThreadExecutingCommand(getCommandKey());
    try {
      executionHook.onRunStart(_cmd);
      executionHook.onExecutionStart(_cmd);
      return getUserExecutionObservable(_cmd);  //the getUserExecutionObservable method already wraps sync exceptions, so this shouldn't throw
    } catch (Throwable ex) {
      //If the above hooks throw, then use that as the result of the run method
      return Observable.error(ex);
    }
  }
});

代码示例来源:origin: PipelineAI/pipeline

@Override
  public void onNext(Integer n) {
    System.out.println("OnNext : " + n + " : " + Thread.currentThread().getName() + " : " + Hystrix.getCommandCount());// + " : " + Hystrix.getCurrentThreadExecutingCommand().name() + " : " + Hystrix.getCommandCount());
  }
});

代码示例来源:origin: PipelineAI/pipeline

@Override
protected Boolean run() {
  try {
    //give the caller thread a chance to check that no thread locals are set on it
    Thread.sleep(100);
  } catch (InterruptedException ex) {
    return false;
  }
  assertEquals("CommandName", Hystrix.getCurrentThreadExecutingCommand().name());
  assertEquals(1, Hystrix.getCommandCount());
  return Hystrix.getCurrentThreadExecutingCommand() != null;
}

代码示例来源:origin: com.netflix.hystrix/hystrix-core

@Override
  public Observable<R> call() {
    executionResult = executionResult.setExecutionOccurred();
    if (!commandState.compareAndSet(CommandState.OBSERVABLE_CHAIN_CREATED, CommandState.USER_CODE_EXECUTED)) {
      return Observable.error(new IllegalStateException("execution attempted while in state : " + commandState.get().name()));
    }
    metrics.markCommandStart(commandKey, threadPoolKey, ExecutionIsolationStrategy.SEMAPHORE);
    // semaphore isolated
    // store the command that is being run
    endCurrentThreadExecutingCommand = Hystrix.startCurrentThreadExecutingCommand(getCommandKey());
    try {
      executionHook.onRunStart(_cmd);
      executionHook.onExecutionStart(_cmd);
      return getUserExecutionObservable(_cmd);  //the getUserExecutionObservable method already wraps sync exceptions, so this shouldn't throw
    } catch (Throwable ex) {
      //If the above hooks throw, then use that as the result of the run method
      return Observable.error(ex);
    }
  }
});

代码示例来源:origin: PipelineAI/pipeline

@Before
public void setup() {
  Hystrix.reset();
}

代码示例来源:origin: PipelineAI/pipeline

@Override
protected Boolean run() {
  assertEquals("SemaphoreIsolatedCommandName", Hystrix.getCurrentThreadExecutingCommand().name());
  System.out.println("Semaphore Thread : " + Thread.currentThread().getName());
  //should be a single execution on the caller thread (since it's busy here)
  assertEquals(1, Hystrix.getCommandCount());
  return Hystrix.getCurrentThreadExecutingCommand() != null;
}

代码示例来源:origin: PipelineAI/pipeline

/**
 * Reset state and release resources in use (such as threadpools) and wait for completion.
 * <p>
 * NOTE: This can result in race conditions if HystrixCommands are concurrently being executed.
 * </p>
 * 
 * @param time
 *            time to wait for thread-pools to shutdown
 * @param unit
 *            {@link TimeUnit} for <pre>time</pre> to wait for thread-pools to shutdown
 */
public static void reset(long time, TimeUnit unit) {
  // shutdown thread-pools
  HystrixThreadPool.Factory.shutdown(time, unit);
  _reset();
}

代码示例来源:origin: com.netflix.hystrix/hystrix-core

/* package */static void endCurrentThreadExecutingCommand() {
  endCurrentThreadExecutingCommand(currentCommand.get());
}

代码示例来源:origin: PipelineAI/pipeline

@Before
public void reset() {
  Hystrix.reset();
}

代码示例来源:origin: PipelineAI/pipeline

@Override
protected Boolean run() {
  assertEquals("CommandName", Hystrix.getCurrentThreadExecutingCommand().name());
  assertEquals(1, Hystrix.getCommandCount());
  return Hystrix.getCurrentThreadExecutingCommand() != null;
}

代码示例来源:origin: com.netflix.hystrix/hystrix-core

/**
 * Reset state and release resources in use (such as thread-pools).
 * <p>
 * NOTE: This can result in race conditions if HystrixCommands are concurrently being executed.
 * </p>
 */
public static void reset() {
  // shutdown thread-pools
  HystrixThreadPool.Factory.shutdown();
  _reset();
}

代码示例来源:origin: PipelineAI/pipeline

@Before
public void init() {
  HystrixCommandMetrics.reset();
  Hystrix.reset();
}

代码示例来源:origin: PipelineAI/pipeline

@Override
protected Boolean run() {
  assertEquals("SemaphoreIsolatedCommandName", Hystrix.getCurrentThreadExecutingCommand().name());
  System.out.println("Semaphore Thread : " + Thread.currentThread().getName());
  //should be a single execution on the caller thread (since it's busy here)
  assertEquals(1, Hystrix.getCommandCount());
  return Hystrix.getCurrentThreadExecutingCommand() != null;
}

代码示例来源:origin: com.netflix.hystrix/hystrix-core

/**
 * Reset state and release resources in use (such as threadpools) and wait for completion.
 * <p>
 * NOTE: This can result in race conditions if HystrixCommands are concurrently being executed.
 * </p>
 * 
 * @param time
 *            time to wait for thread-pools to shutdown
 * @param unit
 *            {@link TimeUnit} for <pre>time</pre> to wait for thread-pools to shutdown
 */
public static void reset(long time, TimeUnit unit) {
  // shutdown thread-pools
  HystrixThreadPool.Factory.shutdown(time, unit);
  _reset();
}

代码示例来源:origin: PipelineAI/pipeline

Hystrix.reset();

代码示例来源:origin: PipelineAI/pipeline

@Override
  public void onNext(Boolean value) {
    System.out.println("OnNext : " + value);
    assertTrue(value);
    assertEquals("CommandName", Hystrix.getCurrentThreadExecutingCommand().name());
    assertEquals(1, Hystrix.getCommandCount());
  }
});

相关文章