/** * Creates a bulkhead with a default config. * * @param name the name of this bulkhead */ public SemaphoreBulkhead(String name) { this(name, BulkheadConfig.ofDefaults()); }
/** * Creates a BulkheadRegistry with a default Bulkhead configuration * * @return a BulkheadRegistry instance backed by a default Bulkhead configuration */ static BulkheadRegistry ofDefaults() { return new InMemoryBulkheadRegistry(BulkheadConfig.ofDefaults()); }
/** * Creates a bulkhead using a configuration supplied * * @param name the name of this bulkhead * @param bulkheadConfig custom bulkhead configuration */ public SemaphoreBulkhead(String name, BulkheadConfig bulkheadConfig) { this.name = name; this.config = bulkheadConfig != null ? bulkheadConfig : BulkheadConfig.ofDefaults(); // init semaphore this.semaphore = new Semaphore(this.config.getMaxConcurrentCalls(), true); this.metrics = new BulkheadMetrics(); this.eventProcessor = new BulkheadEventProcessor(); }
@Test public void testConstructors() { final BulkheadRegistry registry = new InMemoryBulkheadRegistry(BulkheadConfig.ofDefaults()); BulkheadExports.ofIterable("boo_bulkheads", singleton(Bulkhead.ofDefaults("foo"))); BulkheadExports.ofBulkheadRegistry("boo_bulkheads", registry); BulkheadExports.ofSupplier("boo_bulkheads", () -> singleton(Bulkhead.ofDefaults("foo"))); BulkheadExports.ofIterable(singleton(Bulkhead.ofDefaults("foo"))); BulkheadExports.ofBulkheadRegistry(registry); BulkheadExports.ofSupplier(() -> singleton(Bulkhead.ofDefaults("foo"))); }