Mercurial > hg > Database > Christie-sharp
changeset 30:96fc5e71274e
Run HelloWorld
author | riono <e165729@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 06 Apr 2021 22:02:23 +0900 |
parents | 0cd2684e401b |
children | 6399d784c6d1 |
files | Christie_net.csproj Test/Example/HelloWorld/FinishHelloWorld.cs Test/Example/HelloWorld/HelloWorldCodeGear.cs Test/Example/HelloWorld/StartHelloWorld.cs Test/RewritingTest/AttributeCheck.cs codegear/CodeGear.cs codegear/InputDataGear.cs codegear/StartCodeGear.cs daemon/ChristieDaemon.cs daemon/Config.cs daemon/IncomingTcpConnection.cs daemon/ThreadPoolExecutors.cs datagear/LocalDataGearManager.cs datagear/command/Command.cs datagear/dg/DataGear.cs |
diffstat | 15 files changed, 118 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/Christie_net.csproj Thu Jan 21 01:18:26 2021 +0900 +++ b/Christie_net.csproj Tue Apr 06 22:02:23 2021 +0900 @@ -3,15 +3,11 @@ <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.1</TargetFramework> - <StartupObject>Christie_net.AttributeCheck</StartupObject> + <StartupObject>Christie_net.Test.Example.HelloWorld.StartHelloWorld</StartupObject> </PropertyGroup> <ItemGroup> <PackageReference Include="MessagePack" Version="2.1.143" /> </ItemGroup> - <ItemGroup> - <Folder Include="Test" /> - </ItemGroup> - </Project>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Test/Example/HelloWorld/FinishHelloWorld.cs Tue Apr 06 22:02:23 2021 +0900 @@ -0,0 +1,15 @@ +using System; +using Christie_net.annotation; +using Christie_net.codegear; + +namespace Christie_net.Test.Example.HelloWorld { +public class FinishHelloWorld : CodeGear { + [Take] public string hello; + [Take] public string world; + + public override void Run(CodeGearManager cgm) { + //Console.WriteLine("fin:" + hello + " " + world); + cgm.GetLocalDGM().Finish(); + } +} +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Test/Example/HelloWorld/HelloWorldCodeGear.cs Tue Apr 06 22:02:23 2021 +0900 @@ -0,0 +1,15 @@ +using System; +using Christie_net.annotation; +using Christie_net.codegear; + +namespace Christie_net.Test.Example.HelloWorld { +public class HelloWorldCodeGear : CodeGear { + [Take] public string helloWorld; + + public override void Run(CodeGearManager cgm) { + Console.Write(helloWorld + " "); + cgm.Setup(new HelloWorldCodeGear()); + cgm.GetLocalDGM().Put(helloWorld, helloWorld); + } +} +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Test/Example/HelloWorld/StartHelloWorld.cs Tue Apr 06 22:02:23 2021 +0900 @@ -0,0 +1,19 @@ +using System; +using System.Threading; +using Christie_net.codegear; + +namespace Christie_net.Test.Example.HelloWorld { +public class StartHelloWorld : StartCodeGear { + + public StartHelloWorld(CodeGearManager cgm) : base(cgm) { } + + public static void Main(string[] args) { + CodeGearManager cgm = CreateCgm(10000); + cgm.Setup(new HelloWorldCodeGear()); + cgm.Setup(new FinishHelloWorld()); + cgm.GetLocalDGM().Put("helloWorld", "hello"); + cgm.GetLocalDGM().Put("helloWorld", "world"); + + } +} +} \ No newline at end of file
--- a/Test/RewritingTest/AttributeCheck.cs Thu Jan 21 01:18:26 2021 +0900 +++ b/Test/RewritingTest/AttributeCheck.cs Tue Apr 06 22:02:23 2021 +0900 @@ -24,6 +24,7 @@ // } Console.WriteLine("name;" + field.Name + " check;" + Attribute.IsDefined(field, typeof(PeekFrom))); + Console.WriteLine("type:" + field.FieldType); if (Attribute.IsDefined(field, typeof(PeekFrom))) { PeekFrom peekFrom = (PeekFrom) field.GetCustomAttribute(typeof(PeekFrom)); Console.WriteLine("param*" + peekFrom.name);
--- a/codegear/CodeGear.cs Thu Jan 21 01:18:26 2021 +0900 +++ b/codegear/CodeGear.cs Tue Apr 06 22:02:23 2021 +0900 @@ -30,15 +30,15 @@ foreach (var field in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Instance)) { if (Attribute.IsDefined(field, typeof(Take))) { - SetCommand(CommandType.TAKE, "local", field.Name, new DataGear<object>(field.GetType())); + SetCommand(CommandType.TAKE, "local", field.Name, new DataGear<object>(field.FieldType)); } else if (Attribute.IsDefined(field, typeof(Peek))) { - SetCommand(CommandType.PEEK, "local", field.Name, new DataGear<object>(field.GetType())); + SetCommand(CommandType.PEEK, "local", field.Name, new DataGear<object>(field.FieldType)); } else if (Attribute.IsDefined(field, typeof(TakeFrom))) { TakeFrom attri = (TakeFrom) field.GetCustomAttribute(typeof(TakeFrom)); - SetCommand(CommandType.TAKE, attri.name, field.Name, new DataGear<object>(field.GetType())); + SetCommand(CommandType.TAKE, attri.name, field.Name, new DataGear<object>(field.FieldType)); } else if (Attribute.IsDefined(field, typeof(PeekFrom))) { PeekFrom attri = (PeekFrom) field.GetCustomAttribute(typeof(PeekFrom)); - SetCommand(CommandType.PEEK, attri.name, field.Name, new DataGear<object>(field.GetType())); + SetCommand(CommandType.PEEK, attri.name, field.Name, new DataGear<object>(field.FieldType)); } }
--- a/codegear/InputDataGear.cs Thu Jan 21 01:18:26 2021 +0900 +++ b/codegear/InputDataGear.cs Tue Apr 06 22:02:23 2021 +0900 @@ -42,7 +42,8 @@ // commandが実行されるたびにDecrementする private void Decriment() { lock (syncObject) { - if (Interlocked.Decrement(ref count) == 0) { + Interlocked.Decrement(ref count); + if (count == 0) { SetInputValue(); SubmitCG(); } @@ -54,7 +55,7 @@ } public void SetInputValue() { - foreach (var field in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | + foreach (var field in cg.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly | BindingFlags.Instance)) { if (Attribute.IsDefined(field, typeof(Take)) || Attribute.IsDefined(field, typeof(TakeFrom)) || Attribute.IsDefined(field, typeof(Peek)) || Attribute.IsDefined(field, typeof(PeekFrom))) {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/codegear/StartCodeGear.cs Tue Apr 06 22:02:23 2021 +0900 @@ -0,0 +1,29 @@ +using System.Collections.Concurrent; +using System.Threading; +using Christie_net.daemon; + +namespace Christie_net.codegear { +public abstract class StartCodeGear : CodeGear { + private static ConcurrentDictionary<int, CodeGearManager> cgmList = new ConcurrentDictionary<int, CodeGearManager>(); + private static ThreadPoolExecutors threadPoolExecutors = new ThreadPoolExecutors(); + private static int cgmCount = 1; + + public StartCodeGear(CodeGearManager cgm) { + cgm.Setup(this); + } + + public static CodeGearManager CreateCgm(int localPort) { + CodeGearManager cgm = new CodeGearManager(cgmCount, threadPoolExecutors, cgmList, localPort); + cgmList.TryAdd(cgmCount++, cgm); + return cgm; + } + + public static CodeGearManager GetCgm(int number) { + return cgmList[number]; + } + + public override void Run(CodeGearManager cgm) { + + } +} +} \ No newline at end of file
--- a/daemon/ChristieDaemon.cs Thu Jan 21 01:18:26 2021 +0900 +++ b/daemon/ChristieDaemon.cs Tue Apr 06 22:02:23 2021 +0900 @@ -19,11 +19,10 @@ public void Listen() { try { // listen on any address ipv4/ipv6 - IPHostEntry host = Dns.GetHostEntry("::"); - IPAddress ipAddress = host.AddressList[0]; - IPEndPoint localEndPoint = new IPEndPoint(ipAddress, localPort); + + IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, localPort); - Socket socket = new Socket(ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); + Socket socket = new Socket(AddressFamily.InterNetwork , SocketType.Stream, ProtocolType.Tcp); socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); Console.WriteLine("ChristieDaemon, listen: bind to " + localEndPoint); socket.Bind(localEndPoint);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/daemon/Config.cs Tue Apr 06 22:02:23 2021 +0900 @@ -0,0 +1,8 @@ +namespace Christie_net.daemon { +public class Config { + public int localPort = 10000; + public string logFile = null; + public string MCSTADDR = "224.0.0.1"; + +} +} \ No newline at end of file
--- a/daemon/IncomingTcpConnection.cs Thu Jan 21 01:18:26 2021 +0900 +++ b/daemon/IncomingTcpConnection.cs Tue Apr 06 22:02:23 2021 +0900 @@ -26,7 +26,7 @@ public void Run() { //TODO: Data長がわからないので4096で仮置き - byte[] deserializeCommand = new byte[4096]; + byte[] deserializeCommand = new byte[100000]; while (true) { try {
--- a/daemon/ThreadPoolExecutors.cs Thu Jan 21 01:18:26 2021 +0900 +++ b/daemon/ThreadPoolExecutors.cs Tue Apr 06 22:02:23 2021 +0900 @@ -6,13 +6,15 @@ public class ThreadPoolExecutors { // TODO: どこかしらでThreadPoolの設定をする - public ThreadPoolExecutors() { - + int nWorkerThreads; + int nIOThreads; + ThreadPool.GetMinThreads(out nWorkerThreads, out nIOThreads); + ThreadPool.SetMinThreads(nWorkerThreads, nIOThreads); } - public void CreateThreadPool() { - + public ThreadPoolExecutors(int nWorkerThreads, int nIOThreads) { + ThreadPool.SetMinThreads(nWorkerThreads, nIOThreads); } public void Execute(CodeGearExecutor command) {
--- a/datagear/LocalDataGearManager.cs Thu Jan 21 01:18:26 2021 +0900 +++ b/datagear/LocalDataGearManager.cs Tue Apr 06 22:02:23 2021 +0900 @@ -7,18 +7,25 @@ // 通常はこちらを使用する public override void Put(string key, object data) { DataGear<object> dg = new DataGear<object>(data); - PutRun(key, dg); + Put(key, dg); } - public void PutRun(string key, DataGear<object> dg) { + public void Put(string key, DataGear<object> dg) { Command cm = new CommandBuilder().Init(CommandType.PUT).CgmID(1) .ToDgmName("local").Key(key).Dg(dg).Build(); RunCommand(cm); } + // public void PutRun(string key, DataGear<object> dg) { + // Command cm = new CommandBuilder().Init(CommandType.PUT).CgmID(1) + // .ToDgmName("local").Key(key).Dg(dg).Build(); + // RunCommand(cm); + // } + public override void RunCommand(Command cm) { switch (cm.type) { case CommandType.PUT: + //Console.WriteLine("data:" + cm.key + " dg:" + cm.dg.GetData().ToString()); dataGears.SetData(cm); if (waitList.ContainsKey(cm.key)) { RunCommand(waitList.GetAndRemoveCommand(cm.key)); @@ -45,6 +52,7 @@ private void SetData(Command cm) { cm.SetDg(dataGears.GetData(cm)); + } public override void ResolveWaitCommand(string key, DataGear<object> dg) { }
--- a/datagear/command/Command.cs Thu Jan 21 01:18:26 2021 +0900 +++ b/datagear/command/Command.cs Tue Apr 06 22:02:23 2021 +0900 @@ -1,4 +1,5 @@ using System; +using System.Diagnostics; using System.IO; using Christie_net.codegear; using Christie_net.daemon;
--- a/datagear/dg/DataGear.cs Thu Jan 21 01:18:26 2021 +0900 +++ b/datagear/dg/DataGear.cs Tue Apr 06 22:02:23 2021 +0900 @@ -15,6 +15,7 @@ } public void SetData(T data) { + //Console.WriteLine("data ****" + data.GetType() + " clazz;" + clazz); var dataClazz = data.GetType(); if (dataClazz == clazz) { this.data = data; @@ -38,7 +39,7 @@ return; } - throw new InvalidCastException("datagear cannot set class from" + dataClazz.GetType().Name + " to " + + throw new InvalidCastException("datagear cannot set class from " + dataClazz.GetType().Name + " to " + data.GetType().Name); }