-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
2,955 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System; | ||
using System.Threading; | ||
using Metrics; | ||
using NLog; | ||
|
||
namespace ThreadSupport | ||
{ | ||
|
||
/// <summary> | ||
/// This BaseThread class creates a BlockingQueue of type ThreadMessage for the given thread. The name of the queue is | ||
/// specified on the constructor. | ||
/// | ||
/// Additionally: | ||
/// this class creates and instantiates a thread, using the derived classes Runner() method. | ||
/// this class adds the name of the queue to the queuemanager singleton object | ||
/// | ||
/// </summary> | ||
public abstract class BaseThread | ||
{ | ||
private volatile bool _running; | ||
private static readonly Logger logger = LogManager.GetCurrentClassLogger(); | ||
|
||
|
||
public string Qname { get; } | ||
|
||
public bool Running | ||
{ | ||
get { return _running; } | ||
set { _running = value; } | ||
} | ||
|
||
private readonly BlockingQueue<ThreadMessage> _myQueue; | ||
public BlockingQueue<ThreadMessage> MyQueue | ||
{ | ||
get { return _myQueue; } | ||
} | ||
|
||
public string ThreadName { get; } | ||
|
||
private Thread _thisThread; | ||
public Thread ThisThread | ||
{ | ||
get { return _thisThread; } | ||
} | ||
|
||
private static readonly QueueManager qm = QueueManager.Instance; | ||
|
||
protected BaseThread(String threadName, String queueName) | ||
{ | ||
// Set our name | ||
ThreadName = threadName; | ||
|
||
logger.Trace(ThreadName + "|Starting"); | ||
|
||
// Create our queue | ||
_myQueue = new BlockingQueue<ThreadMessage>(); | ||
_myQueue.SetupQueueStats(queueName); | ||
|
||
// Name our queue statistics counter | ||
//_myQueue.SetupQueueStats(ThreadName + "Q"); | ||
|
||
// Add it to the queuemanager so other threads can easily locate this queue | ||
qm.AddQueue(ref _myQueue, queueName); | ||
Qname = queueName; | ||
|
||
// Fire up the Runner method from the derived class | ||
ThreadStart threadStarter = Runner; | ||
_thisThread = new Thread(threadStarter); | ||
} | ||
|
||
public void Start() | ||
{ | ||
_thisThread.Start(); | ||
} | ||
|
||
protected bool TakeFunc(ThreadMessage tm, int i) | ||
{ | ||
//_myQueue.DecrementQueueItemCounter(); | ||
|
||
if ((tm.Cmd == Defines.ThreadExitMsg)) | ||
{ | ||
//logger.Trace(ThreadName + "|Received Exit Command"); | ||
} | ||
return (tm.Cmd != Defines.ThreadExitMsg); | ||
} | ||
protected abstract void Runner(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace ThreadSupport | ||
{ | ||
public static class Defines | ||
{ | ||
public const int ThreadExitMsg = 1; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd" | ||
autoReload="true" | ||
throwExceptions="false" | ||
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log"> | ||
|
||
<!-- optional, add some variables | ||
https://github.com/nlog/NLog/wiki/Configuration-file#variables | ||
--> | ||
<variable name="myvar" value="myvalue"/> | ||
|
||
<!-- | ||
See https://github.com/nlog/nlog/wiki/Configuration-file | ||
for information on customizing logging rules and outputs. | ||
--> | ||
<targets> | ||
<target xsi:type="xsi:type="OutputDebugString" name="ODS" layout="${longdate} ${uppercase:${level}} ${message}"/> | ||
<!-- | ||
add your targets here | ||
See https://github.com/nlog/NLog/wiki/Targets for possible targets. | ||
See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers. | ||
--> | ||
<!-- | ||
Write events to a file with the date in the filename. | ||
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log" | ||
layout="${longdate} ${uppercase:${level}} ${message}" /> | ||
--> | ||
</targets> | ||
<rules> | ||
<!-- add your logging rules here --> | ||
<!-- | ||
Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace) to "f" | ||
<logger name="*" minlevel="Debug" writeTo="f" /> | ||
--> | ||
<logger name="*" minlevel="Trace" writeTo="ODS" /> | ||
</rules> | ||
</nlog> |
Oops, something went wrong.