Skip to content

Commit 422041e

Browse files
committed
Taking existing content and adding it verbatim into the appropriate files.
1 parent 4e91e7b commit 422041e

22 files changed

+1918
-16
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ Planned structure is as follows:
1515
* [Configuration](configuration.md)
1616
* Identity & Authentication
1717
* [Overview](identity_overview.md)
18-
* [Environment Setup](identity_setup.md)
1918
* [Examples](identity_examples.md)
2019
* [Tracing](tracing.md)
2120
* Troubleshooting

asynchronous_programming.md

+311-1
Large diffs are not rendered by default.

configuration.md

+103-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,105 @@
11
# Configuration
22

3-
> https://github.com/Azure/azure-sdk-for-java/wiki/Configuration
3+
Azure Core offers the `Configuration` class as a standard way to load, store, and share environment and runtime application configuration.
4+
5+
## Using Configuration
6+
7+
`Configuration` has APIs to get, check existence, put, and remove key-value properties.
8+
9+
### Get
10+
11+
`Configuration` offers multiple get APIs which offer different levels of convenience but all use the same root logic. Initially the configuration which check to see if it already contains the value in its in-memory cache, if it doesn't it will then attempt to load it from the environment checking Java properties (`System.getProperty`) and the environment (`System.getenv`), in that order, accepting the first non-null value loaded. The default get will return the value as a String with get or default and get and transform convenience APIs also being available.
12+
13+
**_Examples_**
14+
15+
__Load HTTP proxy__
16+
17+
```java
18+
String proxy = configuration.load("HTTP_PROXY");
19+
```
20+
21+
__Load HTTP proxy with default value__
22+
23+
```java
24+
String proxy = configuration.load("HTTP_PROXY", "localhost:8888");
25+
```
26+
27+
__Load HTTP proxy and transform to URL__
28+
29+
```java
30+
URL proxy = configuration.load("HTTP_PROXY", endpoint -> {
31+
try {
32+
return new URL(endpoint);
33+
} catch (MalformedURLException ex) {
34+
return null;
35+
}
36+
});
37+
```
38+
39+
### Check existence
40+
41+
`Configuration` offers a single existence check API to determine if it contains a value for a given key. This provides the ability to check and put a key instead of it loading from the environment when get is used and the configuration doesn't contain the key.
42+
43+
**_Example_**
44+
45+
__Check for HTTP proxy then get or put__
46+
47+
```java
48+
String proxy;
49+
if (configuration.contains("HTTP_PROXY")) {
50+
proxy = configuration.get("HTTP_PROXY");
51+
} else {
52+
configuration.put("HTTP_PROXY", "<default proxy>");
53+
proxy = "<default proxy>";
54+
}
55+
```
56+
57+
### Put
58+
59+
`Configuration` offers a single put API to directly set a key-value property without doing an environment look-up. This provides the ability to insert runtime properties into the configuration without having to update the environment.
60+
61+
**_Example_**
62+
63+
__Put HTTP proxy__
64+
65+
```java
66+
configuration.put("HTTP_PROXY", "localhost:8888");
67+
```
68+
69+
### Remove
70+
71+
`Configuration` offers a single remove API to purge a key from its local cache. This provides the ability to have configuration load the key-value from the environment again if it is updated during runtime of the application. Additionally, it also provides the ability to remove specific configurations from a cloned configuration to modify the behavior of code that accepts configuration as a parameter.
72+
73+
**_Example_**
74+
75+
__Remove SERVER_ENDPOINT__
76+
77+
```java
78+
String purgedProxy = configuration.remove("HTTP_PROXY");
79+
```
80+
81+
## Configuration scoping
82+
83+
`Configuration` has the ability to be scope preventing application properties from leaking into other areas of an application.
84+
85+
### Global configuration
86+
87+
`Configuration` as a singleton global configuration accessible using `Configuration.getGlobalConfiguration()` that will be used as a default in most locations when a `Configuration` isn't supplied. Updating this will allow for the changes to be shared in all spots where the global configuration is used.
88+
89+
### Scoped configuration
90+
91+
Constructing a `Configuration` instance will create a scoped configuration that is used only in location where it is passed into APIs using configuration. This will allow for application configuration to be scoped while retaining its ability to be shared across multiple locations.
92+
93+
## No-op/Empty configuration
94+
95+
In some situation you may not want `Configuration` to attempt to load from the environment or affect execution of an application, for this reason a special `Configuration.NONE` is available. This special configuration no-ops all operations and will always return null when get is used. This will prevent APIs that accept configuration from using it to modify their behavior/execution.
96+
97+
**_Example_**
98+
99+
__Use the no-op/empty configuration when building an HttpClient__
100+
101+
```java
102+
HttpClient httpClient = new NettyAsyncHttpClientBuilder()
103+
.configuration(Configuration.NONE)
104+
.build();
105+
```

0 commit comments

Comments
 (0)