|
1 | 1 | package io.split.client; |
2 | 2 |
|
3 | | -import com.google.common.collect.ConcurrentHashMultiset; |
4 | | -import com.google.common.collect.Multiset; |
5 | 3 | import io.split.client.impressions.AsynchronousImpressionListener; |
6 | 4 | import io.split.client.impressions.ImpressionListener; |
7 | 5 | import io.split.client.impressions.ImpressionsManagerImpl; |
@@ -62,31 +60,19 @@ public class SplitFactoryImpl implements SplitFactory { |
62 | 60 | private final static long SSE_CONNECT_TIMEOUT = 30000; |
63 | 61 | private final static long SSE_SOCKET_TIMEOUT = 70000; |
64 | 62 |
|
65 | | - private static final Multiset<String> USED_API_TOKENS = ConcurrentHashMultiset.create(); |
66 | 63 | private static Random RANDOM = new Random(); |
67 | 64 |
|
68 | 65 | private final SplitClient _client; |
69 | 66 | private final SplitManager _manager; |
70 | 67 | private final Runnable destroyer; |
71 | 68 | private final String _apiToken; |
72 | 69 | private boolean isTerminated = false; |
| 70 | + private final ApiKeyCounter _apiKeyCounter; |
73 | 71 |
|
74 | 72 | public SplitFactoryImpl(String apiToken, SplitClientConfig config) throws URISyntaxException { |
75 | 73 | _apiToken = apiToken; |
76 | | - |
77 | | - if (USED_API_TOKENS.contains(apiToken)) { |
78 | | - String message = String.format("factory instantiation: You already have %s with this API Key. " + |
79 | | - "We recommend keeping only one instance of the factory at all times (Singleton pattern) and reusing " + |
80 | | - "it throughout your application.", |
81 | | - USED_API_TOKENS.count(apiToken) == 1 ? "1 factory" : String.format("%s factories", USED_API_TOKENS.count(apiToken))); |
82 | | - _log.warn(message); |
83 | | - } else if (!USED_API_TOKENS.isEmpty()) { |
84 | | - String message = "factory instantiation: You already have an instance of the Split factory. " + |
85 | | - "Make sure you definitely want this additional instance. We recommend keeping only one instance of " + |
86 | | - "the factory at all times (Singleton pattern) and reusing it throughout your application.“"; |
87 | | - _log.warn(message); |
88 | | - } |
89 | | - USED_API_TOKENS.add(apiToken); |
| 74 | + _apiKeyCounter = ApiKeyCounter.getApiKeyCounterInstance(); |
| 75 | + _apiKeyCounter.add(apiToken); |
90 | 76 |
|
91 | 77 | if (config.blockUntilReady() == -1) { |
92 | 78 | //BlockUntilReady not been set |
@@ -214,7 +200,7 @@ public void destroy() { |
214 | 200 | synchronized (SplitFactoryImpl.class) { |
215 | 201 | if (!isTerminated) { |
216 | 202 | destroyer.run(); |
217 | | - USED_API_TOKENS.remove(_apiToken); |
| 203 | + _apiKeyCounter.remove(_apiToken); |
218 | 204 | isTerminated = true; |
219 | 205 | } |
220 | 206 | } |
|
0 commit comments