Skip to content

Commit fe75a85

Browse files
update: refactor build to use cmabClient instead of default service
1 parent 47c65b5 commit fe75a85

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

core-api/src/main/java/com/optimizely/ab/Optimizely.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
import com.optimizely.ab.bucketing.DecisionService;
2121
import com.optimizely.ab.bucketing.FeatureDecision;
2222
import com.optimizely.ab.bucketing.UserProfileService;
23+
import com.optimizely.ab.cmab.service.CmabCacheValue;
2324
import com.optimizely.ab.cmab.service.CmabService;
25+
import com.optimizely.ab.cmab.service.CmabServiceOptions;
26+
import com.optimizely.ab.cmab.service.DefaultCmabService;
2427
import com.optimizely.ab.config.AtomicProjectConfigManager;
2528
import com.optimizely.ab.config.DatafileProjectConfig;
2629
import com.optimizely.ab.config.EventType;
@@ -46,6 +49,7 @@
4649
import com.optimizely.ab.event.internal.UserEvent;
4750
import com.optimizely.ab.event.internal.UserEventFactory;
4851
import com.optimizely.ab.event.internal.payload.EventBatch;
52+
import com.optimizely.ab.internal.DefaultLRUCache;
4953
import com.optimizely.ab.internal.NotificationRegistry;
5054
import com.optimizely.ab.notification.ActivateNotification;
5155
import com.optimizely.ab.notification.DecisionNotification;
@@ -70,12 +74,14 @@
7074
import com.optimizely.ab.optimizelydecision.OptimizelyDecideOption;
7175
import com.optimizely.ab.optimizelydecision.OptimizelyDecision;
7276
import com.optimizely.ab.optimizelyjson.OptimizelyJSON;
77+
7378
import org.slf4j.Logger;
7479
import org.slf4j.LoggerFactory;
7580

7681
import javax.annotation.Nonnull;
7782
import javax.annotation.Nullable;
7883
import javax.annotation.concurrent.ThreadSafe;
84+
7985
import java.io.Closeable;
8086
import java.util.ArrayList;
8187
import java.util.Arrays;
@@ -85,6 +91,7 @@
8591
import java.util.Map;
8692
import java.util.concurrent.locks.ReentrantLock;
8793

94+
import com.optimizely.ab.cmab.client.CmabClient;
8895
import static com.optimizely.ab.internal.SafetyUtils.tryClose;
8996

9097
/**
@@ -1998,8 +2005,13 @@ public Builder withODPManager(ODPManager odpManager) {
19982005
return this;
19992006
}
20002007

2001-
public Builder withCmabService(CmabService cmabService) {
2002-
this.cmabService = cmabService;
2008+
public Builder withCmabClient(CmabClient cmabClient) {
2009+
int DEFAULT_MAX_SIZE = 1000;
2010+
int DEFAULT_CMAB_CACHE_TIMEOUT = 30 * 60 * 1000;
2011+
DefaultLRUCache<CmabCacheValue> cmabCache = new DefaultLRUCache<>(DEFAULT_MAX_SIZE, DEFAULT_CMAB_CACHE_TIMEOUT);
2012+
CmabServiceOptions cmabServiceOptions = new CmabServiceOptions(logger, cmabCache, cmabClient);
2013+
DefaultCmabService defaultCmabService = new DefaultCmabService(cmabServiceOptions);
2014+
this.cmabService = defaultCmabService;
20032015
return this;
20042016
}
20052017

@@ -2033,6 +2045,10 @@ public Optimizely build() {
20332045
bucketer = new Bucketer();
20342046
}
20352047

2048+
if (cmabService == null) {
2049+
logger.warn("CMAB service is not initiated. CMAB functionality will not be available.");
2050+
}
2051+
20362052
if (decisionService == null) {
20372053
decisionService = new DecisionService(bucketer, errorHandler, userProfileService, cmabService);
20382054
}

core-httpclient-impl/src/main/java/com/optimizely/ab/OptimizelyFactory.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,12 @@
2424

2525
import com.optimizely.ab.cmab.DefaultCmabClient;
2626
import com.optimizely.ab.cmab.client.CmabClientConfig;
27-
import com.optimizely.ab.cmab.service.CmabCacheValue;
28-
import com.optimizely.ab.cmab.service.CmabServiceOptions;
29-
import com.optimizely.ab.cmab.service.DefaultCmabService;
3027
import com.optimizely.ab.config.HttpProjectConfigManager;
3128
import com.optimizely.ab.config.ProjectConfig;
3229
import com.optimizely.ab.config.ProjectConfigManager;
3330
import com.optimizely.ab.event.AsyncEventHandler;
3431
import com.optimizely.ab.event.BatchEventProcessor;
3532
import com.optimizely.ab.event.EventHandler;
36-
import com.optimizely.ab.internal.DefaultLRUCache;
3733
import com.optimizely.ab.internal.PropertyUtils;
3834
import com.optimizely.ab.notification.NotificationCenter;
3935
import com.optimizely.ab.odp.DefaultODPApiManager;
@@ -377,18 +373,13 @@ public static Optimizely newDefaultInstance(ProjectConfigManager configManager,
377373
.build();
378374

379375
DefaultCmabClient defaultCmabClient = new DefaultCmabClient(CmabClientConfig.withDefaultRetry());
380-
int DEFAULT_MAX_SIZE = 1000;
381-
int DEFAULT_CMAB_CACHE_TIMEOUT = 30 * 60 * 1000;
382-
DefaultLRUCache<CmabCacheValue> cmabCache = new DefaultLRUCache<>(DEFAULT_MAX_SIZE, DEFAULT_CMAB_CACHE_TIMEOUT);
383-
CmabServiceOptions cmabServiceOptions = new CmabServiceOptions(logger, cmabCache, defaultCmabClient);
384-
DefaultCmabService cmabService = new DefaultCmabService(cmabServiceOptions);
385376

386377
return Optimizely.builder()
387378
.withEventProcessor(eventProcessor)
388379
.withConfigManager(configManager)
389380
.withNotificationCenter(notificationCenter)
390381
.withODPManager(odpManager)
391-
.withCmabService(cmabService)
382+
.withCmabClient(defaultCmabClient)
392383
.build();
393384
}
394385
}

0 commit comments

Comments
 (0)