pull/1/head
a.bozhenov 5 years ago
parent 886b2fd5b5
commit 689c12e8dc

@ -1,4 +1,5 @@
using System.Threading; using System;
using System.Threading;
using ZeroLevel; using ZeroLevel;
using ZeroLevel.Network; using ZeroLevel.Network;
using ZeroLevel.Services.Applications; using ZeroLevel.Services.Applications;
@ -12,6 +13,12 @@ namespace Consumer
{ {
ReadServiceInfo(); ReadServiceInfo();
AutoregisterInboxes(UseHost()); AutoregisterInboxes(UseHost());
Sheduller.RemindEvery(TimeSpan.FromSeconds(1), () =>
{
Console.SetCursorPosition(0, 0);
Console.WriteLine(_proceed);
});
} }
protected override void StopAction() protected override void StopAction()

@ -13,6 +13,12 @@ namespace Processor
{ {
ReadServiceInfo(); ReadServiceInfo();
AutoregisterInboxes(UseHost()); AutoregisterInboxes(UseHost());
Sheduller.RemindEvery(TimeSpan.FromSeconds(1), () =>
{
Console.SetCursorPosition(0, 0);
Console.WriteLine(_proceed);
});
} }
protected override void StopAction() protected override void StopAction()

@ -14,7 +14,7 @@ namespace Source
ReadServiceInfo(); ReadServiceInfo();
AutoregisterInboxes(UseHost()); AutoregisterInboxes(UseHost());
Sheduller.RemindEvery(TimeSpan.FromMilliseconds(10), () => Sheduller.RemindEvery(TimeSpan.FromMilliseconds(100), () =>
{ {
if (Exchange.Send("test.processor", "handle", Environment.TickCount)) if (Exchange.Send("test.processor", "handle", Environment.TickCount))
{ {

@ -22,6 +22,11 @@ namespace Watcher
var success = Exchange.RequestBroadcastByGroup<ZeroServiceInfo>("Test", "meta", records => var success = Exchange.RequestBroadcastByGroup<ZeroServiceInfo>("Test", "meta", records =>
{ {
if (records.Any() == false)
{
Log.Info("No services");
}
foreach (var record in records.OrderBy(r=>r.Name)) foreach (var record in records.OrderBy(r=>r.Name))
{ {
sb.Append(record.Name); sb.Append(record.Name);

@ -127,6 +127,7 @@ namespace ZeroLevel.Discovery
foreach (var ep in pair.Value) foreach (var ep in pair.Value)
{ {
_table[pair.Key].Endpoints.Remove(ep); _table[pair.Key].Endpoints.Remove(ep);
Log.Debug($"Removed address {ep}");
} }
} }
var badKeys = _table.Where(f => f.Value.Endpoints.Count == 0) var badKeys = _table.Where(f => f.Value.Endpoints.Count == 0)
@ -135,6 +136,7 @@ namespace ZeroLevel.Discovery
foreach (var badKey in badKeys) foreach (var badKey in badKeys)
{ {
_table.Remove(badKey); _table.Remove(badKey);
Log.Debug($"Removed service {badKey}");
} }
} }
finally finally

@ -343,13 +343,14 @@ namespace ZeroLevel.Services.Applications
{ {
try try
{ {
StartAction();
_state = ZeroServiceStatus.Running; _state = ZeroServiceStatus.Running;
StartAction();
Log.Debug($"[{Name}] Service started"); Log.Debug($"[{Name}] Service started");
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Fatal(ex, $"[{Name}] Failed to start service"); Log.Fatal(ex, $"[{Name}] Failed to start service");
Stop();
} }
} }
} }

@ -42,7 +42,11 @@ namespace ZeroLevel
public BootstrapFluent EnableConsoleLog(LogLevel level = LogLevel.FullStandart) { Log.AddConsoleLogger(level); return this; } public BootstrapFluent EnableConsoleLog(LogLevel level = LogLevel.FullStandart) { Log.AddConsoleLogger(level); return this; }
public ZeroServiceStatus Status { get { return _service.Status; } } public ZeroServiceStatus Status { get { return _service.Status; } }
public IServiceExecution Run() { _service.Start(); return this; } public IServiceExecution Run()
{
_service.Start();
return this;
}
public IServiceExecution Stop() public IServiceExecution Stop()
{ {
try try

@ -27,7 +27,6 @@ namespace ZeroLevel.Network
public Exchange(IZeroService owner) public Exchange(IZeroService owner)
{ {
_owner = owner; _owner = owner;
_cachee.OnBrokenConnection += _cachee_OnBrokenConnection;
} }
#endregion Ctor #endregion Ctor
@ -920,7 +919,7 @@ namespace ZeroLevel.Network
{ {
try try
{ {
if (false == client.Request<Treq, Tresp>(inbox, data, resp => { waiter.Signal(); response.Add(resp); }).Success) if (false == client.Request<Treq, Tresp>(inbox, data, resp => { response.Add(resp); waiter.Signal(); }).Success)
{ {
waiter.Signal(); waiter.Signal();
} }
@ -948,7 +947,7 @@ namespace ZeroLevel.Network
{ {
try try
{ {
if (false == client.Request<Tresp>(inbox, resp => { waiter.Signal(); response.Add(resp); }).Success) if (false == client.Request<Tresp>(inbox, resp => { response.Add(resp); waiter.Signal(); }).Success)
{ {
waiter.Signal(); waiter.Signal();
} }
@ -964,11 +963,6 @@ namespace ZeroLevel.Network
} }
return response; return response;
} }
private void _cachee_OnBrokenConnection(IPEndPoint endpoint)
{
//_aliases.Remove(endpoint); ??? no need
}
#endregion #endregion
public void Dispose() public void Dispose()

@ -8,16 +8,6 @@ namespace ZeroLevel.Network
internal sealed class ExClientServerCachee internal sealed class ExClientServerCachee
: IDisposable : IDisposable
{ {
internal event Action<IPEndPoint> OnBrokenConnection;
private void RiseBrokenConnectionEvent(IPEndPoint endpoint)
{
var e = OnBrokenConnection;
if (e != null)
{
e.Invoke(endpoint);
}
}
private static readonly ConcurrentDictionary<string, ExClient> _clientInstances = new ConcurrentDictionary<string, ExClient>(); private static readonly ConcurrentDictionary<string, ExClient> _clientInstances = new ConcurrentDictionary<string, ExClient>();
private readonly ConcurrentDictionary<string, SocketServer> _serverInstances = new ConcurrentDictionary<string, SocketServer>(); private readonly ConcurrentDictionary<string, SocketServer> _serverInstances = new ConcurrentDictionary<string, SocketServer>();
@ -44,12 +34,8 @@ namespace ZeroLevel.Network
} }
instance = new ExClient(new SocketClient(endpoint, router ?? new Router())); instance = new ExClient(new SocketClient(endpoint, router ?? new Router()));
instance.ForceConnect(); instance.ForceConnect();
if (instance.Status != SocketClientStatus.Initialized && if (instance.Status == SocketClientStatus.Initialized
instance.Status != SocketClientStatus.Working) ||instance.Status == SocketClientStatus.Working)
{
OnBrokenConnection(endpoint);
}
else
{ {
_clientInstances[key] = instance; _clientInstances[key] = instance;
return instance; return instance;
@ -58,12 +44,8 @@ namespace ZeroLevel.Network
else else
{ {
var instance = new ExClient(new SocketClient(endpoint, router ?? new Router())); var instance = new ExClient(new SocketClient(endpoint, router ?? new Router()));
if (instance.Status != SocketClientStatus.Initialized && if (instance.Status == SocketClientStatus.Initialized
instance.Status != SocketClientStatus.Working) || instance.Status == SocketClientStatus.Working)
{
OnBrokenConnection(endpoint);
}
else
{ {
return instance; return instance;
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.