Skip to content

Commit

Permalink
- refactored available worker to specify thread id
Browse files Browse the repository at this point in the history
  • Loading branch information
eben-roux committed Jun 30, 2015
1 parent 34cf27e commit 52395db
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Shuttle.ESB.Core/Processing/Distributor/AvailableWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ public class AvailableWorker
{
public Guid Identifier { get; private set; }
public string InboxWorkQueueUri { get; private set; }
public int ManagedThreadId { get; private set; }
public DateTime WorkerSendDate { get; private set; }

public AvailableWorker(WorkerThreadAvailableCommand command)
{
Identifier = command.Identifier;
InboxWorkQueueUri = command.InboxWorkQueueUri;
ManagedThreadId = command.ManagedThreadId;
WorkerSendDate = command.DateSent;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ public interface IWorkerAvailabilityManager

void WorkerAvailable(WorkerThreadAvailableCommand message);
void WorkerStarted(WorkerStartedEvent message);
void RemoveByThread(WorkerThreadAvailableCommand message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,14 @@ public void WorkerStarted(WorkerStartedEvent message)
.ToList();
}
}

public void RemoveByThread(WorkerThreadAvailableCommand message)
{
lock (_padlock)
{
GetAvailableWorkers(message.InboxWorkQueueUri)
.RemoveAll(candidate => candidate.ManagedThreadId == message.ManagedThreadId);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public void ProcessMessage(HandlerContext<WorkerThreadAvailableCommand> context)
? context.Configuration.Inbox.DistributeSendCount
: 5;

context.Configuration.WorkerAvailabilityManager.RemoveByThread(context.Message);

for (var i = 0; i < distributeSendCount; i++)
{
context.Configuration.WorkerAvailabilityManager.WorkerAvailable(context.Message);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading;
using Shuttle.Core.Infrastructure;

namespace Shuttle.ESB.Core
Expand Down Expand Up @@ -32,6 +33,7 @@ public void Waiting(IThreadState state)
{
Identifier = identifier,
InboxWorkQueueUri = bus.Configuration.Inbox.WorkQueue.Uri.ToString(),
ManagedThreadId = Thread.CurrentThread.ManagedThreadId,
DateSent = DateTime.Now
},
c => c.WithRecipient(bus.Configuration.Worker.DistributorControlInboxWorkQueue));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class WorkerThreadAvailableCommand
{
public Guid Identifier { get; set; }
public string InboxWorkQueueUri { get; set; }
public int ManagedThreadId { get; set; }
public DateTime DateSent { get; set; }
}
}
4 changes: 2 additions & 2 deletions Shuttle.ESB.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
[assembly: AssemblyTitle("Shuttle.ESB.Core for .NET Framework 4.5.1")]
#endif

[assembly: AssemblyVersion("3.6.2.0")]
[assembly: AssemblyVersion("3.6.3.0")]
[assembly: AssemblyCopyright("Copyright © Eben Roux 2010-2015")]
[assembly: AssemblyProduct("Shuttle.ESB")]
[assembly: AssemblyCompany("Shuttle")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyInformationalVersion("3.6.2")]
[assembly: AssemblyInformationalVersion("3.6.3")]
[assembly: ComVisible(false)]

0 comments on commit 52395db

Please sign in to comment.