/// <summary>
        /// Bind the given resource for teh given key to the current thread
        /// </summary>
        /// <param name="key">key to bind the value to</param>
        /// <param name="value">value to bind</param>
        public static void BindResource(Object key, Object value)
        {
            AssertUtils.ArgumentNotNull(key, "Key value for thread local storage of transactional resources must not be null");
            AssertUtils.ArgumentNotNull(value, "Transactional resource to bind to thread local storage must not be null");

            IDictionary resources = LogicalThreadContext.GetData(resourcesDataSlotName) as IDictionary;

            //Set thread local resource storage if not found
            if (resources == null)
            {
                resources = new Hashtable();
                LogicalThreadContext.SetData(resourcesDataSlotName, resources);
            }
            if (resources.Contains(key))
            {
                throw new InvalidOperationException("Already value [" + resources[key] + "] for key [" + key +
                                                    "] bound to thread [" + SystemUtils.ThreadId + "]");
            }
            resources.Add(key, value);
            if (LOG.IsDebugEnabled)
            {
                LOG.Debug("Bound value [" + Describe(value) + "] for key [" + Describe(key) + "] to thread [" +
                          SystemUtils.ThreadId + "]");
            }
        }
        /// <summary>
        /// Creates the message converter given its name in the application context.
        /// </summary>
        /// <param name="messageConverterObjectName">Name of the message converter object.</param>
        /// <returns>
        /// A IMessageConverter instance configured via the application context
        /// </returns>
        public IMessageConverter CreateMessageConverter(string messageConverterObjectName)
        {
            AssertUtils.ArgumentHasText(messageConverterObjectName, "MessgaeFormatterObjectName");
            IDictionary converters = LogicalThreadContext.GetData(CONVERTER_DICTIONARY_SLOTNAME) as IDictionary;

            if (converters == null)
            {
                converters = new Hashtable();
                LogicalThreadContext.SetData(CONVERTER_DICTIONARY_SLOTNAME, converters);
            }
            if (!converters.Contains(messageConverterObjectName))
            {
                IMessageConverter mc =
                    (IMessageConverter)
                    applicationContext.GetObject(messageConverterObjectName, typeof(IMessageConverter));
                if (applicationContext.ObjectFactory.GetObjectDefinition(messageConverterObjectName).IsSingleton)
                {
                    log.Warn("MessageConverter with name = [" + messageConverterObjectName + "] should be declared with singleton=false.  Using Clone() to create independent instance for thread local storage");
                    converters.Add(messageConverterObjectName, mc.Clone());
                }
                else
                {
                    converters.Add(messageConverterObjectName, mc);
                }
            }
            return(converters[messageConverterObjectName] as IMessageConverter);
        }
Пример #3
0
            /// <summary>
            /// Binds this
            /// <see cref="Spring.Transaction.Interceptor.TransactionAspectSupport.TransactionInfo"/>
            /// instance to the thread local storage variable for the current thread and
            /// backs up the existing
            /// <see cref="Spring.Transaction.Interceptor.TransactionAspectSupport.TransactionInfo"/>
            /// object for the current thread.
            /// </summary>
            public void BindToThread()
            {
                // Expose current TransactionStatus, preserving any existing TransactionStatus
                // for restoration after this transaction is complete.
                TransactionInfo currentTransactionInfo = LogicalThreadContext.GetData(CURRENT_TRANSACTIONINFO_SLOTNAME) as TransactionInfo;

                _oldTransactionInfo = currentTransactionInfo;
                LogicalThreadContext.SetData(CURRENT_TRANSACTIONINFO_SLOTNAME, this);
            }
Пример #4
0
 /// <summary>
 /// Sets a flag, whether this scope is in "open" state on the current logical thread.
 /// </summary>
 private void SetOpen(bool isOpen)
 {
     if (isOpen)
     {
         LogicalThreadContext.SetData(ISOPEN_KEY, ISOPEN_KEY);
     }
     else
     {
         LogicalThreadContext.FreeNamedDataSlot(ISOPEN_KEY);
     }
 }
Пример #5
0
 /// <summary>
 /// Gets/Sets a flag, whether this scope manages it's own session for the current logical thread or not.
 /// </summary>
 /// <value><c>false</c> if session is managed by this module. <c>false</c> otherwise</value>
 private void SetParticipating(bool participating)
 {
     if (participating)
     {
         LogicalThreadContext.SetData(PARTICIPATE_KEY, PARTICIPATE_KEY);
     }
     else
     {
         LogicalThreadContext.FreeNamedDataSlot(PARTICIPATE_KEY);
     }
 }
Пример #6
0
 /// <summary>
 /// 把当前UnitOfWork压入当前线程的事务线中
 /// 如果当前线程中不存在事务栈,则创建事务栈,并把事务栈放入当前线程
 /// 否则从当前线程中取出栈,并把当前UnitOfWork压入栈中
 /// </summary>
 public static void Push(IUnitOfWork unitOfWork)
 {
     if (ThreadBoundUnitOfWorkStack == null)
     {
         var stack = new Stack <IUnitOfWork>();
         stack.Push(unitOfWork);
         LogicalThreadContext.SetData(UnitOfWorkStack, stack);
     }
     else
     {
         ThreadBoundUnitOfWorkStack.Push(unitOfWork);
     }
 }
