Ejemplo n.º 1
0
        public bool TryEnter()
        {
            bool flag;

            lock (this.ThisLock)
            {
                if (this.count >= this.maxCount)
                {
                    if (this.traceOnFailureToEnter)
                    {
                        this.IncrementFailureCount();
                    }
                    flag = false;
                }
                else
                {
                    ThreadNeutralSemaphore threadNeutralSemaphore = this;
                    threadNeutralSemaphore.count = threadNeutralSemaphore.count + 1;
                    flag = true;
                }
            }
            return(flag);
        }
Ejemplo n.º 2
0
 public void Exit()
 {
     ThreadNeutralSemaphore.Waiter waiter;
     lock (this.ThisLock)
     {
         if (this.count == 0)
         {
             string str = Microsoft.ServiceBus.SR.GetString(Resources.InvalidLockOperation, new object[0]);
             throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SynchronizationLockException(str));
         }
         if (this.waiters == null || this.waiters.Count == 0)
         {
             ThreadNeutralSemaphore threadNeutralSemaphore = this;
             threadNeutralSemaphore.count = threadNeutralSemaphore.count - 1;
             return;
         }
         else
         {
             waiter = this.waiters.Dequeue();
         }
     }
     waiter.Signal();
 }
Ejemplo n.º 3
0
        protected override void OnSend(Message message, TimeSpan timeout)
        {
            base.ThrowIfDisposedOrNotOpen();
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            if (!this.sendLock.TryEnter(timeoutHelper.RemainingTime()))
            {
                ExceptionUtility exceptionUtility  = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility;
                string           sendToViaTimedOut = Resources.SendToViaTimedOut;
                object[]         via = new object[] { this.Via, timeout };
                throw exceptionUtility.ThrowHelperError(new TimeoutException(Microsoft.ServiceBus.SR.GetString(sendToViaTimedOut, via), ThreadNeutralSemaphore.CreateEnterTimedOutException(timeout)));
            }
            try
            {
                base.ThrowIfDisposedOrNotOpen();
                this.ThrowIfOutputSessionClosed();
                bool flag = false;
                try
                {
                    bool allowOutputBatching = message.Properties.AllowOutputBatching;
                    ArraySegment <byte> nums = this.EncodeMessage(message);
                    this.Connection.Write(nums.Array, nums.Offset, nums.Count, !allowOutputBatching, timeoutHelper.RemainingTime(), this.bufferManager);
                    flag = true;
                }
                finally
                {
                    if (!flag)
                    {
                        base.Fault();
                    }
                }
            }
            finally
            {
                this.sendLock.Exit();
            }
        }
Ejemplo n.º 4
0
        private void CloseOutputSession(TimeSpan timeout)
        {
            this.ThrowIfNotOpened();
            this.ThrowIfFaulted();
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            if (!this.sendLock.TryEnter(timeoutHelper.RemainingTime()))
            {
                ExceptionUtility exceptionUtility = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility;
                string           closeTimedOut    = Resources.CloseTimedOut;
                object[]         objArray         = new object[] { timeout };
                throw exceptionUtility.ThrowHelperError(new TimeoutException(Microsoft.ServiceBus.SR.GetString(closeTimedOut, objArray), ThreadNeutralSemaphore.CreateEnterTimedOutException(timeout)));
            }
            try
            {
                this.ThrowIfFaulted();
                if (!this.isOutputSessionClosed)
                {
                    this.isOutputSessionClosed = true;
                    bool flag = true;
                    try
                    {
                        this.Connection.Write(Microsoft.ServiceBus.Channels.SessionEncoder.EndBytes, 0, (int)Microsoft.ServiceBus.Channels.SessionEncoder.EndBytes.Length, true, timeoutHelper.RemainingTime());
                        this.OnOutputSessionClosed(ref timeoutHelper);
                        flag = false;
                    }
                    finally
                    {
                        if (flag)
                        {
                            base.Fault();
                        }
                    }
                }
            }
            finally
            {
                this.sendLock.Exit();
            }
        }
