public void CleanupDoneInlineWithoutArbiter() { Port<int> pa = new Port<int> (); Port<string> pb = new Port<string> (); Type[] types = new Type[] { typeof (int), typeof (string) }; IPortReceive[] ports = new IPortReceive[] { pa, pb }; int count = 1; Handler<ICollection[]> handler = (cols) => { }; var mig = new MultipleItemGather (types, ports, count, handler); var dq = new SerialDispatchQueue (); dq.exec = false; mig.TaskQueue = dq; mig.Execute (); var rec = ports [0].GetReceivers () [0]; var rec2 = ports [0].GetReceivers () [1]; ITask task = null; Assert.IsTrue (rec.Evaluate (new PortElement<int> (10), ref task), "#1"); Assert.IsNotNull (task, "#2"); Assert.AreEqual (ReceiverTaskState.CleanedUp, mig.State, "#3"); Assert.AreEqual (ReceiverTaskState.Persistent, rec.State, "#4"); Assert.AreEqual (ReceiverTaskState.Persistent, rec2.State, "#5"); Assert.AreEqual (0, dq.count, "#6"); }
public void CleanupTask() { Port<int> pa = new Port<int> (); Port<string> pb = new Port<string> (); Type[] types = new Type[] { typeof (int), typeof (string) }; IPortReceive[] ports = new IPortReceive[] { pa, pb }; int count = 2; Handler<ICollection[]> handler = (cols) => { }; var mig = new MultipleItemGather (types, ports, count, handler); var dq = new SerialDispatchQueue (); mig.TaskQueue = dq; mig.Execute (); ITask task = null; var rec = ports [0].GetReceivers () [0]; Assert.IsTrue (rec.Evaluate (new PortElement<int> (10), ref task), "#1"); Assert.IsNull (task, "#2"); Assert.IsTrue (rec.Evaluate (new PortElement<int> (20), ref task), "#3"); Assert.IsNotNull (task, "#4"); mig.Cleanup (task); Assert.AreEqual (2, pa.ItemCount, "#4"); Assert.AreEqual (0, pb.ItemCount, "#5"); Assert.AreEqual (10, pa.Test (), "#6"); Assert.AreEqual (20, pa.Test (), "#7"); }
public JoinReceiver(bool persist, ITask task, params IPortReceive[] ports) : base(task) { if (ports == null) { throw new ArgumentNullException("ports"); } if (persist) { _state = ReceiverTaskState.Persistent; } if (ports == null || ports.Length == 0) { throw new ArgumentOutOfRangeException("aP", Resource1.JoinsMustHaveOnePortMinimumException); } _ports = new Receiver[ports.Length]; int[] array = new int[ports.Length]; int num = 0; for (int i = 0; i < ports.Length; i++) { IPortReceive portReceive = ports[i]; int hashCode = portReceive.GetHashCode(); Receiver receiver = new Receiver(portReceive); _ports[num] = receiver; array[num] = hashCode; receiver.ArbiterContext = num; num++; } Array.Sort <int, Receiver>(array, _ports); }
public Receiver(bool persist, IPortReceive port, ITask task) : base(task) { if (persist) { _state = ReceiverTaskState.Persistent; } _port = port; }
public JoinSinglePortReceiver(bool persist, ITask task, IPortReceive port, int count) : base(task) { if (persist) { _state = ReceiverTaskState.Persistent; } if (count <= 0) { throw new ArgumentException(Resource1.JoinSinglePortReceiverAtLeastOneItemMessage, "count"); } _port = port; _count = count; }
private void Register() { int num = 0; _receivers = new Receiver[_ports.Length]; IPortReceive[] ports = _ports; for (int i = 0; i < ports.Length; i++) { IPortReceive portReceive = ports[i]; Receiver receiver = new GatherPrivateReceiver(portReceive, this); _receivers[num++] = receiver; receiver.TaskQueue = base.TaskQueue; portReceive.RegisterReceiver(receiver); if (_pendingItemCount <= 0) { return; } } }
private void Register() { int num = 0; IPortReceive[] ports = _ports; for (int i = 0; i < ports.Length; i++) { IPortReceive port = ports[i]; Receiver receiver = new MultipleItemHelperReceiver(port, this); receiver._arbiterContext = num; _receivers[num++] = receiver; receiver.TaskQueue = base.TaskQueue; } num = 0; IPortReceive[] ports2 = _ports; for (int j = 0; j < ports2.Length; j++) { IPortReceive portReceive = ports2[j]; portReceive.RegisterReceiver(_receivers[num++]); } }
//FIXME what's the use of the types array? public MultipleItemGather(Type[] types, IPortReceive[] ports, int itemCount, Handler<ICollection[]> handler) { if (types == null) throw new ArgumentNullException("types"); if (ports == null) throw new ArgumentNullException("ports"); if (handler == null) throw new ArgumentNullException("handler"); if (types.Length == 0) throw new ArgumentOutOfRangeException ("types"); if (ports.Length == 0) throw new ArgumentOutOfRangeException ("ports"); if (types.Length != ports.Length) throw new ArgumentOutOfRangeException ("types"); this.types = types; this.ports = ports; this.itemCount = itemCount; this.handler = handler; this.results = new List<object>[ports.Length]; for (int i = 0; i < ports.Length; ++i) this.results [i] = new List<object> (); }
public void CtorBadArgs() { Type[] types = new Type[] { typeof (int), typeof (string) }; IPortReceive[] ports = new IPortReceive[] { new Port<int>(), new Port<string> () }; int count = 1; Handler<ICollection[]> handler = (cols) => {}; new MultipleItemGather (types, ports, count, handler); try { new MultipleItemGather (null, ports, count, handler); Assert.Fail ("#1"); } catch (ArgumentNullException) {} try { new MultipleItemGather (types, null, count, handler); Assert.Fail ("#2"); } catch (ArgumentNullException) {} try { new MultipleItemGather (types, ports, count, null); Assert.Fail ("#3"); } catch (ArgumentNullException) {} try { new MultipleItemGather (new Type[0], ports, count, handler); Assert.Fail ("#4"); } catch (ArgumentOutOfRangeException) {} try { new MultipleItemGather (types, new IPortReceive [0], count, handler); Assert.Fail ("#5"); } catch (ArgumentOutOfRangeException) {} try { new MultipleItemGather (new Type [0], new IPortReceive [0], count, handler); Assert.Fail ("#6"); } catch (ArgumentOutOfRangeException) {} try { new MultipleItemGather (new Type[] { typeof (int) }, ports, count, handler); Assert.Fail ("#7"); } catch (ArgumentOutOfRangeException) {} }
public MultipleItemHelperReceiver(IPortReceive port, MultipleItemReceiver parent) : base(false, port, null) { _parent = parent; }
public void WhatResultDataHas2() { Port<int> pa = new Port<int> (); Port<string> pb = new Port<string> (); ICollection[] res = null; Type[] types = new Type[] { typeof (int), typeof (string) }; IPortReceive[] ports = new IPortReceive[] { pa, pb }; int count = 2; Handler<ICollection[]> handler = (cols) => res = cols;; var mig = new MultipleItemGather (types, ports, count, handler); var dq = new SerialDispatchQueue (); mig.TaskQueue = dq; mig.Execute (); pa.Post (10); //result is post order independent pb.Post ("hw"); Assert.IsTrue (res [0] is List<object>, "#1"); Assert.IsTrue (res [1] is List<object>, "#2"); var la = res [0] as List<object>; var lb = res [1] as List<object>; Assert.AreEqual (10, la [0], "#3"); Assert.AreEqual ("hw", lb [0], "#4"); }
internal MultiItemReceiverSurrogate(IPortReceive port, MultipleItemGather receiver, int number) : base(port, null) { this.receiver = receiver; this.number = number; }
public void PostToPortsAfterExecute6() { Port<int> pa = new Port<int> (); Port<string> pb = new Port<string> (); int resA = 0; int resB = 0; Type[] types = new Type[] { typeof (int), typeof (string) }; IPortReceive[] ports = new IPortReceive[] { pa, pb }; int count = 2; Handler<ICollection[]> handler = (cols) => { resA += cols[0].Count ; resB += cols[1].Count; }; var mig = new MultipleItemGather (types, ports, count, handler); var dq = new SerialDispatchQueue (); mig.TaskQueue = dq; mig.Execute (); pb.Post ("hw"); pa.Post (10); Assert.AreEqual (1, resA, "#1"); Assert.AreEqual (1, resB, "#2"); Assert.AreEqual (1, dq.count, "#3"); Assert.AreEqual (ReceiverTaskState.CleanedUp, mig.State, "#4"); }
public void ExecuteWithArbiter2() { Port<int> pa = new Port<int> (); Port<string> pb = new Port<string> (); Type[] types = new Type[] { typeof (int), typeof (string) }; IPortReceive[] ports = new IPortReceive[] { pa, pb }; int count = 1; Handler<ICollection[]> handler = (cols) => { }; var mig = new MultipleItemGather (types, ports, count, handler); var arbiter = new NakedArbiter (false); var dq = new SerialDispatchQueue (); arbiter.TaskQueue = dq; mig.Arbiter = arbiter; var rec = ports [0].GetReceivers () [0]; ITask task = null; Assert.IsFalse (rec.Evaluate (new PortElement<int> (10), ref task), "#1"); Assert.AreEqual (1, arbiter.calls, "#2"); Assert.IsNotNull (task, "#3"); Assert.AreEqual (ReceiverTaskState.Onetime, mig.State, "#4"); Assert.AreEqual (ReceiverTaskState.Persistent, rec.State, "#5"); }
public void ExecuteWithArbiter1() { Port<int> pa = new Port<int> (); Port<string> pb = new Port<string> (); bool handler_called = false; Type[] types = new Type[] { typeof (int), typeof (string) }; IPortReceive[] ports = new IPortReceive[] { pa, pb }; int count = 2; Handler<ICollection[]> handler = (cols) => { handler_called = true; }; var mig = new MultipleItemGather (types, ports, count, handler); var arbiter = new NakedArbiter (false); var dq = new SerialDispatchQueue (); arbiter.TaskQueue = dq; mig.Arbiter = arbiter; Assert.AreEqual (1, ports [0].GetReceivers ().Length, "#1"); Assert.AreEqual (1, ports [1].GetReceivers ().Length, "#2"); pa.Post (10); Assert.AreEqual (1, ports [0].GetReceivers ().Length, "#4"); Assert.AreEqual (1, ports [1].GetReceivers ().Length, "#3"); Assert.AreEqual (0, dq.count, "#4"); Assert.AreEqual (0, arbiter.calls, "#5"); Assert.AreEqual (ReceiverTaskState.Onetime, mig.State, "#6"); Assert.IsFalse (handler_called, "#13"); pa.Post (10); Assert.AreEqual (1, ports [0].GetReceivers ().Length, "#7"); Assert.AreEqual (1, ports [1].GetReceivers ().Length, "#8"); Assert.AreEqual (1, dq.count, "#9"); Assert.AreEqual (1, arbiter.calls, "#10"); Assert.AreEqual (ReceiverTaskState.Onetime, mig.State, "#11"); Assert.IsTrue (handler_called, "#14"); }
public void Execute2() { Type[] types = new Type[] { typeof (int), typeof (string) }; IPortReceive[] ports = new IPortReceive[] { new Port<int>(), new Port<string> () }; int count = 2; Handler<ICollection[]> handler = (cols) => {}; var mig = new MultipleItemGather (types, ports, count, handler); var dq = new SerialDispatchQueue (); mig.TaskQueue = dq; Assert.AreEqual (0, ports [0].GetReceivers ().Length, "#1"); Assert.AreEqual (0, ports [1].GetReceivers ().Length, "#2"); mig.Execute (); Assert.AreEqual (2, ports [0].GetReceivers ().Length, "#3"); Assert.AreEqual (2, ports [1].GetReceivers ().Length, "#4"); Assert.AreEqual (ReceiverTaskState.Persistent, ports [0].GetReceivers ()[0].State, "#5"); Assert.AreEqual (ReceiverTaskState.Persistent, ports [0].GetReceivers ()[1].State, "#6"); Assert.AreEqual (ReceiverTaskState.Persistent, ports [1].GetReceivers ()[0].State, "#7"); Assert.AreEqual (ReceiverTaskState.Persistent, ports [1].GetReceivers ()[1].State, "#8"); Assert.AreEqual (0, dq.count, "#9"); }
public GatherPrivateReceiver(IPortReceive port, MultipleItemGather parent) : base(true, port, null) { _parent = parent; }
internal NakedReceiver(IPortReceive p, ITask task) : base(p, task) { }
public Receiver(IPortReceive port, ITask task) : this(false, port, task) { }
internal Receiver(IPortReceive port) { _port = port; }
public void Evaluate() { Type[] types = new Type[] { typeof (int), typeof (string) }; IPortReceive[] ports = new IPortReceive[] { new Port<int>(), new Port<string> () }; int count = 1; Handler<ICollection[]> handler = (cols) => {}; var mig = new MultipleItemGather (types, ports, count, handler); try { ITask res = null; mig.Evaluate (new PortElement<int> (10), ref res); Assert.Fail ("#1"); } catch (InvalidOperationException) {} }
internal WeirdReceiver(IPortReceive port) : base(port, null) { this.port = port; port.RegisterReceiver (this); }