Пример #7
0
 /// <summary>
 /// Process the xml file in the given location, and schedule all of the
 /// jobs defined within it.
 /// </summary>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="systemId">The system id.</param>
 /// <param name="sched">The sched.</param>
 public virtual async Task ProcessFileAndScheduleJobs(string fileName, string systemId, IScheduler sched)
 {
     LogicalThreadContext.SetData(ThreadLocalKeyScheduler, sched);
     try
     {
         await ProcessFile(fileName, systemId).ConfigureAwait(false);
         await ExecutePreProcessCommands(sched).ConfigureAwait(false);
         await ScheduleJobs(sched).ConfigureAwait(false);
     }
     finally
     {
         LogicalThreadContext.FreeNamedDataSlot(ThreadLocalKeyScheduler);
     }
 }
 /// <summary>
 /// Process the xml file in the given location, and schedule all of the
 /// jobs defined within it.
 /// </summary>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="systemId">The system id.</param>
 /// <param name="sched">The sched.</param>
 public virtual void ProcessFileAndScheduleJobs(string fileName, string systemId, IScheduler sched)
 {
     LogicalThreadContext.SetData(ThreadLocalKeyScheduler, sched);
     try
     {
         ProcessFile(fileName, systemId);
         ExecutePreProcessCommands(sched);
         ScheduleJobs(sched);
     }
     finally
     {
         LogicalThreadContext.FreeNamedDataSlot(ThreadLocalKeyScheduler);
     }
 }
        /// <summary>
        /// Activate transaction synchronization for the current thread.
        /// </summary>
        /// <remarks>
        /// Called by transaction manager at the beginning of a transaction.
        /// </remarks>
        /// <exception cref="System.InvalidOperationException">
        /// If synchronization is already active.
        /// </exception>
        public static void InitSynchronization()
        {
            if (SynchronizationActive)
            {
                throw new InvalidOperationException("Cannot activate transaction synchronization - already active");
            }
            if (LOG.IsDebugEnabled)
            {
                LOG.Debug("Initializing transaction synchronization");
            }
            ArrayList syncs = new ArrayList();

            LogicalThreadContext.SetData(syncsDataSlotName, syncs);
        }
Пример #10
0
 /// <summary>
 /// Process the xml file in the given location, and schedule all of the
 /// jobs defined within it.
 /// </summary>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="systemId">The system id.</param>
 /// <param name="sched">The sched.</param>
 /// <param name="overwriteExistingJobs">if set to <c>true</c> [over write existing jobs].</param>
 public virtual void ProcessFileAndScheduleJobs(string fileName, string systemId, IScheduler sched,
                                                bool overwriteExistingJobs)
 {
     LogicalThreadContext.SetData(ThreadLocalKeyScheduler, sched);
     try
     {
         ProcessFile(fileName, systemId);
         ScheduleJobs(ScheduledJobs, sched, overwriteExistingJobs);
     }
     finally
     {
         LogicalThreadContext.FreeNamedDataSlot(ThreadLocalKeyScheduler);
     }
 }
Пример #11
0
        /// <summary>
        ///Initialize deferred close for the current thread and the given SessionFactory.
        /// Sessions will not be actually closed on close calls then, but rather at a
        /// processDeferredClose call at a finishing point (like request completion).
        /// </summary>
        /// <param name="sessionFactory">The session factory.</param>
        public static void InitDeferredClose(ISessionFactory sessionFactory)
        {
            AssertUtils.ArgumentNotNull(sessionFactory, "No SessionFactory specified");

            log.Debug("Initializing deferred close of Hibernate Sessions");

            IDictionary holderDictionary = LogicalThreadContext.GetData(DeferredCloseHolderDataSlotName) as IDictionary;

            if (holderDictionary == null)
            {
                holderDictionary = new Hashtable();
                LogicalThreadContext.SetData(DeferredCloseHolderDataSlotName, holderDictionary);
            }
            holderDictionary.Add(sessionFactory, new ListSet());
        }
 /// <summary>
 /// Process the xml file in the given location, and schedule all of the
 /// jobs defined within it.
 /// </summary>
 /// <param name="stream">stream to read XML data from.</param>
 /// <param name="sched">The sched.</param>
 public virtual void ProcessStreamAndScheduleJobs(Stream stream, IScheduler sched)
 {
     LogicalThreadContext.SetData(ThreadLocalKeyScheduler, sched);
     try
     {
         using (var sr = new StreamReader(stream))
         {
             ProcessInternal(sr.ReadToEnd());
         }
         ExecutePreProcessCommands(sched);
         ScheduleJobs(sched);
     }
     finally
     {
         LogicalThreadContext.FreeNamedDataSlot(ThreadLocalKeyScheduler);
     }
 }
