|
16 | 16 | */ |
17 | 17 | package com.optimizely.ab; |
18 | 18 |
|
| 19 | +import java.util.concurrent.TimeUnit; |
| 20 | + |
| 21 | +import org.apache.http.impl.client.CloseableHttpClient; |
| 22 | +import org.slf4j.Logger; |
| 23 | +import org.slf4j.LoggerFactory; |
| 24 | + |
| 25 | +import com.optimizely.ab.cmab.DefaultCmabClient; |
| 26 | +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; |
19 | 30 | import com.optimizely.ab.config.HttpProjectConfigManager; |
20 | 31 | import com.optimizely.ab.config.ProjectConfig; |
21 | 32 | import com.optimizely.ab.config.ProjectConfigManager; |
22 | 33 | import com.optimizely.ab.event.AsyncEventHandler; |
23 | 34 | import com.optimizely.ab.event.BatchEventProcessor; |
24 | 35 | import com.optimizely.ab.event.EventHandler; |
| 36 | +import com.optimizely.ab.internal.DefaultLRUCache; |
25 | 37 | import com.optimizely.ab.internal.PropertyUtils; |
26 | 38 | import com.optimizely.ab.notification.NotificationCenter; |
27 | 39 | import com.optimizely.ab.odp.DefaultODPApiManager; |
28 | 40 | import com.optimizely.ab.odp.ODPApiManager; |
29 | 41 | import com.optimizely.ab.odp.ODPManager; |
30 | | -import org.apache.http.impl.client.CloseableHttpClient; |
31 | | -import org.slf4j.Logger; |
32 | | -import org.slf4j.LoggerFactory; |
33 | | - |
34 | | -import java.util.concurrent.TimeUnit; |
35 | 42 |
|
36 | 43 | /** |
37 | 44 | * OptimizelyFactory is a utility class to instantiate an {@link Optimizely} client with a minimal |
@@ -369,11 +376,19 @@ public static Optimizely newDefaultInstance(ProjectConfigManager configManager, |
369 | 376 | .withApiManager(odpApiManager != null ? odpApiManager : new DefaultODPApiManager()) |
370 | 377 | .build(); |
371 | 378 |
|
| 379 | + 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); |
| 385 | + |
372 | 386 | return Optimizely.builder() |
373 | 387 | .withEventProcessor(eventProcessor) |
374 | 388 | .withConfigManager(configManager) |
375 | 389 | .withNotificationCenter(notificationCenter) |
376 | 390 | .withODPManager(odpManager) |
| 391 | + .withCmabService(cmabService) |
377 | 392 | .build(); |
378 | 393 | } |
379 | 394 | } |
0 commit comments