Skip to content

Commit

Permalink
Reduce visibility of the packages and clarify Liblog dependency (#8)
Browse files Browse the repository at this point in the history
* Reduced the visibility of the adapter to `internal`

* Fixed the namespaces that Liblog uses

* Clarified the purpose of Liblog and how to hide it
  • Loading branch information
dennisdoomen authored Feb 23, 2018
1 parent 4df239b commit 4805677
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 35 deletions.
6 changes: 6 additions & 0 deletions LiquidProjections.PollingEventStore.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_FOREACH/@EntryValue">Required</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_IFELSE/@EntryValue">Required</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_WHILE/@EntryValue">Required</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ACCESSORHOLDER_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">NEVER</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_ANONYMOUSMETHOD_ON_SINGLE_LINE/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_WHILE_ON_NEW_LINE/@EntryValue">True</s:Boolean>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LIMIT/@EntryValue">130</s:Int64>
Expand Down Expand Up @@ -55,7 +56,12 @@
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=NAMESPACE_005FALIAS/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FFIELD/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FRESOURCE/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpAttributeForSingleLineMethodUpgrade/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpRenamePlacementToArrangementMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/UnitTesting/DisabledProviders/=MSTest/@EntryIndexedValue">True</s:Boolean>
Expand Down
6 changes: 5 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Liquid Projections [![Build status](https://ci.appveyor.com/api/projects/status/5j2rboeh9vg8773w/branch/master?svg=true)](https://ci.appveyor.com/project/dennisdoomen/liquidprojections-pollingeventstore-ctw8n/branch/master)

## What is this?
An adapter for event stores that cannot actively push events to [LiquidProjections](https://github.com/liquidprojections/LiquidProjections). It efficiently support multiple concurrent subscribers each interested in a different checkpoint without hitting the underlying event store concurrently
A source-only Nuget package for event stores that cannot actively push events to [LiquidProjections](https://github.com/liquidprojections/LiquidProjections). It efficiently support multiple concurrent subscribers each interested in a different checkpoint without hitting the underlying event store concurrently.

## Important Notes
* This library uses [Liblog](https://github.com/damianh/LibLog) to log details about asynchronous exceptions to your logging framework of choice. You can also have it log more diagnostic messages by setting the `LIQUIDPROJECTIONS_DIAGNOSTICS` condition symbol.
* If you use this library inside your own packaged library, make sure you set the `LIBLOG_PROVIDERS_ONLY` compiler symbol to prevent the LibLog package from leaking into your consumers.
16 changes: 8 additions & 8 deletions Src/LiquidProjections.PollingEventStore/LibLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "LiquidProjections.NEventStore.Logging")]
[assembly: SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed", Scope = "member", Target = "LiquidProjections.NEventStore.Logging.Logger.#Invoke(LiquidProjections.NEventStore.Logging.LogLevel,System.Func`1<System.String>,System.Exception,System.Object[])")]
[assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "LiquidProjections.PollingEventStoreAdapter.Logging")]
[assembly: SuppressMessage("Microsoft.Design", "CA1026:DefaultParametersShouldNotBeUsed", Scope = "member", Target = "LiquidProjections.PollingEventStoreAdapter.Logging.Logger.#Invoke(LiquidProjections.PollingEventStoreAdapter.Logging.LogLevel,System.Func`1<System.String>,System.Exception,System.Object[])")]

// If you copied this file manually, you need to change all "YourRootNameSpace" so not to clash with other libraries
// that use LibLog
#if LIBLOG_PROVIDERS_ONLY
namespace LiquidProjections.NEventStore.LibLog
namespace LiquidProjections.PollingEventStoreAdapter.LibLog
#else
namespace LiquidProjections.NEventStore.Logging
namespace LiquidProjections.PollingEventStoreAdapter.Logging
#endif
{
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#if LIBLOG_PROVIDERS_ONLY
using LiquidProjections.NEventStore.LibLog.LogProviders;
using LiquidProjections.PollingEventStoreAdapter.LibLog.LogProviders;
#else
using LiquidProjections.NEventStore.Logging.LogProviders;
using LiquidProjections.PollingEventStoreAdapter.Logging.LogProviders;
#endif
using System;
#if !LIBLOG_PROVIDERS_ONLY
Expand Down Expand Up @@ -714,9 +714,9 @@ public bool Log(LogLevel logLevel, Func<string> messageFunc, Exception exception
}

#if LIBLOG_PROVIDERS_ONLY
namespace LiquidProjections.NEventStore.LibLog.LogProviders
namespace LiquidProjections.PollingEventStoreAdapter.LibLog.LogProviders
#else
namespace LiquidProjections.NEventStore.Logging.LogProviders
namespace LiquidProjections.PollingEventStoreAdapter.Logging.LogProviders
#endif
{
using System;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard1.1</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DefineConstants>TRACE;RELEASE;NETSTANDARD1_1;LIBLOG_PORTABLE</DefineConstants>
<DefineConstants>TRACE;RELEASE;NETSTANDARD1_1;LIBLOG_PORTABLE;RELEASE;NETSTANDARD1_1;LIQUIDPROJECTIONS_BUILD_TIME</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>TRACE;DEBUG;NETSTANDARD1_1;LIBLOG_PORTABLE</DefineConstants>
<DefineConstants>TRACE;DEBUG;NETSTANDARD1_1;LIBLOG_PORTABLE;DEBUG;NETSTANDARD1_1;LIQUIDPROJECTIONS_BUILD_TIME;LIQUIDPROJECTIONS_DIAGNOSTICS</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="LiquidProjections.Abstractions" Version="2.3.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
<PackageReference Include="System.Dynamic.Runtime" Version="4.3.0" />
</ItemGroup>

</Project>
41 changes: 23 additions & 18 deletions Src/LiquidProjections.PollingEventStore/PollingEventStoreAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Threading;
using System.Threading.Tasks;
using LiquidProjections.Abstractions;
using LiquidProjections.NEventStore.Logging;
using LiquidProjections.PollingEventStoreAdapter.Logging;

namespace LiquidProjections.PollingEventStore
{
Expand All @@ -16,7 +16,12 @@ namespace LiquidProjections.PollingEventStore
/// If the implementation of <see cref="IPassiveEventStore"/> implements <see cref="IDisposable"/>, disposing
/// the <see cref="PollingEventStoreAdapter"/> will also dispose the event store.
/// </remarks>
public class PollingEventStoreAdapter : IDisposable
#if LIQUIDPROJECTIONS_BUILD_TIME
public
#else
internal
#endif
class PollingEventStoreAdapter : IDisposable
{
private readonly TimeSpan pollInterval;
private readonly int maxPageSize;
Expand Down Expand Up @@ -138,7 +143,7 @@ private Page TryGetNextPageFromCache(long previousCheckpoint, string subscriptio
}
}

#if DEBUG
#if LIQUIDPROJECTIONS_DIAGNOSTICS
LogProvider.GetLogger(typeof(PollingEventStoreAdapter)).Debug(() =>
$"Subscription {subscriptionId} has found a page of size {resultPage.Count} " +
$"from checkpoint {resultPage.First().Checkpoint} " +
Expand All @@ -148,7 +153,7 @@ private Page TryGetNextPageFromCache(long previousCheckpoint, string subscriptio
return new Page(previousCheckpoint, resultPage);
}

#if DEBUG
#if LIQUIDPROJECTIONS_DIAGNOSTICS
LogProvider.GetLogger(typeof(PollingEventStoreAdapter)).Debug(() =>
$"Subscription {subscriptionId} has not found the next transaction in the cache.");
#endif
Expand All @@ -158,7 +163,7 @@ private Page TryGetNextPageFromCache(long previousCheckpoint, string subscriptio

private void StartPreloadingNextPage(long previousCheckpoint, string subscriptionId)
{
#if DEBUG
#if LIQUIDPROJECTIONS_DIAGNOSTICS
LogProvider.GetLogger(typeof(PollingEventStoreAdapter)).Debug(() =>
$"Subscription {subscriptionId} has started preloading transactions " +
$"after checkpoint {previousCheckpoint}.");
Expand All @@ -174,7 +179,7 @@ private async Task<Page> LoadNextPageSequentially(long previousCheckpoint, strin
{
if (isDisposed)
{
#if DEBUG
#if LIQUIDPROJECTIONS_DIAGNOSTICS
LogProvider.GetLogger(typeof(PollingEventStoreAdapter)).Debug(() =>
$"Page loading for subscription {subscriptionId} cancelled because the adapter is disposed.");
#endif
Expand All @@ -193,7 +198,7 @@ private async Task<Page> LoadNextPageSequentially(long previousCheckpoint, strin
{
TimeSpan delay = pollInterval - timeAfterPreviousRequest;

#if DEBUG
#if LIQUIDPROJECTIONS_DIAGNOSTICS
LogProvider.GetLogger(typeof(PollingEventStoreAdapter)).Debug(() =>
$"Subscription {subscriptionId} is waiting " +
$"for {delay} before checking for new transactions.");
Expand Down Expand Up @@ -242,15 +247,15 @@ private Task<Page> TryLoadNextPageSequentiallyOrWaitForCurrentLoadingToFinish(lo
{
if (isTaskOwner)
{
#if DEBUG
#if LIQUIDPROJECTIONS_DIAGNOSTICS
LogProvider.GetLogger(typeof(PollingEventStoreAdapter))
.Debug(() => $"Subscription {subscriptionId} created a loader {loader.Id} " +
$"for a page after checkpoint {previousCheckpoint}.");
#endif

if (isDisposed)
{
#if DEBUG
#if LIQUIDPROJECTIONS_DIAGNOSTICS
LogProvider.GetLogger(typeof(PollingEventStoreAdapter))
.Debug(() => $"The loader {loader.Id} is cancelled because the adapter is disposed.");
#endif
Expand All @@ -267,7 +272,7 @@ private Task<Page> TryLoadNextPageSequentiallyOrWaitForCurrentLoadingToFinish(lo
}
else
{
#if DEBUG
#if LIQUIDPROJECTIONS_DIAGNOSTICS
LogProvider.GetLogger(typeof(PollingEventStoreAdapter))
.Debug(() => $"Subscription {subscriptionId} is waiting for loader {loader.Id}.");
#endif
Expand All @@ -288,7 +293,7 @@ private async Task TryLoadNextPageAndMakeLoaderComplete(long previousCheckpoint,
}
finally
{
#if DEBUG
#if LIQUIDPROJECTIONS_DIAGNOSTICS
LogProvider.GetLogger(typeof(PollingEventStoreAdapter)).Debug(() =>
$"Loader for subscription {subscriptionId} is no longer the current one.");
#endif
Expand All @@ -297,7 +302,7 @@ private async Task TryLoadNextPageAndMakeLoaderComplete(long previousCheckpoint,
}
catch (Exception exception)
{
#if DEBUG
#if LIQUIDPROJECTIONS_DIAGNOSTICS
LogProvider.GetLogger(typeof(PollingEventStoreAdapter)).DebugException(
$"Loader for subscription {subscriptionId} has failed.",
exception);
Expand All @@ -307,7 +312,7 @@ private async Task TryLoadNextPageAndMakeLoaderComplete(long previousCheckpoint,
return;
}

#if DEBUG
#if LIQUIDPROJECTIONS_DIAGNOSTICS
LogProvider.GetLogger(typeof(PollingEventStoreAdapter)).Debug(() =>
$"Loader for subscription {subscriptionId} has completed.");
#endif
Expand All @@ -322,7 +327,7 @@ private async Task<Page> TryLoadNextPage(long previousCheckpoint, string subscri
Page cachedPage = TryGetNextPageFromCache(previousCheckpoint, subscriptionId);
if (cachedPage.Transactions.Count > 0)
{
#if DEBUG
#if LIQUIDPROJECTIONS_DIAGNOSTICS
LogProvider.GetLogger(typeof(PollingEventStoreAdapter))
.Debug(() =>
$"Loader for subscription {subscriptionId} has found a page in the cache.");
Expand Down Expand Up @@ -362,15 +367,15 @@ private async Task<Page> TryLoadNextPage(long previousCheckpoint, string subscri

if (transactions.Count > 0)
{
#if DEBUG
#if LIQUIDPROJECTIONS_DIAGNOSTICS
LogProvider.GetLogger(typeof(PollingEventStoreAdapter)).Debug(() =>
$"Loader for subscription {subscriptionId ?? "without ID"} has loaded {transactions.Count} transactions " +
$"from checkpoint {transactions.First().Checkpoint} to checkpoint {transactions.Last().Checkpoint}.");
#endif

if (transactionCacheByPreviousCheckpoint != null)
{
/* Add to cache in reverse order to prevent other projectors
/* Add to cache in reverse order to prevent other projectors
from requesting already loaded transactions which are not added to cache yet. */
for (int index = transactions.Count - 1; index > 0; index--)
{
Expand All @@ -379,7 +384,7 @@ from requesting already loaded transactions which are not added to cache yet. */

transactionCacheByPreviousCheckpoint.Set(previousCheckpoint, transactions[0]);

#if DEBUG
#if LIQUIDPROJECTIONS_DIAGNOSTICS
LogProvider.GetLogger(typeof(PollingEventStoreAdapter)).Debug(() =>
$"Loader for subscription {subscriptionId ?? "without ID"} has cached {transactions.Count} transactions " +
$"from checkpoint {transactions.First().Checkpoint} to checkpoint {transactions.Last().Checkpoint}.");
Expand All @@ -388,7 +393,7 @@ from requesting already loaded transactions which are not added to cache yet. */
}
else
{
#if DEBUG
#if LIQUIDPROJECTIONS_DIAGNOSTICS
LogProvider.GetLogger(typeof(PollingEventStoreAdapter)).Debug(() =>
$"Loader for subscription {subscriptionId} has discovered " +
$"that there are no new transactions yet. Next request for the new transactions will be delayed.");
Expand Down
2 changes: 1 addition & 1 deletion Src/LiquidProjections.PollingEventStore/Subscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.Threading;
using System.Threading.Tasks;
using LiquidProjections.Abstractions;
using LiquidProjections.NEventStore.Logging;
using LiquidProjections.PollingEventStoreAdapter.Logging;

namespace LiquidProjections.PollingEventStore
{
Expand Down

0 comments on commit 4805677

Please sign in to comment.