|
20 | 20 | import com.optimizely.ab.bucketing.DecisionService; |
21 | 21 | import com.optimizely.ab.bucketing.FeatureDecision; |
22 | 22 | import com.optimizely.ab.bucketing.UserProfileService; |
| 23 | +import com.optimizely.ab.cmab.service.CmabCacheValue; |
23 | 24 | import com.optimizely.ab.cmab.service.CmabService; |
| 25 | +import com.optimizely.ab.cmab.service.CmabServiceOptions; |
| 26 | +import com.optimizely.ab.cmab.service.DefaultCmabService; |
24 | 27 | import com.optimizely.ab.config.AtomicProjectConfigManager; |
25 | 28 | import com.optimizely.ab.config.DatafileProjectConfig; |
26 | 29 | import com.optimizely.ab.config.EventType; |
|
46 | 49 | import com.optimizely.ab.event.internal.UserEvent; |
47 | 50 | import com.optimizely.ab.event.internal.UserEventFactory; |
48 | 51 | import com.optimizely.ab.event.internal.payload.EventBatch; |
| 52 | +import com.optimizely.ab.internal.DefaultLRUCache; |
49 | 53 | import com.optimizely.ab.internal.NotificationRegistry; |
50 | 54 | import com.optimizely.ab.notification.ActivateNotification; |
51 | 55 | import com.optimizely.ab.notification.DecisionNotification; |
|
70 | 74 | import com.optimizely.ab.optimizelydecision.OptimizelyDecideOption; |
71 | 75 | import com.optimizely.ab.optimizelydecision.OptimizelyDecision; |
72 | 76 | import com.optimizely.ab.optimizelyjson.OptimizelyJSON; |
| 77 | + |
73 | 78 | import org.slf4j.Logger; |
74 | 79 | import org.slf4j.LoggerFactory; |
75 | 80 |
|
76 | 81 | import javax.annotation.Nonnull; |
77 | 82 | import javax.annotation.Nullable; |
78 | 83 | import javax.annotation.concurrent.ThreadSafe; |
| 84 | + |
79 | 85 | import java.io.Closeable; |
80 | 86 | import java.util.ArrayList; |
81 | 87 | import java.util.Arrays; |
|
85 | 91 | import java.util.Map; |
86 | 92 | import java.util.concurrent.locks.ReentrantLock; |
87 | 93 |
|
| 94 | +import com.optimizely.ab.cmab.client.CmabClient; |
88 | 95 | import static com.optimizely.ab.internal.SafetyUtils.tryClose; |
89 | 96 |
|
90 | 97 | /** |
@@ -1998,8 +2005,13 @@ public Builder withODPManager(ODPManager odpManager) { |
1998 | 2005 | return this; |
1999 | 2006 | } |
2000 | 2007 |
|
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; |
2003 | 2015 | return this; |
2004 | 2016 | } |
2005 | 2017 |
|
@@ -2033,6 +2045,10 @@ public Optimizely build() { |
2033 | 2045 | bucketer = new Bucketer(); |
2034 | 2046 | } |
2035 | 2047 |
|
| 2048 | + if (cmabService == null) { |
| 2049 | + logger.warn("CMAB service is not initiated. CMAB functionality will not be available."); |
| 2050 | + } |
| 2051 | + |
2036 | 2052 | if (decisionService == null) { |
2037 | 2053 | decisionService = new DecisionService(bucketer, errorHandler, userProfileService, cmabService); |
2038 | 2054 | } |
|
0 commit comments