Search in sources :

Example 1 with ClusterSingletonServiceProvider

use of org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider in project controller by opendaylight.

the class ClusterSingletonServiceProviderModule method createInstance.

@Override
public AutoCloseable createInstance() {
    final WaitingServiceTracker<ClusterSingletonServiceProvider> tracker = WaitingServiceTracker.create(ClusterSingletonServiceProvider.class, bundleContext);
    final ClusterSingletonServiceProvider service = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
    // instance will be closed via blueprint.
    return Reflection.newProxy(AutoCloseableDOMClusterSingletonServiceProvider.class, new AbstractInvocationHandler() {

        @Override
        protected Object handleInvocation(final Object proxy, final Method method, final Object[] args) throws Throwable {
            if (method.getName().equals("close")) {
                tracker.close();
                return null;
            } else {
                return method.invoke(service, args);
            }
        }
    });
}
Also used : ClusterSingletonServiceProvider(org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider) AbstractInvocationHandler(com.google.common.reflect.AbstractInvocationHandler) Method(java.lang.reflect.Method)

Aggregations

AbstractInvocationHandler (com.google.common.reflect.AbstractInvocationHandler)1 Method (java.lang.reflect.Method)1 ClusterSingletonServiceProvider (org.opendaylight.mdsal.singleton.common.api.ClusterSingletonServiceProvider)1