pull/1/head
Ogoun 5 years ago
parent b3827ad830
commit c366bcbd5d

@ -1,10 +1,4 @@
using System;
using System.Linq;
using Xunit;
using ZeroLevel.Services.Microservices.Dump;
using ZeroLevel.UnitTests.Models;
namespace ZeroLevel.UnitTests
namespace ZeroLevel.UnitTests
{
// In developing, not working!
public class DumpTests

@ -1,87 +0,0 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading;
using ZeroLevel.Services.Collections;
using System.Collections.Concurrent;
namespace ZeroLevel.Services.Utils
{
public class MultiHandler<T>
: IDisposable
{
private class Executor
{
public Thread Thread;
public Action<T> Handle;
public Func<int> Count;
public bool Canceled;
}
private RoundRobinCollection<Executor> _handlers = new RoundRobinCollection<Executor>();
private readonly object _lock_handlers = new object();
public MultiHandler(Action<T> handler, int size)
{
for (int i = 0; i < size; i++)
{
var t = new Thread((s) =>
{
var queue = new BlockingCollection<T>();
var executor = new Executor
{
Handle = data =>
{
queue.Add(data);
},
Count = () => queue.Count,
Thread = Thread.CurrentThread,
Canceled = false
};
lock (_lock_handlers)
{
((RoundRobinCollection<Executor>)s).Add(executor);
}
try
{
while (!executor.Canceled)
{
T obj;
if (queue.TryTake(out obj, 500))
{
handler(obj);
}
}
queue.Dispose();
}
catch (Exception ex)
{
Log.Error(ex, "[MultiHandler] Loop fault");
}
});
t.IsBackground = true;
t.Start(_handlers);
}
}
public void Append(T t)
{
_handlers.MoveNextAndHandle(h => h.Handle(t));
}
private int Count => _handlers.Source.Sum(h => h.Count());
public void WaitForEmpty()
{
while (Count > 0)
{
Thread.Sleep(300);
}
}
public void Dispose()
{
foreach (var h in _handlers.Source) h.Canceled = true;
}
}
}

@ -2,20 +2,20 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Description>Infrastructure layer tools set.
<Description>Infrastructure layer tool set.
</Description>
<Authors>ogoun</Authors>
<Company>ogoun</Company>
<AssemblyVersion>3.1.8.0</AssemblyVersion>
<PackageReleaseNotes>Fixing and extending</PackageReleaseNotes>
<AssemblyVersion>3.1.9.0</AssemblyVersion>
<PackageReleaseNotes>Fix bugs, append Multiprocessor class</PackageReleaseNotes>
<PackageProjectUrl>https://github.com/ogoun/Zero/wiki</PackageProjectUrl>
<Copyright>Copyright Ogoun 2019</Copyright>
<Copyright>Copyright Ogoun 2020</Copyright>
<PackageLicenseUrl></PackageLicenseUrl>
<PackageIconUrl>https://raw.githubusercontent.com/ogoun/Zero/master/zero.png</PackageIconUrl>
<RepositoryUrl>https://github.com/ogoun/Zero</RepositoryUrl>
<RepositoryType>GitHub</RepositoryType>
<Version>3.1.8</Version>
<FileVersion>3.1.8.0</FileVersion>
<Version>3.1.9</Version>
<FileVersion>3.1.9.0</FileVersion>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>

Loading…
Cancel
Save

Powered by TurnKey Linux.