Renamed Umbraco.Abstractions to Umbraco.Core

This commit is contained in:
Bjarke Berg
2020-02-24 08:21:53 +01:00
parent 46f00cf960
commit 90c2381c86
1117 changed files with 30 additions and 30 deletions

View File

@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
namespace Umbraco.Core.Sync
{
/// <summary>
/// Provides options to the <see cref="DatabaseServerMessenger"/>.
/// </summary>
public class DatabaseServerMessengerOptions
{
/// <summary>
/// Initializes a new instance of the <see cref="DatabaseServerMessengerOptions"/> with default values.
/// </summary>
public DatabaseServerMessengerOptions()
{
DaysToRetainInstructions = 2; // 2 days
ThrottleSeconds = 5; // 5 second
MaxProcessingInstructionCount = 1000;
PruneThrottleSeconds = 60; // 1 minute
}
/// <summary>
/// The maximum number of instructions that can be processed at startup; otherwise the server cold-boots (rebuilds its caches).
/// </summary>
public int MaxProcessingInstructionCount { get; set; }
/// <summary>
/// A list of callbacks that will be invoked if the lastsynced.txt file does not exist.
/// </summary>
/// <remarks>
/// These callbacks will typically be for eg rebuilding the xml cache file, or examine indexes, based on
/// the data in the database to get this particular server node up to date.
/// </remarks>
public IEnumerable<Action> InitializingCallbacks { get; set; }
/// <summary>
/// The number of days to keep instructions in the database; records older than this number will be pruned.
/// </summary>
public int DaysToRetainInstructions { get; set; }
/// <summary>
/// The number of seconds to wait between each sync operations.
/// </summary>
public int ThrottleSeconds { get; set; }
/// <summary>
/// The number of seconds to wait between each prune operations.
/// </summary>
public int PruneThrottleSeconds { get; set; }
}
}

View File

