1 package org.openecomp.config.api;
3 import java.util.Arrays;
8 * The interface Configuration.
10 public interface Configuration {
12 * The constant tenant.
14 public static ThreadLocal<String> tenant = new ThreadLocal<>();
21 public static void setTenantId(String id) {
22 if (id != null && id.trim().length() > 0) {
31 * @return the as string
33 public default String getAsString(String key) {
34 return getAsString(null, key);
40 * @param namespace the namespace
42 * @return the as string
44 public default String getAsString(String namespace, String key) {
45 return getAsString(tenant.get(), namespace, key);
51 * @param tenantId the tenant id
52 * @param namespace the namespace
54 * @return the as string
56 public default String getAsString(String tenantId, String namespace, String key) {
57 return get(tenantId, namespace, key, String.class);
64 * @return the as byte value
66 public default Byte getAsByteValue(String key) {
67 return getAsByteValue(null, key);
73 * @param namespace the namespace
75 * @return the as byte value
77 public default Byte getAsByteValue(String namespace, String key) {
78 return getAsByteValue(tenant.get(), namespace, key);
84 * @param tenantId the tenant id
85 * @param namespace the namespace
87 * @return the as byte value
89 public default Byte getAsByteValue(String tenantId, String namespace, String key) {
90 return get(tenantId, namespace, key, Byte.class);
94 * Gets as short value.
97 * @return the as short value
99 public default Short getAsShortValue(String key) {
100 return getAsShortValue(null, key);
104 * Gets as short value.
106 * @param namespace the namespace
108 * @return the as short value
110 public default Short getAsShortValue(String namespace, String key) {
111 return getAsShortValue(tenant.get(), namespace, key);
115 * Gets as short value.
117 * @param tenantId the tenant id
118 * @param namespace the namespace
120 * @return the as short value
122 public default Short getAsShortValue(String tenantId, String namespace, String key) {
123 return get(tenantId, namespace, key, Short.class);
127 * Gets as integer value.
130 * @return the as integer value
132 public default Integer getAsIntegerValue(String key) {
133 return getAsIntegerValue(null, key);
137 * Gets as integer value.
139 * @param namespace the namespace
141 * @return the as integer value
143 public default Integer getAsIntegerValue(String namespace, String key) {
144 return getAsIntegerValue(tenant.get(), namespace, key);
148 * Gets as integer value.
150 * @param tenantId the tenant id
151 * @param namespace the namespace
153 * @return the as integer value
155 public default Integer getAsIntegerValue(String tenantId, String namespace, String key) {
156 return get(tenantId, namespace, key, Integer.class);
160 * Gets as long value.
163 * @return the as long value
165 public default Long getAsLongValue(String key) {
166 return getAsLongValue(null, key);
170 * Gets as long value.
172 * @param namespace the namespace
174 * @return the as long value
176 public default Long getAsLongValue(String namespace, String key) {
177 return getAsLongValue(tenant.get(), namespace, key);
181 * Gets as long value.
183 * @param tenantId the tenant id
184 * @param namespace the namespace
186 * @return the as long value
188 public default Long getAsLongValue(String tenantId, String namespace, String key) {
189 return get(tenantId, namespace, key, Long.class);
193 * Gets as float value.
196 * @return the as float value
198 public default Float getAsFloatValue(String key) {
199 return getAsFloatValue(null, key);
203 * Gets as float value.
205 * @param namespace the namespace
207 * @return the as float value
209 public default Float getAsFloatValue(String namespace, String key) {
210 return getAsFloatValue(tenant.get(), namespace, key);
214 * Gets as float value.
216 * @param tenantId the tenant id
217 * @param namespace the namespace
219 * @return the as float value
221 public default Float getAsFloatValue(String tenantId, String namespace, String key) {
222 return get(tenantId, namespace, key, Float.class);
226 * Gets as double value.
229 * @return the as double value
231 public default Double getAsDoubleValue(String key) {
232 return getAsDoubleValue(null, key);
236 * Gets as double value.
238 * @param namespace the namespace
240 * @return the as double value
242 public default Double getAsDoubleValue(String namespace, String key) {
243 return getAsDoubleValue(tenant.get(), namespace, key);
247 * Gets as double value.
249 * @param tenantId the tenant id
250 * @param namespace the namespace
252 * @return the as double value
254 public default Double getAsDoubleValue(String tenantId, String namespace, String key) {
255 return get(tenantId, namespace, key, Double.class);
259 * Gets as boolean value.
262 * @return the as boolean value
264 public default Boolean getAsBooleanValue(String key) {
265 return getAsBooleanValue(null, key);
269 * Gets as boolean value.
271 * @param namespace the namespace
273 * @return the as boolean value
275 public default Boolean getAsBooleanValue(String namespace, String key) {
276 return getAsBooleanValue(tenant.get(), namespace, key);
280 * Gets as boolean value.
282 * @param tenantId the tenant id
283 * @param namespace the namespace
285 * @return the as boolean value
287 public default Boolean getAsBooleanValue(String tenantId, String namespace, String key) {
288 return get(tenantId, namespace, key, Boolean.class);
292 * Gets as char value.
295 * @return the as char value
297 public default Character getAsCharValue(String key) {
298 return getAsCharValue(null, key);
302 * Gets as char value.
304 * @param namespace the namespace
306 * @return the as char value
308 public default Character getAsCharValue(String namespace, String key) {
309 return getAsCharValue(tenant.get(), namespace, key);
313 * Gets as char value.
315 * @param tenantId the tenant id
316 * @param namespace the namespace
318 * @return the as char value
320 public default Character getAsCharValue(String tenantId, String namespace, String key) {
321 return get(tenantId, namespace, key, Character.class);
325 * Populate configuration t.
327 * @param <T> the type parameter
328 * @param clazz the clazz
331 public default <T> T populateConfiguration(Class<T> clazz) {
332 return populateConfiguration(null, clazz);
336 * Populate configuration t.
338 * @param <T> the type parameter
339 * @param namespace the namespace
340 * @param clazz the clazz
343 public default <T> T populateConfiguration(String namespace, Class<T> clazz) {
344 return populateConfiguration(tenant.get(), namespace, clazz);
348 * Populate configuration t.
350 * @param <T> the type parameter
351 * @param tenantId the tenant id
352 * @param namespace the namespace
353 * @param clazz the clazz
356 public default <T> T populateConfiguration(String tenantId, String namespace, Class<T> clazz) {
357 return get(tenantId, namespace, null, clazz, Hint.EXTERNAL_LOOKUP);
361 * Gets dynamic configuration.
363 * @param <T> the type parameter
365 * @param clazz the clazz
366 * @param defaultValue the default value
367 * @return the dynamic configuration
369 public default <T> DynamicConfiguration<T> getDynamicConfiguration(String key, Class<T> clazz,
371 return getDynamicConfiguration(null, key, clazz, defaultValue);
375 * Gets dynamic configuration.
377 * @param <T> the type parameter
378 * @param namespace the namespace
380 * @param clazz the clazz
381 * @param defaultValue the default value
382 * @return the dynamic configuration
384 public default <T> DynamicConfiguration<T> getDynamicConfiguration(String namespace, String key,
387 return getDynamicConfiguration(tenant.get(), namespace, key, clazz, defaultValue);
391 * Gets dynamic configuration.
393 * @param <T> the type parameter
394 * @param tenant the tenant
395 * @param namespace the namespace
397 * @param clazz the clazz
398 * @param defaultValue the default value
399 * @return the dynamic configuration
401 public default <T> DynamicConfiguration<T> getDynamicConfiguration(String tenant,
402 String namespace, String key,
405 return DynamicConfiguration
406 .getDynamicConfiguration(tenant, namespace, key, clazz, defaultValue, this);
410 * Gets dynamic configuration values.
412 * @param <T> the type parameter
414 * @param clazz the clazz
415 * @param defaultValue the default value
416 * @return the dynamic configuration values
418 public default <T> DynamicConfiguration<List<T>> getDynamicConfigurationValues(String key,
421 return getDynamicConfigurationValues(null, key, clazz, defaultValue);
425 * Gets dynamic configuration values.
427 * @param <T> the type parameter
428 * @param namespace the namespace
430 * @param clazz the clazz
431 * @param defaultValue the default value
432 * @return the dynamic configuration values
434 public default <T> DynamicConfiguration<List<T>> getDynamicConfigurationValues(String namespace,
438 return getDynamicConfigurationValues(tenant.get(), namespace, key, clazz, defaultValue);
442 * Gets dynamic configuration values.
444 * @param <T> the type parameter
445 * @param tenant the tenant
446 * @param namespace the namespace
448 * @param clazz the clazz
449 * @param defaultValue the default value
450 * @return the dynamic configuration values
452 public default <T> DynamicConfiguration<List<T>> getDynamicConfigurationValues(String tenant,
457 return DynamicConfiguration
458 .getDynConfiguration(tenant, namespace, key, clazz, defaultValue, this);
462 * Gets as string values.
465 * @return the as string values
467 public default List<String> getAsStringValues(String key) {
468 return getAsStringValues(null, key);
472 * Gets as string values.
474 * @param namespace the namespace
476 * @return the as string values
478 public default List<String> getAsStringValues(String namespace, String key) {
479 return getAsStringValues(tenant.get(), namespace, key);
483 * Gets as string values.
485 * @param tenantId the tenant id
486 * @param namespace the namespace
488 * @return the as string values
490 public default List<String> getAsStringValues(String tenantId, String namespace, String key) {
491 String[] tempArray = get(tenantId, namespace, key, String[].class);
492 return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray);
496 * Gets as byte values.
499 * @return the as byte values
501 public default List<Byte> getAsByteValues(String key) {
502 return getAsByteValues(null, key);
506 * Gets as byte values.
508 * @param namespace the namespace
510 * @return the as byte values
512 public default List<Byte> getAsByteValues(String namespace, String key) {
513 return getAsByteValues(tenant.get(), namespace, key);
517 * Gets as byte values.
519 * @param tenantId the tenant id
520 * @param namespace the namespace
522 * @return the as byte values
524 public default List<Byte> getAsByteValues(String tenantId, String namespace, String key) {
525 Byte[] tempArray = get(tenantId, namespace, key, Byte[].class);
526 return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray);
530 * Gets as short values.
533 * @return the as short values
535 public default List<Short> getAsShortValues(String key) {
536 return getAsShortValues(null, key);
540 * Gets as short values.
542 * @param namespace the namespace
544 * @return the as short values
546 public default List<Short> getAsShortValues(String namespace, String key) {
547 return getAsShortValues(tenant.get(), namespace, key);
551 * Gets as short values.
553 * @param tenantId the tenant id
554 * @param namespace the namespace
556 * @return the as short values
558 public default List<Short> getAsShortValues(String tenantId, String namespace, String key) {
559 Short[] tempArray = get(tenantId, namespace, key, Short[].class);
560 return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray);
564 * Gets as integer values.
567 * @return the as integer values
569 public default List<Integer> getAsIntegerValues(String key) {
570 return getAsIntegerValues(null, key);
574 * Gets as integer values.
576 * @param namespace the namespace
578 * @return the as integer values
580 public default List<Integer> getAsIntegerValues(String namespace, String key) {
581 return getAsIntegerValues(tenant.get(), namespace, key);
585 * Gets as integer values.
587 * @param tenantId the tenant id
588 * @param namespace the namespace
590 * @return the as integer values
592 public default List<Integer> getAsIntegerValues(String tenantId, String namespace, String key) {
593 Integer[] tempArray = get(tenantId, namespace, key, Integer[].class);
594 return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray);
598 * Gets as double values.
601 * @return the as double values
603 public default List<Double> getAsDoubleValues(String key) {
604 return getAsDoubleValues(null, key);
608 * Gets as double values.
610 * @param namespace the namespace
612 * @return the as double values
614 public default List<Double> getAsDoubleValues(String namespace, String key) {
615 return getAsDoubleValues(tenant.get(), namespace, key);
619 * Gets as double values.
621 * @param tenantId the tenant id
622 * @param namespace the namespace
624 * @return the as double values
626 public default List<Double> getAsDoubleValues(String tenantId, String namespace, String key) {
627 Double[] tempArray = get(tenantId, namespace, key, Double[].class);
628 return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray);
632 * Gets as float values.
635 * @return the as float values
637 public default List<Float> getAsFloatValues(String key) {
638 return getAsFloatValues(null, key);
642 * Gets as float values.
644 * @param namespace the namespace
646 * @return the as float values
648 public default List<Float> getAsFloatValues(String namespace, String key) {
649 return getAsFloatValues(tenant.get(), namespace, key);
653 * Gets as float values.
655 * @param tenantId the tenant id
656 * @param namespace the namespace
658 * @return the as float values
660 public default List<Float> getAsFloatValues(String tenantId, String namespace, String key) {
661 Float[] tempArray = get(tenantId, namespace, key, Float[].class);
662 return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray);
666 * Gets as boolean values.
669 * @return the as boolean values
671 public default List<Boolean> getAsBooleanValues(String key) {
672 return getAsBooleanValues(null, key);
676 * Gets as boolean values.
678 * @param namespace the namespace
680 * @return the as boolean values
682 public default List<Boolean> getAsBooleanValues(String namespace, String key) {
683 return getAsBooleanValues(tenant.get(), namespace, key);
687 * Gets as boolean values.
689 * @param tenantId the tenant id
690 * @param namespace the namespace
692 * @return the as boolean values
694 public default List<Boolean> getAsBooleanValues(String tenantId, String namespace, String key) {
695 Boolean[] tempArray = get(tenantId, namespace, key, Boolean[].class);
696 return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray);
700 * Gets as character values.
703 * @return the as character values
705 public default List<Character> getAsCharacterValues(String key) {
706 return getAsCharacterValues(null, key);
710 * Gets as character values.
712 * @param namespace the namespace
714 * @return the as character values
716 public default List<Character> getAsCharacterValues(String namespace, String key) {
717 return getAsCharacterValues(tenant.get(), namespace, key);
721 * Gets as character values.
723 * @param tenantId the tenant id
724 * @param namespace the namespace
726 * @return the as character values
728 public default List<Character> getAsCharacterValues(String tenantId, String namespace,
730 Character[] tempArray = get(tenantId, namespace, key, Character[].class);
731 return tempArray == null ? Arrays.asList() : Arrays.asList(tempArray);
737 * @param <T> the type parameter
738 * @param tenant the tenant
739 * @param namespace the namespace
741 * @param clazz the clazz
742 * @param hints the hints
745 public <T> T get(String tenant, String namespace, String key, Class<T> clazz, Hint... hints);
748 * Add configuration change listener.
751 * @param myself the myself
753 public default void addConfigurationChangeListener(String key,
754 ConfigurationChangeListener myself) {
755 addConfigurationChangeListener(null, key, myself);
759 * Add configuration change listener.
761 * @param namespace the namespace
763 * @param myself the myself
765 public default void addConfigurationChangeListener(String namespace, String key,
766 ConfigurationChangeListener myself) {
767 addConfigurationChangeListener(tenant.get(), namespace, key, myself);
771 * Add configuration change listener.
773 * @param tenant the tenant
774 * @param namespace the namespace
776 * @param myself the myself
778 public void addConfigurationChangeListener(String tenant, String namespace, String key,
779 ConfigurationChangeListener myself);
782 * Remove configuration change listener.
785 * @param myself the myself
787 public default void removeConfigurationChangeListener(String key,
788 ConfigurationChangeListener myself) {
789 removeConfigurationChangeListener(null, key, myself);
793 * Remove configuration change listener.
795 * @param namespace the namespace
797 * @param myself the myself
799 public default void removeConfigurationChangeListener(String namespace, String key,
800 ConfigurationChangeListener myself) {
801 removeConfigurationChangeListener(tenant.get(), namespace, key, myself);
805 * Remove configuration change listener.
807 * @param tenant the tenant
808 * @param namespace the namespace
810 * @param myself the myself
812 public void removeConfigurationChangeListener(String tenant, String namespace, String key,
813 ConfigurationChangeListener myself);
815 public default <T> Map<String, T> populateMap(String key, Class<T> clazz){
816 return populateMap(null, key, clazz);
818 public default <T> Map<String, T> populateMap(String namespace, String key, Class<T> clazz){
819 return populateMap(tenant.get(), namespace, key, clazz);
821 public <T> Map<String, T> populateMap(String tenantId, String namespace, String key, Class<T> clazz);
823 public default Map generateMap(String key){
824 return generateMap(null, key);
826 public default Map generateMap(String namespace, String key){
827 return generateMap(tenant.get(), namespace, key);
829 public Map generateMap(String tenantId, String namespace, String key);