Skip to content

Commit 406f9e3

Browse files
authored
updates for SDK 5.0 API + simplify build (#8)
1 parent 56a9462 commit 406f9e3

File tree

19 files changed

+327
-470
lines changed

19 files changed

+327
-470
lines changed

.circleci/config.yml

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
version: 2
1+
version: 2.1
2+
3+
orbs:
4+
win: circleci/[email protected]
25

36
workflows:
47
version: 2
58
test:
69
jobs:
7-
- build
10+
- build-test-linux
11+
- build-test-windows
812

913
jobs:
10-
build:
14+
build-test-linux:
1115
docker:
1216
- image: circleci/java
1317
- image: amazon/dynamodb-local
@@ -25,3 +29,43 @@ jobs:
2529
path: ~/junit
2630
- store_artifacts:
2731
path: ~/junit
32+
33+
build-test-windows:
34+
executor:
35+
name: win/vs2019
36+
shell: powershell.exe
37+
steps:
38+
- checkout
39+
- run:
40+
name: install OpenJDK
41+
command: |
42+
$ProgressPreference = "SilentlyContinue" # prevents console errors from CircleCI host
43+
iwr -outf openjdk.msi https://developers.redhat.com/download-manager/file/java-11-openjdk-11.0.5.10-2.windows.redhat.x86_64.msi
44+
Start-Process msiexec.exe -Wait -ArgumentList '/I openjdk.msi /quiet'
45+
- run:
46+
name: set up DynamoDB
47+
command: |
48+
$ProgressPreference = "SilentlyContinue"
49+
iwr -outf dynamo.zip https://s3-us-west-2.amazonaws.com/dynamodb-local/dynamodb_local_latest.zip
50+
mkdir dynamo
51+
Expand-Archive -Path dynamo.zip -DestinationPath dynamo
52+
- run:
53+
name: run DynamoDB
54+
command: |
55+
cd dynamo
56+
javaw -D"java.library.path=./DynamoDBLocal_lib" -jar DynamoDBLocal.jar
57+
background: true
58+
- run:
59+
name: build and test
60+
command: |
61+
cp gradle.properties.example gradle.properties
62+
.\gradlew.bat --no-daemon test # must use --no-daemon because CircleCI in Windows will hang if there's a daemon running
63+
- run:
64+
name: save test results
65+
command: |
66+
mkdir .\junit
67+
cp build/test-results/test/*.xml junit
68+
- store_test_results:
69+
path: .\junit
70+
- store_artifacts:
71+
path: .\junit

CONTRIBUTING.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,44 @@
1-
Contributing to this library
2-
============================
1+
# Contributing to this library
32

43
The source code for this library is [here](https://github.com/launchdarkly/java-client-dynamodb). We encourage pull-requests and other contributions from the community. Since this library is meant to be used in conjunction with the LaunchDarkly Java SDK, you may want to look at the [Java SDK source code](https://github.com/launchdarkly/java-client) and our [SDK contributor's guide](http://docs.launchdarkly.com/docs/sdk-contributors-guide).
4+
5+
## Submitting bug reports and feature requests
6+
7+
The LaunchDarkly SDK team monitors the [issue tracker](https://github.com/launchdarkly/java-server-sdk-dynamodb/issues) in this repository. Bug reports and feature requests specific to this project should be filed in the issue tracker. The SDK team will respond to all newly filed issues within two business days.
8+
9+
## Submitting pull requests
10+
11+
We encourage pull requests and other contributions from the community. Before submitting pull requests, ensure that all temporary or unintended code is removed. Don't worry about adding reviewers to the pull request; the LaunchDarkly SDK team will add themselves. The SDK team will acknowledge all pull requests within two business days.
12+
13+
## Build instructions
14+
15+
### Prerequisites
16+
17+
The library builds with [Gradle](https://gradle.org/) and should be built against Java 8.
18+
19+
### Building
20+
21+
To build the library without running any tests:
22+
```
23+
./gradlew jar
24+
```
25+
26+
If you wish to clean your working directory between builds, you can clean it by running:
27+
```
28+
./gradlew clean
29+
```
30+
31+
If you wish to use an interim build in another Maven/Gradle project such as [hello-java](https://github.com/launchdarkly/hello-java), you will likely want to publish the artifact to your local Maven repository so that your other project can access it.
32+
```
33+
./gradlew publishToMavenLocal
34+
```
35+
36+
### Testing
37+
38+
To build the library and run all unit tests:
39+
```
40+
./gradlew test
41+
```
42+
43+
The tests expect you to have DynamoDB running locally. The simplest way to do that is with Docker: `docker run -p 8000:8000 amazon/dynamodb-local`
44+

README.md

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
This library provides a DynamoDB-backed persistence mechanism (data store) for the [LaunchDarkly Java SDK](https://github.com/launchdarkly/java-server-sdk), replacing the default in-memory data store.
77

8-
This version of the library is for use with LaunchDarkly Java SDK versions greater than or equal to 4.12.0 and less than 5.0; for Java SDK 5.0 and above, the minimum version of this library is 3.0. It requires at least version 2.1 of the AWS SDK for Java. The minimum Java version is 8 (because that is the minimum Java version of the AWS SDK 2.x). If you need to use Java 7, or if you are already using AWS SDK 1.x for some other purpose, you can use the 1.x releases of this library (which are developed on the "aws-v1" branch of the repository).
8+
This version of the library requires at least version 5.0.0 of the LaunchDarkly Java SDK, and at least version 2.1 of the AWS SDK for Java. The minimum Java version is 8. For Java SDK 4.x, use the latest 2.x version of this library.
9+
10+
If you need to use Java 7, or if you are already using AWS SDK 1.x for some other purpose, you can use the 1.x releases of this library (which are developed on the "aws-v1" branch of the repository).
911

1012
See the [API documentation](https://launchdarkly.github.io/java-server-sdk-dynamodb) for details on classes and methods.
1113

@@ -17,12 +19,12 @@ This assumes that you have already installed the LaunchDarkly Java SDK.
1719

1820
1. In DynamoDB, create a table which has the following schema: a partition key called "namespace" and a sort key called "key", both with a string type. The LaunchDarkly library does not create the table automatically, because it has no way of knowing what additional properties (such as permissions and throughput) you would want it to have.
1921

20-
2. Add this library to your project:
22+
2. Add this library to your project (updating the version number to use the [latest release](https://github.com/launchdarkly/java-server-sdk-dynamodb/releases)):
2123

2224
<dependency>
2325
<groupId>com.launchdarkly</groupId>
2426
<artifactId>launchdarkly-java-server-sdk-dynamodb-store</artifactId>
25-
<version>2.1.0</version>
27+
<version>3.0.0</version>
2628
</dependency>
2729

2830
3. If you do not already have the AWS SDK in your project, add the DynamoDB part of it. (This needs to be added separately, rather than being included in the LaunchDarkly jar, because AWS classes are exposed in the public interface.)
@@ -35,44 +37,37 @@ This assumes that you have already installed the LaunchDarkly Java SDK.
3537

3638
4. Import the LaunchDarkly package and the package for this library:
3739

38-
import com.launchdarkly.client.*;
39-
import com.launchdarkly.client.integrations.*;
40+
import com.launchdarkly.sdk.server.*;
41+
import com.launchdarkly.sdk.server.integrations.*;
4042

4143
5. When configuring your SDK client, add the DynamoDB feature store:
4244

43-
DynamoDbDataStoreBuilder dynamoDbStore = DynamoDb.dataStore("my-table-name");
44-
4545
LDConfig config = new LDConfig.Builder()
46-
.dataStore(Components.persistentDataStore(dynamoDbStore))
46+
.dataStore(
47+
Components.persistentDataStore(
48+
DynamoDb.dataStore("my-table-name")
49+
)
50+
)
4751
.build();
48-
49-
LDClient client = new LDClient("YOUR SDK KEY", config);
5052

5153
By default, the DynamoDB client will try to get your AWS credentials and region name from environment variables and/or local configuration files, as described in the AWS SDK documentation. There are methods in `DynamoDbDataStoreBuilder` for changing the configuration options. Alternatively, if you already have a fully configured DynamoDB client object, you can tell LaunchDarkly to use that:
5254

53-
DynamoDbDataStoreBuilder dynamoDbStore = DynamoDb.dataStore("my-table-name")
54-
.existingClient(myDynamoDbClientInstance);
55+
Components.persistentDataStore(
56+
DynamoDb.dataStore("my-table-name").existingClient(myDynamoDbClientInstance)
57+
)
5558

5659
## Caching behavior
5760

58-
To reduce traffic to DynamoDB, there is an optional in-memory cache that retains the last known data for a configurable amount of time. This is on by default; to turn it off (and guarantee that the latest feature flag data will always be retrieved from DynamoDB for every flag evaluation), configure the store as follows:
59-
60-
By default, for any persistent data store, the Java SDK uses an in-memory cache to reduce traffic to the database; this retains the last known data for a configurable amount of time. To change the caching behavior or disable caching, use the `PersistentDataStoreBuilder` methods:
61-
62-
LDConfig configWithLongerCacheTtl = new LDConfig.Builder()
63-
.dataStore(
64-
Components.persistentDataStore(dynamoDbStore).cacheSeconds(60)
65-
)
66-
.build();
61+
The LaunchDarkly SDK has a standard caching mechanism for any persistent data store, to reduce database traffic. This is configured through the SDK's `PersistentDataStoreBuilder` class as described the SDK documentation. For instance, to specify a cache TTL of 5 minutes:
6762

68-
LDConfig configWithNoCaching = new LDConfig.Builder()
63+
LDConfig config = new LDConfig.Builder()
6964
.dataStore(
70-
Components.persistentDataStore(dynamoDbStore).noCaching()
65+
Components.persistentDataStore(
66+
DynamoDb.dataStore("my-table-name")
67+
).cacheTime(Duration.ofMinutes(5))
7168
)
7269
.build();
7370

74-
For other ways to control the behavior of the cache, see `PersistentDataStoreBuilder` in the Java SDK.
75-
7671
## About LaunchDarkly
7772

7873
* LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:

0 commit comments

Comments
 (0)