Func <IAsyncResult> CreateAcceptor <TChannel> (IChannelListener l) where TChannel : class, IChannel
        {
            IChannelListener <TChannel> r = l as IChannelListener <TChannel>;

            if (r == null)
            {
                return(null);
            }
            AsyncCallback callback = delegate(IAsyncResult result) {
                try {
                    ChannelAccepted(r.EndAcceptChannel(result));
                } catch (Exception ex) {
                    Logger.Error("Exception during finishing channel acceptance.", ex);
                    creator_handle.Set();
                }
            };

            return(delegate {
                try {
                    return r.BeginAcceptChannel(callback, null);
                } catch (Exception ex) {
                    Logger.Error("Exception during accepting channel.", ex);
                    throw;
                }
            });
        }
Esempio n. 2
0
        private IInputChannel RetrieveAsyncChannel(Uri queue, TimeSpan timeout, out IChannelListener parentListener)
        {
            IChannelListener <IInputChannel> listener =
                Util.GetBinding().BuildChannelListener <IInputChannel>(queue, new BindingParameterCollection());

            listener.Open();
            IInputChannel inputChannel;

            try
            {
                IAsyncResult acceptResult = listener.BeginAcceptChannel(timeout, null, null);
                Thread.Sleep(TimeSpan.FromMilliseconds(300.0)); // Dummy work
                inputChannel = listener.EndAcceptChannel(acceptResult);
            }
            catch (TimeoutException)
            {
                listener.Close();
                throw;
            }
            finally
            {
                parentListener = listener;
            }
            return(inputChannel);
        }
Esempio n. 3
0
        /// <summary>
        /// OnBeginAcceptChannel event
        /// </summary>
        /// <param name="timeout"></param>
        /// <param name="callback"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        protected override IAsyncResult OnBeginAcceptChannel(TimeSpan timeout, AsyncCallback callback, object state)
        {
            WCFLogger.Write(TraceEventType.Verbose, "ChannelListener begins accept channel");

            //_innerChannelListener.
            return(innerChannelListener.BeginAcceptChannel(timeout, callback, state));
        }
 protected override IAsyncResult OnBeginAcceptChannel(
     TimeSpan timeout,
     AsyncCallback callback,
     object state
     )
 {
     return(_innerChannelListener.BeginAcceptChannel(timeout, callback, state));
 }
Esempio n. 5
0
        public MainWindow()
        {
            InitializeComponent();

            WSHttpBinding binding = CreateBinding();
            IChannelListener <IReplyChannel> channel = binding.BuildChannelListener <IReplyChannel>(routerUri, new BindingParameterCollection());

            channel.Open();
            channel.BeginAcceptChannel(AcceptChannel, channel);

            Messages = new ObservableCollection <MessageContainer>();
            lbxMessages.ItemsSource = Messages;
        }
Esempio n. 6
0
        /// <summary>
        /// Try to begin accept channel
        /// </summary>
        /// <typeparam name="T">indicating the channel type</typeparam>
        /// <param name="listener">indicating the listener</param>
        /// <param name="callback">indicating the callback</param>
        protected void TryToBeginAcceptChannel <T>(IChannelListener <T> listener, AsyncCallback callback) where T : class, IChannel
        {
            IAsyncResult ar = null;

            do
            {
                try
                {
                    ar = listener.BeginAcceptChannel(callback, null);
                }
                catch (Exception e)
                {
                    BrokerTracing.TraceEvent(TraceEventType.Information, 0, "[FrontEndBase] Exception throwed while begin accept channel: {0}", e);

                    // If it failed to begin accept the channel, it means the listener is failed and we should dispose the frontend
                    ((IDisposable)this).Dispose();
                }
            }while (ar.CompletedSynchronously && listener.State == CommunicationState.Opened);
        }
