44using System . Threading ;
55using System . Threading . Tasks ;
66using LiquidProjections . Abstractions ;
7- using LiquidProjections . NEventStore . Logging ;
7+ using LiquidProjections . PollingEventStoreAdapter . Logging ;
88
99namespace LiquidProjections . PollingEventStore
1010{
@@ -16,7 +16,12 @@ namespace LiquidProjections.PollingEventStore
1616 /// If the implementation of <see cref="IPassiveEventStore"/> implements <see cref="IDisposable"/>, disposing
1717 /// the <see cref="PollingEventStoreAdapter"/> will also dispose the event store.
1818 /// </remarks>
19- public class PollingEventStoreAdapter : IDisposable
19+ #if LIQUIDPROJECTIONS_BUILD_TIME
20+ public
21+ #else
22+ internal
23+ #endif
24+ class PollingEventStoreAdapter : IDisposable
2025 {
2126 private readonly TimeSpan pollInterval ;
2227 private readonly int maxPageSize ;
@@ -138,7 +143,7 @@ private Page TryGetNextPageFromCache(long previousCheckpoint, string subscriptio
138143 }
139144 }
140145
141- #if DEBUG
146+ #if LIQUIDPROJECTIONS_DIAGNOSTICS
142147 LogProvider . GetLogger ( typeof ( PollingEventStoreAdapter ) ) . Debug ( ( ) =>
143148 $ "Subscription { subscriptionId } has found a page of size { resultPage . Count } " +
144149 $ "from checkpoint { resultPage . First ( ) . Checkpoint } " +
@@ -148,7 +153,7 @@ private Page TryGetNextPageFromCache(long previousCheckpoint, string subscriptio
148153 return new Page ( previousCheckpoint , resultPage ) ;
149154 }
150155
151- #if DEBUG
156+ #if LIQUIDPROJECTIONS_DIAGNOSTICS
152157 LogProvider . GetLogger ( typeof ( PollingEventStoreAdapter ) ) . Debug ( ( ) =>
153158 $ "Subscription { subscriptionId } has not found the next transaction in the cache.") ;
154159#endif
@@ -158,7 +163,7 @@ private Page TryGetNextPageFromCache(long previousCheckpoint, string subscriptio
158163
159164 private void StartPreloadingNextPage ( long previousCheckpoint , string subscriptionId )
160165 {
161- #if DEBUG
166+ #if LIQUIDPROJECTIONS_DIAGNOSTICS
162167 LogProvider . GetLogger ( typeof ( PollingEventStoreAdapter ) ) . Debug ( ( ) =>
163168 $ "Subscription { subscriptionId } has started preloading transactions " +
164169 $ "after checkpoint { previousCheckpoint } .") ;
@@ -174,7 +179,7 @@ private async Task<Page> LoadNextPageSequentially(long previousCheckpoint, strin
174179 {
175180 if ( isDisposed )
176181 {
177- #if DEBUG
182+ #if LIQUIDPROJECTIONS_DIAGNOSTICS
178183 LogProvider . GetLogger ( typeof ( PollingEventStoreAdapter ) ) . Debug ( ( ) =>
179184 $ "Page loading for subscription { subscriptionId } cancelled because the adapter is disposed.") ;
180185#endif
@@ -193,7 +198,7 @@ private async Task<Page> LoadNextPageSequentially(long previousCheckpoint, strin
193198 {
194199 TimeSpan delay = pollInterval - timeAfterPreviousRequest ;
195200
196- #if DEBUG
201+ #if LIQUIDPROJECTIONS_DIAGNOSTICS
197202 LogProvider . GetLogger ( typeof ( PollingEventStoreAdapter ) ) . Debug ( ( ) =>
198203 $ "Subscription { subscriptionId } is waiting " +
199204 $ "for { delay } before checking for new transactions.") ;
@@ -242,15 +247,15 @@ private Task<Page> TryLoadNextPageSequentiallyOrWaitForCurrentLoadingToFinish(lo
242247 {
243248 if ( isTaskOwner )
244249 {
245- #if DEBUG
250+ #if LIQUIDPROJECTIONS_DIAGNOSTICS
246251 LogProvider . GetLogger ( typeof ( PollingEventStoreAdapter ) )
247252 . Debug ( ( ) => $ "Subscription { subscriptionId } created a loader { loader . Id } " +
248253 $ "for a page after checkpoint { previousCheckpoint } .") ;
249254#endif
250255
251256 if ( isDisposed )
252257 {
253- #if DEBUG
258+ #if LIQUIDPROJECTIONS_DIAGNOSTICS
254259 LogProvider . GetLogger ( typeof ( PollingEventStoreAdapter ) )
255260 . Debug ( ( ) => $ "The loader { loader . Id } is cancelled because the adapter is disposed.") ;
256261#endif
@@ -267,7 +272,7 @@ private Task<Page> TryLoadNextPageSequentiallyOrWaitForCurrentLoadingToFinish(lo
267272 }
268273 else
269274 {
270- #if DEBUG
275+ #if LIQUIDPROJECTIONS_DIAGNOSTICS
271276 LogProvider . GetLogger ( typeof ( PollingEventStoreAdapter ) )
272277 . Debug ( ( ) => $ "Subscription { subscriptionId } is waiting for loader { loader . Id } .") ;
273278#endif
@@ -288,7 +293,7 @@ private async Task TryLoadNextPageAndMakeLoaderComplete(long previousCheckpoint,
288293 }
289294 finally
290295 {
291- #if DEBUG
296+ #if LIQUIDPROJECTIONS_DIAGNOSTICS
292297 LogProvider . GetLogger ( typeof ( PollingEventStoreAdapter ) ) . Debug ( ( ) =>
293298 $ "Loader for subscription { subscriptionId } is no longer the current one.") ;
294299#endif
@@ -297,7 +302,7 @@ private async Task TryLoadNextPageAndMakeLoaderComplete(long previousCheckpoint,
297302 }
298303 catch ( Exception exception )
299304 {
300- #if DEBUG
305+ #if LIQUIDPROJECTIONS_DIAGNOSTICS
301306 LogProvider . GetLogger ( typeof ( PollingEventStoreAdapter ) ) . DebugException (
302307 $ "Loader for subscription { subscriptionId } has failed.",
303308 exception ) ;
@@ -307,7 +312,7 @@ private async Task TryLoadNextPageAndMakeLoaderComplete(long previousCheckpoint,
307312 return ;
308313 }
309314
310- #if DEBUG
315+ #if LIQUIDPROJECTIONS_DIAGNOSTICS
311316 LogProvider . GetLogger ( typeof ( PollingEventStoreAdapter ) ) . Debug ( ( ) =>
312317 $ "Loader for subscription { subscriptionId } has completed.") ;
313318#endif
@@ -322,7 +327,7 @@ private async Task<Page> TryLoadNextPage(long previousCheckpoint, string subscri
322327 Page cachedPage = TryGetNextPageFromCache ( previousCheckpoint , subscriptionId ) ;
323328 if ( cachedPage . Transactions . Count > 0 )
324329 {
325- #if DEBUG
330+ #if LIQUIDPROJECTIONS_DIAGNOSTICS
326331 LogProvider . GetLogger ( typeof ( PollingEventStoreAdapter ) )
327332 . Debug ( ( ) =>
328333 $ "Loader for subscription { subscriptionId } has found a page in the cache.") ;
@@ -362,15 +367,15 @@ private async Task<Page> TryLoadNextPage(long previousCheckpoint, string subscri
362367
363368 if ( transactions . Count > 0 )
364369 {
365- #if DEBUG
370+ #if LIQUIDPROJECTIONS_DIAGNOSTICS
366371 LogProvider . GetLogger ( typeof ( PollingEventStoreAdapter ) ) . Debug ( ( ) =>
367372 $ "Loader for subscription { subscriptionId ?? "without ID" } has loaded { transactions . Count } transactions " +
368373 $ "from checkpoint { transactions . First ( ) . Checkpoint } to checkpoint { transactions . Last ( ) . Checkpoint } .") ;
369374#endif
370375
371376 if ( transactionCacheByPreviousCheckpoint != null )
372377 {
373- /* Add to cache in reverse order to prevent other projectors
378+ /* Add to cache in reverse order to prevent other projectors
374379 from requesting already loaded transactions which are not added to cache yet. */
375380 for ( int index = transactions . Count - 1 ; index > 0 ; index -- )
376381 {
@@ -379,7 +384,7 @@ from requesting already loaded transactions which are not added to cache yet. */
379384
380385 transactionCacheByPreviousCheckpoint . Set ( previousCheckpoint , transactions [ 0 ] ) ;
381386
382- #if DEBUG
387+ #if LIQUIDPROJECTIONS_DIAGNOSTICS
383388 LogProvider . GetLogger ( typeof ( PollingEventStoreAdapter ) ) . Debug ( ( ) =>
384389 $ "Loader for subscription { subscriptionId ?? "without ID" } has cached { transactions . Count } transactions " +
385390 $ "from checkpoint { transactions . First ( ) . Checkpoint } to checkpoint { transactions . Last ( ) . Checkpoint } .") ;
@@ -388,7 +393,7 @@ from requesting already loaded transactions which are not added to cache yet. */
388393 }
389394 else
390395 {
391- #if DEBUG
396+ #if LIQUIDPROJECTIONS_DIAGNOSTICS
392397 LogProvider . GetLogger ( typeof ( PollingEventStoreAdapter ) ) . Debug ( ( ) =>
393398 $ "Loader for subscription { subscriptionId } has discovered " +
394399 $ "that there are no new transactions yet. Next request for the new transactions will be delayed.") ;
0 commit comments