/* * Copyright (c) 2024 Vaughn Nugent * * Library: VNLib * Package: ObjectCacheServer * File: ObjectCacheServerEntry.cs * * ObjectCacheServerEntry.cs is part of ObjectCacheServer which is part of the larger * VNLib collection of libraries and utilities. * * ObjectCacheServer 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. * * ObjectCacheServer 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; using System.Collections.Generic; using VNLib.Plugins; using VNLib.Utils; using VNLib.Utils.Logging; using VNLib.Plugins.Extensions.Loading; using VNLib.Plugins.Extensions.Loading.Routing; using VNLib.Data.Caching.ObjectCache.Server.Endpoints; using VNLib.Data.Caching.ObjectCache.Server.Clustering; namespace VNLib.Data.Caching.ObjectCache.Server { public sealed class ObjectCacheServerEntry : PluginBase { public override string PluginName => "ObjectCache.Service"; ObjectCacheSystemState? sysState; protected override void OnLoad() { try { //Initialize the cache node builder sysState = this.GetOrCreateSingleton(); sysState.Initialize(); //Route well-known endpoint this.Route(); //Init connect endpoint this.Route(); //We must initialize the replication manager _ = this.GetOrCreateSingleton(); //Setup discovery endpoint only if the user enabled clustering if(!string.IsNullOrWhiteSpace(sysState.ClusterConfig.DiscoveryPath)) { this.Route(); } Log.Information("Plugin loaded"); } catch (KeyNotFoundException kne) { Log.Error("Missing required configuration variables {m}", kne.Message); } } protected override void OnUnLoad() { Log.Information("Plugin unloaded"); } protected override void ProcessHostCommand(string cmd) { if(string.IsNullOrWhiteSpace(cmd)) { return; } ArgumentList al = new(cmd.Split(" ")); if(al.Count == 0) { Log.Warn("Invalid command"); return; } switch (al[0].ToLower(null)) { case "memstats": sysState?.LogMemoryStats(); break; default: Log.Warn("Invalid command"); break; } } } }