Option to set WorkerThreads for SmppServerClient on Bind

.NET library for SMPP protocol

Option to set WorkerThreads for SmppServerClient on Bind

Postby murtz » Thu Jun 08, 2017 10:51 am

The WorkerThreads property in SmppClientBase class works only if set during the evConnected event. In my case, for SmppServerClient, I wanted to set this during the Bind event since this is the time I get to know which account is binding to my server and what is the allowed TPS for that account, then I can set the WorkerThreads accordingly. To achieve this, I added the following new method to ProducerConsumerQueue class,

Code: Select all
        //new method
        public void IncreaseWorkers(int newWorkerCount)
        {
            //return if new count is same or less than old count
            if (newWorkerCount <= Workers)
                return;

            lock (_threadLocker)
            {
                //return if stopped flag is raised
                if (Thread.VolatileRead(ref _stopped) == 1)
                    return;

                //get the previous count of workers
                var workers = Workers;

                //resize workers array to accommodate new threads
                System.Array.Resize(ref _workers, newWorkerCount);

                // Create and start a separate thread for each new worker
                for (int i = workers; i < newWorkerCount; i++)
                {
                    var thread = new Thread(Consume);
                    _workers[i] = thread;
                    thread.Start();
                }
            }
        }


and SmppClientBase class.

Code: Select all
        //new method
        internal void IncreaseWorkerThreads()
        {
            _receiveQueue.IncreaseWorkers(WorkerThreads);
        }


Now, inside SmppServerClient class, under OnBind method I did the following changes.

Code: Select all
        ...

        //get the initial WorkerThreads value
        var workerThreads = this.WorkerThreads;

        if (evBind != null)
        ...

        if (data.Response != null && data.Response.Status == Common.CommandStatus.ESME_ROK)
        {
                //if the WorkerThreads value has increased, call the new method
                if (this.WorkerThreads > workerThreads)
                        IncreaseWorkerThreads();

                ...


See if the above makes sense or if you have a better suggestion.
murtz
 
Posts: 15
Joined: Thu May 14, 2015 11:04 am

Return to Inetlab.SMPP v1.1

Who is online

Users browsing this forum: No registered users and 0 guests