@Override protected Throwable getThrowable() { return new BulkheadFullException(String.format("Bulkhead '%s' is full", bulkhead.getName())); }
private BulkheadMetrics(String prefix, Iterable<Bulkhead> bulkheads) { requireNonNull(prefix); requireNonNull(bulkheads); bulkheads.forEach(bulkhead -> { String name = bulkhead.getName(); //number of available concurrent calls as an integer metricRegistry.register(name(prefix, name, AVAILABLE_CONCURRENT_CALLS), (Gauge<Integer>) () -> bulkhead.getMetrics().getAvailableConcurrentCalls()); } ); }
private Exception bulkheadFullException() { return new BulkheadFullException(String.format("Bulkhead '%s' is full", bulkhead.getName())); }
public static void isCallPermitted(Bulkhead bulkhead) { if(!bulkhead.isCallPermitted()) { throw new BulkheadFullException(String.format("Bulkhead '%s' is full", bulkhead.getName())); } } }
@Override public void onSubscribe(Subscription subscription) { if (SubscriptionHelper.setOnce(this, subscription)) { if (acquireCallPermit()) { childSubscriber.onSubscribe(this); } else { cancel(); childSubscriber.onSubscribe(this); childSubscriber.onError(new BulkheadFullException(String.format("Bulkhead '%s' is full", bulkhead.getName()))); } } }
/** * {@inheritDoc} */ @Override public List<MetricFamilySamples> collect() { final GaugeMetricFamily stats = new GaugeMetricFamily( name, "Bulkhead Stats", asList("name", "param")); for (Bulkhead bulkhead : bulkheadsSupplier.get()) { final Bulkhead.Metrics metrics = bulkhead.getMetrics(); stats.addMetric( asList(bulkhead.getName(), "available_concurrent_calls"), metrics.getAvailableConcurrentCalls()); } return singletonList(stats); } }
private Object handleOther(MethodInvocation invocation, io.github.resilience4j.bulkhead.Bulkhead bulkhead, RecoveryFunction<?> recoveryFunction) throws Throwable { boolean permission = bulkhead.isCallPermitted(); if (!permission) { Throwable t = new BulkheadFullException(String.format("Bulkhead '%s' is full", bulkhead.getName())); return recoveryFunction.apply(t); } try { if (Thread.interrupted()) { throw new IllegalStateException("Thread was interrupted during permission wait"); } return invocation.proceed(); } catch (Exception e) { return recoveryFunction.apply(e); } finally { bulkhead.onComplete(); } } }
@Test public void shouldReturnTheCorrectName() { assertThat(bulkhead.getName()).isEqualTo("test"); }
promise.completeExceptionally(new BulkheadFullException(String.format("Bulkhead '%s' is open", bulkhead.getName())));
Throwable t = new BulkheadFullException(String.format("Bulkhead '%s' is full", bulkhead.getName())); handleRecovery(down, t);
@Override public void bindTo(MeterRegistry registry) { for (Bulkhead bulkhead : bulkheads) { final String name = bulkhead.getName(); Gauge.builder(getName(prefix, name, AVAILABLE_CONCURRENT_CALLS), bulkhead, (cb) -> cb.getMetrics().getAvailableConcurrentCalls()) .register(registry); } } }
} else { final CompletableFuture promise = new CompletableFuture<>(); Throwable t = new BulkheadFullException(String.format("Bulkhead '%s' is full", bulkhead.getName())); try { promise.complete(recoveryFunction.apply(t));
@Test public void shouldReturnTheCorrectName() { Bulkhead bulkhead = registry.bulkhead("test"); assertThat(bulkhead).isNotNull(); assertThat(bulkhead.getName()).isEqualTo("test"); assertThat(bulkhead.getBulkheadConfig().getMaxConcurrentCalls()).isEqualTo(25); assertThat(bulkhead.getMetrics().getAvailableConcurrentCalls()).isEqualTo(25); }
chain1.get("stream/events/:name", ctx -> { String bulkheadName = ctx.getPathTokens().get("name"); Bulkhead bulkhead = bulkheadRegistry.getAllBulkheads().find(b -> b.getName().equals(bulkheadName)) .getOrElseThrow(() -> new IllegalArgumentException(String.format("bulkhead with name %s not found", bulkheadName))); Function<BulkheadEvent, String> data = b -> Jackson.getObjectWriter(chain1.getRegistry()).writeValueAsString(BulkheadEventDTO.createEventDTO(b)); String bulkheadName = ctx.getPathTokens().get("name"); String eventType = ctx.getPathTokens().get("type"); Bulkhead bulkhead = bulkheadRegistry.getAllBulkheads().find(b -> b.getName().equals(bulkheadName)) .getOrElseThrow(() -> new IllegalArgumentException(String.format("bulkhead with name %s not found", bulkheadName))); Flux<BulkheadEvent> eventStream = ReactorAdapter.toFlux(bulkhead.getEventPublisher())
private Exception bulkheadFullException() { return new BulkheadFullException(String.format("Bulkhead '%s' is full", bulkhead.getName())); }
private BulkheadMetrics(String prefix, Iterable<Bulkhead> bulkheads) { requireNonNull(prefix); requireNonNull(bulkheads); bulkheads.forEach(bulkhead -> { String name = bulkhead.getName(); //number of available concurrent calls as an integer metricRegistry.register(name(prefix, name, AVAILABLE_CONCURRENT_CALLS), (Gauge<Integer>) () -> bulkhead.getMetrics().getAvailableConcurrentCalls()); } ); }
@Override public void onSubscribe(Subscription subscription) { if (SubscriptionHelper.setOnce(this, subscription)) { if (acquireCallPermit()) { childSubscriber.onSubscribe(this); } else { cancel(); childSubscriber.onSubscribe(this); childSubscriber.onError(new BulkheadFullException(String.format("Bulkhead '%s' is full", bulkhead.getName()))); } } }
private Object handleOther(MethodInvocation invocation, io.github.resilience4j.bulkhead.Bulkhead bulkhead, RecoveryFunction<?> recoveryFunction) throws Throwable { boolean permission = bulkhead.isCallPermitted(); if (!permission) { Throwable t = new BulkheadFullException(String.format("Bulkhead '%s' is full", bulkhead.getName())); return recoveryFunction.apply(t); } try { if (Thread.interrupted()) { throw new IllegalStateException("Thread was interrupted during permission wait"); } return invocation.proceed(); } catch (Exception e) { return recoveryFunction.apply(e); } finally { bulkhead.onComplete(); } } }
Throwable t = new BulkheadFullException(String.format("Bulkhead '%s' is full", bulkhead.getName())); handleRecovery(down, t);
chain1.get("stream/events/:name", ctx -> { String bulkheadName = ctx.getPathTokens().get("name"); Bulkhead bulkhead = bulkheadRegistry.getAllBulkheads().find(b -> b.getName().equals(bulkheadName)) .getOrElseThrow(() -> new IllegalArgumentException(String.format("bulkhead with name %s not found", bulkheadName))); Function<BulkheadEvent, String> data = b -> Jackson.getObjectWriter(chain1.getRegistry()).writeValueAsString(BulkheadEventDTO.createEventDTO(b)); String bulkheadName = ctx.getPathTokens().get("name"); String eventType = ctx.getPathTokens().get("type"); Bulkhead bulkhead = bulkheadRegistry.getAllBulkheads().find(b -> b.getName().equals(bulkheadName)) .getOrElseThrow(() -> new IllegalArgumentException(String.format("bulkhead with name %s not found", bulkheadName))); Flux<BulkheadEvent> eventStream = ReactorAdapter.toFlux(bulkhead.getEventPublisher())