You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/Tests/TestPipeLine/Processor/ProcessorService.cs

78 lines
2.0 KiB

1 year ago
using System.Collections.Concurrent;
5 years ago
using System.Net;
5 years ago
using ZeroLevel;
using ZeroLevel.Network;
using ZeroLevel.Services.Applications;
namespace Processor
{
public class ProcessorService
: BaseZeroService
{
5 years ago
private Thread _processThread;
5 years ago
protected override void StartAction()
{
5 years ago
_processThread = new Thread(HandleIncoming);
_processThread.IsBackground = true;
_processThread.Start();
5 years ago
ReadServiceInfo();
5 years ago
AutoregisterInboxes(UseHost(8801));
Exchange.RoutesStorage.Set("test.consumer", new IPEndPoint(IPAddress.Loopback, 8802));
5 years ago
Sheduller.RemindEvery(TimeSpan.FromSeconds(1), () =>
{
Console.SetCursorPosition(0, 0);
Console.WriteLine(_proceed);
});
5 years ago
}
5 years ago
private void HandleIncoming()
{
while (_incoming.IsCompleted == false)
{
5 years ago
long data;
if (_incoming.TryTake(out data, 100))
{
var next = (int)(data ^ Interlocked.Increment(ref _proceed));
Exchange.Request<int, bool>("test.consumer", "handle", next, result => { });
}
5 years ago
}
}
5 years ago
protected override void StopAction()
{
}
[ExchangeReplierWithoutArg("meta")]
public ZeroServiceInfo GetCounter(ISocketClient client)
{
return ServiceInfo;
}
private long _proceed = 0;
[ExchangeReplierWithoutArg("Proceed")]
public long GetProceedItemsCount(ISocketClient client)
{
return _proceed;
}
[ExchangeReplierWithoutArg("ping")]
public bool Ping(ISocketClient client)
{
return true;
}
5 years ago
BlockingCollection<long> _incoming = new BlockingCollection<long>();
5 years ago
5 years ago
[ExchangeReplier("handle")]
public bool Handler(ISocketClient client, long data)
5 years ago
{
5 years ago
return _incoming.TryAdd(data);
5 years ago
}
}
}

Powered by TurnKey Linux.