package org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.config.openflow.plugin.impl.rev150327;
import com.google.common.reflect.AbstractInvocationHandler;
import com.google.common.reflect.Reflection;
import java.lang.reflect.Method;
import org.opendaylight.controller.config.api.osgi.WaitingServiceTracker;
import org.opendaylight.openflowplugin.api.openflow.OpenFlowPluginProvider;
import org.opendaylight.openflowplugin.extension.api.OpenFlowPluginExtensionRegistratorProvider;
import org.osgi.framework.BundleContext;
/**
* @deprecated Replaced by blueprint wiring
*/
@Deprecated
public class OpenFlowProviderModule extends AbstractOpenFlowProviderModule {
private BundleContext bundleContext;
public OpenFlowProviderModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver) {
super(identifier, dependencyResolver);
}
public OpenFlowProviderModule(final org.opendaylight.controller.config.api.ModuleIdentifier identifier, final org.opendaylight.controller.config.api.DependencyResolver dependencyResolver, final org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.config.openflow.plugin.impl.rev150327.OpenFlowProviderModule oldModule, final java.lang.AutoCloseable oldInstance) {
super(identifier, dependencyResolver, oldModule, oldInstance);
}
@Override
public AutoCloseable createInstance() {
// The service is provided via blueprint so wait for and return it here for backwards compatibility.
String typeFilter = String.format("(type=%s)", getIdentifier().getInstanceName());
final WaitingServiceTracker<OpenFlowPluginProvider> tracker = WaitingServiceTracker.create(
OpenFlowPluginProvider.class, bundleContext, typeFilter);
final OpenFlowPluginProvider openflowPluginProvider = tracker.waitForService(WaitingServiceTracker.FIVE_MINUTES);
// We don't want to call close on the actual service as its life cycle is controlled by blueprint but
// we do want to close the tracker so create a proxy to override close appropriately.
return Reflection.newProxy(OpenFlowPluginProviderProxyInterface.class, new AbstractInvocationHandler() {
@Override
protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
if (method.getName().equals("close")) {
tracker.close();
return null;
} else {
return method.invoke(openflowPluginProvider, args);
}
}
});
}
public void setBundleContext(BundleContext bundleContext) {
this.bundleContext = bundleContext;
}
@Override
public boolean canReuseInstance(AbstractOpenFlowProviderModule oldModule) {
return true;
}
private static interface OpenFlowPluginProviderProxyInterface extends OpenFlowPluginProvider,
OpenFlowPluginExtensionRegistratorProvider {
}
}