aboutsummaryrefslogtreecommitdiff
path: root/VNLib.Plugins.Extensions.Loading/Events
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2023-01-09 15:09:13 -0500
committerLibravatar vnugent <public@vaughnnugent.com>2023-01-09 15:09:13 -0500
commita46c3bf452d287b50b2e7dd5a24f5995c9fd26f6 (patch)
tree3a978b2dd2887b5c0e25f595516594a647d8e880 /VNLib.Plugins.Extensions.Loading/Events
parent189c6714057bf45553847eaeb9ce97eb7272eb8c (diff)
Restructure
Diffstat (limited to 'VNLib.Plugins.Extensions.Loading/Events')
-rw-r--r--VNLib.Plugins.Extensions.Loading/Events/AsyncIntervalAttribute.cs47
-rw-r--r--VNLib.Plugins.Extensions.Loading/Events/ConfigurableAsyncIntervalAttribute.cs51
-rw-r--r--VNLib.Plugins.Extensions.Loading/Events/EventManagment.cs125
-rw-r--r--VNLib.Plugins.Extensions.Loading/Events/IIntervalScheduleable.cs45
-rw-r--r--VNLib.Plugins.Extensions.Loading/Events/IntervalResultionType.cs49
5 files changed, 0 insertions, 317 deletions
diff --git a/VNLib.Plugins.Extensions.Loading/Events/AsyncIntervalAttribute.cs b/VNLib.Plugins.Extensions.Loading/Events/AsyncIntervalAttribute.cs
deleted file mode 100644
index 85b0b6d..0000000
--- a/VNLib.Plugins.Extensions.Loading/Events/AsyncIntervalAttribute.cs
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
-* Copyright (c) 2022 Vaughn Nugent
-*
-* Library: VNLib
-* Package: VNLib.Plugins.Extensions.Loading
-* File: AsyncIntervalAttribute.cs
-*
-* AsyncIntervalAttribute.cs is part of VNLib.Plugins.Extensions.Loading which is part of the larger
-* VNLib collection of libraries and utilities.
-*
-* VNLib.Plugins.Extensions.Loading is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published
-* by the Free Software Foundation, either version 2 of the License,
-* or (at your option) any later version.
-*
-* VNLib.Plugins.Extensions.Loading 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
-* General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with VNLib.Plugins.Extensions.Loading. If not, see http://www.gnu.org/licenses/.
-*/
-
-using System;
-
-namespace VNLib.Plugins.Extensions.Loading.Events
-{
- /// <summary>
- /// When added to a method schedules it as a callback on a specified interval when
- /// the plugin is loaded, and stops when unloaded
- /// </summary>
- [AttributeUsage(AttributeTargets.Method)]
- public sealed class AsyncIntervalAttribute : Attribute
- {
- internal readonly TimeSpan Interval;
-
- /// <summary>
- /// Intializes the <see cref="AsyncIntervalAttribute"/> with the specified timeout in milliseconds
- /// </summary>
- /// <param name="milliseconds">The interval in milliseconds</param>
- public AsyncIntervalAttribute(int milliseconds)
- {
- Interval = TimeSpan.FromMilliseconds(milliseconds);
- }
- }
-}
diff --git a/VNLib.Plugins.Extensions.Loading/Events/ConfigurableAsyncIntervalAttribute.cs b/VNLib.Plugins.Extensions.Loading/Events/ConfigurableAsyncIntervalAttribute.cs
deleted file mode 100644
index 12c5ec4..0000000
--- a/VNLib.Plugins.Extensions.Loading/Events/ConfigurableAsyncIntervalAttribute.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
-* Copyright (c) 2022 Vaughn Nugent
-*
-* Library: VNLib
-* Package: VNLib.Plugins.Extensions.Loading
-* File: ConfigurableAsyncIntervalAttribute.cs
-*
-* ConfigurableAsyncIntervalAttribute.cs is part of VNLib.Plugins.Extensions.Loading which is part of the larger
-* VNLib collection of libraries and utilities.
-*
-* VNLib.Plugins.Extensions.Loading is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published
-* by the Free Software Foundation, either version 2 of the License,
-* or (at your option) any later version.
-*
-* VNLib.Plugins.Extensions.Loading 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
-* General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with VNLib.Plugins.Extensions.Loading. If not, see http://www.gnu.org/licenses/.
-*/
-
-using System;
-
-namespace VNLib.Plugins.Extensions.Loading.Events
-{
- /// <summary>
- /// When added to a method schedules it as a callback on a specified interval when
- /// the plugin is loaded, and stops when unloaded
- /// </summary>
- [AttributeUsage(AttributeTargets.Method)]
- public sealed class ConfigurableAsyncIntervalAttribute : Attribute
- {
- internal readonly string IntervalPropertyName;
- internal readonly IntervalResultionType Resolution;
-
- /// <summary>
- /// Initializes a <see cref="ConfigurableAsyncIntervalAttribute"/> with the specified
- /// interval property name
- /// </summary>
- /// <param name="configPropName">The configuration property name for the event interval</param>
- /// <param name="resolution">The time resoltion for the event interval</param>
- public ConfigurableAsyncIntervalAttribute(string configPropName, IntervalResultionType resolution)
- {
- IntervalPropertyName = configPropName;
- Resolution = resolution;
- }
- }
-}
diff --git a/VNLib.Plugins.Extensions.Loading/Events/EventManagment.cs b/VNLib.Plugins.Extensions.Loading/Events/EventManagment.cs
deleted file mode 100644
index af55852..0000000
--- a/VNLib.Plugins.Extensions.Loading/Events/EventManagment.cs
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
-* Copyright (c) 2022 Vaughn Nugent
-*
-* Library: VNLib
-* Package: VNLib.Plugins.Extensions.Loading
-* File: EventManagment.cs
-*
-* EventManagment.cs is part of VNLib.Plugins.Extensions.Loading which is part of the larger
-* VNLib collection of libraries and utilities.
-*
-* VNLib.Plugins.Extensions.Loading is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published
-* by the Free Software Foundation, either version 2 of the License,
-* or (at your option) any later version.
-*
-* VNLib.Plugins.Extensions.Loading 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
-* General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with VNLib.Plugins.Extensions.Loading. If not, see http://www.gnu.org/licenses/.
-*/
-
-using System;
-using System.Threading;
-using System.Threading.Tasks;
-
-using VNLib.Utils.Logging;
-
-namespace VNLib.Plugins.Extensions.Loading.Events
-{
-
- /// <summary>
- /// A deletage to form a method signature for shedulable interval callbacks
- /// </summary>
- /// <param name="log">The plugin's default log provider</param>
- /// <param name="pluginExitToken">The plugin's exit token</param>
- /// <returns>A task the represents the asynchronous work</returns>
- public delegate Task AsyncSchedulableCallback(ILogProvider log, CancellationToken pluginExitToken);
-
- /// <summary>
- /// Provides event schedueling extensions for plugins
- /// </summary>
- public static class EventManagment
- {
- /// <summary>
- /// Schedules an asynchronous event interval for the current plugin, that is active until canceled or until the plugin unloads
- /// </summary>
- /// <param name="plugin"></param>
- /// <param name="asyncCallback">An asyncrhonous callback method.</param>
- /// <param name="interval">The event interval</param>
- /// <param name="immediate">A value that indicates if the callback should be run as soon as possible</param>
- /// <returns>An <see cref="EventHandle"/> that can manage the interval state</returns>
- /// <exception cref="ObjectDisposedException"></exception>
- /// <remarks>If exceptions are raised during callback execution, they are written to the plugin's default log provider</remarks>
- public static void ScheduleInterval(this PluginBase plugin, AsyncSchedulableCallback asyncCallback, TimeSpan interval, bool immediate = false)
- {
- plugin.ThrowIfUnloaded();
-
- plugin.Log.Verbose("Interval for {t} scheduled", interval);
-
- //Run interval on plugins bg scheduler
- _ = plugin.DeferTask(() => RunIntervalOnPluginScheduler(plugin, asyncCallback, interval, immediate));
- }
-
- private static async Task RunIntervalOnPluginScheduler(PluginBase plugin, AsyncSchedulableCallback callback, TimeSpan interval, bool immediate)
- {
-
- static async Task RunCallbackAsync(PluginBase plugin, AsyncSchedulableCallback callback)
- {
- try
- {
- //invoke interval callback
- await callback(plugin.Log, plugin.UnloadToken).ConfigureAwait(false);
- }
- catch (OperationCanceledException)
- {
- //unloaded
- plugin.Log.Verbose("Interval callback canceled due to plugin unload or other event cancellation");
- }
- catch (Exception ex)
- {
- plugin.Log.Error(ex, "Unhandled exception raised during timer callback");
- }
- }
-
- //Run callback immediatly if requested
- if (immediate)
- {
- await RunCallbackAsync(plugin, callback);
- }
-
- //Timer loop
- while (true)
- {
- try
- {
- //await delay and wait for plugin cancellation
- await Task.Delay(interval, plugin.UnloadToken);
- }
- catch (TaskCanceledException)
- {
- //Unload token canceled, exit loop
- break;
- }
-
- await RunCallbackAsync(plugin, callback);
- }
- }
-
- /// <summary>
- /// Registers an <see cref="IIntervalScheduleable"/> type's event handler for
- /// raising timed interval events
- /// </summary>
- /// <param name="plugin"></param>
- /// <param name="scheduleable">The instance to schedule for timeouts</param>
- /// <param name="interval">The timeout interval</param>
- /// <returns>An <see cref="EventHandle"/> that can manage the interval state</returns>
- /// <exception cref="ObjectDisposedException"></exception>
- /// <remarks>If exceptions are raised during callback execution, they are written to the plugin's default log provider</remarks>
- public static void ScheduleInterval(this PluginBase plugin, IIntervalScheduleable scheduleable, TimeSpan interval) =>
- ScheduleInterval(plugin, scheduleable.OnIntervalAsync, interval);
- }
-}
diff --git a/VNLib.Plugins.Extensions.Loading/Events/IIntervalScheduleable.cs b/VNLib.Plugins.Extensions.Loading/Events/IIntervalScheduleable.cs
deleted file mode 100644
index 5ff40f4..0000000
--- a/VNLib.Plugins.Extensions.Loading/Events/IIntervalScheduleable.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
-* Copyright (c) 2022 Vaughn Nugent
-*
-* Library: VNLib
-* Package: VNLib.Plugins.Extensions.Loading
-* File: IIntervalScheduleable.cs
-*
-* IIntervalScheduleable.cs is part of VNLib.Plugins.Extensions.Loading which is part of the larger
-* VNLib collection of libraries and utilities.
-*
-* VNLib.Plugins.Extensions.Loading is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published
-* by the Free Software Foundation, either version 2 of the License,
-* or (at your option) any later version.
-*
-* VNLib.Plugins.Extensions.Loading 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
-* General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with VNLib.Plugins.Extensions.Loading. If not, see http://www.gnu.org/licenses/.
-*/
-
-using System.Threading;
-using System.Threading.Tasks;
-
-using VNLib.Utils.Logging;
-
-namespace VNLib.Plugins.Extensions.Loading.Events
-{
- /// <summary>
- /// Exposes a type for asynchronous event schelueling
- /// </summary>
- public interface IIntervalScheduleable
- {
- /// <summary>
- /// A method that is called when the interval time has elapsed
- /// </summary>
- /// <param name="log">The plugin default log provider</param>
- /// <param name="cancellationToken">A token that may cancel an operations if the plugin becomes unloaded</param>
- /// <returns>A task that resolves when the async operation completes</returns>
- Task OnIntervalAsync(ILogProvider log, CancellationToken cancellationToken);
- }
-}
diff --git a/VNLib.Plugins.Extensions.Loading/Events/IntervalResultionType.cs b/VNLib.Plugins.Extensions.Loading/Events/IntervalResultionType.cs
deleted file mode 100644
index d82efc4..0000000
--- a/VNLib.Plugins.Extensions.Loading/Events/IntervalResultionType.cs
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
-* Copyright (c) 2022 Vaughn Nugent
-*
-* Library: VNLib
-* Package: VNLib.Plugins.Extensions.Loading
-* File: IntervalResultionType.cs
-*
-* IntervalResultionType.cs is part of VNLib.Plugins.Extensions.Loading which is part of the larger
-* VNLib collection of libraries and utilities.
-*
-* VNLib.Plugins.Extensions.Loading is free software: you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published
-* by the Free Software Foundation, either version 2 of the License,
-* or (at your option) any later version.
-*
-* VNLib.Plugins.Extensions.Loading 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
-* General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with VNLib.Plugins.Extensions.Loading. If not, see http://www.gnu.org/licenses/.
-*/
-
-namespace VNLib.Plugins.Extensions.Loading.Events
-{
- /// <summary>
- /// The configurable event interval resulution type
- /// </summary>
- public enum IntervalResultionType
- {
- /// <summary>
- /// Specifies event interval resolution in milliseconds
- /// </summary>
- Milliseconds,
- /// <summary>
- /// Specifies event interval resolution in seconds
- /// </summary>
- Seconds,
- /// <summary>
- /// Specifies event interval resolution in minutes
- /// </summary>
- Minutes,
- /// <summary>
- /// Specifies event interval resolution in hours
- /// </summary>
- Hours
- }
-}