Esempio n. 7
0
        private void AcceptChannelAndReceive(IChannelListener<IInputChannel> listener)
        {
            IInputChannel channel;
            TransactionScope transactionToAbortOnAccept = null;

            if (this.Parameters.AbortTxDatagramAccept)
            {
                transactionToAbortOnAccept = new TransactionScope(TransactionScopeOption.RequiresNew);
            }

            if (this.Parameters.AsyncAccept)
            {
                IAsyncResult result = listener.BeginAcceptChannel(null, null);
                channel = listener.EndAcceptChannel(result);
            }
            else
            {
                channel = listener.AcceptChannel();
            }

            if (this.Parameters.AbortTxDatagramAccept)
            {
                transactionToAbortOnAccept.Dispose();
            }

            channel.Open();
            Message message;

            if (this.Parameters.CloseListenerEarly)
            {
                listener.Close();
            }

            try
            {
                using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    Message firstMessage = channel.Receive(this.Parameters.ReceiveTimeout);

                    lock (this.Results)
                    {
                        this.Results.Add(String.Format("Received message with Action '{0}'", firstMessage.Headers.Action));
                    }

                    ts.Complete();
                }
            }
            catch (TimeoutException)
            {
                lock (this.Results)
                {
                    this.Results.Add("Receive timed out.");
                }

                channel.Abort();
                return;
            }

            AutoResetEvent doneReceiving = new AutoResetEvent(false);
            int threadsCompleted = 0;

            for (int i = 0; i < this.Parameters.NumberOfThreads; ++i)
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object unused)
                {
                    do
                    {
                        if (this.Parameters.ReceiverShouldAbort)
                        {
                            this.ReceiveMessage(channel, false);
                            Thread.Sleep(200);
                        }

                        message = this.ReceiveMessage(channel, true);
                    }
                    while (message != null);

                    if (Interlocked.Increment(ref threadsCompleted) == this.Parameters.NumberOfThreads)
                    {
                        doneReceiving.Set();
                    }
                }));
            }

            TimeSpan threadTimeout = TimeSpan.FromMinutes(2.0);
            if (!doneReceiving.WaitOne(threadTimeout, false))
            {
                this.Results.Add(String.Format("Threads did not complete within {0}.", threadTimeout));
            }

            channel.Close();
        }
Esempio n. 8
0
 public IAsyncResult BeginAccept(TimeSpan timeout, AsyncCallback callback, object state)
 {
     return(_listener.BeginAcceptChannel(timeout, callback, state));
 }
Esempio n. 9
0
 public void Open()
 {
     _replyChannelListener = _requestBinding.BuildChannelListener <IReplyChannel>(ResponseUrl, _credentials);
     _replyChannelListener.Open();
     _replyChannelListener.BeginAcceptChannel(ChannelAccepted, _replyChannelListener);
 }
Esempio n. 10
0
        private void AcceptChannelAndReceive(IChannelListener <IInputChannel> listener)
        {
            IInputChannel    channel;
            TransactionScope transactionToAbortOnAccept = null;

            if (this.Parameters.AbortTxDatagramAccept)
            {
                transactionToAbortOnAccept = new TransactionScope(TransactionScopeOption.RequiresNew);
            }

            if (this.Parameters.AsyncAccept)
            {
                IAsyncResult result = listener.BeginAcceptChannel(null, null);
                channel = listener.EndAcceptChannel(result);
            }
            else
            {
                channel = listener.AcceptChannel();
            }

            if (this.Parameters.AbortTxDatagramAccept)
            {
                transactionToAbortOnAccept.Dispose();
            }

            channel.Open();
            Message message;

            if (this.Parameters.CloseListenerEarly)
            {
                listener.Close();
            }

            try
            {
                using (TransactionScope ts = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    Message firstMessage = channel.Receive(this.Parameters.ReceiveTimeout);

                    lock (this.Results)
                    {
                        this.Results.Add(String.Format("Received message with Action '{0}'", firstMessage.Headers.Action));
                    }

                    ts.Complete();
                }
            }
            catch (TimeoutException)
            {
                lock (this.Results)
                {
                    this.Results.Add("Receive timed out.");
                }

                channel.Abort();
                return;
            }

            AutoResetEvent doneReceiving    = new AutoResetEvent(false);
            int            threadsCompleted = 0;

            for (int i = 0; i < this.Parameters.NumberOfThreads; ++i)
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object unused)
                {
                    do
                    {
                        if (this.Parameters.ReceiverShouldAbort)
                        {
                            this.ReceiveMessage(channel, false);
                            Thread.Sleep(200);
                        }

                        message = this.ReceiveMessage(channel, true);
                    }while (message != null);

                    if (Interlocked.Increment(ref threadsCompleted) == this.Parameters.NumberOfThreads)
                    {
                        doneReceiving.Set();
                    }
                }));
            }

            TimeSpan threadTimeout = TimeSpan.FromMinutes(2.0);

            if (!doneReceiving.WaitOne(threadTimeout, false))
            {
                this.Results.Add(String.Format("Threads did not complete within {0}.", threadTimeout));
            }

            channel.Close();
        }
 public void Open()
 {
     _replyChannelListener = _requestBinding.BuildChannelListener<IReplyChannel>(ResponseUrl, _credentials);
     _replyChannelListener.Open();
     _replyChannelListener.BeginAcceptChannel(ChannelAccepted, _replyChannelListener);
 }
 public IAsyncResult BeginAcceptChannel(AsyncCallback callback, object state)
 {
     return(_innerListener.BeginAcceptChannel(callback, state));
 }