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/TestPipeLine/Source/SourceService.cs

90 lines
2.5 KiB

5 years ago
using System;
5 years ago
using System.Net;
5 years ago
using System.Threading;
using ZeroLevel;
using ZeroLevel.Network;
using ZeroLevel.Services.Applications;
namespace Source
{
public class SourceService
: BaseZeroService
{
protected override void StartAction()
{
ReadServiceInfo();
AutoregisterInboxes(UseHost());
5 years ago
Exchange.RoutesStorage.Set("test.processor", new IPEndPoint(IPAddress.Loopback, 8801));
/*Sheduller.RemindEvery(TimeSpan.FromMilliseconds(100), () =>
5 years ago
{
if (Exchange.Send("test.processor", "handle", Environment.TickCount))
{
Interlocked.Increment(ref _proceed);
}
5 years ago
});*/
try
{
using (var waiter = new ManualResetEventSlim(false))
{
while (true)
{
try
{
var ir = Exchange.GetConnection("test.processor")?.Request<long, bool>("handle"
, Environment.TickCount
, s =>
{
Interlocked.Increment(ref _proceed);
waiter.Set();
});
5 years ago
if (ir == null || ir == false)
5 years ago
{
Thread.Sleep(300);
waiter.Set();
}
}
catch
{
Thread.Sleep(300);
waiter.Set();
}
waiter.Wait(5000);
waiter.Reset();
}
}
}
catch
{
Thread.Sleep(300);
}
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;
}
}
}

Powered by TurnKey Linux.