Revert "借助MMF实现StarServer快速查询"

This reverts commit 4605c479bd.
This commit is contained in:
大石头 2022-02-13 23:08:21 +08:00
parent e1a10dad39
commit 97cfc63dda
5 changed files with 12 additions and 35 deletions

View File

@ -1,24 +1,20 @@
using System;
using System.IO.MemoryMappedFiles;
using System.Linq;
using NewLife;
using NewLife.Serialization;
using NewLife.Threading;
using Stardust;
using Stardust.Models;
namespace StarAgent
{
internal class InfoService
{
/// <summary>本地应用服务管理</summary>
public ServiceManager Manager { get; set; }
MemoryMappedFile _mmf;
TimerX _timer2;
public void Start()
{
_mmf = MemoryMappedFile.CreateOrOpen("MMF_Star", 1024);
var mapName = "MMF_Star";
_mmf = MemoryMappedFile.CreateNew(mapName, 1024 * 1024);
_timer2 = new TimerX(DoWork, null, 0, 5_000);
}
@ -31,19 +27,11 @@ namespace StarAgent
private void DoWork(Object state)
{
var set = StarSetting.Current;
var inf = AgentInfo.GetLocal();
inf.Server = set.Server;
inf.Services = Manager?.Services.Select(e => e.Name).ToArray();
var buf = Binary.FastWrite(inf).ReadBytes();
//var buf = Binary.FastWrite(inf).ReadBytes();
//var view = _mmf.CreateViewAccessor();
//view.Write(0, buf.Length);
//view.WriteArray(4, buf, 0, buf.Length);
var ms = _mmf.CreateViewStream(0, 1024, MemoryMappedFileAccess.Write);
Binary.FastWrite(inf, ms);
var view = _mmf.CreateViewAccessor();
view.WriteArray(0, buf, 0, buf.Length);
}
}
}

View File

@ -208,7 +208,7 @@ namespace StarAgent
_Manager.Start();
_infoService = new InfoService { Manager = _Manager };
_infoService = new InfoService();
_infoService.Start();
base.StartWork(reason);

View File

@ -31,7 +31,6 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="..\StarAgent\InfoService.cs" Link="InfoService.cs" />
<Compile Include="..\StarAgent\Program.cs" Link="Program.cs" />
<Compile Include="..\StarAgent\Setting.cs" Link="Setting.cs" />
<Compile Include="..\StarAgent\StarService.cs" Link="StarService.cs" />

View File

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Linq;
using System.Net;
using System.Net.Http;
@ -14,9 +13,12 @@ using NewLife.Http;
using NewLife.Log;
using NewLife.Messaging;
using NewLife.Net;
using NewLife.Reflection;
using NewLife.Remoting;
using NewLife.Serialization;
using Stardust.Models;
#if !NET40
using TaskEx = System.Threading.Tasks.Task;
#endif
namespace Stardust
{
@ -32,7 +34,6 @@ namespace Stardust
private readonly AgentInfo _local;
private ApiClient _client;
private MemoryMappedFile _mmf;
#endregion
#region
@ -57,21 +58,12 @@ namespace Stardust
var set = StarSetting.Current;
if (set.Debug) _client.EncoderLog = XTrace.Log;
var mapName = "MMF_Star";
_mmf = MemoryMappedFile.CreateOrOpen(mapName, 1024 * 1024);
}
/// <summary>获取信息</summary>
/// <returns></returns>
public AgentInfo GetInfo()
{
Init();
var ms = _mmf.CreateViewStream(0, 1024, MemoryMappedFileAccess.Read);
var inf = Binary.FastRead<AgentInfo>(ms);
if (inf != null && inf.ProcessId > 0) return inf;
var task = GetInfoAsync();
if (task.Wait(500)) return task.Result;
@ -339,7 +331,7 @@ namespace Stardust
/// <param name="target">目标目录</param>
public static Task ProbeAsync(String url = null, String version = null, String target = null)
{
return Task.Run(() =>
return TaskEx.Run(() =>
{
var client = new LocalStarClient();
client.ProbeAndInstall(url, version, target);

View File

@ -104,9 +104,7 @@ namespace Test
//}
var client = new LocalStarClient();
//client.ProbeAndInstall(null, "1.6");
var inf = client.GetInfo();
XTrace.WriteLine(inf.ToJson(true));
client.ProbeAndInstall(null, "1.6");
//var p = Process.GetCurrentProcess();
//var name = p.MainModule.FileName;