@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using Umbraco.Core.Services;
namespace Umbraco.Core.Sync
{
/// <summary>
/// A registrar that stores registered server nodes in the database.
/// </summary>
/// <remarks>
/// This is the default registrar which determines a server's role by using a master election process.
/// The master election process doesn't occur until just after startup so this election process doesn't really affect the primary startup phase.
/// </remarks>
public sealed class DatabaseServerRegistrar : IServerRegistrar
{
private readonly Lazy<IServerRegistrationService> _registrationService;
/// <summary>
/// Gets or sets the registrar options.
/// </summary>
public DatabaseServerRegistrarOptions Options { get; }
/// <summary>
/// Initializes a new instance of the <see cref="DatabaseServerRegistrar"/> class.
/// </summary>
/// <param name="registrationService">The registration service.</param>
/// <param name="options">Some options.</param>
public DatabaseServerRegistrar(Lazy<IServerRegistrationService> registrationService, DatabaseServerRegistrarOptions options)
{
Options = options ?? throw new ArgumentNullException(nameof(options));
_registrationService = registrationService ?? throw new ArgumentNullException(nameof(registrationService));
}
/// <summary>
/// Gets the registered servers.
/// </summary>
public IEnumerable<IServerAddress> Registrations => _registrationService.Value.GetActiveServers();
/// <summary>
/// Gets the role of the current server in the application environment.
/// </summary>
public ServerRole GetCurrentServerRole()
{
var service = _registrationService.Value;
return service.GetCurrentServerRole();
}
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.ComponentModel;
namespace Umbraco.Core.Sync
{
/// <summary>
/// Provides options to the <see cref="DatabaseServerRegistrar"/>.
/// </summary>
public sealed class DatabaseServerRegistrarOptions
{
/// <summary>
/// Initializes a new instance of the <see cref="DatabaseServerRegistrarOptions"/> class with default values.
/// </summary>
public DatabaseServerRegistrarOptions()
{
StaleServerTimeout = TimeSpan.FromMinutes(2); // 2 minutes
RecurringSeconds = 60; // do it every minute
}
/// <summary>
/// The amount of seconds to wait between calls to the database on the background thread
/// </summary>
public int RecurringSeconds { get; set; }
/// <summary>
/// The time span to wait before considering a server stale, after it has last been accessed.
/// </summary>
public TimeSpan StaleServerTimeout { get; set; }
}
}

View File

@@ -0,0 +1,15 @@
namespace Umbraco.Core.Sync
{
/// <summary>
/// Provides the address of a server.
/// </summary>
public interface IServerAddress
{
/// <summary>
/// Gets the server address.
/// </summary>
string ServerAddress { get; }
// TODO: Should probably add things like port, protocol, server name, app id
}
}

View File

@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using Umbraco.Core.Cache;
namespace Umbraco.Core.Sync
{
/// <summary>
/// Broadcasts distributed cache notifications to all servers of a load balanced environment.
/// </summary>
/// <remarks>Also ensures that the notification is processed on the local environment.</remarks>
public interface IServerMessenger
{
/// <summary>
/// Notifies the distributed cache, for a specified <see cref="ICacheRefresher"/>.
/// </summary>
/// <param name="refresher">The ICacheRefresher.</param>
/// <param name="payload">The notification content.</param>
void PerformRefresh<TPayload>(ICacheRefresher refresher, TPayload[] payload);
/// <summary>
/// Notifies the distributed cache of specified item invalidation, for a specified <see cref="ICacheRefresher"/>.
/// </summary>
/// <typeparam name="T">The type of the invalidated items.</typeparam>
/// <param name="refresher">The ICacheRefresher.</param>
/// <param name="getNumericId">A function returning the unique identifier of items.</param>
/// <param name="instances">The invalidated items.</param>
void PerformRefresh<T>(ICacheRefresher refresher, Func<T, int> getNumericId, params T[] instances);
/// <summary>
/// Notifies the distributed cache of specified item invalidation, for a specified <see cref="ICacheRefresher"/>.
/// </summary>
/// <typeparam name="T">The type of the invalidated items.</typeparam>
/// <param name="refresher">The ICacheRefresher.</param>
/// <param name="getGuidId">A function returning the unique identifier of items.</param>
/// <param name="instances">The invalidated items.</param>
void PerformRefresh<T>(ICacheRefresher refresher, Func<T, Guid> getGuidId, params T[] instances);
/// <summary>
/// Notifies all servers of specified items removal, for a specified <see cref="ICacheRefresher"/>.
/// </summary>
/// <typeparam name="T">The type of the removed items.</typeparam>
/// <param name="refresher">The ICacheRefresher.</param>
/// <param name="getNumericId">A function returning the unique identifier of items.</param>
/// <param name="instances">The removed items.</param>
void PerformRemove<T>(ICacheRefresher refresher, Func<T, int> getNumericId, params T[] instances);
/// <summary>
/// Notifies all servers of specified items removal, for a specified <see cref="ICacheRefresher"/>.
/// </summary>
/// <param name="refresher">The ICacheRefresher.</param>
/// <param name="numericIds">The unique identifiers of the removed items.</param>
void PerformRemove(ICacheRefresher refresher, params int[] numericIds);
/// <summary>
/// Notifies all servers of specified items invalidation, for a specified <see cref="ICacheRefresher"/>.
/// </summary>
/// <param name="refresher">The ICacheRefresher.</param>
/// <param name="numericIds">The unique identifiers of the invalidated items.</param>
void PerformRefresh(ICacheRefresher refresher, params int[] numericIds);
/// <summary>
/// Notifies all servers of specified items invalidation, for a specified <see cref="ICacheRefresher"/>.
/// </summary>
/// <param name="refresher">The ICacheRefresher.</param>
/// <param name="guidIds">The unique identifiers of the invalidated items.</param>
void PerformRefresh(ICacheRefresher refresher, params Guid[] guidIds);
/// <summary>
/// Notifies all servers of a global invalidation for a specified <see cref="ICacheRefresher"/>.
/// </summary>
/// <param name="refresher">The ICacheRefresher.</param>
void PerformRefreshAll(ICacheRefresher refresher);
}
}

View File

@@ -0,0 +1,21 @@
using System.Collections.Generic;
namespace Umbraco.Core.Sync
{
/// <summary>
/// Provides server registrations to the distributed cache.
/// </summary>
public interface IServerRegistrar
{
/// <summary>
/// Gets the server registrations.
/// </summary>
IEnumerable<IServerAddress> Registrations { get; }
/// <summary>
/// Gets the role of the current server in the application environment.
/// </summary>
ServerRole GetCurrentServerRole();
}
}

View File

@@ -0,0 +1,16 @@
namespace Umbraco.Core.Sync
{
/// <summary>
/// The message type to be used for syncing across servers.
/// </summary>
public enum MessageType
{
RefreshAll,
RefreshById,
RefreshByJson,
RemoveById,
RefreshByInstance,
RemoveByInstance,
RefreshByPayload
}
}

View File

@@ -0,0 +1,44 @@
using System;
namespace Umbraco.Core.Sync
{
/// <summary>
/// Describes <see cref="RefreshInstruction"/> refresh action type.
/// </summary>
[Serializable]
public enum RefreshMethodType
{
// NOTE
// that enum should get merged somehow with MessageType and renamed somehow
// but at the moment it is exposed in CacheRefresher webservice through RefreshInstruction
// so for the time being we keep it as-is for backward compatibility reasons
RefreshAll,
RefreshByGuid,
RefreshById,
RefreshByIds,
RefreshByJson,
RemoveById,
// would adding values break backward compatibility?
//RemoveByIds
// these are MessageType values
// note that AnythingByInstance are local messages and cannot be distributed
/*
RefreshAll,
RefreshById,
RefreshByJson,
RemoveById,
RefreshByInstance,
RemoveByInstance
*/
// NOTE
// in the future we want
// RefreshAll
// RefreshById / ByInstance (support enumeration of int or guid)
// RemoveById / ByInstance (support enumeration of int or guid)
// Notify (for everything JSON)
}
}

View File

@@ -0,0 +1,28 @@
namespace Umbraco.Core.Sync
{
/// <summary>
/// The role of a server in an application environment.
/// </summary>
public enum ServerRole : byte
{
/// <summary>
/// The server role is unknown.
/// </summary>
Unknown = 0,
/// <summary>
/// The server is the single server of a single-server environment.
/// </summary>
Single = 1,
/// <summary>
/// In a multi-servers environment, the server is a replica server.
/// </summary>
Replica = 2,
/// <summary>
/// In a multi-servers environment, the server is the master server.
/// </summary>
Master = 3
}
}

View File

@@ -0,0 +1,43 @@
using System;
using System.Collections.Generic;
namespace Umbraco.Core.Sync
{
/// <summary>
/// Can be used when Umbraco is definitely not operating in a Load Balanced scenario to micro-optimize some startup performance
/// </summary>
/// <remarks>
/// The micro optimization is specifically to avoid a DB query just after the app starts up to determine the <see cref="ServerRole"/>
/// which by default is done with master election by a database query. The master election process doesn't occur until just after startup
/// so this micro optimization doesn't really affect the primary startup phase.
/// </remarks>
public class SingleServerRegistrar : IServerRegistrar
{
private readonly IRuntimeState _runtime;
private readonly Lazy<IServerAddress[]> _registrations;
public IEnumerable<IServerAddress> Registrations => _registrations.Value;
public SingleServerRegistrar(IRuntimeState runtime)
{
_runtime = runtime;
_registrations = new Lazy<IServerAddress[]>(() => new IServerAddress[] { new ServerAddressImpl(_runtime.ApplicationUrl.ToString()) });
}
public ServerRole GetCurrentServerRole()
{
return ServerRole.Single;
}
private class ServerAddressImpl : IServerAddress
{
public ServerAddressImpl(string serverAddress)
{
ServerAddress = serverAddress;
}
public string ServerAddress { get; }
}
}
}