Class Registry


  • public class Registry
    extends java.lang.Object
    • Field Detail

      • SYSTEM_PROPERTY_FAILSAFE_ACTIVE

        public static final java.lang.String SYSTEM_PROPERTY_FAILSAFE_ACTIVE
        See Also:
        Constant Field Values
      • FAILSAVE_NOTENANTACTIVE

        public static final boolean FAILSAVE_NOTENANTACTIVE
    • Constructor Detail

      • Registry

        public Registry()
    • Method Detail

      • getSlaveTenants

        public static java.util.Map<java.lang.String,​SlaveTenant> getSlaveTenants()
        returns immutable map of slave tenant configuration
      • getSlaveJunitTenant

        public static SlaveTenant getSlaveJunitTenant()
        returns a slave tenant instance if exist otherwise throws IllegalStateException.
      • destroyAndForceStartup

        public static void destroyAndForceStartup()
        Can be called to ensure new Singletons are created and all startup()-Hookins are called again. This is normally done at system startup (in Registry.static{}) and before a new system database initialization is made
      • getCurrentTenantActivationTrace

        protected static java.lang.Exception getCurrentTenantActivationTrace()
      • setCurrentTenantInternal

        protected static void setCurrentTenantInternal​(Tenant tenant)
      • getCurrentTenantInternal

        protected static Tenant getCurrentTenantInternal()
      • destroy

        public static void destroy​(boolean all)
      • startup

        public static void startup()
        This method starts up the Registry. If the Registry is already started, it returns immediately. It is usually safe to call this method from several places to ensure the Registry is correctly started. (e.g. in Item(), Manager() ) Note that if system shutdown is in progress (RedeployUtilities.isShutdownInProgress()), this method returns immediately without doing anything.
      • getSingleton

        public static <T> T getSingleton​(java.lang.Class<T> clazz)
      • runAsTenant

        public static <T> T runAsTenant​(Tenant tenant,
                                        java.util.concurrent.Callable<T> callable)
                                 throws java.lang.Exception
        Runs a given Callable within the given tenant. The previously active tenant (if one is set) is deactivated before and activated afterward execution. If the same tenant was active, it stays active. If none was active before there will be no tenant active afterwards.
        Throws:
        java.lang.Exception
      • activateMasterTenantAndFailIfAlreadySet

        @Deprecated(since="ages",
                    forRemoval=true)
        public static Tenant activateMasterTenantAndFailIfAlreadySet()
        Deprecated, for removal: This API element is subject to removal in a future version.
        Activates the master tenant.
        Returns:
        the previous tenant
        Throws:
        java.lang.IllegalStateException - if the current tenant is already set
      • activateMasterTenant

        public static Tenant activateMasterTenant()
        Internal note: currently called via reflection from JUnitTestRunner to assure that "ant yunit" will work
        Returns:
        the previous tenant
      • activateMasterTenantForInit

        public static Tenant activateMasterTenantForInit()
      • assureTenantStarted

        protected static boolean assureTenantStarted​(AbstractTenant sys)
      • setCurrentTenantByID

        public static void setCurrentTenantByID​(java.lang.String tenantID)
      • hasCurrentTenant

        public static boolean hasCurrentTenant()
        Tells whether the callers thread is already associated with a tenant.
      • isCurrentTenant

        public static boolean isCurrentTenant​(Tenant tenant)
        Tells whether the callers thread is associated with the given tenant.
      • getCurrentTenantNoFallback

        public static <T extends Tenant> T getCurrentTenantNoFallback()
        Returns the tenant currently associated with the callers thread or NULL if no tenant had been activated.
        See Also:
        getCurrentTenant()
      • isCurrentTenantStarted

        public static boolean isCurrentTenantStarted()
      • getCurrentTenant

        public static <T extends Tenant> T getCurrentTenant()
        Returns the tenant currently associated with the callers thread. This may be any SlaveTenant or (as default) the MasterTenant.

        Please note that depending upon the setting of activate.tenant.fallback this method will automatically activate the master tenant if no current tenant could be found!

        Throws:
        java.lang.IllegalStateException - in case no tenant has been activated and fallback mode is not switched on (system property 'activate.tenant.fallback')
        See Also:
        getCurrentTenantNoFallback()
      • getTenantByID

        public static <T extends Tenant> T getTenantByID​(java.lang.String id)
        Return the tenant by its ID or NULL if no tenant was found.
      • getMasterTenant

        public static MasterTenant getMasterTenant()
      • getClusterID

        public static final int getClusterID()
        Returns the cluster ID assigned to this platform instance.
      • getClusterGroups

        public static final java.util.Collection<java.lang.String> getClusterGroups()
      • setPreferredClusterID

        @Deprecated(since="ages",
                    forRemoval=true)
        public static void setPreferredClusterID​(int clusterid)
        Deprecated, for removal: This API element is subject to removal in a future version.
        since ages - UseactivateStandaloneMode() instead
        set the preferred clusternode. note that this setting will be ignored if the registry is already initialized (e.g. if running on tomcat). it can be useful if running as a standalone application to ensure a different clusternode
        Parameters:
        clusterid - the preferred clusternode (0-15). if set to -1, the preferral is cleared.
      • getPreferredClusterID

        @Deprecated(since="ages",
                    forRemoval=true)
        public static int getPreferredClusterID()
        Deprecated, for removal: This API element is subject to removal in a future version.
        since ages - useisStandaloneMode() instead
      • activateStandaloneMode

        public static void activateStandaloneMode()
      • isStandaloneMode

        public static boolean isStandaloneMode()
      • getGlobalApplicationContext

        @Deprecated(since="5.0",
                    forRemoval=true)
        public static org.springframework.context.ApplicationContext getGlobalApplicationContext()
        Deprecated, for removal: This API element is subject to removal in a future version.
        since 5.0 use getCoreApplicationContext() instead
        See Also:
        getCoreApplicationContext()
      • getApplicationContext

        public static org.springframework.context.ApplicationContext getApplicationContext()
        Tries to retrieve web implementation of the ApplicationContext from the current ServletContext or from http session WebSessionFunctions.getCurrentHttpSession() if it fails it fall backs to core application spring context see getCoreApplicationContext().
        Returns:
        current application context
      • getServletContextIfExists

        public static javax.servlet.ServletContext getServletContextIfExists()
        Returns servlet context if invoked in webcontext
        Returns:
        servlet context if available, otherwise null
      • getCoreApplicationContext

        public static org.springframework.context.ApplicationContext getCoreApplicationContext()
        Method returns an instance of ApplicationContext context.
        • If current thread 'has a tenant'. This context consists of merged of every available extension beans definition(s) (its core part spring definitions) specific for the tenant. The bean definitions can be provided using properties as :
           ${extname}.application-context = ...
           

          The context also has as a parent global 'super' context @see getSingletonGlobalApplicationContext().

        • Otherwise it returns a empty context which in most case will cause application to fail.
        Returns:
        current global application context
      • getSingletonGlobalApplicationContext

        public static org.springframework.context.ApplicationContext getSingletonGlobalApplicationContext()
        This method returns a global 'super' spring context. This context is not tenant aware. It contains a beans defined in spring configuration defined in properties as :
          ${extname}.global-application-context = ...
         

        Warning In most cases this context won't contain a business logic beans only those infrastructure ones which needs to stay in memory longer than tenant lifecycle.
      • registerTenantListener

        public static void registerTenantListener​(TenantListener listener)
        Registers a TenantListener which will be then notified on tenant start up / shut down.
        Parameters:
        listener - the listener to register for notifications
        Since:
        3.1-u1
      • unregisterTenantListener

        public static void unregisterTenantListener​(TenantListener listener)
        Unregisters a TenantListener for not be notified on tenant start up / shut down anymore.
        Parameters:
        listener - the listener to unregister for notifications
        Since:
        3.1-u1
      • getTenantListeners

        public static java.util.List<TenantListener> getTenantListeners()
        Gets all listeners registered for getting tenant notifications.
        Returns:
        Unmodifiable list of all registered listeners
        Since:
        3.1-u1