Ejemplo n.º 1
0
        /// <summary>
        /// Gets a thread-specific algorithm instance.
        /// </summary>
        /// <returns></returns>
        public UserIdMappingAlgorithm GetAlgorithm()
        {
            UserIdMappingAlgorithm algorithm = null;
            int threadId = Thread.CurrentThread.ManagedThreadId;

            lock (m_perThreadMappingAlgPoolLock)
            {
                if (m_perThreadMappingAlgPool.ContainsKey(threadId))
                {
                    // an algorithm instance is available for re-use in the current thread
                    algorithm = m_perThreadMappingAlgPool[threadId];
                }
            }

            if (algorithm == null)
            {
                lock (m_baseMappingAlgorithmLock)
                {
                    // create a new algorithm instance for this thread
                    algorithm = new UserIdMappingAlgorithm(m_baseMappingAlgorithm);
                }

                lock (m_perThreadMappingAlgPoolLock)
                {
                    // add the new instance to the pool for re-use
                    m_perThreadMappingAlgPool.Add(threadId, algorithm);
                }
            }

            return(algorithm);
        }
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="cpy"></param>
 public UserIdMappingAlgorithm(
     UserIdMappingAlgorithm cpy)
 {
     lock (cpy.m_configBackupLock)
     {
         Initialize(cpy.m_userIdentityMappings, cpy.m_sessions);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="userIdentityMappingsConfig"></param>
 public UserIdMappingAlgorithmPool(
     UserIdentityMappings userIdentityMappingsConfig,
     NotifyingCollection <Session> sessions)
 {
     m_baseMappingAlgorithm = new UserIdMappingAlgorithm(userIdentityMappingsConfig, sessions);
 }