-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP jvm example SSE * jvm example: add SSE error branches to enum checks * add greeting to SSE example * update version in examples * cleanup * bump growthbook version in the android project
- Loading branch information
1 parent
4dfceae
commit 735ca66
Showing
12 changed files
with
117 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
.../src/main/kotlin/com/growthbook/example/plugins/growthbook/AcmeDonutFeaturesRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package com.growthbook.example.plugins.growthbook | ||
|
||
import growthbook.sdk.java.FeatureRefreshStrategy | ||
import growthbook.sdk.java.GBFeaturesRepository | ||
|
||
class AcmeDonutFeaturesRepository( | ||
endpoint: String, | ||
apiHost: String, | ||
clientKey: String, | ||
encryptionKey: String? = null, | ||
ttlSeconds: Int | ||
) : GBFeaturesRepository(endpoint, encryptionKey, ttlSeconds) | ||
) : GBFeaturesRepository(apiHost, clientKey, encryptionKey, FeatureRefreshStrategy.STALE_WHILE_REVALIDATE, ttlSeconds) |
8 changes: 5 additions & 3 deletions
8
...main/kotlin/com/growthbook/example/plugins/growthbook/BasicEncryptedFeaturesRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package com.growthbook.example.plugins.growthbook | ||
|
||
import growthbook.sdk.java.FeatureRefreshStrategy | ||
import growthbook.sdk.java.GBFeaturesRepository | ||
|
||
class BasicEncryptedFeaturesRepository( | ||
endpoint: String, | ||
encryptionKey: String, | ||
apiHost: String, | ||
clientKey: String, | ||
encryptionKey: String? = null, | ||
ttlSeconds: Int | ||
) : GBFeaturesRepository(endpoint, encryptionKey, ttlSeconds) | ||
) : GBFeaturesRepository(apiHost, clientKey, encryptionKey, FeatureRefreshStrategy.STALE_WHILE_REVALIDATE, ttlSeconds) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
jvm-spring-web/src/main/java/com/example/demo/services/RealTimeSSEFeaturesService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.example.demo.services; | ||
|
||
import growthbook.sdk.java.FeatureFetchException; | ||
import growthbook.sdk.java.FeatureRefreshCallback; | ||
import growthbook.sdk.java.FeatureRefreshStrategy; | ||
import growthbook.sdk.java.GBFeaturesRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class RealTimeSSEFeaturesService extends GBFeaturesRepository { | ||
@Autowired | ||
public RealTimeSSEFeaturesService() { | ||
super( | ||
"https://cdn.growthbook.io", | ||
"sdk-pGmC6LrsiUoEUcpZ", | ||
null, | ||
FeatureRefreshStrategy.SERVER_SENT_EVENTS, | ||
null | ||
); | ||
|
||
this.onFeaturesRefresh(new FeatureRefreshCallback() { | ||
@Override | ||
public void onRefresh(String featuresJson) { | ||
System.out.println("🔵 RealTimeSSEFeaturesService -> Features have been refreshed"); | ||
System.out.println(featuresJson); | ||
} | ||
}); | ||
|
||
try { | ||
this.initialize(); | ||
} catch (FeatureFetchException e) { | ||
this.handleError(e); | ||
} | ||
} | ||
|
||
void handleError(FeatureFetchException e) { | ||
e.printStackTrace(); | ||
|
||
switch (e.getErrorCode()) { | ||
case NO_RESPONSE_ERROR -> { | ||
// Handle NO_RESPONSE_ERROR | ||
} | ||
|
||
case SSE_CONNECTION_ERROR -> { | ||
// Handle SSE_CONNECTION_ERROR | ||
} | ||
|
||
case CONFIGURATION_ERROR, UNKNOWN -> { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
} |