X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fbinding%2Fimpl%2FRpcProviderRegistryImpl.java;h=ffc72657f0e3ef406961738c6c3598ac044ecd9e;hp=8773476caee9ee4fd01f7b75b3b128bb331e3edd;hb=928525541a36fac7aaa672d61417b853d08f7f6c;hpb=edb3b76df1fa27594d5f9ee368d737576b0b38f8 diff --git a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcProviderRegistryImpl.java b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcProviderRegistryImpl.java index 8773476cae..ffc72657f0 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcProviderRegistryImpl.java +++ b/opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/sal/binding/impl/RpcProviderRegistryImpl.java @@ -1,5 +1,13 @@ +/* + * Copyright (c) 2013 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.sal.binding.impl; +import java.util.EventListener; import java.util.Map; import java.util.Map.Entry; import java.util.HashMap; @@ -42,9 +50,10 @@ public class RpcProviderRegistryImpl implements // private final Map, RpcRouter> rpcRouters = new WeakHashMap<>(); private final ListenerRegistry>> routeChangeListeners = ListenerRegistry .create(); + private final ListenerRegistry routerInstantiationListener = ListenerRegistry.create(); private final static Logger LOG = LoggerFactory.getLogger(RpcProviderRegistryImpl.class); - + private final String name; public String getName() { @@ -75,7 +84,7 @@ public class RpcProviderRegistryImpl implements // T publicProxy = getRpcService(type); RpcService currentDelegate = RuntimeCodeHelper.getDelegate(publicProxy); checkState(currentDelegate == null, "Rpc service is already registered"); - LOG.debug("Registering {} as global implementation of {} in {}",implementation,type.getSimpleName(),this); + LOG.debug("Registering {} as global implementation of {} in {}", implementation, type.getSimpleName(), this); RuntimeCodeHelper.setDelegate(publicProxy, implementation); return new RpcProxyRegistration(type, implementation, this); } @@ -89,46 +98,73 @@ public class RpcProviderRegistryImpl implements // if (potentialProxy != null) { return potentialProxy; } - synchronized(this) { + synchronized (this) { /** - * Potential proxy could be instantiated by other thread while we were - * waiting for the lock. + * Potential proxy could be instantiated by other thread while we + * were waiting for the lock. */ - + potentialProxy = (T) publicProxies.get(type); if (potentialProxy != null) { return (T) potentialProxy; } T proxy = rpcFactory.getDirectProxyFor(type); - LOG.debug("Created {} as public proxy for {} in {}",proxy,type.getSimpleName(),this); + LOG.debug("Created {} as public proxy for {} in {}", proxy, type.getSimpleName(), this); publicProxies.put(type, proxy); return proxy; } } - private RpcRouter getRpcRouter(Class type) { + @SuppressWarnings("unchecked") + public RpcRouter getRpcRouter(Class type) { RpcRouter potentialRouter = rpcRouters.get(type); if (potentialRouter != null) { return (RpcRouter) potentialRouter; } - synchronized(this) { + synchronized (this) { /** - * Potential Router could be instantiated by other thread while we were - * waiting for the lock. + * Potential Router could be instantiated by other thread while we + * were waiting for the lock. */ - potentialRouter = rpcRouters.get(type); + potentialRouter = rpcRouters.get(type); if (potentialRouter != null) { return (RpcRouter) potentialRouter; } - RpcRouter router = rpcFactory.getRouterFor(type,name); + RpcRouter router = rpcFactory.getRouterFor(type, name); router.registerRouteChangeListener(new RouteChangeForwarder(type)); - LOG.debug("Registering router {} as global implementation of {} in {}",router,type.getSimpleName(),this); + LOG.debug("Registering router {} as global implementation of {} in {}", router, type.getSimpleName(), this); RuntimeCodeHelper.setDelegate(getRpcService(type), router.getInvocationProxy()); rpcRouters.put(type, router); + notifyListenersRoutedCreated(router); return router; } } + private void notifyListenersRoutedCreated(RpcRouter router) { + + for (ListenerRegistration listener : routerInstantiationListener) { + try { + listener.getInstance().onRpcRouterCreated(router); + } catch (Exception e) { + LOG.error("Unhandled exception during invoking listener {}", e); + } + } + + } + + public ListenerRegistration registerRouterInstantiationListener( + RouterInstantiationListener listener) { + ListenerRegistration reg = routerInstantiationListener.register(listener); + try { + for (RpcRouter router : rpcRouters.values()) { + listener.onRpcRouterCreated(router); + } + } catch (Exception e) { + LOG.error("Unhandled exception during invoking listener {}", e); + } + return reg; + } + @Override public >> ListenerRegistration registerRouteChangeListener( L listener) { @@ -143,6 +179,10 @@ public class RpcProviderRegistryImpl implements // this.rpcFactory = rpcFactory; } + public interface RouterInstantiationListener extends EventListener { + void onRpcRouterCreated(RpcRouter router); + } + private class RouteChangeForwarder implements RouteChangeListener, InstanceIdentifier> {