本文整理了Java中org.opendaylight.controller.sal.binding.api.RpcProviderRegistry
类的一些代码示例,展示了RpcProviderRegistry
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RpcProviderRegistry
类的具体详情如下:
包路径:org.opendaylight.controller.sal.binding.api.RpcProviderRegistry
类名称:RpcProviderRegistry
[英]Provides a registry for Remote Procedure Call (RPC) service implementations. The RPCs are defined in YANG models.
There are 2 types of RPCs:
Global RPC
An RPC is global if there is intended to be only 1 registered implementation. A global RPC is not explicitly declared as such, essentially any RPC that is not defined to be routed is considered global.
Global RPCs are registered using the #addRpcImplementation(Class,RpcService) method.
Routed RPC
MD-SAL supports routing of RPC between multiple implementations where the appropriate implementation is selected at run time based on the content of the RPC message as described in YANG model.
RPC routing is based on:
A context type is modeled in YANG using a combination of a YANG identity
and Opendaylight specific extensions from yang-ext
module. These extensions are:
identity
. Instance identifiers that reference these nodes are valid route identifiers for RPCs that reference this context type.instance-identifier
as a reference to the particular context type defined by the specified context identity
. The value of this leaf is used by the RPC broker at run time to route the RPC request to the correct implementation. Note that context-reference
may only be used on leaf elements of type instance-identifier
or a type derived from instance-identifier
.The following snippet declares a simple YANG identity
named example-context
: module example ... } }
We then use the declared identity to define a context type by using it in combination with the context-instance
YANG extension. We'll associate the context type with a list element in the data tree. This defines the set of nodes whose instance identifiers are valid for the example-context
context type.
The following YANG snippet imports the yang-ext
module and defines the list element named item
inside a container named foo
: module foo import yang-ext {prefix ext;} ... container foo list item key "id"; leaf id {type string;} ext:context-instance "example-context"; } } ... } }
The statement ext:context-instance "example-context";
inside the list element declares that any instance identifier referencing item
in the data tree is valid for example-context
. For example, the following instance identifier:
InstanceIdentifier.create(Foo.class).child(Item.class,new ItemKey("Foo"))
is valid for example-context
. However the following:
InstanceIdentifier.create(Example.class)
is not valid.
So using an identity
in combination with context-instance
we have effectively defined a context type that can be referenced in a YANG RPC input.
To define an RPC to be routed based on the context type we need to add an input leaf element that references the context type which will hold an instance identifier value to be used to route the RPC.
The following snippet defines an RPC named show-item
with 2 leaf elements as input: item
of type instance-identifier
and description
:
module foo {
...
import yang-ext {prefix ext;}
...
rpc show-item {
input {
leaf item {
type instance-identifier;
ext:context-reference example-context;
}
leaf description {
type "string";
}
}
}
}
We mark the item
leaf with a context-reference
statement that references the example-context
context type. RPC calls will then be routed based on the instance identifier value contained in item
. Only instance identifiers that point to a foo/item
node are valid as input.
The generated RPC Service interface for the module is:
interface FooService implements RpcService {
Future
}
For constructing the RPC input, there are generated classes ShowItemInput and ShowItemInputBuilder.
To register a routed implementation for the show-item
RPC, we must use the #addRoutedRpcImplementation(Class,RpcService) method. This will return a RoutedRpcRegistration instance which can then be used to register / unregister routed paths associated with the registered implementation.
The following snippet registers myImpl
as the RPC implementation for an item
with key "foo"
:
// Create the instance identifier path for item "foo"
InstanceIdentifier path = InstanceIdentifier.create(Foo.class).child(Item.class, new ItemKey("foo"));
// Register myImpl as the implementation for the FooService RPC interface
RoutedRpcRegistration reg = rpcRegistry.addRoutedRpcImplementation(FooService.class, myImpl);
// Now register for the context type and specific path ID. The context type is specified by the
// YANG-generated class for the example-context identity.
reg.registerPath(ExampleContext.class, path);
It is also possible to register the same implementation for multiple paths:
InstanceIdentifier One= InstanceIdentifier.create(Foo.class).child(Item.class, new ItemKey("One"));
InstanceIdentifier two = InstanceIdentifier.create(Foo.class).child(Item.class, new ItemKey("Two"));
RoutedRpcRegistration reg = rpcRegistry.addRoutedRpcImplementation(FooService.class, myImpl);
reg.registerPath(ExampleContext.class, one);
reg.registerPath(ExampleContext.class, two);
When another client invokes the showItem(ShowItemInput)
method on the proxy instance retrieved via RpcConsumerRegistry#getRpcService(Class), the proxy will inspect the arguments in ShowItemInput, extract the InstanceIdentifier value of the item
leaf and select the implementation whose registered path matches the InstanceIdentifier value of the item
leaf.
Notes for RPC Implementations
The generated interfaces require implementors to return java.util.concurrent.Future
Implementations should do processing of RPC calls asynchronously and update the returned java.util.concurrent.Future instance when processing is complete. However using com.google.common.util.concurrent.Futures#immediateFuture(Object)is valid only if the result is immediately available and asynchronous processing is unnecessary and would only introduce additional complexity.
The org.opendaylight.yangtools.yang.common.RpcResult is a generic wrapper for the RPC output payload, if any, and also allows for attaching error or warning information (possibly along with the payload) should the RPC processing partially or completely fail. This is intended to provide additional human readable information for users of the API and to transfer warning / error information across the system so it may be visible via other external APIs such as Restconf.
It is recommended to use the org.opendaylight.yangtools.yang.common.RpcResultfor conveying appropriate error information on failure rather than purposely throwing unchecked exceptions if at all possible. While unchecked exceptions will fail the returned java.util.concurrent.Future, using the intended RpcResult to convey the error information is more user-friendly.
[中]为远程过程调用(RPC)服务实现提供注册表。RPC在YANG模型中定义。
有两种类型的RPC:
*全球的
*路由
全局RPC
如果打算只有一个注册的实现,则RPC是全局的。全局RPC没有明确声明为全局RPC,本质上任何未定义为路由的RPC都被视为全局RPC。
全局RPC使用#addRpcImplementation(Class,RpcService)方法注册。
路由RPC
MD-SAL支持在多个实现之间路由RPC,其中在运行时根据RPC消息的内容选择适当的实现,如模型中所述。
RPC路由基于:
*路由标识符-一个组织。露天采光。扬格工具。杨。结合InstanceIdentifier值,它是RPC输入的一部分。此值用于在运行时选择正确的实现。
*上下文类型-一个定义的构造,用于约束特定RPC的有效路由标识符子集。
####上下文类型
使用YANGidentity
和yang-ext
模块中特定于Opendaylight的扩展组合,在YANG中对上下文类型进行建模。这些扩展是:
*context instance——在YANG模型的数据树部分中,它用于定义将节点与指定上下文[$2$]关联的上下文类型。引用这些节点的实例标识符是引用此上下文类型的RPC的有效路由标识符。
*上下文引用-在RPC输入中,它用于将instance-identifier
类型的叶标记为对指定上下文identity
定义的特定上下文类型的引用。RPC代理在运行时使用此叶的值将RPC请求路由到正确的实现。请注意,context-reference
只能用于类型为instance-identifier
或派生自instance-identifier
的叶元素。
下面的代码片段声明了一个名为example-context
的简单YANGidentity
:module example…}
然后,我们将声明的标识与context-instance
扩展结合使用,来定义上下文类型。我们将上下文类型与数据树中的列表元素相关联。这定义了其实例标识符对example-context
上下文类型有效的节点集。
下面的代码段导入yang-ext
模块,并在名为foo
的容器中定义名为item
的列表元素:module foo import YANG ext{prefix ext;}。。。容器foo列表项键“id”;叶id{type string;}ext:context实例“示例上下文”;}}}…}
list元素中的语句ext:context-instance "example-context";
声明数据树中引用item
的任何实例标识符对example-context
有效。例如,以下实例标识符:
InstanceIdentifier.create(Foo.class).child(Item.class,new ItemKey("Foo"))
有效期为[$18$]。但是以下内容:
InstanceIdentifier.create(Example.class)
无效。
因此,结合使用identity
和context-instance
,我们已经有效地定义了一个可以在RPC输入中引用的上下文类型。
要根据上下文类型定义要路由的RPC,我们需要添加一个输入叶元素,该元素引用上下文类型,该上下文类型将保存用于路由RPC的实例标识符值。
以下代码段定义了一个名为show-item
的RPC,其中有两个叶元素作为输入:item
,类型分别为instance-identifier
和[$24$]:
module foo {
...
import yang-ext {prefix ext;}
...
rpc show-item {
input {
leaf item {
type instance-identifier;
ext:context-reference example-context;
}
leaf description {
type "string";
}
}
}
}
我们用一个引用example-context
上下文类型的context-reference
语句标记item
叶子。然后,将根据item
中包含的实例标识符值路由RPC调用。只有指向foo/item
节点的实例标识符作为输入有效。
为模块生成的RPC服务接口为:
interface FooService implements RpcService {
Future
}
为了构造RPC输入,有生成的类ShowItemInput和ShowItemInputBuilder。
要注册show-item
RPC的路由实现,我们必须使用#addRoutedPrcImplementation(Class,RpcService)方法。这将返回一个RoutedRpcRegistration实例,该实例可用于注册/注销与已注册实现关联的路由路径。
以下代码段将myImpl
注册为具有键"foo"
的item
的RPC实现:
// Create the instance identifier path for item "foo"
InstanceIdentifier path = InstanceIdentifier.create(Foo.class).child(Item.class, new ItemKey("foo"));
// Register myImpl as the implementation for the FooService RPC interface
RoutedRpcRegistration reg = rpcRegistry.addRoutedRpcImplementation(FooService.class, myImpl);
// Now register for the context type and specific path ID. The context type is specified by the
// YANG-generated class for the example-context identity.
reg.registerPath(ExampleContext.class, path);
也可以为多个路径注册相同的实现:
InstanceIdentifier One= InstanceIdentifier.create(Foo.class).child(Item.class, new ItemKey("One"));
InstanceIdentifier two = InstanceIdentifier.create(Foo.class).child(Item.class, new ItemKey("Two"));
RoutedRpcRegistration reg = rpcRegistry.addRoutedRpcImplementation(FooService.class, myImpl);
reg.registerPath(ExampleContext.class, one);
reg.registerPath(ExampleContext.class, two);
当另一个客户端对通过RpcConsumerRegistry#getRpcService(类)检索的代理实例调用showItem(ShowItemInput)
方法时,代理将检查ShowItemInput中的参数,提取item
叶的InstanceIdentifier值,并选择注册路径与item
叶的InstanceIdentifier值匹配的实现。
RPC实现说明
####R结果
生成的接口要求实现者返回java。util。同时发生的未来组织。露天采光。扬格工具。杨。常见的RpcResult<{RpcName}输出>>实例。
实现应该异步处理RPC调用,并更新返回的java。util。同时发生的处理完成时的未来实例。但是使用com。谷歌。常见的util。同时发生的Futures#immediateFuture(Object)只有在结果立即可用且异步处理不必要且只会增加复杂性时才有效。
组织。露天采光。扬格工具。杨。常见的RpcResult是RPC输出有效负载(如果有)的通用包装器,还允许在RPC处理部分或完全失败时附加错误或警告信息(可能与有效负载一起)。这旨在为API用户提供额外的人类可读信息,并在整个系统中传输警告/错误信息,以便可以通过其他外部API(如Restconf)看到。
建议使用该组织。露天采光。扬格工具。杨。常见的rpcresults用于在失败时传递适当的错误信息,而不是在可能的情况下故意抛出未经检查的异常。而未经检查的异常将使返回的java失败。util。同时发生的将来,使用预期的RPC结果来传递错误信息会更方便用户。
代码示例来源:origin: org.opendaylight.faas/fabric
public void start() {
rpcRegistration = rpcRegistry.addRpcImplementation(FabricEndpointService.class, this);
}
代码示例来源:origin: org.opendaylight.faas/fabric-mgr-impl
/**
* Injects services.
*/
public void initialize() {
this.rpcRegistration =
FabMgrDatastoreDependency.getRpcRegistry().addRpcImplementation(VcNetNodeService.class, this);
this.epService = FabMgrDatastoreDependency.getRpcRegistry().getRpcService(FabricEndpointService.class);
this.fabServiceService = FabMgrDatastoreDependency.getRpcRegistry().getRpcService(FabricServiceService.class);
this.fabService = FabMgrDatastoreDependency.getRpcRegistry().getRpcService(FabricService.class);
}
代码示例来源:origin: org.opendaylight.controller/sal-binding-broker-impl
@Override
public
final T implementation) throws IllegalStateException {
return service(RpcProviderRegistry.class).addRoutedRpcImplementation(serviceInterface, implementation);
}
代码示例来源:origin: org.opendaylight.vtn/manager.it.ofmock
/**
* {@inheritDoc}
*/
@Override
public
return rpcRegistry.getRpcService(type);
}
代码示例来源:origin: org.opendaylight.bgpcep/pcep-tunnel-provider
@Override
public java.lang.AutoCloseable createInstance() {
final PCEPTunnelTopologyProvider ttp = PCEPTunnelTopologyProvider.create(getDataProviderDependency(),
getSourceTopologyDependency().getInstanceIdentifier(), getTopologyId());
final NetworkTopologyPcepService ntps = getRpcRegistryDependency().getRpcService(NetworkTopologyPcepService.class);
final TunnelProgramming tp = new TunnelProgramming(getSchedulerDependency(), getDataProviderDependency(), ntps);
final BindingAwareBroker.RoutedRpcRegistration
TopologyTunnelPcepProgrammingService.class, tp);
final InstanceIdentifier
new TopologyKey(getTopologyId())).build();
reg.registerPath(NetworkTopologyContext.class, topology);
final class TunnelTopologyReferenceCloseable extends DefaultTopologyReference implements AutoCloseable {
public TunnelTopologyReferenceCloseable(final InstanceIdentifier
super(instanceIdentifier);
}
@Override
public void close() {
reg.close();
tp.close();
ttp.close();
}
}
return new TunnelTopologyReferenceCloseable(ttp.getTopologyReference().getInstanceIdentifier());
}
}
代码示例来源:origin: org.opendaylight.controller/sal-binding-util
@Override
public
final L listener) {
return getRpcRegistryChecked().registerRouteChangeListener(listener);
}
代码示例来源:origin: org.opendaylight.nic/nemo-renderer
public NEMORenderer(DataBroker dataBroker0, RpcProviderRegistry rpcProviderRegistry0) {
this.dataBroker = dataBroker0;
this.rpcProviderRegistry = rpcProviderRegistry0;
this.nemoEngine = rpcProviderRegistry.getRpcService(NemoIntentService.class);
}
代码示例来源:origin: org.opendaylight.controller/sal-binding-broker-impl
@Override
public
final L arg0) {
return service(RpcProviderRegistry.class).registerRouteChangeListener(arg0);
}
代码示例来源:origin: org.opendaylight.faas/fabric
public void start() {
rpcRegistration = rpcRegistry.addRpcImplementation(FabricServiceService.class, this);
}
代码示例来源:origin: org.opendaylight.genius/resourcemanager-impl
@Override
public void onSessionInitiated(ProviderContext session) {
LOG.info("ResourceManagerserviceProvider Session Initiated");
dataBroker = session.getSALService(DataBroker.class);
idManager = rpcProviderRegistry.getRpcService(IdManagerService.class);
resourceManager = new ResourceManager(dataBroker, idManager);
rpcRegistration = rpcProviderRegistry.addRpcImplementation(ResourceManagerService.class, resourceManager);
createIdpools();
}
代码示例来源:origin: org.opendaylight.tsdr/tsdr-snmp-data-collector
public TsdrCollectorSpiService getTSDRService(){
if(this.collectorSPIService==null){
this.collectorSPIService = this.rpcRegistry
.getRpcService(TsdrCollectorSpiService.class);
}
return this.collectorSPIService;
}
代码示例来源:origin: org.opendaylight.controller/sal-binding-util
@Override
public
throws IllegalStateException {
return getRpcRegistryChecked().addRoutedRpcImplementation(type, implementation);
}
代码示例来源:origin: opendaylight/controller
@Override
public
registerRouteChangeListener(final L listener) {
return getRpcRegistryChecked().registerRouteChangeListener(listener);
}
代码示例来源:origin: org.opendaylight.faas/fabric
public void start() {
rpcRegistration = rpcRegistry.addRpcImplementation(FabricResourcesService.class, this);
}
代码示例来源:origin: org.opendaylight.tsdr/tsdr-collector-spi
@Override
public java.lang.AutoCloseable createInstance() {
CollectorSPIImpl service = new CollectorSPIImpl(getRpcRegistryDependency().getRpcService(TsdrMetricDataService.class),getRpcRegistryDependency().getRpcService(TsdrLogDataService.class));
final RpcRegistration
logger.info("TSDR Data Collector SPI Mudule initialized");
return new AutoCloseable() {
@Override
public void close() throws Exception {
addRpcImplementation.close();
}
};
}
}
代码示例来源:origin: org.opendaylight.genius/arputil-impl
OdlInterfaceRpcService getInterfaceRpcService() {
if (intfRpc == null ) {
intfRpc = rpc.getRpcService(OdlInterfaceRpcService.class);
}
return intfRpc;
}
代码示例来源:origin: opendaylight/controller
@Override
public
final T implementation) throws IllegalStateException {
return getRpcRegistryChecked().addRoutedRpcImplementation(type, implementation);
}
代码示例来源:origin: org.opendaylight.controller/sal-binding-util
@Override
public
L listener) {
return getSALService(RpcProviderRegistry.class).registerRouteChangeListener(listener);
}
代码示例来源:origin: org.opendaylight.faas/fabric
public void start() {
rpcRegistration = rpcRegistry.addRpcImplementation(FabricService.class, this);
}
代码示例来源:origin: org.opendaylight.openflowplugin/test-extension
@Override
public java.lang.AutoCloseable createInstance() {
Test extTest = new Test();
SalFlowService flowService = getRpcRegistryDependency().getRpcService(SalFlowService.class);
extTest.setFlowService(flowService);
final RpcRegistration
return new AutoCloseable() {
@Override
public void close() throws Exception {
registry.close();
}
};
}