@Test public void cancelReleasesPermit() throws Exception { ConnectionFactory<String, ListenableAsyncCloseable> o = newMockConnectionFactory(); when(o.newConnection(any(), any())).thenReturn(never()); ConnectionFactory<String, ? extends ListenableAsyncCloseable> cf = makeCF(LimitingConnectionFactoryFilter.withMax(1), o); connectlistener.listen(cf.newConnection("c1", null)).verifyNoEmissions(); connectAndVerifyFailed(cf); connectlistener.cancel(); ListenableAsyncCloseable c = mock(ListenableAsyncCloseable.class); when(c.onClose()).thenReturn(Completable.never()); when(o.newConnection(any(), any())).thenReturn(succeeded(c)); cf.newConnection("c2", null).toFuture().get(); }
public static <A, C extends ListenableAsyncCloseable> ConnectionFactoryFilter<A, C> withMax( int maxConnections) { return new LimitingConnectionFactoryFilter<>(new MaxConnectionsLimiter<>(maxConnections)); }
LimitingConnectionFactoryFilter implements ConnectionFactoryFilter<ResolvedAddress, C> { public static <A, C extends ListenableAsyncCloseable> ConnectionFactoryFilter<A, C> withMax( int maxConnections) { return new LimitingConnectionFactoryFilter<>(new MaxConnectionsLimiter<>(maxConnections)); } }
LimitingConnectionFactoryFilter implements ConnectionFactoryFilter<ResolvedAddress, C> { public static <A, C extends ListenableAsyncCloseable> ConnectionFactoryFilter<A, C> withMax( int maxConnections) { return new LimitingConnectionFactoryFilter<>(new MaxConnectionsLimiter<>(maxConnections)); } private  LimitingConnectionFactoryFilter(final ConnectionLimiter<ResolvedAddress, C> limiter); }
LimitingConnectionFactoryFilter implements ConnectionFactoryFilter<ResolvedAddress, C> { public static <A, C extends ListenableAsyncCloseable> ConnectionFactoryFilter<A, C> withMax( int maxConnections) { return new LimitingConnectionFactoryFilter<>(new MaxConnectionsLimiter<>(maxConnections)); } private  LimitingConnectionFactoryFilter(final ConnectionLimiter<ResolvedAddress, C> limiter); static ConnectionFactoryFilter<A, C> withMax(
            int maxConnections); static ConnectionFactoryFilter<A, C> with(
            ConnectionLimiter<A, C> limiter); @Override ConnectionFactory<ResolvedAddress, C> create(final ConnectionFactory<ResolvedAddress, C> original); }
LimitingConnectionFactoryFilter implements ConnectionFactoryFilter<ResolvedAddress, C> { public static <A, C extends ListenableAsyncCloseable> ConnectionFactoryFilter<A, C> withMax( int maxConnections) { return new LimitingConnectionFactoryFilter<>(new MaxConnectionsLimiter<>(maxConnections)); } private  LimitingConnectionFactoryFilter(final ConnectionLimiter<ResolvedAddress, C> limiter); static ConnectionFactoryFilter<A, C> withMax(
            int maxConnections); static ConnectionFactoryFilter<A, C> with(
            ConnectionLimiter<A, C> limiter); @Override ConnectionFactory<ResolvedAddress, C> create(final ConnectionFactory<ResolvedAddress, C> original);  }