8000 Fix: Added notificationRegistry to make sure that odpSettings updates by mnoman09 · Pull Request #501 · optimizely/java-sdk · GitHub
[go: up one dir, main page]

Skip to content

Fix: Added notificationRegistry to make sure that odpSettings updates #501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added getCachedconfig Function to return ProjectConfig without wait, …
…but the default implementation of it will return null.
  • Loading branch information
NomanShoaib committed Jan 18, 2023
commit 38d735a865abfae89ceac3fd5baf25756dea0858
8 changes: 4 additions & 4 deletions core-api/src/main/java/com/optimizely/ab/Optimizely.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ private Optimizely(@Nonnull EventHandler eventHandler,

if (odpManager != null) {
odpManager.getEventManager().start();
if (!(projectConfigManager instanceof PollingProjectConfigManager)) {
if (projectConfigManager.getCachedConfig() != null) {
updateODPSettings();
}
if (projectConfigManager != null && projectConfigManager.getSDKKey() != null) {
if (projectConfigManager.getSDKKey() != null) {
NotificationRegistry.getInternalNotificationCenter(projectConfigManager.getSDKKey()).
addNotificationHandler(UpdateConfigNotification.class,
configNotification -> { updateODPSettings(); });
Expand Down Expand Up @@ -1485,8 +1485,8 @@ public void identifyUser(@Nonnull String userId) {
}

private void updateODPSettings() {
if (odpManager != null && getProjectConfig() != null) {
ProjectConfig projectConfig = getProjectConfig();
ProjectConfig projectConfig = projectConfigManager.getCachedConfig();
if (odpManager != null && projectConfig != null) {
odpManager.updateSettings(projectConfig.getHostForODP(), projectConfig.getPublicKeyForODP(), projectConfig.getAllSegments());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2019, Optimizely and contributors
* Copyright 2019, 2023, Optimizely and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -27,6 +27,16 @@ public ProjectConfig getConfig() {
return projectConfigReference.get();
}

/**
* Access to current cached project configuration.
*
* @return {@link ProjectConfig}
*/
@Override
public ProjectConfig getCachedConfig() {
return projectConfigReference.get();
}

public void setConfig(ProjectConfig projectConfig) {
projectConfigReference.set(projectConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ public PollingProjectConfigManager(long period, TimeUnit timeUnit, long blocking

protected abstract ProjectConfig poll();

/**
* Access to current cached project configuration, This is to make sure that config returns without any wait, even if it is null.
*
* @return {@link ProjectConfig}
*/
@Override
public ProjectConfig getCachedConfig() {
return currentProjectConfig.get();
}

/**
* Only allow the ProjectConfig to be set to a non-null value, if and only if the value has not already been set.
* @param projectConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ public interface ProjectConfigManager {
*/
ProjectConfig getConfig();

/**
* Implementations of this method should not block until a datafile is available, instead return current cached project configuration.
*
* NOTE: To use ODP segments, implementation of this function is required to return current project configuration.
* @return ProjectConfig
*/
default ProjectConfig getCachedConfig() { return null; }

default String getSDKKey() {
return null;
}
Expand Down
0