Пример #1
0
        public virtual void Sync_Transactional_2()
        {
            int expected = 3;

            using (INamedChannel <int> c = new mq.Channel <int>("test-sync" + Salt))
            {
                Task.Factory.StartNew(() =>
                {
                    Thread.Sleep(Timeblok);
                    c.Write(expected);
                });

                IAbortableOperation <int> res = c.Consume(Timeblok * 20);
                Assert.AreEqual(expected, res.Value);
                res.Abort();
                res = c.Consume(Timeblok * 20);
                Assert.AreEqual(expected, res.Value);
                res.Abort();

                res = c.Consume(Timeblok * 20);
                Assert.AreEqual(expected, res.Value);
                res.Commit();

                try
                {
                    c.Consume(Timeblok / 2);
                    Assert.Fail("Expected exception.");
                }
                catch (Exception e)
                {
                    Assert.IsInstanceOfType(e, typeof(TimeoutException));
                }
            }
        }
Пример #2
0
        public IAbortableOperation <T> Consume(int timeoutMillis)
        {
            using (TimeoutManager timeout = TimeoutManager.Start(timeoutMillis))
            {
                IAbortableOperation <T> rd = _source.Consume(timeout);

                _destiantion.Write(Pipe(rd.Value), timeout);

                IAbortableOperation <T> wr = _destiantion.Consume(timeout);

                return(new AbortableOperationImpl <T>(wr.Value, () => { rd.Commit(); wr.Commit(); }, () => { wr.Abort(); rd.Abort(); }));
            }
        }
Пример #3
0
        public T Read(int timeoutMillis)
        {
            IAbortableOperation <T> temp = Consume(timeoutMillis);

            try
            {
                return(temp.Value);
            }
            finally
            {
                temp.Commit();
            }
        }
Пример #4
0
        public void Consume(Action <T> action, int timeoutMillis)
        {
            IAbortableOperation <T> temp = Consume(timeoutMillis);

            try
            {
                action(temp.Value);
            }
            catch (Exception e)
            {
                temp.Abort();
                throw new OperationCanceledException("Consume cancelled by action exception.", e);
            }
            temp.Commit();
        }
Пример #5
0
        public IAbortableOperation <D> Consume(int timeoutMillis)
        {
            IAbortableOperation <S> temp = _channel.Consume(timeoutMillis);

            return(new AbortableOperationImpl <D>(Transform(temp.Value), temp.Commit, temp.Abort));
        }