Mercurial > hg > Database > Christie-sharp
changeset 28:84e0b85af821
update CodeGearManager
author | riono <e165729@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 20 Jan 2021 02:21:55 +0900 |
parents | efb06874a34e |
children | 0cd2684e401b |
files | Christie_net.csproj Test/RewritingTest/AttributeCheck.cs Test/RewritingTest/Program.cs annotation/PeekFrom.cs annotation/TakeFrom.cs codegear/CodeGear.cs codegear/CodeGearManager.cs |
diffstat | 7 files changed, 187 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/Christie_net.csproj Tue Jan 19 20:18:32 2021 +0900 +++ b/Christie_net.csproj Wed Jan 20 02:21:55 2021 +0900 @@ -3,7 +3,7 @@ <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.1</TargetFramework> - <StartupObject>TaskCreateOptionTest</StartupObject> + <StartupObject>Christie_net.AttributeCheck</StartupObject> </PropertyGroup> <ItemGroup>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Test/RewritingTest/AttributeCheck.cs Wed Jan 20 02:21:55 2021 +0900 @@ -0,0 +1,32 @@ +using System; +using System.Reflection; +using Christie_net.annotation; + +namespace Christie_net { +public class AttributeCheck { + [Take] private int num = 0; + [Peek] public string name = "riono"; + [PeekFrom("meme")] protected string nextName = "local"; + + public AttributeCheck() { + nextName = "dsaql"; + } + + private static void Main(string[] args) { + AttributeCheck attributeCheck = new AttributeCheck(); + + foreach (var field in attributeCheck.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic + | BindingFlags.DeclaredOnly | BindingFlags.Instance)) { + foreach (var attribute in field.GetCustomAttributes(false)) { + Console.WriteLine(attribute); + + if (attribute.GetType() == typeof(PeekFrom)) { + PeekFrom peekFrom = (PeekFrom) attribute; + + Console.WriteLine("val " + field.GetValue(attributeCheck) ); + } + } + } + } +} +} \ No newline at end of file
--- a/Test/RewritingTest/Program.cs Tue Jan 19 20:18:32 2021 +0900 +++ b/Test/RewritingTest/Program.cs Wed Jan 20 02:21:55 2021 +0900 @@ -1,8 +1,10 @@ using System; +using Christie_net.annotation; namespace Christie_net { -internal class Program { - //[Peek] Test testindex; +public class Program { + [Take] + private int test; private static void Main(string[] args) { Console.WriteLine("Hello World!");
--- a/annotation/PeekFrom.cs Tue Jan 19 20:18:32 2021 +0900 +++ b/annotation/PeekFrom.cs Wed Jan 20 02:21:55 2021 +0900 @@ -5,8 +5,10 @@ public class PeekFrom : Attribute { private string _name; - public string Value() { - return _name; + public PeekFrom(string name) { + _name = name; } + + public string name => _name; } } \ No newline at end of file
--- a/annotation/TakeFrom.cs Tue Jan 19 20:18:32 2021 +0900 +++ b/annotation/TakeFrom.cs Wed Jan 20 02:21:55 2021 +0900 @@ -5,8 +5,10 @@ public class TakeFrom : Attribute { private string _name; - public string Value() { - return _name; + public TakeFrom(string name) { + _name = name; } + + public string name => _name; } } \ No newline at end of file
--- a/codegear/CodeGear.cs Tue Jan 19 20:18:32 2021 +0900 +++ b/codegear/CodeGear.cs Wed Jan 20 02:21:55 2021 +0900 @@ -1,5 +1,111 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using Christie_net.annotation; +using Christie_net.datagear; +using Christie_net.datagear.command; +using Christie_net.datagear.dg; + namespace Christie_net.codegear { public abstract class CodeGear { private InputDataGear idg; + private List<Command> commandList = new List<Command>(); + private CodeGearManager cgm; + private DataGearManager localDgm; + private CodeGearExecutor cge; + + public CodeGear() { + idg = new InputDataGear(this); + } + + protected abstract void Run(CodeGearManager cgm); + + public void Setup(CodeGearManager cgm) { + + } + + public void Setup(CodeGearManager cgm, int priority) { + this.cgm = cgm; + this.cge = new CodeGearExecutor(this, this.cgm, priority); + this.localDgm = cgm.GetLocalDGM(); + + foreach (var field in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic + | BindingFlags.DeclaredOnly | BindingFlags.Instance)) { + foreach (var attribute in field.GetCustomAttributes(false)) { + if (attribute.GetType() == typeof(Take)) { + SetCommand(CommandType.TAKE,"local", field.Name, new DataGear<object>(field.GetType())); + } else if (attribute.GetType() == typeof(Peek)) { + SetCommand(CommandType.PEEK, "local" , field.Name, new DataGear<object>(field.GetType())); + } else if (attribute.GetType() == typeof(TakeFrom)) { + TakeFrom attri = (TakeFrom) attribute; + SetCommand(CommandType.TAKE, attri.name, field.Name, new DataGear<object>(field.GetType())); + } else if (attribute.GetType() == typeof(PeekFrom)) { + PeekFrom attri = (PeekFrom) attribute; + SetCommand(CommandType.PEEK, attri.name, field.Name, new DataGear<object>(field.GetType())); + } + } + } + + //idg.finishInput(cgm, commandList); + } + + public void SetCommand(CommandType type, string toDgmName, string key, DataGear<Object> dg) { + Command command = new CommandBuilder().Init(type).Cg(this) + .CgmID(cgm.cgmID) + .ToDgmName(toDgmName) + .Key(key) + .Dg(dg) + .Build(); + + commandList.Add(command); + } + + public DataGearManager GetLocalDgm() { + return localDgm; + } + + public DataGearManager GetDgm(string dgmName) { + return cgm.GetDGM(dgmName); + } + + public CodeGear Put(string dgmName, string key, object data) { + GetDgm(dgmName).Put(key, data); + return this; + } + + public CodeGear Put(string key, object data) { + localDgm.Put(key, data); + return this; + } + + public bool ContainsDgm(string dgmName) { + return cgm.ContainsDgm(dgmName); + } + + public void Finish(string managerKey) { + if (cgm.GetDgmList().ContainsKey(managerKey)) ; + cgm.GetDgmList()[managerKey].Finish(); + } + + public void Flip(string dgmName, string key) { + foreach (var field in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic + | BindingFlags.DeclaredOnly | BindingFlags.Instance)) { + if (field.Name == key) { + try { + GetDgm(dgmName).Put(key, field.GetValue(this)); + } catch {} + } + } + } + + public InputDataGear GetIdg() { + return idg; + } + + public CodeGearExecutor GetCge() { + return cge; + } } } \ No newline at end of file
--- a/codegear/CodeGearManager.cs Tue Jan 19 20:18:32 2021 +0900 +++ b/codegear/CodeGearManager.cs Wed Jan 20 02:21:55 2021 +0900 @@ -8,7 +8,7 @@ namespace Christie_net.codegear { public class CodeGearManager { private ConcurrentDictionary<string, DataGearManager> dgmList = new ConcurrentDictionary<string, DataGearManager>(); - private ConcurrentDictionary<int, CodeGearManager> cgmList = new ConcurrentDictionary<int, CodeGearManager>(); + private ConcurrentDictionary<int, CodeGearManager> cgmList; private ThreadPoolExecutors threadPoolExecutors; private LocalDataGearManager localDgm = new LocalDataGearManager(); private ConcurrentDictionary<string, IncomingTcpConnection> acceptHash = @@ -40,7 +40,41 @@ } public RemoteDataGearManager CreateRemoteDGM(string dgmName, string address, int port) { - RemoteDataGearManager remote = new RemoteDataGearManager(dgmName, address, port, this); + RemoteDataGearManager remote = new RemoteDataGearManager(address, port, this); + dgmList.TryAdd(dgmName, remote); + + return remote; + } + + public void Submit(CodeGear cg) { + threadPoolExecutors.Execute(cg.GetCge()); + } + + public void Setup(CodeGear cg, int priority = 5) { + cg.Setup(this, priority); + } + + public ConcurrentDictionary<int, CodeGearManager> GetCgmList() { + return cgmList; + } + + public ConcurrentDictionary<string, DataGearManager> GetDgmList() { + return dgmList; + } + + public bool ContainsDgm(string dgmName) { + return dgmList.ContainsKey(dgmName); + } + + public void SetAccept(string key, IncomingTcpConnection incoming) { + acceptHash.TryAdd(key, incoming); + } + + // broadcast data + public void PutAllDgm(string key, Object data) { + foreach (var dgm in dgmList.Values) { + dgm.Put(key, data); + } } } } \ No newline at end of file