@Test public void testProxyDoesNotOverrideClose() throws IOException { Service service = ServicePoolProxy.create(Service.class, NEVER_RETRY, _pool, SUPPLIER, false); service.close(); @SuppressWarnings("unchecked") ArgumentCaptor<ServiceCallback<Service, ?>> captor = (ArgumentCaptor) ArgumentCaptor.forClass(ServiceCallback.class); verify(_pool).execute(same(CONTEXT), same(NEVER_RETRY), captor.capture()); captor.getValue().call(FOO_SERVICE); verify(FOO_SERVICE).close(); verify(_pool, never()).close(); }
static <S> S create(Class<S> serviceType, RetryPolicy retryPolicy, ServicePool<S> pool, PartitionContextSupplier partitionContextSupplier, boolean shutdownPoolOnClose) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); Class<?>[] interfaces = shutdownPoolOnClose ? new Class<?>[] {serviceType, Closeable.class} : new Class<?>[] {serviceType}; ServicePoolProxy<S> proxy = new ServicePoolProxy<S>( serviceType, retryPolicy, pool, partitionContextSupplier, shutdownPoolOnClose); return serviceType.cast(Proxy.newProxyInstance(loader, interfaces, proxy)); }
ServicePoolProxy extends AbstractInvocationHandler { static <S> S create(Class<S> serviceType, RetryPolicy retryPolicy, ServicePool<S> pool, PartitionContextSupplier partitionContextSupplier, boolean shutdownPoolOnClose) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); Class<?>[] interfaces = shutdownPoolOnClose ? new Class<?>[] {serviceType, Closeable.class} : new Class<?>[] {serviceType}; ServicePoolProxy<S> proxy = new ServicePoolProxy<S>( serviceType, retryPolicy, pool, partitionContextSupplier, shutdownPoolOnClose); return serviceType.cast(Proxy.newProxyInstance(loader, interfaces, proxy)); } }
ServicePoolProxy extends AbstractInvocationHandler { static <S> S create(Class<S> serviceType, RetryPolicy retryPolicy, ServicePool<S> pool, PartitionContextSupplier partitionContextSupplier, boolean shutdownPoolOnClose) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); Class<?>[] interfaces = shutdownPoolOnClose ? new Class<?>[] {serviceType, Closeable.class} : new Class<?>[] {serviceType}; ServicePoolProxy<S> proxy = new ServicePoolProxy<S>( serviceType, retryPolicy, pool, partitionContextSupplier, shutdownPoolOnClose); return serviceType.cast(Proxy.newProxyInstance(loader, interfaces, proxy)); } ServicePoolProxy(Class<S> serviceType, RetryPolicy retryPolicy, ServicePool<S> servicePool,
                     PartitionContextSupplier partitionContextSupplier, boolean shutdownPoolOnClose); }
ServicePoolProxy extends AbstractInvocationHandler { static <S> S create(Class<S> serviceType, RetryPolicy retryPolicy, ServicePool<S> pool, PartitionContextSupplier partitionContextSupplier, boolean shutdownPoolOnClose) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); Class<?>[] interfaces = shutdownPoolOnClose ? new Class<?>[] {serviceType, Closeable.class} : new Class<?>[] {serviceType}; ServicePoolProxy<S> proxy = new ServicePoolProxy<S>( serviceType, retryPolicy, pool, partitionContextSupplier, shutdownPoolOnClose); return serviceType.cast(Proxy.newProxyInstance(loader, interfaces, proxy)); } ServicePoolProxy(Class<S> serviceType, RetryPolicy retryPolicy, ServicePool<S> servicePool,
                     PartitionContextSupplier partitionContextSupplier, boolean shutdownPoolOnClose); @Override String toString(); }
ServicePoolProxy extends AbstractInvocationHandler { static <S> S create(Class<S> serviceType, RetryPolicy retryPolicy, ServicePool<S> pool, PartitionContextSupplier partitionContextSupplier, boolean shutdownPoolOnClose) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); Class<?>[] interfaces = shutdownPoolOnClose ? new Class<?>[] {serviceType, Closeable.class} : new Class<?>[] {serviceType}; ServicePoolProxy<S> proxy = new ServicePoolProxy<S>( serviceType, retryPolicy, pool, partitionContextSupplier, shutdownPoolOnClose); return serviceType.cast(Proxy.newProxyInstance(loader, interfaces, proxy)); } ServicePoolProxy(Class<S> serviceType, RetryPolicy retryPolicy, ServicePool<S> servicePool,
                     PartitionContextSupplier partitionContextSupplier, boolean shutdownPoolOnClose); @Override String toString();  }