Reuse found Set
[mdsal.git] / docs / model-registration.rst
1
2 ############################
3 Registering Models with OSGi
4 ############################
5
6 The OSGi framework activates the *OSGiModelRuntime* component, who initiates:
7
8 * **YangModuleInfoScanner** - tracks bundles and attempts to retrieve *YangModuleInfo*, which it then feeds to *YangModuleInfoRegistry*
9 * **YangModuleInfoRegistry** - updates *SchemaContext* each time new *YangModuleInfo* is added/removed
10
11 The diagram below shows the process of registering the modules found in a recently tracked bundle.
12 The **YangModuleInfoScanner** collects the *ModuleInfo*-s from that bundle and forwards them to the **YangModuleInfoRegistry**.
13 From there the **ModuleInfoSnapshotResolver** checks for existing registration of each *YangModuleInfo*
14 and if exists, it reuses, otherwise creates a fresh registration with the help of *YangTextSchemaContextResolver*.
15
16 After each *ModuleInfo* is registered, the **YangModuleInfoScanner** initiates a snapshot update
17 on the **YangModuleInfoRegistry**. During the snapshot capture, the *EffectiveSchemaContext*
18 is updated and preserved within that snapshot.
19
20 .. uml::
21
22   @startuml
23     boundary " " <<OSGi Tracker>>
24     participant OSGiModelRuntime as "OSGiModelRuntime"
25     participant YangModuleInfoScanner as "YangModuleInfoScanner"
26     participant YangModuleInfoRegistry as "YangModuleInfoRegistry"
27     participant ModuleInfoSnapshotResolver as "ModuleInfoSnapshotResolver"
28     participant YangTextSchemaContextResolver as "YangTextSchemaContextResolver"
29
30     -> OSGiModelRuntime : OSGi Component activation
31     activate OSGiModelRuntime
32
33     OSGiModelRuntime -> YangModuleInfoScanner: Initialize YangModuleInfoScanner as BundleTracker
34     activate YangModuleInfoScanner
35
36     OSGiModelRuntime -> YangModuleInfoRegistry: Initialize YangModuleInfoRegistry
37     activate YangModuleInfoRegistry
38
39     deactivate OSGiModelRuntime
40     deactivate YangModuleInfoScanner
41     deactivate YangModuleInfoRegistry
42
43     " " -> YangModuleInfoScanner : Bundle registered
44     activate YangModuleInfoScanner
45
46     YangModuleInfoScanner -> YangModuleInfoScanner: Load the services \nfrom the bundle \nthat was recently tracked.
47
48     YangModuleInfoScanner -> YangModuleInfoScanner: Collect YangModuleInfo-s \nfrom loaded services
49
50     YangModuleInfoScanner -> YangModuleInfoRegistry: Register collected ModuleInfos
51     activate YangModuleInfoRegistry
52
53     YangModuleInfoRegistry -> ModuleInfoSnapshotResolver: Register ModuleInfos
54     activate ModuleInfoSnapshotResolver
55
56     alt No previous Registration for the ModuleInfo => create a fresh Registration
57         ModuleInfoSnapshotResolver -> YangTextSchemaContextResolver : Register provided ModuleInfo
58         activate YangTextSchemaContextResolver
59
60         YangTextSchemaContextResolver --> ModuleInfoSnapshotResolver: Return fresh Registration
61         deactivate YangTextSchemaContextResolver
62
63         ModuleInfoSnapshotResolver -> YangModuleInfoRegistry: Return fresh Registration
64     else Registration for provided ModuleInfo exists
65         ModuleInfoSnapshotResolver -> YangModuleInfoRegistry : Return existing Registration
66         deactivate ModuleInfoSnapshotResolver
67     end
68
69     YangModuleInfoRegistry -> YangModuleInfoScanner: Return Registration
70
71     YangModuleInfoScanner -> YangModuleInfoRegistry : Scanner update
72
73     YangModuleInfoRegistry -> ModuleInfoSnapshotResolver : Take a snapshot
74     activate ModuleInfoSnapshotResolver
75
76     ModuleInfoSnapshotResolver -> YangTextSchemaContextResolver : Ask for new schema context
77     activate YangTextSchemaContextResolver
78
79     YangTextSchemaContextResolver -> YangTextSchemaContextResolver : Create EffectiveModelContext \nfrom registered sources
80
81     YangTextSchemaContextResolver -> ModuleInfoSnapshotResolver : Return created schema context
82     deactivate YangTextSchemaContextResolver
83
84     ModuleInfoSnapshotResolver -> YangModuleInfoRegistry : Return a snapshot with the created schema context
85     deactivate ModuleInfoSnapshotResolver
86
87     YangModuleInfoRegistry -> YangModuleInfoRegistry : Save the snapshot
88
89     YangModuleInfoRegistry -> YangModuleInfoScanner : Done
90     deactivate YangModuleInfoRegistry
91
92     YangModuleInfoScanner -> " " : Return Registration
93     deactivate YangModuleInfoRegistry
94
95
96     deactivate YangModuleInfoRegistry
97     deactivate YangModuleInfoScanner
98   @enduml
99
100 The diagram below shows all relevant components and their relations.
101
102 .. uml::
103
104   @startuml
105     class "OSGiModuleRuntime" as runtime {
106       void deactivate()
107     }
108     class "YangModuleInfoScanner" as bundleTracker {
109       Registration addingBundle()
110       void modifiedBundle()
111       void removedBundle()
112     }
113     class "YangModuleInfoRegistry" as registry {
114       Registration registerBundle()
115       void scanerUpdate()
116       void enableScannerAndUpdate()
117       void scannerShutdown()
118     }
119     class "ModuleInfoSnapshotResolver" as resolver {
120       List<Registration> registerModuelInfos()
121       ModuleInfoSnapshot takeSnapshot()
122     }
123     class "YangTextSchemaContextResolver" as textResolver {
124       YangTextSchemaSourceRegistration registerSource()
125       EffectiveModelContext getEffectiveModelContext()
126     }
127
128     runtime -- bundleTracker : initiates
129     runtime -- registry : initiates
130
131     registry -- resolver
132     resolver -- textResolver
133   @enduml