/*
* Copyright (c) 2023 Vaughn Nugent
*
* Library: VNLib
* Package: VNLib.Data.Caching.Extensions
* File: CacheNodeConfiguration.cs
*
* CacheNodeConfiguration.cs is part of VNLib.Data.Caching.Extensions which is part of the larger
* VNLib collection of libraries and utilities.
*
* VNLib.Data.Caching.Extensions is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* VNLib.Data.Caching.Extensions is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see https://www.gnu.org/licenses/.
*/
using System;
namespace VNLib.Data.Caching.Extensions.Clustering
{
///
/// A cache configuration for cache servers (nodes)
///
public class CacheNodeConfiguration : CacheClientConfiguration
{
///
/// The address for clients to connect to
///
public Uri? ConnectEndpoint { get; private set; }
///
/// Whether or not to advertise ourself to peer nodes
///
public bool BroadcastAdverisment { get; private set; }
///
/// Define the endpoint for clients to connect to to discover
/// other discovertable nodes
///
public Uri? DiscoveryEndpoint { get; private set; }
///
/// Gets the configuration for this node as an advertisment
///
public CacheNodeAdvertisment Advertisment
{
get
{
return new CacheNodeAdvertisment()
{
DiscoveryEndpoint = DiscoveryEndpoint,
ConnectEndpoint = ConnectEndpoint,
NodeId = NodeId
};
}
}
///
/// Sets the full address of our cache endpoint for clients to connect to
///
/// The uri clients will attempt to connect to
public CacheNodeConfiguration WithCacheEndpoint(Uri connectUri)
{
ConnectEndpoint = connectUri;
return this;
}
///
/// Enables or disables the advertisement of this node to other nodes
///
/// The absolute endpoint clients will use to connect to
public CacheNodeConfiguration EnableAdvertisment(Uri? discoveryEndpoint)
{
BroadcastAdverisment = discoveryEndpoint != null;
DiscoveryEndpoint = discoveryEndpoint;
return this;
}
///
public string NodeId { get; private set; } = null!;
///
/// Specifies the current server's cluster node id. If this
/// is a server connection attempting to listen for changes on the
/// remote server, this id must be set and unique
///
/// The cluster node id of the current server
/// Chainable fluent object
///
public CacheNodeConfiguration WithNodeId(string nodeId)
{
NodeId = nodeId ?? throw new ArgumentNullException(nameof(nodeId));
//Update the node id in the node collection
(NodeCollection as NodeDiscoveryCollection)!.SetSelfId(nodeId);
return this;
}
}
}