Skip to content

Commit ba51e73

Browse files
authored
Merge pull request #22 from smdn/introduce-protocolhandler
Introduce protocol abstraction interfaces
2 parents df3da32 + 9410e38 commit ba51e73

15 files changed

+3000
-1185
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// SPDX-FileCopyrightText: 2025 smdn <smdn@smdn.jp>
2+
// SPDX-License-Identifier: MIT
3+
using System.Text;
4+
5+
using Smdn.Net.MuninPlugin;
6+
7+
namespace Smdn.Net.MuninNode.Protocol;
8+
9+
/// <summary>
10+
/// An interface for referencing properties that represent the profile of the constructed <c>Munin-Node</c>.
11+
/// </summary>
12+
public interface IMuninNodeProfile {
13+
/// <summary>
14+
/// Gets the string representing the hostname of the node.
15+
/// </summary>
16+
/// <remarks>
17+
/// This value is used as the response to the `node` command.
18+
/// </remarks>
19+
/// <seealso href="https://guide.munin-monitoring.org/en/latest/master/network-protocol.html">
20+
/// Data exchange between master and node - `node` command
21+
/// </seealso>
22+
public string HostName { get; }
23+
24+
/// <summary>
25+
/// Gets the string representing the version information of the node.
26+
/// </summary>
27+
/// <remarks>
28+
/// This value is used as the response to the `version` command.
29+
/// </remarks>
30+
/// <seealso href="https://guide.munin-monitoring.org/en/latest/master/network-protocol.html">
31+
/// Data exchange between master and node - `version` command
32+
/// </seealso>
33+
public string Version { get; }
34+
35+
/// <summary>
36+
/// Gets the <see cref="IPluginProvider"/> representing the munin plugins provided by the node.
37+
/// </summary>
38+
/// <remarks>
39+
/// This value is used as the response to the `list`, `config` and `fetch` command.
40+
/// </remarks>
41+
/// <seealso href="https://guide.munin-monitoring.org/en/latest/master/network-protocol.html">
42+
/// Data exchange between master and node - `list`, `config` and `fetch` command
43+
/// </seealso>
44+
public IPluginProvider PluginProvider { get; }
45+
46+
/// <summary>
47+
/// Gets the <see cref="Encoding"/> used for data exchange with the <c>munin master</c>.
48+
/// </summary>
49+
public Encoding Encoding { get; }
50+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// SPDX-FileCopyrightText: 2025 smdn <smdn@smdn.jp>
2+
// SPDX-License-Identifier: MIT
3+
using System;
4+
using System.Buffers;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
8+
using Smdn.Net.MuninNode.Transport;
9+
10+
namespace Smdn.Net.MuninNode.Protocol;
11+
12+
/// <summary>
13+
/// Provides an interface that abstracts the handling of data exchange
14+
/// protocols with <c>munin master</c> in <c>Munin-Node</c>.
15+
/// </summary>
16+
/// <seealso href="https://guide.munin-monitoring.org/en/latest/master/network-protocol.html">
17+
/// Data exchange between master and node
18+
/// </seealso>
19+
public interface IMuninProtocolHandler {
20+
/// <summary>
21+
/// Handles the start of a transaction processing requests from <c>munin master</c>.
22+
/// </summary>
23+
/// <param name="client">
24+
/// The <see cref="IMuninNodeClient"/> to which the request is sent from and
25+
/// to which the response should be sent back.
26+
/// </param>
27+
/// <param name="cancellationToken">
28+
/// The <see cref="CancellationToken"/> to monitor for cancellation requests.
29+
/// </param>
30+
/// <returns>
31+
/// The <see cref="ValueTask"/> that represents the asynchronous operation.
32+
/// </returns>
33+
/// <exception cref="ArgumentNullException">
34+
/// <paramref name="client"/> is <see langword="null"/>.
35+
/// </exception>
36+
/// <exception cref="MuninNodeClientDisconnectedException">
37+
/// <paramref name="client"/> has been disconnected.
38+
/// </exception>
39+
ValueTask HandleTransactionStartAsync(
40+
IMuninNodeClient client,
41+
CancellationToken cancellationToken
42+
);
43+
44+
/// <summary>
45+
/// Handles the end of a transaction processing requests from <c>munin master</c>.
46+
/// </summary>
47+
/// <param name="client">
48+
/// The <see cref="IMuninNodeClient"/> to which the request is sent from and
49+
/// to which the response should be sent back.
50+
/// </param>
51+
/// <param name="cancellationToken">
52+
/// The <see cref="CancellationToken"/> to monitor for cancellation requests.
53+
/// </param>
54+
/// <returns>
55+
/// The <see cref="ValueTask"/> that represents the asynchronous operation.
56+
/// </returns>
57+
/// <exception cref="ArgumentNullException">
58+
/// <paramref name="client"/> is <see langword="null"/>.
59+
/// </exception>
60+
/// <exception cref="MuninNodeClientDisconnectedException">
61+
/// <paramref name="client"/> has been disconnected.
62+
/// </exception>
63+
ValueTask HandleTransactionEndAsync(
64+
IMuninNodeClient client,
65+
CancellationToken cancellationToken
66+
);
67+
68+
/// <summary>
69+
/// Handles commands from the <c>munin master</c> and sends back a response.
70+
/// </summary>
71+
/// <param name="client">
72+
/// The <see cref="IMuninNodeClient"/> to which the request is sent from and
73+
/// to which the response should be sent back.
74+
/// </param>
75+
/// <param name="commandLine">
76+
/// The <see cref="ReadOnlySequence{T}"/> representing the command line requested from the <paramref name="client"/>.
77+
/// </param>
78+
/// <param name="cancellationToken">
79+
/// The <see cref="CancellationToken"/> to monitor for cancellation requests.
80+
/// </param>
81+
/// <returns>
82+
/// The <see cref="ValueTask"/> that represents the asynchronous operation.
83+
/// </returns>
84+
/// <exception cref="ArgumentNullException">
85+
/// <paramref name="client"/> is <see langword="null"/>.
86+
/// </exception>
87+
/// <exception cref="MuninNodeClientDisconnectedException">
88+
/// <paramref name="client"/> has been disconnected.
89+
/// </exception>
90+
ValueTask HandleCommandAsync(
91+
IMuninNodeClient client,
92+
ReadOnlySequence<byte> commandLine,
93+
CancellationToken cancellationToken
94+
);
95+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// SPDX-FileCopyrightText: 2025 smdn <smdn@smdn.jp>
2+
// SPDX-License-Identifier: MIT
3+
using System;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
7+
namespace Smdn.Net.MuninNode.Protocol;
8+
9+
/// <summary>
10+
/// Provides an interface that abstracts the factory for creating the munin
11+
/// protocol handler used by <c>Munin-Node</c>.
12+
/// </summary>
13+
/// <seealso cref="NodeBase"/>
14+
/// <seealso cref="IMuninProtocolHandler"/>
15+
public interface IMuninProtocolHandlerFactory {
16+
/// <summary>
17+
/// Creates and returns a <see cref="IMuninProtocolHandler"/> for the specific <c>Munin-Node</c>.
18+
/// </summary>
19+
/// <param name="profile">
20+
/// The <see cref="IMuninNodeProfile"/> that represents the profile of the <c>Munin-Node</c>
21+
/// for which this handler to be created will process requests.
22+
/// </param>
23+
/// <param name="cancellationToken">
24+
/// The <see cref="CancellationToken"/> to monitor for cancellation requests.
25+
/// </param>
26+
/// <returns>
27+
/// The <see cref="ValueTask{IMuninProtocolHandler}"/> that represents the asynchronous operation,
28+
/// creating the <see cref="IMuninProtocolHandler"/> bound to the <paramref name="profile"/>.
29+
/// </returns>
30+
/// <exception cref="ArgumentNullException">
31+
/// <paramref name="profile"/> is <see langword="null"/>.
32+
/// </exception>
33+
ValueTask<IMuninProtocolHandler> CreateAsync(
34+
IMuninNodeProfile profile,
35+
CancellationToken cancellationToken
36+
);
37+
}

0 commit comments

Comments
 (0)