Search in sources :

Example 1 with RpcService

use of org.opendaylight.yangtools.yang.binding.RpcService in project controller by opendaylight.

the class RoutedRpcMetadata method create.

@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public Object create() throws ComponentDefinitionException {
    RpcProviderRegistry rpcRegistry = (RpcProviderRegistry) container.getComponentInstance(OpendaylightNamespaceHandler.RPC_REGISTRY_NAME);
    Object implementation = container.getComponentInstance(implementationRefId);
    try {
        if (!RpcService.class.isAssignableFrom(implementation.getClass())) {
            throw new ComponentDefinitionException(String.format("Implementation \"ref\" instance %s for \"%s\" is not an RpcService", implementation.getClass(), ROUTED_RPC_IMPLEMENTATION));
        }
        List<Class<RpcService>> rpcInterfaces = RpcImplementationBean.getImplementedRpcServiceInterfaces(interfaceName, implementation.getClass(), container.getBundleContext().getBundle(), ROUTED_RPC_IMPLEMENTATION);
        if (rpcInterfaces.size() > 1) {
            throw new ComponentDefinitionException(String.format("Implementation \"ref\" instance %s for \"%s\" implements more than one RpcService " + "interface (%s). Please specify the exact \"interface\"", implementation.getClass(), ROUTED_RPC_IMPLEMENTATION, rpcInterfaces));
        }
        Class<RpcService> rpcInterface = rpcInterfaces.iterator().next();
        LOG.debug("{}: create - adding routed implementation {} for RpcService {}", logName(), implementation, rpcInterface);
        return rpcRegistry.addRoutedRpcImplementation(rpcInterface, (RpcService) implementation);
    } catch (final ComponentDefinitionException e) {
        throw e;
    } catch (final Exception e) {
        throw new ComponentDefinitionException(String.format("Error processing \"%s\" for %s", ROUTED_RPC_IMPLEMENTATION, implementation.getClass()), e);
    }
}
Also used : ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) RpcService(org.opendaylight.yangtools.yang.binding.RpcService) RpcProviderRegistry(org.opendaylight.controller.sal.binding.api.RpcProviderRegistry) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException)

Example 2 with RpcService

use of org.opendaylight.yangtools.yang.binding.RpcService in project controller by opendaylight.

the class AbstractInvokableServiceMetadata method create.

@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public final Object create() throws ComponentDefinitionException {
    log.debug("{}: In create: interfaceName: {}", logName(), interfaceName);
    super.onCreate();
    try {
        RpcService rpcService = rpcRegistry.getRpcService(rpcInterface);
        log.debug("{}: create returning service {}", logName(), rpcService);
        return rpcService;
    } catch (final RuntimeException e) {
        throw new ComponentDefinitionException("Error getting RPC service for " + interfaceName, e);
    }
}
Also used : ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) DOMRpcService(org.opendaylight.controller.md.sal.dom.api.DOMRpcService) RpcService(org.opendaylight.yangtools.yang.binding.RpcService)

Example 3 with RpcService

use of org.opendaylight.yangtools.yang.binding.RpcService in project controller by opendaylight.

the class AbstractInvokableServiceMetadata method init.

@SuppressWarnings({ "checkstyle:IllegalCatch", "unchecked" })
@Override
public final void init(final ExtendedBlueprintContainer container) {
    super.init(container);
    final Class<?> interfaceClass;
    try {
        interfaceClass = container().getBundleContext().getBundle().loadClass(interfaceName);
    } catch (final Exception e) {
        throw new ComponentDefinitionException(String.format("%s: Error obtaining interface class %s", logName(), interfaceName), e);
    }
    if (!RpcService.class.isAssignableFrom(interfaceClass)) {
        throw new ComponentDefinitionException(String.format("%s: The specified interface %s is not an RpcService", logName(), interfaceName));
    }
    rpcInterface = (Class<RpcService>) interfaceClass;
}
Also used : ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) DOMRpcService(org.opendaylight.controller.md.sal.dom.api.DOMRpcService) RpcService(org.opendaylight.yangtools.yang.binding.RpcService) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException)

Example 4 with RpcService

use of org.opendaylight.yangtools.yang.binding.RpcService in project controller by opendaylight.

the class RpcImplementationBean method init.

@SuppressWarnings("checkstyle:IllegalCatch")
public void init() {
    try {
        List<Class<RpcService>> rpcInterfaces = getImplementedRpcServiceInterfaces(interfaceName, implementation.getClass(), bundle, RPC_IMPLEMENTATION);
        LOG.debug("{}: init - adding implementation {} for RpcService interface(s) {}", bundle.getSymbolicName(), implementation, rpcInterfaces);
        for (Class<RpcService> rpcInterface : rpcInterfaces) {
            rpcRegistrations.add(rpcRegistry.addRpcImplementation(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);
    }
}
Also used : ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) RpcService(org.opendaylight.yangtools.yang.binding.RpcService) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException)

Example 5 with RpcService

use of org.opendaylight.yangtools.yang.binding.RpcService in project openflowplugin by opendaylight.

the class RpcContextImpl method lookupRpcService.

@Override
public <S extends RpcService> S lookupRpcService(final Class<S> serviceClass) {
    RoutedRpcRegistration<?> registration = rpcRegistrations.get(serviceClass);
    final RpcService rpcService = registration.getInstance();
    return serviceClass.cast(rpcService);
}
Also used : RpcService(org.opendaylight.yangtools.yang.binding.RpcService)

Aggregations

RpcService (org.opendaylight.yangtools.yang.binding.RpcService)5 ComponentDefinitionException (org.osgi.service.blueprint.container.ComponentDefinitionException)4 DOMRpcService (org.opendaylight.controller.md.sal.dom.api.DOMRpcService)2 RpcProviderRegistry (org.opendaylight.controller.sal.binding.api.RpcProviderRegistry)1