Mercurial > hg > Database > Christie-sharp
changeset 29:0cd2684e401b
update InputDataGear and more
author | riono <e165729@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 21 Jan 2021 01:18:26 +0900 |
parents | 84e0b85af821 |
children | 96fc5e71274e |
files | Test/RewritingTest/AttributeCheck.cs codegear/CodeGear.cs codegear/CodeGearExecutor.cs codegear/InputDataGear.cs daemon/AcceptThread.cs daemon/Connection.cs daemon/IncomingTcpConnection.cs daemon/ThreadPoolExecutors.cs datagear/DataGearManager.cs datagear/LocalDataGearManager.cs datagear/RemoteDataGearManager.cs datagear/command/TakeCommand.cs |
diffstat | 12 files changed, 98 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- a/Test/RewritingTest/AttributeCheck.cs Wed Jan 20 02:21:55 2021 +0900 +++ b/Test/RewritingTest/AttributeCheck.cs Thu Jan 21 01:18:26 2021 +0900 @@ -15,16 +15,18 @@ 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); + foreach (var field in attributeCheck.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic + | BindingFlags.DeclaredOnly | BindingFlags.Instance)) { + // if (attribute.GetType() == typeof(PeekFrom)) { + // PeekFrom peekFrom = (PeekFrom) attribute; + // + // Console.WriteLine("val " + field.GetValue(attributeCheck) ); + // } - if (attribute.GetType() == typeof(PeekFrom)) { - PeekFrom peekFrom = (PeekFrom) attribute; - - Console.WriteLine("val " + field.GetValue(attributeCheck) ); - } + Console.WriteLine("name;" + field.Name + " check;" + Attribute.IsDefined(field, typeof(PeekFrom))); + if (Attribute.IsDefined(field, typeof(PeekFrom))) { + PeekFrom peekFrom = (PeekFrom) field.GetCustomAttribute(typeof(PeekFrom)); + Console.WriteLine("param*" + peekFrom.name); } } }
--- a/codegear/CodeGear.cs Wed Jan 20 02:21:55 2021 +0900 +++ b/codegear/CodeGear.cs Thu Jan 21 01:18:26 2021 +0900 @@ -20,35 +20,29 @@ idg = new InputDataGear(this); } - protected abstract void Run(CodeGearManager cgm); + public abstract void Run(CodeGearManager cgm); - public void Setup(CodeGearManager cgm) { - - } - - public void Setup(CodeGearManager cgm, int priority) { + public void Setup(CodeGearManager cgm, int priority = 5) { 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())); - } + 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())); + } else if (Attribute.IsDefined(field, typeof(Peek))) { + SetCommand(CommandType.PEEK, "local", field.Name, new DataGear<object>(field.GetType())); + } 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())); + } 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())); } } - //idg.finishInput(cgm, commandList); + idg.FinishInput(cgm, commandList); } public void SetCommand(CommandType type, string toDgmName, string key, DataGear<Object> dg) { @@ -90,8 +84,8 @@ } public void Flip(string dgmName, string key) { - foreach (var field in this.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic - | BindingFlags.DeclaredOnly | BindingFlags.Instance)) { + 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));
--- a/codegear/CodeGearExecutor.cs Wed Jan 20 02:21:55 2021 +0900 +++ b/codegear/CodeGearExecutor.cs Thu Jan 21 01:18:26 2021 +0900 @@ -2,7 +2,7 @@ public class CodeGearExecutor { private CodeGear cg; private CodeGearManager cgm; - private int priority = 1; + private int priority = 5; public CodeGearExecutor(CodeGear cg, CodeGearManager cgm, int priority) { this.cg = cg; @@ -11,7 +11,7 @@ } public void Run() { - //cg.Run(); + cg.Run(cgm); } public int GetPriority() {
--- a/codegear/InputDataGear.cs Wed Jan 20 02:21:55 2021 +0900 +++ b/codegear/InputDataGear.cs Thu Jan 21 01:18:26 2021 +0900 @@ -1,33 +1,77 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Reflection; +using System.Threading; +using Christie_net.annotation; using Christie_net.datagear.command; using Christie_net.datagear.dg; namespace Christie_net.codegear { // InputDataGearの待ち合わせの管理 public class InputDataGear { - public ConcurrentDictionary<string, DataGear<Type>> inputValue = new ConcurrentDictionary<string, DataGear<Type>>(); - //public CodeGearManager cgm; + public ConcurrentDictionary<string, DataGear<object>> inputValue = new ConcurrentDictionary<string, DataGear<object>>(); + public CodeGearManager cgm; public CodeGear cg; - private int count; + private int count = 0; + private readonly object syncObject = new object(); public InputDataGear(CodeGear cg) { this.cg = cg; } - // private void FinishInput(CodeGearManager cgm, List<Command> commandList) { - // this.cgm = cgm; - // count = commandList.Count; - // - // if (count == 0) SubmitCG(); - // - // foreach (Command cm in commandList) cgm.GetDGM(cm.toDgmName).RunCommand(cm); - // } + public void FinishInput(CodeGearManager cgm, List<Command> commandList) { + this.cgm = cgm; + Interlocked.Add(ref count, commandList.Count); + + if (count == 0) { + SubmitCG(); + } + + foreach (Command cm in commandList) { + cgm.GetDGM(cm.toDgmName).RunCommand(cm); + } + } + + public void SetInputs(string key, DataGear<object> dg) { + inputValue.TryAdd(key, dg); + Decriment(); + } - public void SetInputs(string key, DataGear<Type> dg) { - //inputValue.AddOrUpdate(key, dg); + // commandが実行されるたびにDecrementする + private void Decriment() { + lock (syncObject) { + if (Interlocked.Decrement(ref count) == 0) { + SetInputValue(); + SubmitCG(); + } + } + } + + private void SubmitCG() { + cgm.Submit(cg); + } + + public void SetInputValue() { + foreach (var field in this.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))) { + try { + field.SetValue(cg, TypeCheck(field.Name)); + } catch {} + } + } + } + + public Object TypeCheck(string key) { + if (inputValue[key].GetData() != null) { + return inputValue[key].GetData(); + } else { + throw new ArgumentException("'" + key + "' is null! this DataGear required type of " + + inputValue[key].GetClazz()); + } } } } \ No newline at end of file
--- a/daemon/AcceptThread.cs Wed Jan 20 02:21:55 2021 +0900 +++ b/daemon/AcceptThread.cs Thu Jan 21 01:18:26 2021 +0900 @@ -30,7 +30,7 @@ Task.Factory.StartNew( () => incoming.Run(), TaskCreationOptions.LongRunning); - //cgm.SetAccept(key, in); + cgm.SetAccept(key, incoming); OutboundTcpConnection outbound = new OutboundTcpConnection(connection); Task.Factory.StartNew(
--- a/daemon/Connection.cs Wed Jan 20 02:21:55 2021 +0900 +++ b/daemon/Connection.cs Thu Jan 21 01:18:26 2021 +0900 @@ -19,8 +19,6 @@ this.socket = socket; this.cgm = cgm; } - - public Connection(){} public void SendCommand(Command cmd) { sendQueue.TryAdd(cmd);
--- a/daemon/IncomingTcpConnection.cs Wed Jan 20 02:21:55 2021 +0900 +++ b/daemon/IncomingTcpConnection.cs Thu Jan 21 01:18:26 2021 +0900 @@ -25,9 +25,9 @@ } public void Run() { + //TODO: Data長がわからないので4096で仮置き byte[] deserializeCommand = new byte[4096]; - while (true) { try { // データはRemotemessage(Command), length, dataの順で入っている @@ -44,6 +44,7 @@ try { MessagePackDataGear<object> dg = new MessagePackDataGear<object>(data, Type.GetType(msg.clazz)); + cgm.GetLocalDGM().Put(msg.key, dg); } catch (TypeLoadException e) { Console.WriteLine(e.StackTrace); } @@ -56,7 +57,7 @@ .Key(msg.key) .Clazz(Type.GetType(msg.clazz)) .Connection(connection).Build(); - //cgm.GetLocalDGM().RunCommand(cm); + cgm.GetLocalDGM().RunCommand(cm); } catch (TypeLoadException e) { Console.WriteLine(e.StackTrace); } @@ -69,7 +70,7 @@ try { MessagePackDataGear<object> dg = new MessagePackDataGear<object>(data, Type.GetType(msg.clazz)); - // cgm.GetDGM(msg.fromDgmName).ResolveWaitCommand(msg.key, dg); + cgm.GetDGM(msg.fromDmgName).ResolveWaitCommand(msg.key, dg); } catch (TypeLoadException e) { Console.WriteLine(e.StackTrace); }
--- a/daemon/ThreadPoolExecutors.cs Wed Jan 20 02:21:55 2021 +0900 +++ b/daemon/ThreadPoolExecutors.cs Thu Jan 21 01:18:26 2021 +0900 @@ -5,6 +5,8 @@ namespace Christie_net.daemon { public class ThreadPoolExecutors { + // TODO: どこかしらでThreadPoolの設定をする + public ThreadPoolExecutors() { }
--- a/datagear/DataGearManager.cs Wed Jan 20 02:21:55 2021 +0900 +++ b/datagear/DataGearManager.cs Thu Jan 21 01:18:26 2021 +0900 @@ -11,7 +11,7 @@ public WaitList waitList = new WaitList(); public abstract void Put(string key, object data); public abstract void RunCommand(Command cm); - public abstract void ResolveWaitCommand(string key, DataGear<Type> dg); + public abstract void ResolveWaitCommand(string key, DataGear<object> dg); public abstract void Finish(); public abstract void Close(); public abstract void Shutdown();
--- a/datagear/LocalDataGearManager.cs Wed Jan 20 02:21:55 2021 +0900 +++ b/datagear/LocalDataGearManager.cs Thu Jan 21 01:18:26 2021 +0900 @@ -47,7 +47,7 @@ cm.SetDg(dataGears.GetData(cm)); } - public override void ResolveWaitCommand(string key, DataGear<Type> dg) { } + public override void ResolveWaitCommand(string key, DataGear<object> dg) { } public override void Finish() { }
--- a/datagear/RemoteDataGearManager.cs Wed Jan 20 02:21:55 2021 +0900 +++ b/datagear/RemoteDataGearManager.cs Thu Jan 21 01:18:26 2021 +0900 @@ -80,7 +80,7 @@ } - public override void ResolveWaitCommand(string key, DataGear<Type> dg) { + public override void ResolveWaitCommand(string key, DataGear<object> dg) { Command cm = waitList.GetAndRemoveCommand(key); cm.SetDg(dg); cm.Execute();
--- a/datagear/command/TakeCommand.cs Wed Jan 20 02:21:55 2021 +0900 +++ b/datagear/command/TakeCommand.cs Thu Jan 21 01:18:26 2021 +0900 @@ -6,7 +6,7 @@ this.clazz = dg.GetClazz(); } public override void Execute() { - //cg.getIdg() + cg.GetIdg().SetInputs(key, dg); } public override MemoryStream Convert() {