//Reads the durable instance context id from the incoming
        //messages.
        protected string ReadContextId(Message message)
        {
            IContextManager contextManager =
                ContextManagerFactory.CreateContextManager(contextType,
                                                           this.contextStoreLocation,
                                                           this.endpointAddress);

            string contextId = contextManager.ReadContext(message);

            if (contextId == null)
            {
                throw new CommunicationException(
                          ResourceHelper.GetString("ExContextNotFound"));
            }

            // Add the context id to the properties collection of the Message.
            // This way we can pass the context id to the service model layer in a
            // consistent manner regardless of the context type.
            message.Properties.Add(DurableInstanceContextUtility.ContextIdProperty, contextId);

            return(contextId);
        }
        object IInstanceProvider.GetInstance(InstanceContext instanceContext, Message message)
        {
            object obj = null;

            lock (poolLock)
            {
                if (pool.Count > 0)
                {
                    obj = pool.Pop();
                }
                else
                {
                    obj = CreateNewPoolObject();
                }
                activeObjectsCount++;
            }

            WritePoolMessage(ResourceHelper.GetString("MsgNewObject"));

            idleTimer.Stop();

            return(obj);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Clean up procedure.
        /// </summary>
        void idleTimer_Elapsed(object sender, ElapsedEventArgs args)
        {
            idleTimer.Stop();

            lock (poolLock)
            {
                if (activeObjectsCount == 0)
                {
                    // Remove the surplus objects.
                    if (pool.Count > minPoolSize)
                    {
                        while (pool.Count != minPoolSize)
                        {
                            #if (DEBUG)
                            WritePoolMessage(
                                ResourceHelper.GetString("MsgObjectRemoving"));
                            #endif

                            object removedItem = pool.Pop();

                            if (removedItem is IDisposable)
                            {
                                ((IDisposable)removedItem).Dispose();
                            }
                        }
                    }
                    else if (pool.Count < minPoolSize)
                    {
                        // Reinitialize the missing objects.
                        while (pool.Count != minPoolSize)
                        {
                            pool.Push(CreateNewPoolObject());
                        }
                    }
                }
            }
        }