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;h=dc22891b471dc2aaa623f096e21395099f0d7328;hb=c31af714994cbaed40299758460916b2c7101158;hp=6f2186be88cc4479216174f91ae2b9e79c7b18db;hpb=d71e327e51db32e967f7ebcb186e148f37f28117;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 index 6f2186be88..dc22891b47 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 @@ -1,25 +1,30 @@ +/* + * 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 java.awt.image.SinglePixelPackedSampleModel; +import static com.google.common.base.Preconditions.checkNotNull; 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.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.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; @@ -31,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"); @@ -45,7 +50,7 @@ public class BindingContextUtils { consumer.onSessionInitialized(context); return context; } - + public static ProviderContext createProviderContextAndInitialize(BindingAwareProvider provider, ClassToInstanceMap serviceProvider) { ProviderContext context = createProviderContext(provider, serviceProvider); @@ -57,9 +62,9 @@ public class BindingContextUtils { // FIXME: Create Proxy return instance; } - + private static class SingleConsumerContextImpl implements ConsumerContext, AutoCloseable { - + private ClassToInstanceMap alreadyRetrievedServices; private ClassToInstanceMap serviceProvider; @@ -72,7 +77,7 @@ 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."); @@ -82,7 +87,7 @@ public class BindingContextUtils { } return tryToRetrieveSalService(service); } - + private synchronized T tryToRetrieveSalService(Class service) { final T potential = alreadyRetrievedServices.getInstance(service); if(potential != null) { @@ -96,44 +101,44 @@ public class BindingContextUtils { alreadyRetrievedServices.put(service, retrieved); return retrieved; } - + @Override public final void close() throws Exception { alreadyRetrievedServices = null; serviceProvider = null; } } - + private static class SingleProviderContextImpl extends SingleConsumerContextImpl implements ProviderContext { public SingleProviderContextImpl(ClassToInstanceMap serviceProvider) { super(serviceProvider); } - + @Override 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) {