예제 #1
0
        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));
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        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();
            }
        }
예제 #4
0
 public override void Feed(Event e)
 {
     if (queue != null)
     {
         queue.Enqueue(e);
     }
 }
예제 #5
0
 /// <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);
     }
 }
예제 #6
0
 public override void Close(Event finalItem)
 {
     lock (queue)
     {
         queue.Enqueue(finalItem);
         closing = true;
         Monitor.PulseAll(queue);
     }
 }
예제 #7
0
 /// <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);
 }
예제 #8
0
        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);
            }
        }
예제 #9
0
 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);
     }
 }
예제 #10
0
 /// <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);
 }
예제 #11
0
 /// <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);
 }
예제 #12
0
        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;
        }
예제 #13
0
 public override void Enqueue(Event item)
 {
     lock (queue)
     {
         if (!closing)
         {
             queue.Enqueue(item);
             if (queue.Count == 1)
             {
                 Monitor.Pulse(queue);
             }
         }
     }
 }
예제 #14
0
 /// <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);
     }
 }
예제 #15
0
        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);
            }
        }
예제 #16
0
        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();
        }
예제 #17
0
        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;
            }
        }
예제 #18
0
        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));
        }
예제 #19
0
 void OnEvent(Event e)
 {
 }
예제 #20
0
파일: Server.cs 프로젝트: nice1378/x2clr
 void Send(Event e)
 {
     LinkSession.Send(e);
 }
예제 #21
0
        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);
        }
예제 #22
0
 public WaitForSingleEvent(Coroutine coroutine, Event e, double seconds)
     : this(coroutine, null, e, seconds)
 {
 }
예제 #23
0
 public WaitForSingleEvent(Coroutine coroutine, Event e)
     : this(coroutine, null, e, Config.Coroutine.DefaultTimeout)
 {
 }
예제 #24
0
 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();
 }
예제 #25
0
 public override void Enqueue(Event item)
 {
     queue.Enqueue(item);
 }
예제 #26
0
 public WaitForSingleResponse(Coroutine coroutine, Event request,
         Event response)
     : this(coroutine, request, response, Config.Coroutine.DefaultTimeout)
 {
 }
예제 #27
0
 public override bool TryDequeue(out Event value)
 {
     lock (queue)
     {
         if (queue.Count == 0)
         {
             value = null;
             return false;
         }
         value = queue.Dequeue();
         return true;
     }
 }
예제 #28
0
 public override bool TryDequeue(out Event value)
 {
     return queue.TryDequeue(out value);
 }
예제 #29
0
 protected override bool Process(Event e)
 {
     switch (e.GetTypeId())
     {
         case BuiltinEventType.HeartbeatEvent:
             // Do nothing
             break;
         default:
             return base.Process(e);
     }
     return true;
 }
예제 #30
0
 void Send(Event e)
 {
     if (LinkSession == null)
     {
         return;
     }
     LinkSession.Send(e);
 }