Ejemplo n.º 5
0
        public bool WaitForMessage(TimeSpan timeout)
        {
            bool flag;

            Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
            if (!this.sourceLock.TryEnter(timeoutHelper.RemainingTime()))
            {
                ExceptionUtility exceptionUtility       = DiagnosticUtility.ExceptionUtility;
                string           waitForMessageTimedOut = Resources.WaitForMessageTimedOut;
                object[]         objArray = new object[] { timeout };
                throw exceptionUtility.ThrowHelperError(new TimeoutException(Microsoft.ServiceBus.SR.GetString(waitForMessageTimedOut, objArray), ThreadNeutralSemaphore.CreateEnterTimedOutException(timeout)));
            }
            try
            {
                flag = this.source.WaitForMessage(timeoutHelper.RemainingTime());
            }
            finally
            {
                this.sourceLock.Exit();
            }
            return(flag);
        }
Ejemplo n.º 6
0
        public Message Receive(TimeSpan timeout)
        {
            Message message;

            Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.TimeoutHelper(timeout);
            if (!this.sourceLock.TryEnter(timeoutHelper.RemainingTime()))
            {
                ExceptionUtility exceptionUtility = DiagnosticUtility.ExceptionUtility;
                string           receiveTimedOut2 = Resources.ReceiveTimedOut2;
                object[]         objArray         = new object[] { timeout };
                throw exceptionUtility.ThrowHelperError(new TimeoutException(Microsoft.ServiceBus.SR.GetString(receiveTimedOut2, objArray), ThreadNeutralSemaphore.CreateEnterTimedOutException(timeout)));
            }
            try
            {
                message = this.source.Receive(timeoutHelper.RemainingTime());
            }
            finally
            {
                this.sourceLock.Exit();
            }
            return(message);
        }
Ejemplo n.º 7
0
 public SynchronizedMessageSource(Microsoft.ServiceBus.Channels.IMessageSource source)
 {
     this.source     = source;
     this.sourceLock = new ThreadNeutralSemaphore(1);
 }
Ejemplo n.º 8
0
            public bool Wait(TimeSpan timeout)
            {
                bool flag = true;

                if (!Microsoft.ServiceBus.Common.TimeoutHelper.WaitOne(this.waitHandle, timeout))
                {
                    if (this.parent.RemoveWaiter(this))
                    {
                        flag = false;
                    }
                    else
                    {
                        this.waitHandle.WaitOne();
                    }
                }
                this.waitHandle.Close();
                if (this.aborted)
                {
                    throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(ThreadNeutralSemaphore.CreateObjectAbortedException());
                }
                return(flag);
            }
Ejemplo n.º 9
0
 public void Wait()
 {
     this.waitHandle.WaitOne();
     this.waitHandle.Close();
     if (this.aborted)
     {
         throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(ThreadNeutralSemaphore.CreateObjectAbortedException());
     }
 }
Ejemplo n.º 10
0
 public SyncWaiter(ThreadNeutralSemaphore parent)
 {
     this.waitHandle = new AutoResetEvent(false);
     this.parent     = parent;
 }
Ejemplo n.º 11
0
 private ThreadNeutralSemaphore.SyncWaiter EnterCore()
 {
     ThreadNeutralSemaphore.SyncWaiter syncWaiter;
     lock (this.ThisLock)
     {
         if (this.aborted)
         {
             throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(ThreadNeutralSemaphore.CreateObjectAbortedException());
         }
         if (this.count >= this.maxCount)
         {
             if (this.traceOnFailureToEnter)
             {
                 this.IncrementFailureCount();
             }
             ThreadNeutralSemaphore.SyncWaiter syncWaiter1 = new ThreadNeutralSemaphore.SyncWaiter(this);
             this.Waiters.Enqueue(syncWaiter1);
             return(syncWaiter1);
         }
         else
         {
             ThreadNeutralSemaphore threadNeutralSemaphore = this;
             threadNeutralSemaphore.count = threadNeutralSemaphore.count + 1;
             syncWaiter = null;
         }
     }
     return(syncWaiter);
 }
Ejemplo n.º 12
0
 public void Enter(TimeSpan timeout)
 {
     if (!this.TryEnter(timeout))
     {
         throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(ThreadNeutralSemaphore.CreateEnterTimedOutException(timeout));
     }
 }
 public AlreadyOpeningAsyncResult(ThreadNeutralSemaphore semaphore, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
 {
     this.semaphore = semaphore;
     this.semaphore.Enter(new Action <object>(this.Callback), this);
 }