X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fblueprint%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fblueprint%2Fext%2FRpcImplementationBean.java;h=94d5b3b22f33ad2175823b2326aaaf6130b8a189;hp=a8fc47ab454f93209dc1e3383033a6b461ce020d;hb=HEAD;hpb=042b763254cc60083c54c50ab6328e7600b22396 diff --git a/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/RpcImplementationBean.java b/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/RpcImplementationBean.java deleted file mode 100644 index a8fc47ab45..0000000000 --- a/opendaylight/blueprint/src/main/java/org/opendaylight/controller/blueprint/ext/RpcImplementationBean.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2016 Brocade Communications 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.blueprint.ext; - -import com.google.common.base.Strings; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import org.opendaylight.mdsal.binding.api.RpcProviderService; -import org.opendaylight.yangtools.concepts.ObjectRegistration; -import org.opendaylight.yangtools.yang.binding.RpcService; -import org.osgi.framework.Bundle; -import org.osgi.service.blueprint.container.ComponentDefinitionException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Blueprint bean corresponding to the "rpc-implementation" element that registers an RPC implementation with - * the RpcProviderRegistry. - * - * @author Thomas Pantelis - */ -public class RpcImplementationBean { - private static final Logger LOG = LoggerFactory.getLogger(RpcImplementationBean.class); - static final String RPC_IMPLEMENTATION = "rpc-implementation"; - - private final List> rpcRegistrations = new ArrayList<>(); - private RpcProviderService rpcProvider = null; - private Bundle bundle = null; - private String interfaceName = null; - private RpcService implementation = null; - - public void setRpcProvider(final RpcProviderService rpcProvider) { - this.rpcProvider = rpcProvider; - } - - public void setBundle(final Bundle bundle) { - this.bundle = bundle; - } - - public void setInterfaceName(final String interfaceName) { - this.interfaceName = interfaceName; - } - - public void setImplementation(final RpcService implementation) { - this.implementation = implementation; - } - - @SuppressWarnings("checkstyle:IllegalCatch") - public void init() { - try { - final var rpcInterfaces = getImplementedRpcServiceInterfaces(interfaceName, - implementation.getClass(), bundle, RPC_IMPLEMENTATION); - - LOG.debug("{}: init - adding implementation {} for RpcService interface(s) {}", bundle.getSymbolicName(), - implementation, rpcInterfaces); - - for (var rpcInterface : rpcInterfaces) { - rpcRegistrations.add(rpcProvider.registerRpcImplementation(rpcInterface, implementation)); - } - } catch (final ComponentDefinitionException e) { - throw e; - } catch (final Exception e) { - throw new ComponentDefinitionException(String.format( - "Error processing \"%s\" for %s", RPC_IMPLEMENTATION, implementation.getClass()), e); - } - } - - public void destroy() { - for (ObjectRegistration reg: rpcRegistrations) { - reg.close(); - } - } - - @SuppressWarnings("unchecked") - static List> getImplementedRpcServiceInterfaces(final String interfaceName, - final Class implementationClass, final Bundle bundle, final String logName) - throws ClassNotFoundException { - if (!Strings.isNullOrEmpty(interfaceName)) { - Class rpcInterface = bundle.loadClass(interfaceName); - - if (!rpcInterface.isAssignableFrom(implementationClass)) { - throw new ComponentDefinitionException(String.format( - "The specified \"interface\" %s for \"%s\" is not implemented by RpcService \"ref\" %s", - interfaceName, logName, implementationClass)); - } - - return Collections.singletonList((Class)rpcInterface); - } - - final var rpcInterfaces = new ArrayList>(); - for (var intface : implementationClass.getInterfaces()) { - if (RpcService.class.isAssignableFrom(intface)) { - rpcInterfaces.add((Class) intface); - } - } - - if (rpcInterfaces.isEmpty()) { - throw new ComponentDefinitionException(String.format( - "The \"ref\" instance %s for \"%s\" does not implemented any RpcService interfaces", - implementationClass, logName)); - } - - return rpcInterfaces; - } -}