-
Notifications
You must be signed in to change notification settings - Fork 8
/
service.configurator.html
5427 lines (5387 loc) · 689 KB
/
service.configurator.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>150 Configurator Specification - OSGi Compendium 8</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
<link rel="home" href="index.html" title="OSGi Compendium" />
<link rel="up" href="index.html" title="OSGi Compendium" />
<link rel="prev" href="service.zigbee.html" title="149 Device Service Specification for ZigBee™ Technology" />
<link rel="next" href="service.jakartars.html" title="151 Whiteboard Specification for Jakarta™ RESTful Web Services" />
<meta name="Section-title" content="150 Configurator Specification" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="shortcut icon" href="images/favicon.png" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="css/custom.css" />
<link rel="stylesheet" type="text/css" href="css/github.css" />
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Ubuntu:regular,bold&subset=Latin" /><script type="text/javascript" src="js/highlight.pack.js"></script><script type="text/javascript" src="js/main.js"></script></head>
<body>
<div id="fullbody">
<div id="header">
<div class="menu-top-container"></div>
<div id="shadow-block"><a class="logo" href="index.html"><img src="images/OSGi.svg" alt="OSGi Working Group Documentation" /><h1>OSGi Compendium Release 8</h1></a></div>
</div>
<div id="mobile-menu-icon">⋮</div>
<div id="column-two">
<div id="content">
<div id="scrollable">
<div class="navheader">
<table width="100%" summary="Navigation header">
<tr>
<td width="20%" align="left"><a accesskey="p" href="service.zigbee.html">Prev</a>
</td>
<th width="60%" align="center"> </th>
<td width="20%" align="right"> <a accesskey="n" href="service.jakartars.html">Next</a></td>
</tr>
</table>
<hr />
</div>
<div class="chapter">
<div xmlns="" class="titlepage">
<div>
<div>
<h1 xmlns="http://www.w3.org/1999/xhtml" class="title"><a xmlns="" class="anchor" id="service.configurator"></a><span xmlns="" class="number">150</span> Configurator Specification
</h1>
</div>
<div>
<p xmlns="http://www.w3.org/1999/xhtml" class="releaseinfo"><a xmlns="" class="xref" href="service.configurator.html#org.osgi.service.configurator" title="150.12 org.osgi.service.configurator">Version 1.0</a></p>
</div>
</div>
</div>
<div class="section">
<div xmlns="" class="titlepage">
<div>
<div>
<h2 xmlns="http://www.w3.org/1999/xhtml" class="title" style="clear: both"><a xmlns="" class="anchor" id="d0e130267"></a><span xmlns="" class="number">150.1</span> Introduction
</h2>
</div>
</div>
</div>
<p>OSGi defines a model to provide bundles with configurations. This is
specified in the Configuration Admin specification where a configuration
is identified by a persistent identity (PID). A PID is a unique token,
recommended to be conforming to the symbolic name syntax. A configuration
consists of a set of properties, where a property consists of a string key
and a corresponding value. The type of the value is limited to the
primitive types and their wrappers, Strings, or Java Arrays/List/Vector of
these.
</p>
<p>This specification defines a mechanism to feed configurations into
the Configuration Admin Service through configuration resources. A single
configuration resource can feed multiple PIDs with configuration and
multiple configuration resources can be provided in one or more
bundles.
</p>
</div>
<div class="section">
<div xmlns="" class="titlepage">
<div>
<div>
<h2 xmlns="http://www.w3.org/1999/xhtml" class="title" style="clear: both"><a xmlns="" class="anchor" id="d0e130274"></a><span xmlns="" class="number">150.2</span> Entities
</h2>
</div>
</div>
</div>
<p>The following entities are used in this specification.</p>
<div class="itemizedlist">
<ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
<p><span class="emphasis"><em>Configuration Admin Service</em></span> - Standard
service to configure OSGi-based systems. See <a xmlns="" class="xref" href="service.cm.html" title="104 Configuration Admin Service Specification"><em xmlns="http://www.w3.org/1999/xhtml">Configuration Admin Service Specification</em></a>.
</p>
</li>
<li class="listitem">
<p><span class="emphasis"><em>Configuration Resource</em></span> - A JSON resource in
a bundle containing configurations. This resource is processed by an
implementation of this specification.
</p>
</li>
<li class="listitem">
<p><span class="emphasis"><em>Extendee</em></span> - The extendee is a bundle
containing configuration resources. It is
<span class="emphasis"><em>extended</em></span> by an implementation of this
specification.
</p>
</li>
<li class="listitem">
<p><span class="emphasis"><em>Configurator</em></span> - The Configurator implements
the behavior specified in this specification. It processes
configuration resources and passes the configuration dictionary on to
the Configuration Admin Service.
</p>
</li>
<li class="listitem">
<p><span class="emphasis"><em>Configuration dictionary</em></span> - The
configuration information when it is passed to the Configuration Admin
Service. It consists of a <code class="code">Dictionary</code> object with a number
of properties and identifiers.
</p>
</li>
<li class="listitem">
<p><span class="emphasis"><em>Persistent Identity (PID)</em></span> - A configuration
dictionary is associated with a unique PID to identify the destination
of this data. See <a xmlns="" class="xref" href="service.cm.html#i1233800" title="104.3 The Persistent Identity">The Persistent Identity</a>.
</p>
</li>
<li class="listitem">
<p><span class="emphasis"><em>Configuration Object</em></span> - Implements the
<code class="code">Configuration</code> interface and contains the configuration
dictionary for a Managed Service or one of the configuration
dictionaries for a Managed Service Factory. These objects are
manipulated by configuring bundles.
</p>
</li>
<li class="listitem">
<p><span class="emphasis"><em>Coordinator Service</em></span> - The coordinator
groups related operations to optimize handling of these operations.
Using the coordinator with configuration updates can minimize the
volatility in the system. See <a xmlns="" class="xref" href="service.coordinator.html" title="130 Coordinator Service Specification"><em xmlns="http://www.w3.org/1999/xhtml">Coordinator Service Specification</em></a>.
</p>
</li>
</ul>
</div>
<div class="figure"><a xmlns="" class="anchor" id="d0e130335"></a><p class="title"><strong>Figure <span xmlns="" class="number">150</span>.1 Configurator Entity Overview</strong></p>
<div class="figure-contents">
<div class="mediaobject" align="center"><img src="images/150-configurator-overview.png" align="middle" width="450" height="279" alt="Configurator Entity Overview" /></div>
</div>
</div><br class="figure-break" /></div>
<div class="section">
<div xmlns="" class="titlepage">
<div>
<div>
<h2 xmlns="http://www.w3.org/1999/xhtml" class="title" style="clear: both"><a xmlns="" class="anchor" id="service.configurator-resources"></a><span xmlns="" class="number">150.3</span> Configuration Resources
</h2>
</div>
</div>
</div>
<p>The Configurator is processing configuration resources containing
configurations. The resources can either be part of a bundle or be
provided to the Configurator on startup.
</p>
<div class="section">
<div xmlns="" class="titlepage">
<div>
<div>
<h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a xmlns="" class="anchor" id="d0e130346"></a><span xmlns="" class="number">150.3.1</span> Configuration Resource Format
</h3>
</div>
</div>
</div>
<p>The format for a configuration resource is <a xmlns="" class="xref" href="service.configurator.html#service.configurator-json.ref" title="JSON (JavaScript Object Notation)">[1] <em>JSON (JavaScript Object Notation)</em></a> and it must be UTF-8 encoded.
An example configuration resource has the following structure:
</p><pre xmlns="" class="programlisting"><code>{
// Resource Format Version
":configurator:resource-version" : 1,
// First Configuration
"pid.a": {
"key": "val",
"some_number": 123
},
// Second Configuration
"pid.b": {
"a_boolean": true
}
}</code></pre><p>Comments in the form of <a xmlns="" class="xref" href="service.configurator.html#service.configurator-jsmin.ref" title="JSMin (The JavaScript Minifier)">[2] <em>JSMin (The JavaScript Minifier)</em></a> comments are supported, that
is, any text on the same line after <code class="code">//</code> is ignored and any
text between <code class="code">/* */</code> is ignored.
</p>
<p>Configuration resources provide a set of configuration
dictionaries each with a <span class="emphasis"><em>PID</em></span> key to target a
specific PID in the Configuration Admin Service and zero or more
configuration values for this PID. Keys starting with the prefix
<code class="code">:configurator:</code> contain information about the resource or
instructions for the Configurator and therefore are not interpreted as
PIDs containing configurations. If a key contains an invalid PID, this
entry is ignored and the Configurator should log an error with the Log
Service if available.
</p>
<p>The Configurator defines the following special keys on the
resource level.
</p>
<div class="table"><a xmlns="" class="anchor" id="d0e130375"></a><p class="title"><strong>Table <span xmlns="" class="number">150</span>.1 Resource-level Configurator Keys</strong></p>
<div class="table-contents">
<table summary="Resource-level Configurator Keys" width="100%" style="border-collapse: collapse;border-top: 0.5pt solid ; border-bottom: 0.5pt solid ; border-left: 0.5pt solid ; border-right: 0.5pt solid ; ">
<colgroup>
<col />
<col />
<col />
<col />
</colgroup>
<thead>
<tr>
<th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">Key</th>
<th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">Value type</th>
<th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">Syntax</th>
<th style="border-bottom: 0.5pt solid ; ">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">
<p><code class="code">:configurator:</code></p>
<p><code class="code"> resource-version</code></p>
</td>
<td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">Number</td>
<td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; "><span class="emphasis"><em>integer</em></span> > 0
</td>
<td style="border-bottom: 0.5pt solid ; ">The version of the configuration resource format. This
specification only supports version <code class="code">1</code>. If this
entry is omitted then version <code class="code">1</code> is assumed.
Resources specifying an unsupported or invalid version are
ignored and the Configurator should log an error with the Log
Service if available.
</td>
</tr>
<tr>
<td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">
<p><code class="code">:configurator:</code></p>
<p><code class="code"> symbolic-name</code></p>
</td>
<td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">String</td>
<td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; "><span class="emphasis"><em>symbolic-name</em></span></td>
<td style="border-bottom: 0.5pt solid ; ">The symbolic name of the configuration resource. If not
specified the symbolic name of the bundle containing the
resource is used. <span class="emphasis"><em>Mandatory</em></span> for
configuration resources that do not reside in a bundle.
</td>
</tr>
<tr>
<td style="border-right: 0.5pt solid ; "><code class="code">:configurator:version</code></td>
<td style="border-right: 0.5pt solid ; ">String</td>
<td style="border-right: 0.5pt solid ; "><span class="emphasis"><em>version</em></span></td>
<td style="">The version of this configuration resource. If not
specified the version of the bundle containing the resource is
used. <span class="emphasis"><em>Mandatory</em></span> for configuration resources
that do not reside in a bundle.
</td>
</tr>
</tbody>
</table>
</div>
</div><br class="table-break" /></div>
<div class="section">
<div xmlns="" class="titlepage">
<div>
<div>
<h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a xmlns="" class="anchor" id="d0e130448"></a><span xmlns="" class="number">150.3.2</span> PIDs, Factory Configurations and Targeted PIDs
</h3>
</div>
</div>
</div>
<p>Configuration resources provide a set of configuration
dictionaries each with a <span class="emphasis"><em>PID</em></span> key to target a
specific PID in the Configuration Admin Service.
</p>
<p>Factory configurations can be addressed using the
<span class="emphasis"><em>factory PID</em></span> and a name by starting with the factory
PID, appending a tilde (<code class="code">'~' \u007e</code>), and then appending the
name. This ensures a well-known name for the factory configuration
instance. The PID for such a configuration is exactly this key. The
Configurator must use the <code class="code">getFactoryConfiguration</code> methods
on Configuration Admin Service to create or obtain configurations with
the given factory PID and name.
</p>
<p>Targeted PIDs are supported through the configuration resource. In
the case of single configurations, the full targeted PID is used as the
key. For factory configurations, the key is assembled by chaining the
targeted factory PID, a tilde (<code class="code">'~' \u007e</code>), and the
name.
</p>
<p>The Configurator obtains all configurations with the location
value of <code class="code">?</code> to allow the configurations to be received by
multiple bundles.
</p>
<p>The Configurator uses the
<code class="code">Configuration.updateIfDifferent</code> method on the configuration
object to avoid any volatility in the system if the configuration
applied has not been changed.
</p>
</div>
<div class="section">
<div xmlns="" class="titlepage">
<div>
<div>
<h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a xmlns="" class="anchor" id="d0e130482"></a><span xmlns="" class="number">150.3.3</span> Configuration Dictionary
</h3>
</div>
</div>
</div>
<p>A configuration dictionary for the Configuration Admin Service is
specified through a JSON object in the configuration resource. It is
introduced using the <span class="emphasis"><em>PID</em></span> as the key. The value is a
JSON object containing the configuration dictionary.
</p>
<p>The Configurator removes any comments and all properties where the
key is starting with the special prefix <code class="code">:configurator:</code> from
the configuration object before converting it to a configuration
dictionary that is provided to the Configuration Admin Service.
</p>
<p>The Configurator defines special keys that can be used within the
configuration object.
</p>
<div class="table"><a xmlns="" class="anchor" id="d0e130497"></a><p class="title"><strong>Table <span xmlns="" class="number">150</span>.2 PID-level Configurator Keys</strong></p>
<div class="table-contents">
<table summary="PID-level Configurator Keys" width="100%" style="border-collapse: collapse;border-top: 0.5pt solid ; border-bottom: 0.5pt solid ; border-left: 0.5pt solid ; border-right: 0.5pt solid ; ">
<colgroup>
<col />
<col />
<col />
<col />
</colgroup>
<thead>
<tr>
<th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">Key</th>
<th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">Value type</th>
<th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">Syntax</th>
<th style="border-bottom: 0.5pt solid ; ">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; "><code class="code">:configurator:policy</code></td>
<td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">String</td>
<td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; "><code class="code">default</code> or <code class="code">force</code></td>
<td style="border-bottom: 0.5pt solid ; ">Specifies the overwrite policy on configurations set by
non-Configurator sources. See <a xmlns="" class="xref" href="service.configurator.html#service.configurator-policy" title="150.3.6 Overwrite Policies">Overwrite Policies</a>.
</td>
</tr>
<tr>
<td style="border-right: 0.5pt solid ; "><code class="code">:configurator:ranking</code></td>
<td style="border-right: 0.5pt solid ; ">Number</td>
<td style="border-right: 0.5pt solid ; "><span class="emphasis"><em>integer</em></span></td>
<td style="">The ranking of this configuration. If multiple bundles
provide configuration for the same PID ranking rules are used to
decide which configuration gets applied, see <a xmlns="" class="xref" href="service.configurator.html#service.configurator-ranking" title="150.3.5 Ranking">Ranking</a>.
</td>
</tr>
</tbody>
</table>
</div>
</div><br class="table-break" /></div>
<div class="section">
<div xmlns="" class="titlepage">
<div>
<div>
<h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a xmlns="" class="anchor" id="d0e130545"></a><span xmlns="" class="number">150.3.4</span> Data Types
</h3>
</div>
</div>
</div>
<p>Configuration values support data types as specified with the
<span class="emphasis"><em>Filter Syntax</em></span> in the OSGi Core Specification.
Configuration resources are specified in JSON, which supports a more
basic set of data types. The following table describes how values are
converted from JSON to configuration values.
</p>
<div class="table"><a xmlns="" class="anchor" id="d0e130553"></a><p class="title"><strong>Table <span xmlns="" class="number">150</span>.3 JSON Conversions</strong></p>
<div class="table-contents">
<table summary="JSON Conversions" style="border-collapse: collapse;border-top: 0.5pt solid ; border-bottom: 0.5pt solid ; border-left: 0.5pt solid ; border-right: 0.5pt solid ; ">
<colgroup>
<col />
<col />
</colgroup>
<thead>
<tr>
<th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">JSON type</th>
<th style="border-bottom: 0.5pt solid ; ">To Java type</th>
</tr>
</thead>
<tbody>
<tr>
<td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">Boolean</td>
<td style="border-bottom: 0.5pt solid ; "><code class="code">Boolean</code></td>
</tr>
<tr>
<td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">Number</td>
<td style="border-bottom: 0.5pt solid ; ">
<p>Whole number: <code class="code">Long</code></p>
<p>Floating point number: <code class="code">Double</code></p>
</td>
</tr>
<tr>
<td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">String</td>
<td style="border-bottom: 0.5pt solid ; "><code class="code">String</code></td>
</tr>
<tr>
<td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">Array</td>
<td style="border-bottom: 0.5pt solid ; ">Array, or if requested <code class="code">Collection</code>. Contents
are boxed. If the array contents are of the same JSON type, the
associated Java type is used as the array type. Otherwise the
array elements are converted to String and a
<code class="code">String[]</code> array is used.
</td>
</tr>
<tr>
<td style="border-right: 0.5pt solid ; ">Object</td>
<td style="">Literal object as JSON String</td>
</tr>
</tbody>
</table>
</div>
</div><br class="table-break" /><p>If a specific data type is required for a configuration, the
Configurator can be instructed to convert the JSON value to a given data
type. The target type can be specified by adding a colon <code class="code">:</code>
and the desired data type to the property name. Supported data types are
<code class="code">String</code>, <code class="code">Integer</code>, <code class="code">Long</code>,
<code class="code">Float</code>, <code class="code">Double</code>, <code class="code">Byte</code>,
<code class="code">Short</code>, <code class="code">Character</code> and <code class="code">Boolean</code>.
Additionally arrays of Scalar or primitive types are supported and
<code class="code">Collection</code> of scalar. The primitive types that can be
specified for arrays are: <code class="code">int</code>, <code class="code">long</code>,
<code class="code">float</code>, <code class="code">double</code>, <code class="code">byte</code>,
<code class="code">short</code>, <code class="code">char</code>, <code class="code">boolean</code>. For
<code class="code">Collection</code> the Configurator picks a suitable implementation
that preserves order. Both bare <code class="code">Collection</code> as well as typed
collections that use the generics style notation are supported. If a
requested conversion cannot be performed, then the configuration is not
processed and the Configurator implementation should log an
error.
</p>
<p>An example configuration resource with typed data:</p><pre xmlns="" class="programlisting"><code>{
"my.pid": {
"port:Integer" : 300,
"an_int_array:int[]" : [2, 3, 4],
"an_Integer_collection:Collection<Integer>" : [2, 3, 4],
"complex": {
"a" : 1,
"b" : "two"
}
}
}</code></pre><p>The above configuration gets converted to a configuration
dictionary with the following entries (in pseudo Java language):
</p><pre xmlns="" class="programlisting"><code>Integer port = 300;
int[] an_int_array = {2, 3, 4};
Collection<Integer> an_Integer_collection = {2, 3, 4};
String complex = "{ \"1\" : 1, \"b\" : \"two\" }"</code></pre><p>As an alternative of specifying data types for the Configurator,
consumers of configuration can convert the configuration values to the
desired type by using the OSGi Converter see <a xmlns="" class="xref" href="util.converter.html" title="707 Converter Specification"><em xmlns="http://www.w3.org/1999/xhtml">Converter Specification</em></a>. A convenient way to convert a configuration
map to the desired data types is by using the Converter to convert it to
an annotation instance or by using a Declarative Services component
property type.
</p>
<div class="section">
<div xmlns="" class="titlepage">
<div>
<div>
<h4 xmlns="http://www.w3.org/1999/xhtml" class="title"><a xmlns="" class="anchor" id="d0e130682"></a><span xmlns="" class="number">150.3.4.1</span> Binary Data
</h4>
</div>
</div>
</div>
<p>In some cases binary data is associated with configurations such
as certificates, security keys or other resources. The Configurator
can manage this binary data. The bundle developer places the binaries
in a location in the extendee and references it from the configuration
resource, marking its type as <code class="code">binary</code>:
</p><pre xmlns="" class="programlisting"><code>{
"my.config": {
"security.enabled": true,
"public.key:binary" : "/OSGI-INF/files/mykey.pub"
}
}</code></pre><p>When the Configurator applies the configuration, it extracts the
binary file to a public area on the file system. The Configurator
creates a subdirectory with as name the PID of the configuration. The
PID must be URL-encoded to ensure that it does not contain characters
that are illegal on a file system. The binary file is extracted in
this subdirectory. The Configurator then applies the configuration
with as value for the binary entry the absolute path of the extracted
binary file.
</p>
<p>A binary data property can also specify an array of binary
resources by declaring the <code class="code">binary[]</code> data type. Each
resource referenced is extracted as a separate file on the file system
and the value of the property will be an array of strings, each string
being the full path of one extracted binary.
</p>
<p>By default a directory called <code class="code">binaries</code> in the
bundle data area of the Configurator implementation is used. An
alternative location can be specified via the
<code class="code">configurator.binaries</code> framework property. The value of
this property must be an absolute path on the file system to which the
Configurator has write access. If the directory does not exist the
Configurator will create it. If the Configurator cannot write to this
location, it logs an error and uses the default location
instead.
</p>
<p>When a configuration is removed, its associated binary files are
also removed from the file system. When a configuration is updated,
associated binary files are updated, if necessary. In the case of an
update the Configurator should use a different filename for the
extracted binary file to avoid any open file lock issues.
</p>
</div>
</div>
<div class="section">
<div xmlns="" class="titlepage">
<div>
<div>
<h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a xmlns="" class="anchor" id="service.configurator-ranking"></a><span xmlns="" class="number">150.3.5</span> Ranking
</h3>
</div>
</div>
</div>
<p>The order in which the Configurator processes bundles is not
defined. To control which configurations are in effect configuration
ranking can be used. Configuration ranking is similar to service
ranking; it is an integer which defaults to 0. Configurations with a
higher ranking are preferred over configurations with a lower ranking.
When multiple configurations arrive over time it is possible that the
Configurator changes the effective configuration if a higher ranked
configuration arrives later. The design of the Configurator is such that
the effective set of configurations once the system stabilizes is
consistent, regardless of the order in which bundles are installed and
processed.
</p>
<p>The ranking of a configuration can be specified by adding the
<code class="code">:configurator:ranking</code> property. The value of this property
is converted to an <code class="code">Integer</code> as defined by the Converter
specification. If the value cannot be converted a warning should be
logged. When multiple configurations for a given PID have the same
ranking the bundle providing the configuration with the lowest bundle ID
is preferred. If multiple configurations for the same PID with the same
ranking are specified within a single bundle, the first one encountered
is used.
</p>
<p>The following example shows two bundles with a configuration
resource containing a configuration for the same PID:
</p><pre xmlns="" class="programlisting"><code>Resource in Bundle A:
{
"my.pid": {
"port:Integer" : 300,
":configurator:ranking" : 100
}
}
Resource in Bundle B:
{
"my.pid": {
"port:Integer" : 100,
":configurator:ranking" : 10
}
}</code></pre><p>Bundle A contains the configuration with the higher ranking.
Therefore, regardless of the installation order of bundle A and B, the
configuration from Bundle A will be in effect after both bundles are
installed and processed by the Configurator.
</p>
</div>
<div class="section">
<div xmlns="" class="titlepage">
<div>
<div>
<h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a xmlns="" class="anchor" id="service.configurator-policy"></a><span xmlns="" class="number">150.3.6</span> Overwrite Policies
</h3>
</div>
</div>
</div>
<p>In an IT operations scenario configurations are often updated by a
systems administrator to suit the deployments requirements. In such
scenarios it may be undesirable to have these modifications overwritten
by a software update which includes a configuration resource. In other
cases, bundles with configuration resources are used to enforce best
practices or compliance with corporate guidelines, which should replace
any previous manual settings. This specification defines policies to
define the overwrite behavior of the Configurator when configurations
have been set or modified by another entity.
</p>
<p>Configuration policies are set by specifying the
<code class="code">:configurator:policy</code> property. Accepted values are
<code class="code">default</code> and <code class="code">force</code>. This policy defines the
behavior when a configuration to be applied was set by another entity in
the system, or if it was modified by someone from the values set by the
Configurator. The default value for this property is
<code class="code">default</code>. If the specified value is invalid an error is
logged and the default value is used.
</p>
<div class="table"><a xmlns="" class="anchor" id="d0e130747"></a><p class="title"><strong>Table <span xmlns="" class="number">150</span>.4 Applying Configurations: Overwrite Policies</strong></p>
<div class="table-contents">
<table summary="Applying Configurations: Overwrite Policies" style="border-collapse: collapse;border-top: 0.5pt solid ; border-bottom: 0.5pt solid ; border-left: 0.5pt solid ; border-right: 0.5pt solid ; ">
<colgroup>
<col />
<col />
</colgroup>
<thead>
<tr>
<th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">Policy value</th>
<th style="border-bottom: 0.5pt solid ; ">Action</th>
</tr>
</thead>
<tbody>
<tr>
<td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; "><code class="code">default</code></td>
<td style="border-bottom: 0.5pt solid ; ">No action</td>
</tr>
<tr>
<td style="border-right: 0.5pt solid ; "><code class="code">force</code></td>
<td style="">Configuration is added</td>
</tr>
</tbody>
</table>
</div>
</div><br class="table-break" /><p>The Configurator must keep track of configuration change count
values to identify configurations that were changed by other entities or
administrators.
</p>
<p>When a bundle that provides configuration resources is
uninstalled, the Configurator removes any configurations that it has
provided on behalf of this bundle from the system. Before it removes a
configuration the Configurator checks with the Configuration Admin
Service whether the configuration it has provided has been changed by
another entity. If the configuration has not been changed by another
entity it is removed. If it has been changed then whether the
configuration is removed depends on the value of the
<code class="code">configurator:policy</code> property:
</p>
<div class="table"><a xmlns="" class="anchor" id="d0e130777"></a><p class="title"><strong>Table <span xmlns="" class="number">150</span>.5 Removing externally modified configurations</strong></p>
<div class="table-contents">
<table summary="Removing externally modified configurations" style="border-collapse: collapse;border-top: 0.5pt solid ; border-bottom: 0.5pt solid ; border-left: 0.5pt solid ; border-right: 0.5pt solid ; ">
<colgroup>
<col />
<col />
</colgroup>
<thead>
<tr>
<th style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; ">Policy value</th>
<th style="border-bottom: 0.5pt solid ; ">Action</th>
</tr>
</thead>
<tbody>
<tr>
<td style="border-right: 0.5pt solid ; border-bottom: 0.5pt solid ; "><code class="code">default</code></td>
<td style="border-bottom: 0.5pt solid ; ">No action</td>
</tr>
<tr>
<td style="border-right: 0.5pt solid ; "><code class="code">force</code></td>
<td style="">Configuration is removed</td>
</tr>
</tbody>
</table>
</div>
</div><br class="table-break" /><p>When a configuration is removed the Configurator checks whether
another, lower ranked, configuration resource is available. If present
the Configurator sets this configuration.
</p>
<p>The following examples explain the two policy options. In the
first example Bundle A contains a configuration for the PID
<code class="code">my.pid</code> without specifying the policy. In this case the
default policy is used:
</p><pre xmlns="" class="programlisting"><code>{
"my.pid": {
"port:Integer" : 300
}
}</code></pre><p>The following actions demonstrate the behavior of the default
policy:
</p>
<div class="orderedlist">
<ol class="orderedlist" type="1">
<li class="listitem">
<p>The framework is started without any configuration for PID
<code class="code">my.pid</code>.
</p>
</li>
<li class="listitem">
<p>Bundle A is installed, the Configurator creates the
configuration for PID <code class="code">my.pid</code>.
</p>
</li>
<li class="listitem">
<p>An administrator manually changes the configuration for PID
<code class="code">my.pid</code>.
</p>
</li>
<li class="listitem">
<p>Bundle A is updated with an updated configuration for PID
<code class="code">my.pid</code>. The Configurator detects the manual change of
the configuration in Configuration Admin Service and does not apply
the updated configuration from the bundle.
</p>
</li>
<li class="listitem">
<p>Bundle A is uninstalled. The Configurator detects the manual
change of the configuration in Configuration Admin Service and does
not delete the configuration.
</p>
</li>
</ol>
</div>
<p>In the second example Bundle A contains a configuration for the
PID <code class="code">my.pid</code> this time with the overwrite policy set to
<code class="code">force</code>.
</p><pre xmlns="" class="programlisting"><code>{
"my.pid": {
"port:Integer" : 300,
":configurator:policy" : "force"
}
}</code></pre><p>The following actions demonstrate the behavior of the force
policy:
</p>
<div class="orderedlist">
<ol class="orderedlist" type="1">
<li class="listitem">
<p>The framework is started without any configuration for PID
<code class="code">my.pid</code>.
</p>
</li>
<li class="listitem">
<p>Bundle A is installed, the Configurator creates the
configuration for PID <code class="code">my.pid</code>.
</p>
</li>
<li class="listitem">
<p>An administrator manually changes the configuration for PID
<code class="code">my.pid</code>.
</p>
</li>
<li class="listitem">
<p>Bundle A is updated with an updated configuration for PID
<code class="code">my.pid</code>. The Configurator applies the updated
configuration.
</p>
</li>
<li class="listitem">
<p>Bundle A is uninstalled. The Configurator detects the manual
change of the configuration in Configuration Admin Service and
deletes the configuration.
</p>
</li>
</ol>
</div>
</div>
</div>
<div class="section">
<div xmlns="" class="titlepage">
<div>
<div>
<h2 xmlns="http://www.w3.org/1999/xhtml" class="title" style="clear: both"><a xmlns="" class="anchor" id="d0e130879"></a><span xmlns="" class="number">150.4</span> Bundle Configuration Resources
</h2>
</div>
</div>
</div>
<p>The Configurator follows the OSGi extender model and looks for JSON
configuration resources in installed bundles, if the bundle has opted-in
to be processed. In order to get processed, a bundle must require the
Configurator extender:
</p><pre xmlns="" class="programlisting"><code>Require-Capability: osgi.extender;
filter := "(&(osgi.extender=osgi.configurator)
(version>=<a class="xref" href="service.configurator.html#org.osgi.service.configurator" title="150.12 org.osgi.service.configurator">1.0</a>)(!(version>=2.0)))"</code></pre><p>The Configurator must ensure to only process bundles that it is
wired to by the resolver.
</p>
<p>By default the configuration resources are in the
<code class="code">OSGI-INF/configurator</code> directory in the bundle.
</p>
<p>Configuration files are UTF-8 encoded and have the
<code class="code">.json</code> file extension. Files not having this extension are
ignored. The Configurator processes the configuration resources within a
single bundle in lexical order using the full resource path for
sorting.
</p>
</div>
<div class="section">
<div xmlns="" class="titlepage">
<div>
<div>
<h2 xmlns="http://www.w3.org/1999/xhtml" class="title" style="clear: both"><a xmlns="" class="anchor" id="d0e130900"></a><span xmlns="" class="number">150.5</span> Initial Configurations
</h2>
</div>
</div>
</div>
<p>When the Configurator starts it calls
<code class="code">bundleContext.getProperty("configurator.initial")</code> to obtain
initial configurations from the runtime environment. If this property is
available its value is processed as follows:
</p>
<div class="orderedlist">
<ol class="orderedlist" type="1">
<li class="listitem">
<p>If the value starts with a left curly bracket ('{'
<code class="code">\u007B</code>), ignoring any leading white space, the
Configurator will interpret the value as a literal configuration JSON
resource.
</p>
</li>
<li class="listitem">
<p>Otherwise the value is treated as a comma-separated list of
URLs. The Configurator will read the resource at each URL and parse it
as a JSON Configuration resource. If any errors occur during this
process they are logged and the URL is skipped. The URLs are processed
in alphabetical order of their provided value.
</p>
</li>
</ol>
</div>
<p>The ranking of these configurations can be set in the configuration
resource as described in <a xmlns="" class="xref" href="service.configurator.html#service.configurator-ranking" title="150.3.5 Ranking">Ranking</a>.
The Configurator treats the initial configurations as being provided from
a bundle with the bundle id <code class="code">-1</code>.
</p>
<p>If the framework is restarted, the Configurator needs to check
whether the provided initial configurations are different than on the
previous startup. The implementation is free to use whatever is
appropriate to perform this check, like comparing last modified for the
URLs or using a hash etc. If the provided configuration is different than
on a previous startup, this is treated like a bundle update with an
updated configuration.
</p>
</div>
<div class="section">
<div xmlns="" class="titlepage">
<div>
<div>
<h2 xmlns="http://www.w3.org/1999/xhtml" class="title" style="clear: both"><a xmlns="" class="anchor" id="d0e130927"></a><span xmlns="" class="number">150.6</span> Life Cycle
</h2>
</div>
</div>
</div>
<p>The Configurator uses the Configuration Admin Service. Therefore the
Configurator implementation should require the Configuration Admin Service
through a service requirement. The Configurator should not start
processing configuration resources until it has runtime access to the
Configuration Admin Service.
</p>
<p>The Configurator uses the Configuration Admin Service that is
visible to both the Configurator itself as well as the bundle that is
being processed. If there are multiple candidates, the service with the
highest ranking is used. If there is no Configuration Admin Service
visible to both the bundle that is processed and the Configurator, the
processing is delayed until such a service becomes available.
</p>
<p>When the Configurator starts, it processes all started bundles and
applies configurations provided by those bundles. From then on, the
Configurator processes bundles as they enter the <code class="code">STARTING</code>
state. The Configurator should process as many bundles as possible in a
single pass to minimize volatility for PIDs where multiple configurations
with different rankings are provided.
</p>
<p>When a bundle containing configuration resources is updated, the
configurations must be updated in the Configuration Admin Service to which
they were originally provided, keeping in mind that the system might have
been restarted in-between. One way of keeping track of the original
Configuration Admin Service is via the bundle location of the bundle
providing the service. If this service is not available the Configurator
must attempt to apply the updated configuration when this Configuration
Admin Service re-appears.
</p>
<p>Configurations remain in the system until the bundle that provided
the configurations is uninstalled. When this happens, the Configurator
must uninstall the configurations from the Configuration Admin Service to
which it originally installed it as is the case with updates. If this
Configuration Admin Service is not available at this time, the
Configurator must remember the configurations that are to be removed, and
remove them when the Configuration Admin Service re-appears at a later
time.
</p>
<p>When the Configurator becomes active, it must check whether
configurations that it installed previously are still valid. If the
bundles that provided these configurations have been uninstalled, the
associated configurations must be removed. If a bundle is updated the
associated configurations are also updated. The Configurator calls
<code class="code">updateIfDifferent</code> on the configuration to avoid volatility in
the system if the actual configuration values did not change.
</p>
<p>When updating or removing configurations, the Configurator must take
the <a xmlns="" class="xref" href="service.configurator.html#service.configurator-policy" title="150.3.6 Overwrite Policies">Overwrite Policies</a> into account. This means
that for certain policy values an externally modified configuration is not
replaced or removed.
</p>
<p>When a bundle that provides the Configuration Admin Service is
uninstalled, the Configurator considers all configurations previously
provided to that Configuration Admin Service as not yet applied. If
another Configuration Admin Service is or becomes visible to both the
Configurator and the bundle containing configuration resources, the
Configurator will provide the configurations to this Configuration Admin
Service as new.
</p>
<p>When the Configurator is stopped or uninstalled the configurations
applied will remain in the system.
</p>
</div>
<div class="section">
<div xmlns="" class="titlepage">
<div>
<div>
<h2 xmlns="http://www.w3.org/1999/xhtml" class="title" style="clear: both"><a xmlns="" class="anchor" id="d0e130956"></a><span xmlns="" class="number">150.7</span> Grouping and Coordinations
</h2>
</div>
</div>
</div>
<p>The <a xmlns="" class="xref" href="service.coordinator.html" title="130 Coordinator Service Specification"><em xmlns="http://www.w3.org/1999/xhtml">Coordinator Service Specification</em></a> defines a mechanism for
multiple parties to collaborate on a common task without <span class="emphasis"><em>a
priori</em></span> knowledge of who will collaborate in that task. The
Configurator must participate in such scenarios to coordinate with
provisioning or configuration tasks.
</p>
<p>Whenever the Configurator is processing configuration resources and
interacting with the Configuration Admin Service, the Configurator must
check whether a Coordinator Service is present. If it is present, the
Configurator checks for an implicit coordination on the current thread. If
such an implicit coordination exists, the Configurator does not need to
create one. However, if such an implicit coordination is not present, the
Configurator starts an implicit coordination on the current thread when
interacting with the Configuration Admin Service and ends this coordinator
when it is finished doing the current set of work. The Configurator does
not need to delay applying any changes to the Configuration Admin Service
until the coordination ends.
</p>
</div>
<div class="section">
<div xmlns="" class="titlepage">
<div>
<div>
<h2 xmlns="http://www.w3.org/1999/xhtml" class="title" style="clear: both"><a xmlns="" class="anchor" id="d0e130968"></a><span xmlns="" class="number">150.8</span> Security
</h2>
</div>
</div>
</div>
<p>When Java permissions are enabled, the Configurator must perform the
following security procedures.
</p>
<div class="section">
<div xmlns="" class="titlepage">
<div>
<div>
<h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a xmlns="" class="anchor" id="d0e130973"></a><span xmlns="" class="number">150.8.1</span> Configuration Permission
</h3>
</div>
</div>
</div>
<p>The Configurator manages configurations on behalf of the bundle
containing the configuration resources. Therefore the Configurator needs
to have the
<code class="code">ConfigurationPermission[*,org.osgi.service.cm.ConfigurationPermission.CONFIGURE]</code>.
</p>
<p>Every bundle has the implicit right to receive and configure
configurations with a location that exactly matches the Bundle's
location or that is <code class="code">null</code>. Therefore the extendee does not
need to special permissions.
</p>
</div>
<div class="section">
<div xmlns="" class="titlepage">
<div>
<div>
<h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a xmlns="" class="anchor" id="d0e130986"></a><span xmlns="" class="number">150.8.2</span> Service Permission
</h3>
</div>
</div>
</div>
<p>The Configurator needs <code class="code">ServicePermission[<interface>,
GET]</code> for the <code class="code">Coordinator</code> service.
</p>
<p>The extendee needs <code class="code">ServicePermission[<interface>,
GET]</code> for the Configuration Admin Service.
</p>
</div>
<div class="section">
<div xmlns="" class="titlepage">
<div>
<div>
<h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a xmlns="" class="anchor" id="d0e131002"></a><span xmlns="" class="number">150.8.3</span> Configuration Admin Service
</h3>
</div>
</div>
</div>
<p>The Configurator does get the Configuration Admin Service on
behalf of the extendee. Therefore the extendee needs to be included in
permission checks for getting the Configuration Admin Service. The
Configurator needs to perform the required calls to ensure the extendee
has the necessary permission to get the Configuration Admin
Service.
</p>
</div>
<div class="section">
<div xmlns="" class="titlepage">
<div>
<div>
<h3 xmlns="http://www.w3.org/1999/xhtml" class="title"><a xmlns="" class="anchor" id="d0e131007"></a><span xmlns="" class="number">150.8.4</span> File Permission
</h3>