Skip to content

Commit 4f91943

Browse files
committed
Internalize much of the channel and message infrastructure
1 parent 8109d4c commit 4f91943

File tree

6 files changed

+24
-34
lines changed

6 files changed

+24
-34
lines changed

src/Microsoft.ML.Core/Data/IHostEnvironment.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ public readonly struct ChannelMessage
190190
/// </summary>
191191
public string Message => _args != null ? string.Format(_message, _args) : _message;
192192

193-
public ChannelMessage(ChannelMessageKind kind, MessageSensitivity sensitivity, string message)
193+
[BestFriend]
194+
internal ChannelMessage(ChannelMessageKind kind, MessageSensitivity sensitivity, string message)
194195
{
195196
Contracts.CheckNonEmpty(message, nameof(message));
196197
Kind = kind;
@@ -199,7 +200,8 @@ public ChannelMessage(ChannelMessageKind kind, MessageSensitivity sensitivity, s
199200
_args = null;
200201
}
201202

202-
public ChannelMessage(ChannelMessageKind kind, MessageSensitivity sensitivity, string fmt, params object[] args)
203+
[BestFriend]
204+
internal ChannelMessage(ChannelMessageKind kind, MessageSensitivity sensitivity, string fmt, params object[] args)
203205
{
204206
Contracts.CheckNonEmpty(fmt, nameof(fmt));
205207
Contracts.CheckNonEmpty(args, nameof(args));

src/Microsoft.ML.Core/Data/ProgressReporter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ namespace Microsoft.ML.Runtime.Data
1414
/// <summary>
1515
/// The progress reporting classes used by <see cref="HostEnvironmentBase{THostEnvironmentBase}"/> descendants.
1616
/// </summary>
17-
public static class ProgressReporting
17+
[BestFriend]
18+
internal static class ProgressReporting
1819
{
1920
/// <summary>
2021
/// The progress channel for <see cref="ConsoleEnvironment"/>.

src/Microsoft.ML.Core/Data/ServerChannel.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace Microsoft.ML.Runtime
1919
/// delegates will be published in some fashion, with the target scenario being
2020
/// that the library will publish some sort of restful API.
2121
/// </summary>
22+
[BestFriend]
2223
public sealed class ServerChannel : ServerChannel.IPendingBundleNotification, IDisposable
2324
{
2425
// See ServerChannel.md for a more elaborate discussion of high level usage and design.
@@ -250,7 +251,8 @@ public void AddDoneAction(Action onDone)
250251
}
251252
}
252253

253-
public static class ServerChannelUtilities
254+
[BestFriend]
255+
internal static class ServerChannelUtilities
254256
{
255257
/// <summary>
256258
/// Convenience method for <see cref="ServerChannel.Start"/> that looks more idiomatic to typical

src/Microsoft.ML.Core/Environment/HostEnvironmentBase.cs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ namespace Microsoft.ML.Runtime.Data
1515
/// Base class for channel providers. This is a common base class for<see cref="HostEnvironmentBase{THostEnvironmentBase}"/>.
1616
/// The ParentFullName, ShortName, and FullName may be null or empty.
1717
/// </summary>
18-
public abstract class ChannelProviderBase : IExceptionContext
18+
[BestFriend]
19+
internal abstract class ChannelProviderBase : IExceptionContext
1920
{
2021
/// <summary>
2122
/// Data keys that are attached to the exception thrown via the exception context.
@@ -79,43 +80,22 @@ public virtual TException Process<TException>(TException ex)
7980
/// <summary>
8081
/// Message source (a channel) that generated the message being dispatched.
8182
/// </summary>
82-
public interface IMessageSource
83+
[BestFriend]
84+
internal interface IMessageSource
8385
{
8486
string ShortName { get; }
8587
string FullName { get; }
8688
bool Verbose { get; }
8789
}
8890

89-
/// <summary>
90-
/// A <see cref="IHostEnvironment"/> that is also a channel listener can attach
91-
/// listeners for messages, as sent through <see cref="IChannelProvider.StartPipe{TMessage}"/>.
92-
/// </summary>
93-
public interface IMessageDispatcher : IHostEnvironment
94-
{
95-
/// <summary>
96-
/// Listen on this environment to messages of a particular type.
97-
/// </summary>
98-
/// <typeparam name="TMessage">The message type</typeparam>
99-
/// <param name="listenerFunc">The action to perform when a message of the
100-
/// appropriate type is received.</param>
101-
void AddListener<TMessage>(Action<IMessageSource, TMessage> listenerFunc);
102-
103-
/// <summary>
104-
/// Removes a previously added listener.
105-
/// </summary>
106-
/// <typeparam name="TMessage">The message type</typeparam>
107-
/// <param name="listenerFunc">The previous listener function that is now being removed.</param>
108-
void RemoveListener<TMessage>(Action<IMessageSource, TMessage> listenerFunc);
109-
}
110-
11191
/// <summary>
11292
/// A basic host environment suited for many environments.
11393
/// This also supports modifying the concurrency factor, provides the ability to subscribe to pipes via the
11494
/// AddListener/RemoveListener methods, and exposes the <see cref="ProgressReporting.ProgressTracker"/> to
11595
/// query progress.
11696
/// </summary>
11797
[BestFriend]
118-
internal abstract class HostEnvironmentBase<TEnv> : ChannelProviderBase, IHostEnvironment, IDisposable, IChannelProvider, IMessageDispatcher
98+
internal abstract class HostEnvironmentBase<TEnv> : ChannelProviderBase, IHostEnvironment, IDisposable, IChannelProvider
11999
where TEnv : HostEnvironmentBase<TEnv>
120100
{
121101
/// <summary>

src/Microsoft.ML.Core/Environment/TelemetryMessage.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ namespace Microsoft.ML.Runtime
1313
/// <summary>
1414
/// A telemetry message.
1515
/// </summary>
16-
public abstract class TelemetryMessage
16+
[BestFriend]
17+
internal abstract class TelemetryMessage
1718
{
1819
public static TelemetryMessage CreateCommand(string commandName, string commandText)
1920
{
@@ -40,7 +41,8 @@ public static TelemetryMessage CreateException(Exception exception)
4041
/// <summary>
4142
/// Message with one long text and bunch of small properties (limit on value is ~1020 chars)
4243
/// </summary>
43-
public sealed class TelemetryTrace : TelemetryMessage
44+
[BestFriend]
45+
internal sealed class TelemetryTrace : TelemetryMessage
4446
{
4547
public readonly string Text;
4648
public readonly string Name;
@@ -57,7 +59,8 @@ public TelemetryTrace(string text, string name, string type)
5759
/// <summary>
5860
/// Message with exception
5961
/// </summary>
60-
public sealed class TelemetryException : TelemetryMessage
62+
[BestFriend]
63+
internal sealed class TelemetryException : TelemetryMessage
6164
{
6265
public readonly Exception Exception;
6366
public TelemetryException(Exception exception)
@@ -70,7 +73,8 @@ public TelemetryException(Exception exception)
7073
/// <summary>
7174
/// Message with metric value and it properites
7275
/// </summary>
73-
public sealed class TelemetryMetric : TelemetryMessage
76+
[BestFriend]
77+
internal sealed class TelemetryMetric : TelemetryMessage
7478
{
7579
public readonly string Name;
7680
public readonly double Value;

src/Microsoft.ML.Data/Commands/DataCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ public abstract class ArgumentsBase
5656
public KeyValuePair<string, IComponentFactory<IDataView, IDataTransform>>[] Transform;
5757
}
5858

59-
public abstract class ImplBase<TArgs> : ICommand
59+
[BestFriend]
60+
internal abstract class ImplBase<TArgs> : ICommand
6061
where TArgs : ArgumentsBase
6162
{
6263
protected readonly IHost Host;

0 commit comments

Comments
 (0)