DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Public Attributes | Protected Member Functions | Properties | Private Member Functions | Private Attributes | List of all members
Deveel.Data.Diagnostics.ThreadedQueue< TMessage > Class Template Referenceabstract
Inheritance diagram for Deveel.Data.Diagnostics.ThreadedQueue< TMessage >:

Public Member Functions

void Dispose ()
 

Public Attributes

const int DefaultThreadCount = 2
 

Protected Member Functions

 ThreadedQueue ()
 
abstract void Consume (TMessage message)
 
void Enqueue (TMessage message)
 
virtual void Dispose (bool disposing)
 

Properties

virtual int ThreadCount [get]
 

Private Member Functions

 ~ThreadedQueue ()
 
void Start ()
 
void Stop ()
 
void RouteMessages ()
 

Private Attributes

readonly Queue< TMessage > messageQueue
 
List< Thread > threads
 
bool started
 
bool route
 
AutoResetEvent reset
 
bool disposed
 

Detailed Description

Type Constraints
TMessage :class 

Definition at line 26 of file ThreadedQueue.cs.

Constructor & Destructor Documentation

Deveel.Data.Diagnostics.ThreadedQueue< TMessage >.ThreadedQueue ( )
inlineprotected

Definition at line 43 of file ThreadedQueue.cs.

43  {
44 #if PCL
45  cancellationTokenSource = new CancellationTokenSource();
46  cancellationToken = cancellationTokenSource.Token;
47 #endif
48 
49  messageQueue = new Queue<TMessage>();
50  }
readonly Queue< TMessage > messageQueue
Deveel.Data.Diagnostics.ThreadedQueue< TMessage >.~ThreadedQueue ( )
inlineprivate

Definition at line 52 of file ThreadedQueue.cs.

52  {
53  Dispose(false);
54  }

Member Function Documentation

abstract void Deveel.Data.Diagnostics.ThreadedQueue< TMessage >.Consume ( TMessage  message)
protectedpure virtual
void Deveel.Data.Diagnostics.ThreadedQueue< TMessage >.Dispose ( )
inline

Definition at line 157 of file ThreadedQueue.cs.

157  {
158  Dispose(true);
159  GC.SuppressFinalize(this);
160  }
virtual void Deveel.Data.Diagnostics.ThreadedQueue< TMessage >.Dispose ( bool  disposing)
inlineprotectedvirtual

Reimplemented in Deveel.Data.Diagnostics.EventRegistry.

Definition at line 162 of file ThreadedQueue.cs.

162  {
163  if (disposed) {
164  if (disposing) {
165  Stop();
166  }
167 
168 #if PCL
169  tasks = null;
170 #else
171  threads = null;
172 #endif
173  disposed = true;
174  }
175  }
void Deveel.Data.Diagnostics.ThreadedQueue< TMessage >.Enqueue ( TMessage  message)
inlineprotected

Definition at line 144 of file ThreadedQueue.cs.

144  {
145  Start();
146 
147  if (!route)
148  return;
149 
150  lock (((ICollection) messageQueue).SyncRoot) {
151  messageQueue.Enqueue(message);
152  }
153 
154  reset.Set();
155  }
readonly Queue< TMessage > messageQueue
void Deveel.Data.Diagnostics.ThreadedQueue< TMessage >.RouteMessages ( )
inlineprivate

Definition at line 128 of file ThreadedQueue.cs.

128  {
129  while (route) {
130  reset.WaitOne();
131 
132  TMessage message;
133 
134  lock (((ICollection) messageQueue).SyncRoot) {
135  message = messageQueue.Dequeue();
136  }
137 
138  Consume(message);
139  }
140  }
abstract void Consume(TMessage message)
readonly Queue< TMessage > messageQueue
void Deveel.Data.Diagnostics.ThreadedQueue< TMessage >.Start ( )
inlineprivate

Definition at line 60 of file ThreadedQueue.cs.

60  {
61  if (started)
62  return;
63 
64 
65 #if PCL
66  tasks = new List<Task>();
67 #else
68  threads = new List<Thread>(ThreadCount);
69 #endif
70 
71  for (int i = 0; i < ThreadCount; i++) {
72 #if PCL
73  tasks.Add(new Task(RouteMessages, cancellationToken));
74 #else
75  var thread = new Thread(RouteMessages) {
76  IsBackground = true,
77  Name = String.Format("{0}.QueueConsumer {1}", GetType().Name, i)
78  };
79 
80  threads.Add(thread);
81 #endif
82  }
83 
84  route = true;
85  reset = new AutoResetEvent(false);
86 
87 #if PCL
88  foreach (var task in tasks) {
89  task.Start();
90  }
91 #else
92  foreach (var thread in threads) {
93  thread.Start();
94  }
95 #endif
96 
97  started = true;
98  }
A long string in the system.
void Deveel.Data.Diagnostics.ThreadedQueue< TMessage >.Stop ( )
inlineprivate

Definition at line 100 of file ThreadedQueue.cs.

100  {
101  route = false;
102 
103  if (!started)
104  return;
105 
106 #if PCL
107  cancellationTokenSource.Cancel(true);
108 
109  foreach (var task in tasks) {
110  try {
111  task.Wait(300);
112  } catch (TaskCanceledException) {
113  }
114  }
115 #else
116  foreach (var thread in threads) {
117  try {
118  thread.Join(300);
119  thread.Interrupt();
120  } catch (ThreadInterruptedException) {
121  }
122  }
123 #endif
124 
125  started = false;
126  }

Member Data Documentation

const int Deveel.Data.Diagnostics.ThreadedQueue< TMessage >.DefaultThreadCount = 2

Definition at line 41 of file ThreadedQueue.cs.

bool Deveel.Data.Diagnostics.ThreadedQueue< TMessage >.disposed
private

Definition at line 39 of file ThreadedQueue.cs.

readonly Queue<TMessage> Deveel.Data.Diagnostics.ThreadedQueue< TMessage >.messageQueue
private

Definition at line 27 of file ThreadedQueue.cs.

AutoResetEvent Deveel.Data.Diagnostics.ThreadedQueue< TMessage >.reset
private

Definition at line 37 of file ThreadedQueue.cs.

bool Deveel.Data.Diagnostics.ThreadedQueue< TMessage >.route
private

Definition at line 36 of file ThreadedQueue.cs.

bool Deveel.Data.Diagnostics.ThreadedQueue< TMessage >.started
private

Definition at line 35 of file ThreadedQueue.cs.

List<Thread> Deveel.Data.Diagnostics.ThreadedQueue< TMessage >.threads
private

Definition at line 33 of file ThreadedQueue.cs.

Property Documentation

virtual int Deveel.Data.Diagnostics.ThreadedQueue< TMessage >.ThreadCount
get

Definition at line 56 of file ThreadedQueue.cs.


The documentation for this class was generated from the following file: