Package de.hybris.platform.core
Class Registry
- java.lang.Object
-
- de.hybris.platform.core.Registry
-
public class Registry extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRegistry.Initprotected static classRegistry.TenantHolder
-
Field Summary
Fields Modifier and Type Field Description static booleanFAILSAVE_NOTENANTACTIVEstatic java.lang.StringSYSTEM_PROPERTY_FAILSAFE_ACTIVE
-
Constructor Summary
Constructors Constructor Description Registry()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static TenantactivateMasterTenant()Internal note: currently called via reflection from JUnitTestRunner to assure that "ant yunit" will workstatic TenantactivateMasterTenant(de.hybris.platform.core.Registry.REPLACE replace)Deprecated, for removal: This API element is subject to removal in a future version.since ages - useactivateMasterTenant(),setCurrentTenant(Tenant)orsetCurrentTenantByID(String)insteadstatic TenantactivateMasterTenantAndFailIfAlreadySet()Deprecated, for removal: This API element is subject to removal in a future version.since ages - useactivateMasterTenant(),setCurrentTenant(Tenant)orsetCurrentTenantByID(String)insteadstatic TenantactivateMasterTenantForInit()static voidactivateStandaloneMode()protected static booleanassureTenantStarted(AbstractTenant sys)static voiddestroy(boolean all)static voiddestroyAndForceStartup()Can be called to ensure new Singletons are created and all startup()-Hookins are called again.static org.springframework.context.ApplicationContextgetApplicationContext()Tries to retrieve web implementation of theApplicationContextfrom the currentServletContextor from http sessionWebSessionFunctions.getCurrentHttpSession()if it fails it fall backs to core application spring context seegetCoreApplicationContext().static java.util.Collection<java.lang.String>getClusterGroups()static intgetClusterID()Returns the cluster ID assigned to this platform instance.static org.springframework.context.ApplicationContextgetCoreApplicationContext()Method returns an instance ofApplicationContextcontext.static <T extends Tenant>
TgetCurrentTenant()Returns the tenant currently associated with the callers thread.protected static java.lang.ExceptiongetCurrentTenantActivationTrace()protected static TenantgetCurrentTenantInternal()static <T extends Tenant>
TgetCurrentTenantNoFallback()Returns the tenant currently associated with the callers thread orNULLif no tenant had been activated.static org.springframework.context.ApplicationContextgetGlobalApplicationContext()Deprecated, for removal: This API element is subject to removal in a future version.since 5.0 usegetCoreApplicationContext()insteadstatic MasterTenantgetMasterTenant()static <T> TgetNonTenantSingleton(SingletonCreator.Creator<T> creator)static PersistenceManagergetPersistenceManager()static intgetPreferredClusterID()Deprecated, for removal: This API element is subject to removal in a future version.since ages - useisStandaloneMode()insteadstatic javax.servlet.ServletContextgetServletContextIfExists()Returns servlet context if invoked in webcontextstatic <T> TgetSingleton(SingletonCreator.Creator<T> creator)static <T> TgetSingleton(java.lang.Class<T> clazz)static org.springframework.context.ApplicationContextgetSingletonGlobalApplicationContext()This method returns a global 'super' spring context.static SlaveTenantgetSlaveJunitTenant()returns a slave tenant instance if exist otherwise throwsIllegalStateException.static java.util.Map<java.lang.String,SlaveTenant>getSlaveTenants()returns immutable map of slave tenant configurationstatic <T extends Tenant>
TgetTenantByID(java.lang.String id)Return the tenant by its ID or NULL if no tenant was found.static java.util.List<TenantListener>getTenantListeners()Gets all listeners registered for getting tenant notifications.static booleanhasCurrentTenant()Tells whether the callers thread is already associated with a tenant.static booleanisCurrentTenant(Tenant tenant)Tells whether the callers thread is associated with the given tenant.static booleanisCurrentTenantStarted()static booleanisStandaloneMode()static voidregisterTenantListener(TenantListener listener)Registers aTenantListenerwhich will be then notified on tenant start up / shut down.static <T> TreplaceSingleton(SingletonCreator.Creator<T> creator)static <T> TrunAsTenant(Tenant tenant, java.util.concurrent.Callable<T> callable)Runs a given Callable within the given tenant.static voidsetCurrentTenant(Tenant tenant)Activates the given tenant as current tenant for the callers thread.static voidsetCurrentTenantByID(java.lang.String tenantID)protected static voidsetCurrentTenantInternal(Tenant tenant)static voidsetPreferredClusterID(int clusterid)Deprecated, for removal: This API element is subject to removal in a future version.since ages - UseactivateStandaloneMode()insteadstatic voidstartup()This method starts up the Registry.static voidunregisterTenantListener(TenantListener listener)Unregisters aTenantListenerfor not be notified on tenant start up / shut down anymore.static voidunsetCurrentTenant()De-activates the currently active tenant for the callers thread.
-
-
-
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
-
-
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 throwsIllegalStateException.
-
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.
-
getNonTenantSingleton
public static <T> T getNonTenantSingleton(SingletonCreator.Creator<T> creator)
-
getSingleton
public static <T> T getSingleton(java.lang.Class<T> clazz)
-
getSingleton
public static <T> T getSingleton(SingletonCreator.Creator<T> creator)
-
replaceSingleton
public static <T> T replaceSingleton(SingletonCreator.Creator<T> creator)
-
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
-
setCurrentTenant
public static void setCurrentTenant(Tenant tenant)
Activates the given tenant as current tenant for the callers thread.
-
activateMasterTenantAndFailIfAlreadySet
@Deprecated(since="ages", forRemoval=true) public static Tenant activateMasterTenantAndFailIfAlreadySet()Deprecated, for removal: This API element is subject to removal in a future version.since ages - useactivateMasterTenant(),setCurrentTenant(Tenant)orsetCurrentTenantByID(String)insteadActivates 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()
-
activateMasterTenant
@Deprecated(since="ages", forRemoval=true) public static Tenant activateMasterTenant(de.hybris.platform.core.Registry.REPLACE replace)Deprecated, for removal: This API element is subject to removal in a future version.since ages - useactivateMasterTenant(),setCurrentTenant(Tenant)orsetCurrentTenantByID(String)instead
-
assureTenantStarted
protected static boolean assureTenantStarted(AbstractTenant sys)
-
setCurrentTenantByID
public static void setCurrentTenantByID(java.lang.String tenantID)
-
unsetCurrentTenant
public static void unsetCurrentTenant()
De-activates the currently active tenant for the callers thread. In case no tenant had been active this method has no effect.
-
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 orNULLif 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 anySlaveTenantor (as default) theMasterTenant.Please note that depending upon the setting of
activate.tenant.fallbackthis 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.
-
getPersistenceManager
public static PersistenceManager getPersistenceManager()
-
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()insteadset 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 usegetCoreApplicationContext()instead- See Also:
getCoreApplicationContext()
-
getApplicationContext
public static org.springframework.context.ApplicationContext getApplicationContext()
Tries to retrieve web implementation of theApplicationContextfrom the currentServletContextor from http sessionWebSessionFunctions.getCurrentHttpSession()if it fails it fall backs to core application spring context seegetCoreApplicationContext().- 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 ofApplicationContextcontext.- 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
- 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 :
-
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 aTenantListenerwhich 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 aTenantListenerfor 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
-
-