pull/1/head
a.bozhenov 5 years ago
parent 4f721fdbc8
commit 9d03789686

@ -31,7 +31,8 @@ namespace TestApp
StoreConnection("mytest", new IPEndPoint(IPAddress.Loopback, 8800)); StoreConnection("mytest", new IPEndPoint(IPAddress.Loopback, 8800));
StoreConnection("mymeta", new IPEndPoint(IPAddress.Loopback, 8801)); StoreConnection("mymeta", new IPEndPoint(IPAddress.Loopback, 8801));
Sheduller.RemindEvery(TimeSpan.FromSeconds(1), () => int count = 0;
Sheduller.RemindWhile(TimeSpan.FromSeconds(1), () =>
{ {
var client = ConnectToService("mytest"); var client = ConnectToService("mytest");
client.Send("pum"); client.Send("pum");
@ -42,6 +43,8 @@ namespace TestApp
s => Log.Info($"Response: {s}")); s => Log.Info($"Response: {s}"));
client.Request<string>("now", s => Log.Info($"Response date: {s}")); client.Request<string>("now", s => Log.Info($"Response date: {s}"));
client.Request<string>(BaseSocket.DEFAULT_REQUEST_WITHOUT_ARGS_INBOX, s => Log.Info($"Response ip: {s}")); client.Request<string>(BaseSocket.DEFAULT_REQUEST_WITHOUT_ARGS_INBOX, s => Log.Info($"Response ip: {s}"));
count++;
return count > 3;
}); });
Sheduller.RemindEvery(TimeSpan.FromSeconds(3), () => Sheduller.RemindEvery(TimeSpan.FromSeconds(3), () =>

@ -1,6 +1,4 @@
using System; using ZeroLevel;
using System.Net;
using ZeroLevel;
namespace TestApp namespace TestApp
{ {
@ -10,8 +8,8 @@ namespace TestApp
{ {
Bootstrap.Startup<MyService>(args, Bootstrap.Startup<MyService>(args,
() => Configuration.ReadSetFromIniFile("config.ini")) () => Configuration.ReadSetFromIniFile("config.ini"))
//.ReadServiceInfo() .EnableConsoleLog(ZeroLevel.Services.Logging.LogLevel.System | ZeroLevel.Services.Logging.LogLevel.FullDebug)
//.UseDiscovery() .UseDiscovery()
.Run() .Run()
.WaitWhileStatus(ZeroServiceStatus.Running) .WaitWhileStatus(ZeroServiceStatus.Running)
.Stop(); .Stop();

@ -8,7 +8,6 @@ ServiceType=site
[log] [log]
path=logs path=logs
console=true
[webapi] [webapi]
port=8183 port=8183

@ -21,7 +21,7 @@ namespace ZeroLevel.Discovery
Injector.Default.Register<RouteTable>(routeTable); Injector.Default.Register<RouteTable>(routeTable);
var socketPort = Configuration.Default.First<int>("socketport"); var socketPort = Configuration.Default.First<int>("socketport");
_exInbox = UseHost(socketPort); _exInbox = UseHost(socketPort);
_exInbox.RegisterInbox<IEnumerable<ServiceEndpointsInfo>>("services", (_, __) => routeTable.Get()); _exInbox.RegisterInbox<IEnumerable<ServiceEndpointsInfo>>("services", (_) => routeTable.Get());
_exInbox.RegisterInbox<ZeroServiceInfo, InvokeResult>("register", (client, info) => routeTable.Append(info, client)); _exInbox.RegisterInbox<ZeroServiceInfo, InvokeResult>("register", (client, info) => routeTable.Append(info, client));
} }

@ -4,7 +4,11 @@
{ {
private static void Main(string[] args) private static void Main(string[] args)
{ {
Bootstrap.Startup<DiscoveryService>(args); Bootstrap.Startup<DiscoveryService>(args)
.Run()
.WaitWhileStatus(ZeroServiceStatus.Running)
.Stop();
Bootstrap.Shutdown();
} }
} }
} }

@ -3,6 +3,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Reflection; using System.Reflection;
using ZeroLevel.Services.Logging;
namespace ZeroLevel namespace ZeroLevel
{ {
@ -38,6 +39,8 @@ namespace ZeroLevel
public BootstrapFluent ReadServiceInfo() { _service?.ReadServiceInfo(); return this; } public BootstrapFluent ReadServiceInfo() { _service?.ReadServiceInfo(); return this; }
public BootstrapFluent ReadServiceInfo(IConfigurationSet config) { _service?.ReadServiceInfo(config); return this; } public BootstrapFluent ReadServiceInfo(IConfigurationSet config) { _service?.ReadServiceInfo(config); 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()

@ -60,8 +60,8 @@ namespace ZeroLevel.Network
_sendThread = new Thread(SendFramesJob); _sendThread = new Thread(SendFramesJob);
_sendThread.IsBackground = true; _sendThread.IsBackground = true;
_sendThread.Start(); _sendThread.Start();
_stream.BeginRead(_buffer, 0, DEFAULT_RECEIVE_BUFFER_SIZE, ReceiveAsyncCallback, null);
Working(); Working();
_stream.BeginRead(_buffer, 0, DEFAULT_RECEIVE_BUFFER_SIZE, ReceiveAsyncCallback, null);
} }
#region API #region API
@ -295,7 +295,8 @@ namespace ZeroLevel.Network
_parser.Push(_buffer, count); _parser.Push(_buffer, count);
_last_rw_time = DateTime.UtcNow.Ticks; _last_rw_time = DateTime.UtcNow.Ticks;
} }
if (Status == SocketClientStatus.Working) if (Status == SocketClientStatus.Working
|| Status == SocketClientStatus.Initialized)
{ {
_stream.BeginRead(_buffer, 0, DEFAULT_RECEIVE_BUFFER_SIZE, ReceiveAsyncCallback, null); _stream.BeginRead(_buffer, 0, DEFAULT_RECEIVE_BUFFER_SIZE, ReceiveAsyncCallback, null);
} }

Loading…
Cancel
Save

Powered by TurnKey Linux.