Class StandaloneBeanContext

    • Constructor Detail

      • StandaloneBeanContext

        public StandaloneBeanContext​(ExecutionContext executionContext,
                                     BeanIdStore beanIdStore,
                                     Map<String,​Object> beanMap)
        Create the StandAloneBeanContext
        Parameters:
        executionContext - The ExecutionContext to which this object is bound to.
        beanIdStore - The BeanIdStore to which this object is bound to.
        beanMap - The Map in which the bean's will be set. It is important not to modify this map outside of the BeanRepository! It is only provided as constructor parameter because in some situations we need to control which Map is used.
    • Method Detail

      • addBean

        public void addBean​(BeanId beanId,
                            Object bean)
        Description copied from interface: BeanContext
        Add a bean instance under the specified BeanId.
        Specified by:
        addBean in interface BeanContext
        Parameters:
        beanId - The BeanId under which the bean is to be stored.
        bean - The bean instance to be stored.
      • addBean

        public void addBean​(BeanId beanId,
                            Object bean,
                            Fragment<?> source)
        Description copied from interface: BeanContext
        Add a bean instance under the specified beanId string.

        Generates a BeanId in the background.

        Specified by:
        addBean in interface BeanContext
        Parameters:
        beanId - The BeanId under which the bean is to be stored.
        bean - The bean instance to be stored.
        source - Source fragment.
      • addBean

        public void addBean​(String beanId,
                            Object bean)
        Description copied from interface: BeanContext
        Add a bean instance under the specified beanId.

        If performance is important, you should get (and cache) a BeanId instance for the beanId String and then use the BeanContext.addBean(BeanId, Object, Fragment) method.

        Specified by:
        addBean in interface BeanContext
        Parameters:
        beanId - The beanId under which the bean is to be stored.
        bean - The bean instance to be stored.
      • addBean

        public void addBean​(String beanId,
                            Object bean,
                            Fragment<?> source)
        Description copied from interface: BeanContext
        Add a bean instance under the specified beanId.

        If performance is important, you should get (and cache) a BeanId instance for the beanId String and then use the BeanContext.addBean(BeanId, Object, Fragment) method.

        Specified by:
        addBean in interface BeanContext
        Parameters:
        beanId - The beanId under which the bean is to be stored.
        bean - The bean instance to be stored.
        source - Source fragment.
      • containsBean

        public boolean containsBean​(BeanId beanId)
        Description copied from interface: BeanContext
        Looks if a bean instance is set under the BeanId
        Specified by:
        containsBean in interface BeanContext
        Parameters:
        beanId - The BeanId under which is looked.
      • getBeanId

        public BeanId getBeanId​(String beanId)
        Description copied from interface: BeanContext
        Get the BeanId instance for the specified beanId String.

        Regsiters the beanId if it's not already registered.

        Specified by:
        getBeanId in interface BeanContext
        Parameters:
        beanId - The beanId String.
        Returns:
        The associated BeanId instance.
      • getBean

        public Object getBean​(BeanId beanId)
        Description copied from interface: BeanContext
        Get the current bean, specified by the supplied BeanId.

        Specified by:
        getBean in interface BeanContext
        Parameters:
        beanId - The BeanId of the bean to be returned.
        Returns:
        The bean instance, otherwise null.
      • getBean

        public Object getBean​(String beanId)
        Description copied from interface: BeanContext
        Returns the bean by it's beanId name.

        Returns the first bean of the specified type from the BeanContext instance.

        Specified by:
        getBean in interface BeanContext
        Parameters:
        beanId - The type of the bean to be returned.
        Returns:
        The bean instance, otherwise null.
      • getBean

        public <T> T getBean​(Class<T> beanType)
        Description copied from interface: BeanContext
        Returns the bean by it's beanId name.

        Returns the first bean of the specified type from the BeanContext instance.

        Specified by:
        getBean in interface BeanContext
        Parameters:
        beanType - The type of the bean to be returned.
        Returns:
        The bean instance, otherwise null.
      • removeBean

        public Object removeBean​(BeanId beanId,
                                 Fragment<?> source)
        Description copied from interface: BeanContext
        Removes a bean and all its associated lifecycle beans from the bean map
        Specified by:
        removeBean in interface BeanContext
        Parameters:
        beanId - The beanId to remove the beans from.
        source - Source fragment.
      • removeBean

        public Object removeBean​(String beanId,
                                 Fragment<?> source)
        Description copied from interface: BeanContext
        Removes a bean and all its associated lifecycle beans from the bean map
        Specified by:
        removeBean in interface BeanContext
        Parameters:
        beanId - The beanId to remove the beans from.
        source - Source fragment.
      • clear

        public void clear()
        Description copied from interface: BeanContext
        Removes all the beans from the bean map
        Specified by:
        clear in interface BeanContext
      • getBeanMap

        public Map<String,​Object> getBeanMap()
        Description copied from interface: BeanContext
        This returns a map which is backed by this repository. Changes made in the map are reflected back into the repository. There are some important side notes:
        • The write performance of the map isn't as good as the write performance of the BeanRepository because it needs to find or register the BeanId every time. The read performance are as good as any normal Map.
        • The entrySet() method returns an UnmodifiableSet
        • When a bean gets removed from the BeanRepository then only the value of the map entry is set to null. This means that null values should be regarded as deleted beans. That is also why the size() of the bean map isn't accurate. It also counts the null value entries.

        Only use the Map if you absolutely needed it else you should use the BeanRepository.

        Specified by:
        getBeanMap in interface BeanContext
      • setBeanInContext

        public void setBeanInContext​(BeanId beanId,
                                     boolean inContext)
        Description copied from interface: BeanContext
        Mark the bean as being in context.

        This is "set" when we enter the fragment around which the bean is created and unset when we exit.

        Specified by:
        setBeanInContext in interface BeanContext
        Parameters:
        beanId - The bean ID.
        inContext - True if the bean is in context, otherwise false.