X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fbinding%2Futil%2FBindingContextUtils.java;h=3d7e27754d97c65b291ad8c3f399ee9f8d4c4580;hp=d164f82222bb50781ca854b2c5a661791468c1a6;hb=12fcdfe39aa26dcba7fd3bb4d4c68e3d02e65c51;hpb=405ea7ce68d22bd3d2501857c5253793b581b086 diff --git a/opendaylight/md-sal/sal-binding-util/src/main/java/org/opendaylight/controller/md/sal/binding/util/BindingContextUtils.java b/opendaylight/md-sal/sal-binding-util/src/main/java/org/opendaylight/controller/md/sal/binding/util/BindingContextUtils.java index d164f82222..3d7e27754d 100644 --- a/opendaylight/md-sal/sal-binding-util/src/main/java/org/opendaylight/controller/md/sal/binding/util/BindingContextUtils.java +++ b/opendaylight/md-sal/sal-binding-util/src/main/java/org/opendaylight/controller/md/sal/binding/util/BindingContextUtils.java @@ -7,30 +7,28 @@ */ package org.opendaylight.controller.md.sal.binding.util; -import java.awt.image.SinglePixelPackedSampleModel; +import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.collect.ClassToInstanceMap; +import com.google.common.collect.MutableClassToInstanceMap; import org.opendaylight.controller.md.sal.common.api.routing.RouteChangeListener; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ConsumerContext; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration; import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration; -import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; -import org.opendaylight.controller.sal.binding.api.BindingAwareProvider.ProviderFunctionality; -import org.opendaylight.controller.sal.binding.api.rpc.RpcContextIdentifier; import org.opendaylight.controller.sal.binding.api.BindingAwareConsumer; +import org.opendaylight.controller.sal.binding.api.BindingAwareProvider; import org.opendaylight.controller.sal.binding.api.BindingAwareService; import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry; import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.opendaylight.controller.sal.binding.api.rpc.RpcContextIdentifier; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.RpcService; -import static com.google.common.base.Preconditions.*; - -import com.google.common.collect.ClassToInstanceMap; -import com.google.common.collect.MutableClassToInstanceMap; - -public class BindingContextUtils { +public final class BindingContextUtils { + private BindingContextUtils() { + } public static ConsumerContext createConsumerContext(BindingAwareConsumer consumer, ClassToInstanceMap serviceProvider) { @@ -38,7 +36,7 @@ public class BindingContextUtils { checkNotNull(serviceProvider,"Service map should not be null"); return new SingleConsumerContextImpl(serviceProvider); } - + public static ProviderContext createProviderContext(BindingAwareProvider provider, ClassToInstanceMap serviceProvider) { checkNotNull(provider,"Provider should not be null"); @@ -52,7 +50,7 @@ public class BindingContextUtils { consumer.onSessionInitialized(context); return context; } - + public static ProviderContext createProviderContextAndInitialize(BindingAwareProvider provider, ClassToInstanceMap serviceProvider) { ProviderContext context = createProviderContext(provider, serviceProvider); @@ -64,13 +62,13 @@ public class BindingContextUtils { // FIXME: Create Proxy return instance; } - + private static class SingleConsumerContextImpl implements ConsumerContext, AutoCloseable { - + private ClassToInstanceMap alreadyRetrievedServices; private ClassToInstanceMap serviceProvider; - public SingleConsumerContextImpl(ClassToInstanceMap serviceProvider) { + SingleConsumerContextImpl(ClassToInstanceMap serviceProvider) { this.alreadyRetrievedServices = MutableClassToInstanceMap.create(); this.serviceProvider = serviceProvider; } @@ -79,72 +77,60 @@ public class BindingContextUtils { public final T getRpcService(Class module) { return getSALService(RpcConsumerRegistry.class).getRpcService(module); } - + @Override public final T getSALService(Class service) { checkNotNull(service,"Service class should not be null."); T potential = alreadyRetrievedServices.getInstance(service); - if(potential != null) { + if (potential != null) { return potential; } return tryToRetrieveSalService(service); } - + private synchronized T tryToRetrieveSalService(Class service) { final T potential = alreadyRetrievedServices.getInstance(service); - if(potential != null) { + if (potential != null) { return potential; } final T requested = serviceProvider.getInstance(service); - if(requested == null) { - throw new IllegalArgumentException("Requested service "+service.getName() +" is not available."); + if (requested == null) { + throw new IllegalArgumentException("Requested service " + service.getName() + " is not available."); } final T retrieved = BindingContextUtils.createContextProxyOrReturnService(service,requested); alreadyRetrievedServices.put(service, retrieved); return retrieved; } - + @Override - public final void close() throws Exception { + public final void close() { alreadyRetrievedServices = null; serviceProvider = null; } } - + private static class SingleProviderContextImpl extends SingleConsumerContextImpl implements ProviderContext { - public SingleProviderContextImpl(ClassToInstanceMap serviceProvider) { + SingleProviderContextImpl(ClassToInstanceMap serviceProvider) { super(serviceProvider); } - + @Override - public >> ListenerRegistration registerRouteChangeListener( - L listener) { + public >> ListenerRegistration + registerRouteChangeListener(L listener) { return getSALService(RpcProviderRegistry.class).registerRouteChangeListener(listener); } - + @Override public RoutedRpcRegistration addRoutedRpcImplementation(Class type, T implementation) throws IllegalStateException { return getSALService(RpcProviderRegistry.class).addRoutedRpcImplementation(type, implementation); } - + @Override public RpcRegistration addRpcImplementation(Class type, T implementation) throws IllegalStateException { return getSALService(RpcProviderRegistry.class).addRpcImplementation(type, implementation); } - - @Deprecated - @Override - public void registerFunctionality(ProviderFunctionality functionality) { - // NOOP - } - - @Deprecated - @Override - public void unregisterFunctionality(ProviderFunctionality functionality) { - // NOOP - } } }