X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fbinding%2Futil%2FBindingContextUtils.java;fp=opendaylight%2Fmd-sal%2Fsal-binding-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fbinding%2Futil%2FBindingContextUtils.java;h=0000000000000000000000000000000000000000;hb=2611e6a728e586ea34dd891f30a473bf54d6cbd8;hp=914f6d5516f427d58107f4dbfbe5539e071f36ab;hpb=aaea3e9a92ae9d6fac04c4a065db4b35cbca9ed0;p=controller.git 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 deleted file mode 100644 index 914f6d5516..0000000000 --- a/opendaylight/md-sal/sal-binding-util/src/main/java/org/opendaylight/controller/md/sal/binding/util/BindingContextUtils.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.md.sal.binding.util; - -import static java.util.Objects.requireNonNull; - -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.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; - -@Deprecated(forRemoval = true) -public final class BindingContextUtils { - private BindingContextUtils() { - } - - public static ConsumerContext createConsumerContext(final BindingAwareConsumer consumer, - final ClassToInstanceMap serviceProvider) { - requireNonNull(consumer, "Consumer should not be null"); - return new SingleConsumerContextImpl(requireNonNull(serviceProvider, "Service map should not be null")); - } - - public static ProviderContext createProviderContext(final BindingAwareProvider provider, - final ClassToInstanceMap serviceProvider) { - requireNonNull(provider, "Provider should not be null"); - return new SingleProviderContextImpl(requireNonNull(serviceProvider, "Service map should not be null")); - } - - public static ConsumerContext createConsumerContextAndInitialize(final BindingAwareConsumer consumer, - final ClassToInstanceMap serviceProvider) { - ConsumerContext context = createConsumerContext(consumer, serviceProvider); - consumer.onSessionInitialized(context); - return context; - } - - public static ProviderContext createProviderContextAndInitialize(final BindingAwareProvider provider, - final ClassToInstanceMap serviceProvider) { - ProviderContext context = createProviderContext(provider, serviceProvider); - provider.onSessionInitiated(context); - return context; - } - - public static T createContextProxyOrReturnService(final Class service, - final T instance) { - // FIXME: Create Proxy - return instance; - } - - private static class SingleConsumerContextImpl implements ConsumerContext, AutoCloseable { - - private ClassToInstanceMap alreadyRetrievedServices; - private ClassToInstanceMap serviceProvider; - - SingleConsumerContextImpl(final ClassToInstanceMap serviceProvider) { - this.alreadyRetrievedServices = MutableClassToInstanceMap.create(); - this.serviceProvider = serviceProvider; - } - - @Override - public final T getRpcService(final Class module) { - return getSALService(RpcConsumerRegistry.class).getRpcService(module); - } - - @Override - public final T getSALService(final Class service) { - T potential = alreadyRetrievedServices.getInstance(requireNonNull(service, - "Service class should not be null.")); - if (potential != null) { - return potential; - } - return tryToRetrieveSalService(service); - } - - private synchronized T tryToRetrieveSalService(final Class service) { - final T potential = alreadyRetrievedServices.getInstance(service); - if (potential != null) { - return potential; - } - final T requested = serviceProvider.getInstance(service); - 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() { - alreadyRetrievedServices = null; - serviceProvider = null; - } - } - - private static class SingleProviderContextImpl extends SingleConsumerContextImpl implements ProviderContext { - SingleProviderContextImpl(final ClassToInstanceMap serviceProvider) { - super(serviceProvider); - } - - @Override - public >> ListenerRegistration - registerRouteChangeListener(final L listener) { - return getSALService(RpcProviderRegistry.class).registerRouteChangeListener(listener); - } - - @Override - public RoutedRpcRegistration addRoutedRpcImplementation(final Class type, - final T implementation) { - return getSALService(RpcProviderRegistry.class).addRoutedRpcImplementation(type, implementation); - } - - @Override - public RpcRegistration addRpcImplementation(final Class type, - final T implementation) { - return getSALService(RpcProviderRegistry.class).addRpcImplementation(type, implementation); - } - } -}