Skip to content

Commit

Permalink
Service / Simplification Documentation and Release Prep (#809)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottf authored Aug 17, 2023
1 parent 607e4c9 commit c91ec41
Show file tree
Hide file tree
Showing 82 changed files with 873 additions and 342 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ opts.AsyncErrorEventHandler += (sender, args) =>
opts.ServerDiscoveredEventHandler += (sender, args) =>
{
Console.WriteLine("A new server has joined the cluster:");
Console.WriteLine(" " + String.Join(", ", args.Conn.DiscoveredServers));
Console.WriteLine(" " + string.Join(", ", args.Conn.DiscoveredServers));
};

opts.ClosedEventHandler += (sender, args) =>
Expand Down
6 changes: 3 additions & 3 deletions src/Benchmarks/JsMulti/JsMultiTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void Main(string[] args)
Run(new Context(args), false, true);
}

public static IList<Stats> Run(String[] args) {
public static IList<Stats> Run(string[] args) {
return Run(new Context(args), false, true);
}

Expand Down Expand Up @@ -382,11 +382,11 @@ private static void _ack(Stats stats, Msg m) {
stats.Stop();
}

private static void Report(string label, int total, String message) {
private static void Report(string label, int total, string message) {
Log(label, message + " " + Stats.Format(total));
}

private static int ReportMaybe(string label, Context ctx, int total, int unReported, String message) {
private static int ReportMaybe(string label, Context ctx, int total, int unReported, string message) {
if (unReported >= ctx.ReportFrequency) {
Report(label, total, message);
return 0; // there are 0 unreported now
Expand Down
32 changes: 16 additions & 16 deletions src/Benchmarks/JsMulti/Settings/Arguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@ public class Arguments
public const string Individual = "individual";
public const string Shared = "shared";

private IList<String> args = new List<String>();
private IList<string> args = new List<string>();

public static Arguments Instance() { return new Arguments(); }
public static Arguments Instance(String subject) { return Instance().Subject(subject); }
public static Arguments PubSync(String subject) { return Instance().Action(JsmAction.PubSync).Subject(subject); }
public static Arguments PubAsync(String subject) { return Instance().Action(JsmAction.PubAsync).Subject(subject); }
public static Arguments PubCore(String subject) { return Instance().Action(JsmAction.PubCore).Subject(subject); }
public static Arguments SubPush(String subject) { return Instance().Action(JsmAction.SubPush).Subject(subject); }
public static Arguments SubQueue(String subject) { return Instance().Action(JsmAction.SubQueue).Subject(subject); }
public static Arguments SubPull(String subject) { return Instance().Action(JsmAction.SubPull).Subject(subject); }
public static Arguments SubPullQueue(String subject) { return Instance().Action(JsmAction.SubPullQueue).Subject(subject); }

private Arguments Add(String option) {
public static Arguments Instance(string subject) { return Instance().Subject(subject); }
public static Arguments PubSync(string subject) { return Instance().Action(JsmAction.PubSync).Subject(subject); }
public static Arguments PubAsync(string subject) { return Instance().Action(JsmAction.PubAsync).Subject(subject); }
public static Arguments PubCore(string subject) { return Instance().Action(JsmAction.PubCore).Subject(subject); }
public static Arguments SubPush(string subject) { return Instance().Action(JsmAction.SubPush).Subject(subject); }
public static Arguments SubQueue(string subject) { return Instance().Action(JsmAction.SubQueue).Subject(subject); }
public static Arguments SubPull(string subject) { return Instance().Action(JsmAction.SubPull).Subject(subject); }
public static Arguments SubPullQueue(string subject) { return Instance().Action(JsmAction.SubPullQueue).Subject(subject); }

private Arguments Add(string option) {
args.Add("-" + option);
return this;
}

private Arguments Add(String option, Object value) {
private Arguments Add(string option, Object value) {
args.Add("-" + option);
args.Add(value.ToString());
return this;
Expand All @@ -52,7 +52,7 @@ public Arguments Action(JsmAction action) {
return Add("a", action);
}

public Arguments Server(String server) {
public Arguments Server(string server) {
return Add("s", server);
}

Expand All @@ -65,7 +65,7 @@ public Arguments LatencyFlag(bool lf) {
}

// todo
// public ArgumentBuilder OptionsFactory(String optionsFactoryClassName) {
// public ArgumentBuilder OptionsFactory(string optionsFactoryClassName) {
// return Add("of", optionsFactoryClassName);
// }

Expand Down Expand Up @@ -93,7 +93,7 @@ public Arguments Replicas(int replicas) {
return Add("c", replicas);
}

public Arguments Subject(String subject) {
public Arguments Subject(string subject) {
if (subject == null) {
return this;
}
Expand Down Expand Up @@ -162,7 +162,7 @@ public string[] ToArray()
}

public void PrintCommandLine(TextWriter ps) {
foreach (String a in args) {
foreach (string a in args) {
ps.Write(a + " ");
}
ps.WriteLine("");
Expand Down
2 changes: 1 addition & 1 deletion src/NATS.Client/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ public IPAddress ClientIP
clientIp = info.ClientIp;
}

return !String.IsNullOrEmpty(clientIp) ? IPAddress.Parse(clientIp) : null;
return !string.IsNullOrEmpty(clientIp) ? IPAddress.Parse(clientIp) : null;
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/NATS.Client/IConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,6 @@ public interface IConnection : IDisposable
/// <summary>
/// Get a consumer context for a specific named stream and specific named consumer.
/// Verifies that the stream and consumer exist.
/// EXPERIMENTAL API SUBJECT TO CHANGE
/// </summary>
/// <param name="streamName">the name of the stream</param>
/// <param name="consumerName">the name of the consumer</param>
Expand All @@ -1118,7 +1117,6 @@ public interface IConnection : IDisposable
/// <summary>
/// Get a consumer context for a specific named stream and specific named consumer.
/// Verifies that the stream and consumer exist.
/// EXPERIMENTAL API SUBJECT TO CHANGE
/// </summary>
/// <param name="streamName">the name of the stream</param>
/// <param name="consumerName">the name of the consumer</param>
Expand Down
8 changes: 4 additions & 4 deletions src/NATS.Client/Internals/JsonUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,14 @@ public static List<string> OptionalStringList(JSONNode node, string field)
}

[Obsolete("Method name replaced with proper spelling, 'StringStringDictionary'")]
public static Dictionary<string, string> StringStringDictionay(JSONNode node, string field)
public static IDictionary<string, string> StringStringDictionay(JSONNode node, string field)
{
return StringStringDictionary(node, field, false);
}

public static Dictionary<string, string> StringStringDictionary(JSONNode node, string field, bool nullIfEmpty = false)
public static IDictionary<string, string> StringStringDictionary(JSONNode node, string field, bool nullIfEmpty = false)
{
Dictionary<string, string> temp = new Dictionary<string, string>();
IDictionary<string, string> temp = new Dictionary<string, string>();
JSONNode meta = node[field];
foreach (string key in meta.Keys)
{
Expand Down Expand Up @@ -244,7 +244,7 @@ public static void AddField(JSONObject o, string field, JSONNode value)
}
}

public static void AddField(JSONObject o, String fname, Dictionary<string, string> dictionary) {
public static void AddField(JSONObject o, string fname, IDictionary<string, string> dictionary) {
if (dictionary != null && dictionary.Count > 0) {
JSONObject d = new JSONObject();
foreach (string key in dictionary.Keys)
Expand Down
20 changes: 10 additions & 10 deletions src/NATS.Client/Internals/JwtUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public static class JwtUtils
/// <pre>
/// NKey userKey = NKey.createUser(new SecureRandom());
/// NKey signingKey = loadFromSecretStore();
/// String jwt = IssueUserJWT(signingKey, accountId, userKey.EncodedPublicKey);
/// String.format(JwtUtils.NatsUserJwtFormat, jwt, userKey.EncodedSeed);
/// string jwt = IssueUserJWT(signingKey, accountId, userKey.EncodedPublicKey);
/// string.format(JwtUtils.NatsUserJwtFormat, jwt, userKey.EncodedSeed);
/// </pre>
/// </summary>
public static readonly string NatsUserJwtFormat =
Expand Down Expand Up @@ -112,7 +112,7 @@ public static string IssueUserJWT(NkeyPair signingKey, string accountId, string
/// <param name="tags">optional list of tags to be included in the JWT.</param>
/// <param name="issuedAt">the current epoch seconds.</param>
/// <returns>a JWT</returns>
public static string IssueUserJWT(NkeyPair signingKey, string accountId, string publicUserKey, string name, Duration expiration, String[] tags, long issuedAt)
public static string IssueUserJWT(NkeyPair signingKey, string accountId, string publicUserKey, string name, Duration expiration, string[] tags, long issuedAt)
{
return IssueUserJWT(signingKey, publicUserKey, name, expiration, issuedAt, null, new UserClaim(accountId, tags));
}
Expand All @@ -129,7 +129,7 @@ public static string IssueUserJWT(NkeyPair signingKey, string accountId, string
/// <param name="issuedAt">the current epoch seconds.</param>
/// <param name="audience">optional audience</param>
/// <returns>a JWT</returns>
public static string IssueUserJWT(NkeyPair signingKey, string accountId, string publicUserKey, string name, Duration expiration, String[] tags, long issuedAt, string audience)
public static string IssueUserJWT(NkeyPair signingKey, string accountId, string publicUserKey, string name, Duration expiration, string[] tags, long issuedAt, string audience)
{
return IssueUserJWT(signingKey, publicUserKey, name, expiration, issuedAt, audience, new UserClaim(accountId, tags));
}
Expand All @@ -145,7 +145,7 @@ public static string IssueUserJWT(NkeyPair signingKey, string accountId, string
/// <param name="audience">optional audience</param>
/// <param name="nats">the user claim</param>
/// <returns>a JWT</returns>
public static string IssueUserJWT(NkeyPair signingKey, string publicUserKey, string name, Duration expiration, long issuedAt, String audience, UserClaim nats)
public static string IssueUserJWT(NkeyPair signingKey, string publicUserKey, string name, Duration expiration, long issuedAt, string audience, UserClaim nats)
{
// Validate the signingKey:
if (signingKey.Type != Nkeys.PrefixType.Account)
Expand Down Expand Up @@ -226,34 +226,34 @@ public static string issueJWT(NkeyPair signingKey, string publicUserKey, string
/// </summary>
/// <param name="jwt">the encoded jwt</param>
/// <returns>the claim body json</returns>
public static string GetClaimBody(String jwt)
public static string GetClaimBody(string jwt)
{
return FromBase64UrlEncoded(jwt.Split('.')[1]);
}
}

public class UserClaim : JsonSerializable {
public string IssuerAccount; // User
public String[] Tags; // User/GenericFields
public string[] Tags; // User/GenericFields
public string Type = "user"; // User/GenericFields
public int Version = 2; // User/GenericFields
public Permission Pub; // User/UserPermissionLimits/Permissions
public Permission Sub; // User/UserPermissionLimits/Permissions
public ResponsePermission Resp; // User/UserPermissionLimits/Permissions
public String[] Src; // User/UserPermissionLimits/Limits/UserLimits
public string[] Src; // User/UserPermissionLimits/Limits/UserLimits
public IList<TimeRange> Times; // User/UserPermissionLimits/Limits/UserLimits
public string Locale; // User/UserPermissionLimits/Limits/UserLimits
public long Subs = JwtUtils.NoLimit; // User/UserPermissionLimits/Limits/NatsLimits
public long Data = JwtUtils.NoLimit; // User/UserPermissionLimits/Limits/NatsLimits
public long Payload = JwtUtils.NoLimit; // User/UserPermissionLimits/Limits/NatsLimits
public bool BearerToken; // User/UserPermissionLimits
public String[] AllowedConnectionTypes; // User/UserPermissionLimits
public string[] AllowedConnectionTypes; // User/UserPermissionLimits

public UserClaim(string issuerAccount) {
this.IssuerAccount = issuerAccount;
}

public UserClaim(string issuerAccount, String[] tags) {
public UserClaim(string issuerAccount, string[] tags) {
IssuerAccount = issuerAccount;
Tags = tags;
}
Expand Down
12 changes: 6 additions & 6 deletions src/NATS.Client/Internals/ServerVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal class ServerVersion : IComparable<ServerVersion> {
readonly int patch;
readonly string extra;

internal ServerVersion(String v) {
internal ServerVersion(string v) {
string[] split = v.Replace("v", "").Replace("-", ".").Split('.');
if (v.StartsWith("v")) {
split = v.Substring(1).Replace("-", ".").Split('.');
Expand Down Expand Up @@ -93,23 +93,23 @@ public int CompareTo(ServerVersion o)
return c;
}

public static bool IsNewer(String v, String than) {
public static bool IsNewer(string v, string than) {
return new ServerVersion(v).CompareTo(new ServerVersion(than)) > 0;
}

public static bool IsSame(String v, String than) {
public static bool IsSame(string v, string than) {
return new ServerVersion(v).CompareTo(new ServerVersion(than)) == 0;
}

public static bool IsOlder(String v, String than) {
public static bool IsOlder(string v, string than) {
return new ServerVersion(v).CompareTo(new ServerVersion(than)) < 0;
}

public static bool IsSameOrOlder(String v, String than) {
public static bool IsSameOrOlder(string v, string than) {
return new ServerVersion(v).CompareTo(new ServerVersion(than)) <= 0;
}

public static bool IsSameOrNewer(String v, String than) {
public static bool IsSameOrNewer(string v, string than) {
return new ServerVersion(v).CompareTo(new ServerVersion(than)) >= 0;
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/NATS.Client/Internals/Validator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal static void Required(object o, string label) {
}
}

internal static void Required<TKey, TValue>(Dictionary<TKey, TValue> d, string label) {
internal static void Required<TKey, TValue>(IDictionary<TKey, TValue> d, string label) {
if (d == null || d.Count == 0) {
throw new ArgumentException($"{label} cannot be null or empty.");
}
Expand All @@ -50,16 +50,16 @@ internal static string ValidateSubject(string s, bool required)
return ValidateSubject(s, "Subject", required, false);
}

public static String ValidateSubject(String subject, String label, bool required, bool cantEndWithGt) {
public static string ValidateSubject(string subject, string label, bool required, bool cantEndWithGt) {
if (EmptyAsNull(subject) == null) {
if (required) {
throw new ArgumentException($"{label} cannot be null or empty.");
}
return null;
}
String[] segments = subject.Split('.');
string[] segments = subject.Split('.');
for (int x = 0; x < segments.Length; x++) {
String segment = segments[x];
string segment = segments[x];
if (segment.Equals(">")) {
if (cantEndWithGt || x != segments.Length - 1) { // if it can end with gt, gt must be last segment
throw new ArgumentException(label + " cannot contain '>'");
Expand Down Expand Up @@ -445,7 +445,7 @@ internal static long ValidateNotNegative(long l, string label) {
// Helpers
// ----------------------------------------------------------------------------------------------------

public static bool NullOrEmpty(String s)
public static bool NullOrEmpty(string s)
{
return string.IsNullOrWhiteSpace(s);
}
Expand Down Expand Up @@ -607,7 +607,7 @@ public static string EmptyAsNull(string s)
return NullOrEmpty(s) ? null : s;
}

public static String EmptyOrNullAs(String s, String ifEmpty) {
public static string EmptyOrNullAs(string s, string ifEmpty) {
return NullOrEmpty(s) ? ifEmpty : s;
}

Expand Down Expand Up @@ -658,7 +658,7 @@ public static string ValidateSemVer(string s, string label, bool required)
});
}

public static bool IsSemVer(String s)
public static bool IsSemVer(string s)
{
return Regex.IsMatch(s, SemVerPattern);
}
Expand Down
1 change: 0 additions & 1 deletion src/NATS.Client/JetStream/ApiConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ internal static class ApiConstants
internal const string AllowRollupHdrs = "allow_rollup_hdrs";
internal const string AllowDirect = "allow_direct";
internal const string Api = "api";
internal const string ApiUrl = "api_url";
internal const string AuthRequired = "auth_required";
internal const string AverageProcessingTime = "average_processing_time";
internal const string Backoff = "backoff";
Expand Down
1 change: 0 additions & 1 deletion src/NATS.Client/JetStream/BaseConsumeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ namespace NATS.Client.JetStream
/// <summary>
/// Base Consume Options are provided to customize the way the consume and
/// fetch operate. It is the base class for ConsumeOptions and FetchConsumeOptions.
/// SIMPLIFICATION IS EXPERIMENTAL AND SUBJECT TO CHANGE
/// </summary>
public class BaseConsumeOptions
{
Expand Down
1 change: 0 additions & 1 deletion src/NATS.Client/JetStream/ConsumeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace NATS.Client.JetStream
{
/// <summary>
/// Consume Options are provided to customize the consume operation.
/// SIMPLIFICATION IS EXPERIMENTAL AND SUBJECT TO CHANGE
/// </summary>
public class ConsumeOptions : BaseConsumeOptions
{
Expand Down
4 changes: 2 additions & 2 deletions src/NATS.Client/JetStream/ConsumerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public sealed class ConsumerConfiguration : JsonSerializable
internal bool? _headersOnly;
internal bool? _memStorage;
internal IList<Duration> _backoff;
internal Dictionary<string, string> _metadata;
internal IDictionary<string, string> _metadata;

public DeliverPolicy DeliverPolicy => _deliverPolicy ?? DeliverPolicy.All;
public AckPolicy AckPolicy => _ackPolicy ?? AckPolicy.Explicit;
Expand Down Expand Up @@ -87,7 +87,7 @@ public sealed class ConsumerConfiguration : JsonSerializable
public bool HeadersOnly => _headersOnly ?? false;
public bool MemStorage => _memStorage ?? false;
public IList<Duration> Backoff => _backoff ?? new List<Duration>();
public Dictionary<string, string> Metadata => _metadata ?? new Dictionary<string, string>();
public IDictionary<string, string> Metadata => _metadata ?? new Dictionary<string, string>();

internal ConsumerConfiguration(string json) : this(JSON.Parse(json)) {}

Expand Down
2 changes: 1 addition & 1 deletion src/NATS.Client/JetStream/ConsumerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal OrderedPullSubscribeOptionsBuilder(string streamName, ConsumerConfigura
}

/// <summary>
/// SIMPLIFICATION IS EXPERIMENTAL AND SUBJECT TO CHANGE
/// Implementation of IConsumerContext
/// </summary>
internal class ConsumerContext : IConsumerContext, SimplifiedSubscriptionMaker
{
Expand Down
1 change: 0 additions & 1 deletion src/NATS.Client/JetStream/FetchConsumeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace NATS.Client.JetStream
{
/// <summary>
/// Consume Options are provided to customize the consume operation.
/// SIMPLIFICATION IS EXPERIMENTAL AND SUBJECT TO CHANGE
/// </summary>
public class FetchConsumeOptions : BaseConsumeOptions
{
Expand Down
Loading

0 comments on commit c91ec41

Please sign in to comment.