Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

Commit

Permalink
Attempt to add a generic config type to all of the classes to ease co…
Browse files Browse the repository at this point in the history
…nfiguration usage.
  • Loading branch information
DJGosnell committed Sep 15, 2016
1 parent bc3c824 commit 5f8c537
Show file tree
Hide file tree
Showing 39 changed files with 199 additions and 163 deletions.
16 changes: 8 additions & 8 deletions src/DtronixMessageQueue.Tests.Performance/MqPerformanceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public MqPerformanceTest(string[] args) {


private static void StartClient(int total_loops, int total_messages, int total_frames, int frame_size) {
var cl = new MqClient<SimpleMqSession>(new MqSocketConfig() {
var cl = new MqClient<SimpleMqSession, MqConfig>(new MqConfig() {
Ip = "127.0.0.1",
Port = 2828
});
Expand All @@ -79,7 +79,7 @@ private static void StartClient(int total_loops, int total_messages, int total_f
double[] total_values = {0, 0, 0};

for (int i = 0; i < total_frames; i++) {
message.Add(new MqFrame(SequentialBytes(frame_size), MqFrameType.More, (MqSocketConfig)cl.Config));
message.Add(new MqFrame(SequentialBytes(frame_size), MqFrameType.More, (MqConfig)cl.Config));
}

cl.IncomingMessage += (sender, args) => {
Expand Down Expand Up @@ -133,12 +133,12 @@ private static void StartClient(int total_loops, int total_messages, int total_f
}

private static void StartServer(int total_messages, int total_clients) {
var server = new MqServer<SimpleMqSession>(new MqSocketConfig() {
var server = new MqServer<SimpleMqSession, MqConfig>(new MqConfig() {
Ip = "127.0.0.1",
Port = 2828
});

var builder = new MqMessageWriter((MqSocketConfig) server.Config);
var builder = new MqMessageWriter((MqConfig) server.Config);
builder.Write("COMPLETE");

var complete_message = builder.ToMessage(true);
Expand Down Expand Up @@ -190,7 +190,7 @@ private static void StartServer(int total_messages, int total_clients) {


static void MqInProcessTest() {
var config = new MqSocketConfig {
var config = new MqConfig {
Ip = "127.0.0.1",
Port = 2828
};
Expand Down Expand Up @@ -230,8 +230,8 @@ static void MqInProcessTest() {
Console.ReadLine();
}

private static void MqInProcessPerformanceTests(int runs, int loops, MqMessage message, MqSocketConfig config) {
var server = new MqServer<SimpleMqSession>(config);
private static void MqInProcessPerformanceTests(int runs, int loops, MqMessage message, MqConfig config) {
var server = new MqServer<SimpleMqSession, MqConfig>(config);
server.Start();

double[] total_values = {0, 0, 0};
Expand All @@ -241,7 +241,7 @@ private static void MqInProcessPerformanceTests(int runs, int loops, MqMessage m
var wait = new AutoResetEvent(false);
var complete_test = new AutoResetEvent(false);

var client = new MqClient<SimpleMqSession>(config);
var client = new MqClient<SimpleMqSession, MqConfig>(config);

Console.WriteLine("| Build | Messages | Msg Bytes | Milliseconds | Msg/sec | MBps |");
Console.WriteLine("|---------|------------|-----------|--------------|------------|----------|");
Expand Down
13 changes: 7 additions & 6 deletions src/DtronixMessageQueue.Tests.Performance/RpcPerformanceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace DtronixMessageQueue.Tests.Performance {
class RpcPerformanceTest {
public RpcPerformanceTest(string[] args) {
var config = new MqSocketConfig() {
var config = new RpcConfig {
Ip = "127.0.0.1",
Port = 2828
};
Expand All @@ -26,18 +26,19 @@ public RpcPerformanceTest(string[] args) {
}


private void RpcSingleProcessTest(int runs, int loops, MqSocketConfig config, RpcTestType type) {
var server = new RpcServer<SimpleRpcSession>(config);
private void RpcSingleProcessTest(int runs, int loops, RpcConfig config, RpcTestType type) {
var server = new RpcServer<SimpleRpcSession, RpcConfig>(config);
TestService test_service;
double[] total_values = { 0, 0 };
var sw = new Stopwatch();
var wait = new AutoResetEvent(false);
var complete_test = new AutoResetEvent(false);
var client = new RpcClient<SimpleRpcSession>(config);
var client = new RpcClient<SimpleRpcSession, RpcConfig>(config);

server.Connected += (sender, args) => {

test_service = new TestService();
args.Session.AddService(test_service);

test_service.Completed += (o, session) => {
sw.Stop();
var mode = "Release";
Expand All @@ -53,7 +54,7 @@ private void RpcSingleProcessTest(int runs, int loops, MqSocketConfig config, Rp

wait.Set();
};
args.Session.AddService(test_service);

};


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using DtronixMessageQueue.Rpc;

namespace DtronixMessageQueue.Tests.Performance.Services.Server {
public interface ICalculatorService : IRemoteService <SimpleRpcSession>{
public interface ICalculatorService : IRemoteService <SimpleRpcSession, RpcConfig>{
int Add(int number_1, int number_2);
int Subtract(int number_1, int number_2);
int Multiply(int number_1, int number_2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private void VerifyComplete() {

}

internal interface ITestService : IRemoteService<SimpleRpcSession> {
internal interface ITestService : IRemoteService<SimpleRpcSession, RpcConfig> {
void TestNoReturn();
int TestIncrement();
void TestSetup(int calls);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DtronixMessageQueue.Tests.Performance {
public class SimpleMqSession : MqSession<SimpleMqSession> {
public class SimpleMqSession : MqSession<SimpleMqSession, MqConfig> {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

namespace DtronixMessageQueue.Tests.Performance {

public class SimpleRpcSession : RpcSession<SimpleRpcSession> {
public class SimpleRpcSession : RpcSession<SimpleRpcSession, RpcConfig> {
}
}
12 changes: 6 additions & 6 deletions src/DtronixMessageQueue.Tests/Mq/MqClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,17 @@ public void Client_notifies_server_closing_session() {

[Fact]
public void Client_times_out() {
var client_config = new MqSocketConfig {
var client_config = new MqConfig {
Ip = Config.Ip,
Port = Config.Port,
PingFrequency = 60000
};


Client = new MqClient<SimpleMqSession> (client_config);
Client = new MqClient<SimpleMqSession, MqConfig> (client_config);

Config.PingTimeout = 500;
Server = new MqServer<SimpleMqSession>(Config);
Server = new MqServer<SimpleMqSession, MqConfig>(Config);


Client.Closed += (sender, args) => {
Expand All @@ -217,17 +217,17 @@ public void Client_times_out() {

[Fact]
public void Client_prevents_times_out() {
var client_config = new MqSocketConfig {
var client_config = new MqConfig {
Ip = Config.Ip,
Port = Config.Port,
PingFrequency = 100
};


Client = new MqClient<SimpleMqSession>(client_config);
Client = new MqClient<SimpleMqSession, MqConfig>(client_config);

Config.PingTimeout = 200;
Server = new MqServer<SimpleMqSession>(Config);
Server = new MqServer<SimpleMqSession, MqConfig>(Config);


Client.Closed += (sender, args) => {
Expand Down
2 changes: 1 addition & 1 deletion src/DtronixMessageQueue.Tests/Mq/MqFrameBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class MqFrameBuilderTests {
private MqFrame last_frame;
private MqFrame more_frame;
private MqFrameBuilder frame_builder;
private MqSocketConfig config = new MqSocketConfig();
private MqConfig config = new MqConfig();
private MqFrame command_frame;
private MqFrame ping_frame;

Expand Down
2 changes: 1 addition & 1 deletion src/DtronixMessageQueue.Tests/Mq/MqFrameTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class MqFrameTests {
private MqFrame actual_frame;
private byte[] actual_bytes;
private byte[] expected_bytes;
MqSocketConfig config = new MqSocketConfig();
MqConfig config = new MqConfig();

public MqFrameTests() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class MqMessageWriterReaderTests {
public ITestOutputHelper Output;
private MqMessageWriter message_builder;
private MqMessageReader message_reader;
private MqSocketConfig config = new MqSocketConfig();
private MqConfig config = new MqConfig();

private const string FillerText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

Expand Down
12 changes: 6 additions & 6 deletions src/DtronixMessageQueue.Tests/Mq/MqTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ public class MqTestsBase : IDisposable {
private Random random = new Random();
public ITestOutputHelper Output;

public MqServer<SimpleMqSession> Server { get; protected set; }
public MqClient<SimpleMqSession> Client { get; protected set; }
public MqServer<SimpleMqSession, MqConfig> Server { get; protected set; }
public MqClient<SimpleMqSession, MqConfig> Client { get; protected set; }
public int Port { get; }

protected MqSocketConfig Config;
protected MqConfig Config;

public Exception LastException { get; set; }

Expand All @@ -26,13 +26,13 @@ public MqTestsBase(ITestOutputHelper output) {
this.Output = output;
Port = FreeTcpPort();

Config = new MqSocketConfig {
Config = new MqConfig {
Ip = "127.0.0.1",
Port = Port
};

Server = new MqServer<SimpleMqSession>(Config);
Client = new MqClient<SimpleMqSession>(Config);
Server = new MqServer<SimpleMqSession, MqConfig>(Config);
Client = new MqClient<SimpleMqSession, MqConfig>(Config);
}


Expand Down
2 changes: 1 addition & 1 deletion src/DtronixMessageQueue.Tests/Mq/SimpleMqSession.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace DtronixMessageQueue.Tests.Mq {
public class SimpleMqSession : MqSession<SimpleMqSession> {
public class SimpleMqSession : MqSession<SimpleMqSession, MqConfig> {
}
}
12 changes: 6 additions & 6 deletions src/DtronixMessageQueue.Tests/Rpc/RpcTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public class RpcTestsBase : IDisposable {
private Random random = new Random();
public ITestOutputHelper Output;

public RpcServer<SimpleRpcSession> Server { get; protected set; }
public RpcClient<SimpleRpcSession> Client { get; protected set; }
public RpcServer<SimpleRpcSession, RpcConfig> Server { get; protected set; }
public RpcClient<SimpleRpcSession, RpcConfig> Client { get; protected set; }
public int Port { get; }

protected MqSocketConfig Config;
protected RpcConfig Config;

public Exception LastException { get; set; }

Expand All @@ -27,13 +27,13 @@ public RpcTestsBase(ITestOutputHelper output) {
this.Output = output;
Port = FreeTcpPort();

Config = new MqSocketConfig {
Config = new RpcConfig {
Ip = "127.0.0.1",
Port = Port
};

Server = new RpcServer<SimpleRpcSession>(Config);
Client = new RpcClient<SimpleRpcSession>(Config);
Server = new RpcServer<SimpleRpcSession, RpcConfig>(Config);
Client = new RpcClient<SimpleRpcSession, RpcConfig>(Config);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public int LongRunningTask(int number_1, int number_2, CancellationToken token)
}
}

public interface ICalculatorService : IRemoteService<SimpleRpcSession> {
public interface ICalculatorService : IRemoteService<SimpleRpcSession, RpcConfig> {
int Add(int number_1, int number_2);
int Subtract(int number_1, int number_2);
int Multiply(int number_1, int number_2);
Expand Down
2 changes: 1 addition & 1 deletion src/DtronixMessageQueue.Tests/Rpc/SimpleRpcSession.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using DtronixMessageQueue.Rpc;

namespace DtronixMessageQueue.Tests.Rpc {
public class SimpleRpcSession : RpcSession<SimpleRpcSession> {
public class SimpleRpcSession : RpcSession<SimpleRpcSession, RpcConfig> {
}
}
3 changes: 2 additions & 1 deletion src/DtronixMessageQueue/DtronixMessageQueue.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@
<Compile Include="MqMessageReader.cs" />
<Compile Include="MqMessageWriter.cs" />
<Compile Include="MqSession.cs" />
<Compile Include="MqSocketConfig.cs" />
<Compile Include="MqConfig.cs" />
<Compile Include="Rpc\IRemoteService.cs" />
<Compile Include="Rpc\RpcClient.cs" />
<Compile Include="Rpc\RpcConfig.cs" />
<Compile Include="Rpc\RpcMessageType.cs" />
<Compile Include="Rpc\RpcProxy.cs" />
<Compile Include="Rpc\RpcRemoteException.cs" />
Expand Down
5 changes: 3 additions & 2 deletions src/DtronixMessageQueue/IncomingMessageEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ namespace DtronixMessageQueue {
/// <summary>
/// Event args for when a new message has been processed and is ready for usage.
/// </summary>
public class IncomingMessageEventArgs<TSession> : EventArgs
where TSession : MqSession<TSession>, new() {
public class IncomingMessageEventArgs<TSession, TConfig> : EventArgs
where TSession : MqSession<TSession, TConfig>, new()
where TConfig : MqConfig {

/// <summary>
/// Messages ready to be read.
Expand Down
17 changes: 9 additions & 8 deletions src/DtronixMessageQueue/MqClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ namespace DtronixMessageQueue {
/// <summary>
/// Client used to connect to a remote message queue server.
/// </summary>
public class MqClient<TSession> : SocketClient<TSession>
where TSession : MqSession<TSession>, new() {
public class MqClient<TSession, TConfig> : SocketClient<TSession, TConfig>
where TSession : MqSession<TSession, TConfig>, new()
where TConfig : MqConfig {

/// <summary>
/// Internal postmaster.
/// </summary>
private readonly MqPostmaster<TSession> postmaster;
private readonly MqPostmaster<TSession, TConfig> postmaster;

/// <summary>
/// Event fired when a new message arrives at the mailbox.
/// </summary>
public event EventHandler<IncomingMessageEventArgs<TSession>> IncomingMessage;
public event EventHandler<IncomingMessageEventArgs<TSession, TConfig>> IncomingMessage;

/// <summary>
/// Timer used to verify that the sessions are still connected.
Expand All @@ -30,20 +31,20 @@ public class MqClient<TSession> : SocketClient<TSession>
/// <summary>
/// Initializes a new instance of a message queue.
/// </summary>
public MqClient(MqSocketConfig config) : base(config) {
public MqClient(TConfig config) : base(config) {

// Override the default connection limit and read/write workers.
config.MaxConnections = 1;
config.MaxReadWriteWorkers = 4;
timeout_timer = new Timer(TimeoutCallback);
postmaster = new MqPostmaster<TSession>(config);
postmaster = new MqPostmaster<TSession, TConfig>(config);

Setup();
}

protected override void OnConnect(TSession session) {
// Start the timeout timer.
var ping_frequency = ((MqSocketConfig) Config).PingFrequency;
var ping_frequency = ((MqConfig) Config).PingFrequency;

if (ping_frequency > 0) {
timeout_timer.Change(ping_frequency/2, ping_frequency);
Expand Down Expand Up @@ -73,7 +74,7 @@ private void TimeoutCallback(object state) {
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The event object containing the mailbox to retrieve the message from.</param>
private void OnIncomingMessage(object sender, IncomingMessageEventArgs<TSession> e) {
private void OnIncomingMessage(object sender, IncomingMessageEventArgs<TSession, TConfig> e) {
IncomingMessage?.Invoke(sender, e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using DtronixMessageQueue.Socket;

namespace DtronixMessageQueue {
public class MqSocketConfig : SocketConfig {
public class MqConfig : SocketConfig {
private int max_read_write_workers = 4;

/// <summary>
Expand Down
Loading

0 comments on commit 5f8c537

Please sign in to comment.