public void TestInstanceMethods() { var handler1 = new MethodHandler<Event>(intBox1.Increment); var handler2 = new MethodHandler<Event>(intBox1.Increment); var handler3 = new MethodHandler<Event>(intBox1.Decrement); var handler4 = new MethodHandler<Event>(intBox2.Decrement); // Properties Assert.True(handler1.Action.Equals(handler2.Action)); Assert.False(handler2.Action.Equals(handler3.Action)); Assert.False(handler3.Action.Equals(handler4.Action)); // Invocation Event e = new Event(); handler1.Invoke(e); Assert.AreEqual(1, intBox1.Value); handler2.Invoke(e); Assert.AreEqual(2, intBox1.Value); handler3.Invoke(e); Assert.AreEqual(1, intBox1.Value); Assert.AreEqual(0, intBox2.Value); handler4.Invoke(e); Assert.AreEqual(1, intBox1.Value); Assert.AreEqual(-1, intBox2.Value); // Equality Assert.True(handler1.Equals(handler2)); Assert.False(handler2.Equals(handler3)); Assert.False(handler3.Equals(handler4)); }
protected WaitForMultipleEvents(Coroutine coroutine, Event[] requests, double seconds, params Event[] e) { this.coroutine = coroutine; if (!Object.ReferenceEquals(requests, null)) { waitHandle = WaitHandlePool.Acquire(); for (int i = 0, count = requests.Length; i < count; ++i) { requests[i]._WaitHandle = waitHandle; } for (int i = 0, count = e.Length; i < count; ++i) { e[i]._WaitHandle = waitHandle; } } expected = e; actual = new Event[expected.Length]; handlerTokens = new Binder.Token[expected.Length]; for (int i = 0; i < expected.Length; ++i) { handlerTokens[i] = Flow.Bind(expected[i], OnEvent); } if (seconds > 0) { TimeoutEvent timeoutEvent = new TimeoutEvent { Key = this }; timeoutToken = Flow.Bind(timeoutEvent, OnTimeout); timerToken = TimeFlow.Default.Reserve(timeoutEvent, seconds); } }
void OnEvent(Event e) { for (int i = 0; i < expected.Length; ++i) { if (actual[i] == null && expected[i].Equivalent(e)) { Flow.Unbind(handlerTokens[i]); handlerTokens[i] = new Binder.Token(); actual[i] = e; ++count; break; } } if (count >= expected.Length) { if (timerToken.HasValue) { TimeFlow.Default.Cancel(timerToken.Value); Flow.Unbind(timeoutToken); } if (waitHandle != 0) { WaitHandlePool.Release(waitHandle); } coroutine.Result = actual; coroutine.Continue(); } }
public override void Feed(Event e) { if (queue != null) { queue.Enqueue(e); } }
/// <summary> /// Broadcasts the specified event to all the connected clients. /// </summary> public void Broadcast(Event e) { List<LinkSession> snapshot = TakeSessionsSnapshot(); for (int i = 0, count = snapshot.Count; i < count; ++i) { snapshot[i].Send(e); } }
public override void Close(Event finalItem) { lock (queue) { queue.Enqueue(finalItem); closing = true; Monitor.PulseAll(queue); } }
/// <summary> /// Sends out the specified event through this link channel. /// </summary> public override void Send(Event e) { LinkSession currentSession = Session; if (Object.ReferenceEquals(currentSession, null)) { Log.Warn("{0} dropped event {1}", Name, e); return; } currentSession.Send(e); }
public WaitForMultipleEvents(Coroutine coroutine, params Event[] e) { this.coroutine = coroutine; expected = e; actual = new Event[expected.Length]; for (int i = 0; i < expected.Length; ++i) { Flow.Bind(expected[i], OnEvent); } }
public WaitForSingleEvent(Coroutine coroutine, Event e, double seconds) { this.coroutine = coroutine; handlerToken = Flow.Bind(e, OnEvent); if (seconds >= 0) { TimeoutEvent timeoutEvent = new TimeoutEvent { Key = this }; timeoutToken = Flow.Bind(timeoutEvent, OnTimeout); timerToken = TimeFlow.Default.Reserve(timeoutEvent, seconds); } }
/// <summary> /// Sends out the specified event through this link channel. /// </summary> public override void Send(Event e) { using (new ReadLock(rwlock)) { if (session == null) { Log.Warn("{0} dropped event {1}", Name, e); return; } } session.Send(e); }
/// <summary> /// Sends out the specified event through this link channel. /// </summary> public override void Send(Event e) { LinkSession session; using (new ReadLock(rwlock)) { if (!sessions.TryGetValue(e._Handle, out session)) { return; } } session.Send(e); }
void OnEvent(Event e) { if (timerToken.HasValue) { TimeFlow.Default.Cancel(timerToken.Value); Flow.Unbind(timeoutToken); } Flow.Unbind(handlerToken); coroutine.Context = e; coroutine.Continue(); coroutine.Context = null; }
public override void Enqueue(Event item) { lock (queue) { if (!closing) { queue.Enqueue(item); if (queue.Count == 1) { Monitor.Pulse(queue); } } } }
/// <summary> /// Broadcasts the specified event to all the connected clients. /// </summary> public void Broadcast(Event e) { List<LinkSession> snapshot; using (new ReadLock(rwlock)) { snapshot = new List<LinkSession>(sessions.Count); var list = sessions.Values; for (int i = 0, count = list.Count; i < count; ++i) { snapshot.Add(list[i]); } } for (int i = 0, count = snapshot.Count; i < count; ++i) { snapshot[i].Send(e); } }
protected WaitForSingleEvent(Coroutine coroutine, Event request, Event e, double seconds) { this.coroutine = coroutine; if (!Object.ReferenceEquals(request, null)) { int waitHandle = WaitHandlePool.Acquire(); request._WaitHandle = waitHandle; e._WaitHandle = waitHandle; } handlerToken = Flow.Bind(e, OnEvent); if (seconds > 0) { TimeoutEvent timeoutEvent = new TimeoutEvent { Key = this }; timeoutToken = Flow.Bind(timeoutEvent, OnTimeout); timerToken = TimeFlow.Default.Reserve(timeoutEvent, seconds); } }
void OnEvent(Event e) { Flow.Unbind(handlerToken); if (timerToken.HasValue) { TimeFlow.Default.Cancel(timerToken.Value); Flow.Unbind(timeoutToken); } int waitHandle = handlerToken.Key._WaitHandle; if (waitHandle != 0) { WaitHandlePool.Release(waitHandle); } coroutine.Result = e; coroutine.Continue(); }
void OnEvent(Event e) { for (int i = 0; i < expected.Length; ++i) { if (actual[i] == null && expected[i].IsEquivalent(e)) { Flow.Unbind(expected[i], OnEvent); actual[i] = e; ++count; break; } } if (count >= expected.Length) { coroutine.Context = actual; coroutine.Continue(); coroutine.Context = null; } }
public void TestStaticMethods() { var handler1 = new MethodHandler<Event>(IntBox.StaticIncrement); var handler2 = new MethodHandler<Event>(IntBox.StaticIncrement); var handler3 = new MethodHandler<Event>(IntBox.StaticDecrement); // Properties Assert.True(handler1.Action.Equals(handler2.Action)); Assert.False(handler2.Action.Equals(handler3.Action)); // Invocation Event e = new Event(); handler1.Invoke(e); Assert.AreEqual(1, IntBox.StaticValue); handler2.Invoke(e); Assert.AreEqual(2, IntBox.StaticValue); handler3.Invoke(e); Assert.AreEqual(1, IntBox.StaticValue); // Equality Assert.True(handler1.Equals(handler2)); Assert.False(handler2.Equals(handler3)); }
void OnEvent(Event e) { }
void Send(Event e) { LinkSession.Send(e); }
protected override void OnEventSent(Event e) { hasSent = true; if (e.GetTypeId() != BuiltinEventType.HeartbeatEvent) { Log.Debug("{0} {1} sent event {2}", link.Name, InternalHandle, e); } else { Log.Trace("{0} {1} sent event {2}", link.Name, InternalHandle, e); } base.OnEventSent(e); }
public WaitForSingleEvent(Coroutine coroutine, Event e, double seconds) : this(coroutine, null, e, seconds) { }
public WaitForSingleEvent(Coroutine coroutine, Event e) : this(coroutine, null, e, Config.Coroutine.DefaultTimeout) { }
public WaitForSingleResponse(Coroutine coroutine, Event request, Event response, double seconds) : base(coroutine, request, response, seconds) { if (Object.ReferenceEquals(request, null)) { throw new ArgumentNullException(); } request.Post(); }
public override void Enqueue(Event item) { queue.Enqueue(item); }
public WaitForSingleResponse(Coroutine coroutine, Event request, Event response) : this(coroutine, request, response, Config.Coroutine.DefaultTimeout) { }
public override bool TryDequeue(out Event value) { lock (queue) { if (queue.Count == 0) { value = null; return false; } value = queue.Dequeue(); return true; } }
public override bool TryDequeue(out Event value) { return queue.TryDequeue(out value); }
protected override bool Process(Event e) { switch (e.GetTypeId()) { case BuiltinEventType.HeartbeatEvent: // Do nothing break; default: return base.Process(e); } return true; }
void Send(Event e) { if (LinkSession == null) { return; } LinkSession.Send(e); }