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)); } } }
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(); })); } }
public T Read(int timeoutMillis) { IAbortableOperation <T> temp = Consume(timeoutMillis); try { return(temp.Value); } finally { temp.Commit(); } }
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(); }
public IAbortableOperation <D> Consume(int timeoutMillis) { IAbortableOperation <S> temp = _channel.Consume(timeoutMillis); return(new AbortableOperationImpl <D>(Transform(temp.Value), temp.Commit, temp.Abort)); }