All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bazaarvoice.ostrich.dropwizard.pool.ManagedServicePoolProxy Maven / Gradle / Ivy

package com.bazaarvoice.ostrich.dropwizard.pool;

import com.bazaarvoice.ostrich.RetryPolicy;
import com.bazaarvoice.ostrich.pool.ServicePoolBuilder;
import com.bazaarvoice.ostrich.pool.ServicePoolProxies;
import com.yammer.dropwizard.lifecycle.Managed;

import static com.google.common.base.Preconditions.checkArgument;

/**
 * Adapts the Dropwizard {@link Managed} interface for a dynamic service proxy created by
 * {@link ServicePoolBuilder#buildProxy(RetryPolicy)}.  This allows Dropwizard to shutdown service pools cleanly.
 * 

* Here's how to use this class with an instance of a Dropwizard {@code Environment}: *

 *  Environment environment = ...;
 *  Service service = ServicePoolBuilder.create(Service.class)
 *     .withServiceFactory(...)
 *     .buildProxy(...);
 *  environment.manage(new ManagedServicePoolProxy(service));
 * 
*/ public class ManagedServicePoolProxy implements Managed { private final Object _proxy; /** * Wraps the specified dynamic proxy with the Dropwizard {@link Managed} interface. * @param proxy A dynamic service proxy created by {@link ServicePoolBuilder#buildProxy(RetryPolicy)}. */ public ManagedServicePoolProxy(Object proxy) { checkArgument(ServicePoolProxies.isProxy(proxy)); _proxy = proxy; } @Override public void start() { // Nothing to do } @Override public void stop() { ServicePoolProxies.close(_proxy); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy