Ejemplo n.º 1
0
 public override void StartClient(GetNextRequestState state)
 {
     if (state != null)
     {
         state.Invoke();
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a IService instance with specified index.
        /// </summary>
        /// <param name="getNextRequest">
        /// trigger the client to retrieve next request
        /// </param>
        /// <param name="clientIndex">
        /// index of the client
        /// </param>
        public virtual async Task CreateClientAsync(bool getNextRequest, int clientIndex)
        {
            if (this.IServiceClient != null)
            {
                BrokerTracing.TraceWarning(
                    BrokerTracing.GenerateTraceString(
                        "RequestSender",
                        "CreateClientAsync",
                        this.TaskId,
                        clientIndex,
                        this.IServiceClient.ToString(),
                        string.Empty,
                        "Closed former client proxy."));

                this.CloseClient();
            }

            try
            {
                await this.CreateClientAsync().ConfigureAwait(false);

                BrokerTracing.TraceVerbose(
                    BrokerTracing.GenerateTraceString(
                        "RequestSender",
                        "CreateClientAsync",
                        this.TaskId,
                        clientIndex,
                        this.IServiceClient.ToString(),
                        string.Empty,
                        "Created a new client."));

                this.Dispatcher.PassBindingFlags[clientIndex] = true;

                GetNextRequestState state = null;

                if (getNextRequest)
                {
                    state = new GetNextRequestState(this.Dispatcher.GetNextRequest, clientIndex);
                }

                this.StartClient(state);
            }
            catch (Exception e)
            {
                BrokerTracing.TraceEvent(
                    TraceEventType.Error,
                    0,
                    "[RequestSender] .CreateClientAsync: ID = {0}, init client failed: {1}",
                    this.TaskId,
                    e);

                if (this.IServiceClient != null)
                {
                    this.CloseClient();
                }

                this.Dispatcher.CloseThis();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Async open the connection and start to process requests.
        /// </summary>
        public void AsyncStart(GetNextRequestState state, int serviceOperationTimeout)
        {
            BrokerTracing.TraceVerbose("[AzureServiceClient]. AsyncStart is called.");

            this.serviceOperationTimeout = serviceOperationTimeout;

            Guid clientGuid = this.ServiceClient.ClientGuid;

            if (Interlocked.CompareExchange(ref this.clientOpenAsync, 1, 0) == 0)
            {
                if (state != null)
                {
                    lock (this.SyncObjForStateList)
                    {
                        // this.stateList cannot be null before BeginOpen is called.
                        BrokerTracing.TraceVerbose("[AzureServiceClient]. AsyncStart: Add async state to the list before BeginOpen is called, client {0}", clientGuid);
                        this.stateList.Add(state);
                    }
                }

                BrokerTracing.TraceVerbose("[AzureServiceClient]. AsyncStart: BeginOpen the client {0}", clientGuid);

                ThreadPool.QueueUserWorkItem(
                    new ThreadHelper <object>(new WaitCallback(AzureServiceClient.AsyncStartWorker)).CallbackRoot,
                    new object[] { this, this.serviceOperationTimeout });
            }
            else
            {
                BrokerTracing.TraceVerbose("[AzureServiceClient]. AsyncStart: BeginOpen is already called, client {0}", clientGuid);

                if (state != null)
                {
                    lock (this.SyncObjForStateList)
                    {
                        if (this.stateList != null)
                        {
                            BrokerTracing.TraceVerbose("[AzureServiceClient]. AsyncStart: Add async state to the list after BeginOpen is called, client {0}", clientGuid);
                            this.stateList.Add(state);
                        }
                        else
                        {
                            // if this.stateList is null, TriggerGetNextRequest is already called.
                            BrokerTracing.TraceVerbose("[AzureServiceClient]. AsyncStart: Call GetNextRequest method, client {0}", clientGuid);
                            state.Invoke();
                        }
                    }
                }
            }
        }
        public void OnPremiseRequestSender_StartClient()
        {
            MockDispatcher dispatcher = new MockDispatcher();

            OnPremiseRequestSender sender = new OnPremiseRequestSender(this.address, this.binding, this.serviceOperationTimeout, dispatcher, this.serviceInitializationTimeout, this.initEndpointNotFoundWaitPeriod);

            sender.CreateClientAsync(false, 0);

            bool clientStart = false;

            GetNextRequestState state =
                new GetNextRequestState(
                    (index) =>
            {
                clientStart = true;
            },
                    0);

            sender.StartClient(state);

            Assert.AreEqual(clientStart, true, "The local variable clientStart should be set when start client.");
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Start client.
 /// </summary>
 /// <param name="state">GetNextRequestState instance</param>
 public abstract void StartClient(GetNextRequestState state);
Ejemplo n.º 6
0
 public override void StartClient(GetNextRequestState state)
 {
     this.Client.Start(state, this.BackendServiceOperationTimeout);
 }