Class ThreadLocalScope

  • All Implemented Interfaces:
    Scope

    public class ThreadLocalScope
    extends java.lang.Object
    implements Scope
    Thread local Petite bean scope. Holds beans in thread local scopes. Be careful with this scope, if you do not have control on threads! For example, app servers may have a thread pools, so threads may not finish when expected. ThreadLocalScope can not invoke destroy methods.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static java.lang.ThreadLocal<java.util.Map<java.lang.String,​BeanData>> context  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean accept​(Scope referenceScope)
      Defines allowed referenced scopes that can be injected into the thread-local scoped bean.
      java.lang.Object lookup​(java.lang.String name)
      Lookups for bean name.
      void register​(BeanDefinition beanDefinition, java.lang.Object bean)
      Registers the bean within the current scope.
      void remove​(java.lang.String name)
      Removes the bean from the scope entirely.
      void shutdown()
      Shutdowns the scope by removing all beans and calling destroy methods.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • context

        protected static java.lang.ThreadLocal<java.util.Map<java.lang.String,​BeanData>> context
    • Constructor Detail

    • Method Detail

      • lookup

        public java.lang.Object lookup​(java.lang.String name)
        Description copied from interface: Scope
        Lookups for bean name. Returns null if bean is not found or yet registered.
        Specified by:
        lookup in interface Scope
      • register

        public void register​(BeanDefinition beanDefinition,
                             java.lang.Object bean)
        Description copied from interface: Scope
        Registers the bean within the current scope. Usually registers it by its name from BeanDefinition. Also it may register destroy methods of a bean within this scope.
        Specified by:
        register in interface Scope
      • remove

        public void remove​(java.lang.String name)
        Description copied from interface: Scope
        Removes the bean from the scope entirely. Destroy methods are not called as it is assumed that bean is destroyed manually.
        Specified by:
        remove in interface Scope
      • accept

        public boolean accept​(Scope referenceScope)
        Defines allowed referenced scopes that can be injected into the thread-local scoped bean.
        Specified by:
        accept in interface Scope
      • shutdown

        public void shutdown()
        Description copied from interface: Scope
        Shutdowns the scope by removing all beans and calling destroy methods.
        Specified by:
        shutdown in interface Scope