Пример #13
0
 /// <summary>
 /// Process the xml file in the given location, and schedule all of the
 /// jobs defined within it.
 /// </summary>
 /// <param name="stream">stream to read XML data from.</param>
 /// <param name="sched">The sched.</param>
 public virtual async Task ProcessStreamAndScheduleJobs(Stream stream, IScheduler sched)
 {
     LogicalThreadContext.SetData(ThreadLocalKeyScheduler, sched);
     try
     {
         using (var sr = new StreamReader(stream))
         {
             ProcessInternal(await sr.ReadToEndAsync().ConfigureAwait(false));
         }
         await ExecutePreProcessCommands(sched).ConfigureAwait(false);
         await ScheduleJobs(sched).ConfigureAwait(false);
     }
     finally
     {
         LogicalThreadContext.FreeNamedDataSlot(ThreadLocalKeyScheduler);
     }
 }
        /// <summary>
        /// Creates the message queue given its name in the application context.
        /// </summary>
        /// <param name="messageQueueObjectName">Name of the message queue object.</param>
        /// <returns>
        /// A MessageQueue instance configured via the application context
        /// </returns>
        public MessageQueue CreateMessageQueue(string messageQueueObjectName)
        {
            AssertUtils.ArgumentHasText(messageQueueObjectName, "DefaultMessageQueueObjectName");
            IDictionary queues = LogicalThreadContext.GetData(QUEUE_DICTIONARY_SLOTNAME) as IDictionary;

            if (queues == null)
            {
                queues = new Hashtable();
                LogicalThreadContext.SetData(QUEUE_DICTIONARY_SLOTNAME, queues);
            }
            if (!queues.Contains(messageQueueObjectName))
            {
                MessageQueue mq = applicationContext.GetObject(messageQueueObjectName) as MessageQueue;
                queues.Add(messageQueueObjectName, mq);
            }
            return(queues[messageQueueObjectName] as MessageQueue);
        }
        /// <summary>
        /// Bind the given resource for teh given key to the current thread
        /// </summary>
        /// <param name="key">key to bind the value to</param>
        /// <param name="value">value to bind</param>
        public static void BindResource(Object key, Object value)
        {
            var resources = LogicalThreadContext.GetData(RESOURCES_DATA_SLOT_NAME) as IDictionary;

            //Set thread local resource storage if not found
            if (resources == null)
            {
                resources = new Hashtable();
                LogicalThreadContext.SetData(RESOURCES_DATA_SLOT_NAME, resources);
            }
            if (resources.Contains(key))
            {
                throw new InvalidOperationException("Already value [" + resources[key] + "] for key [" + key +
                                                    "] bound to thread [" + Thread.CurrentThread.ManagedThreadId + "]");
            }
            resources.Add(key, value);
            if (log.IsDebugEnabled)
            {
                log.Debug("Bound value [" + Describe(value) + "] for key [" + Describe(key) + "] to thread [" +
                          Thread.CurrentThread.ManagedThreadId + "]");
            }
        }
Пример #16
0
 /// <summary>
 /// Sets the user credentials for current thread.  The given username and password
 /// strings will be added to the connection string for all subsequent GetConnection
 /// requests.  This will override any statically specified user credentials, that is,
 /// set by the properties Username nad Password.
 /// </summary>
 /// <param name="user">The username part of the connection string.</param>
 /// <param name="pass">The password part of the connection string.</param>
 public void SetCredentialsForCurrentThread(string user, string pass)
 {
     LogicalThreadContext.SetData(USERNAME, user);
     LogicalThreadContext.SetData(PASSWORD, pass);
 }
Пример #17
0
 /// <summary>
 /// 设置当前线程运行环境的WarehouseId
 /// </summary>
 /// <param name="warehouseId">a WarehouseId</param>
 public static void SetCurrentThreadWarehouseId(string warehouseId)
 {
     AssertUtils.StringNotNullOrEmpty(warehouseId, "warehouseId");
     LogicalThreadContext.SetData(CURRENT_WAREHOUSE_ID, warehouseId);
 }
Пример #18
0
 public void Before(MethodInfo method, object[] args, object target)
 {
     LogicalThreadContext.SetData(ORDERING_SLOT, new object());
 }
Пример #19
0
 ///<summary>
 /// TODO
 ///</summary>
 ///<param name="applicationContext"></param>
 ///<param name="name"></param>
 ///<param name="isContainerManaged"></param>
 private static void SetCurrentHandlerConfiguration(IConfigurableApplicationContext applicationContext, string name, bool isContainerManaged)
 {
     LogicalThreadContext.SetData(CURRENTHANDLER_OBJECTDEFINITION, new HandlerConfigurationMetaData(applicationContext, name, isContainerManaged));
 }
Пример #20
0
 /// <summary>
 /// Restores the previous
 /// <see cref="Spring.Transaction.Interceptor.TransactionAspectSupport.TransactionInfo"/>
 /// object to the current thread.
 /// </summary>
 public void RestoreThreadLocalStatus()
 {
     // Use stack to restore old transaction TransactionInfo.
     // Will be null if none was set.
     LogicalThreadContext.SetData(CURRENT_TRANSACTIONINFO_SLOTNAME, _oldTransactionInfo);
 }