Package de.hybris.platform.core
Class AbstractTenant
java.lang.Object
de.hybris.platform.core.AbstractTenant
- All Implemented Interfaces:
DataSourceProvider,Tenant,Serializable
- Direct Known Subclasses:
MasterTenant,SlaveTenant,TestTenantStub
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interfaceprotected static classprotected static classstatic enumstatic enumclass -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidactivateAlternativeDataSource(String id, boolean asMaster) voidSwitches to a specified (by the id) master data source for the current thread.Switches to a slave data source for the current thread.voidSwitches to a specified (by the id) slave data source for the current thread.protected voidassertTenant(JaloSession session) protected voidprotected voidbackgroundThreadFinished(Thread thread, Runnable payload) protected voidbackgroundThreadStarted(Thread thread, Runnable payload) voidBe careful! This method is intended for internal testing.protected final booleanbooleanprotected booleancanSwitch(AbstractTenant.DataSourceSelection currentSelection, boolean toMaster) voidbooleanprotected HybrisDataSourcecreateAlternativeDataSource(DataSourceFactory factory, String id, Map<String, String> params, boolean readOnly) protected List<AbstractTenant.DataSourceHolder>createAlternativeDataSources(DataSourceFactory defaultFactory, ConfigIntf cfg, Collection<HybrisDataSource> createdForRollback) createAndRegisterBackgroundThread(Runnable payload, ThreadFactory factory) protected Cacheprotected DataSourceFactoryprotected DataSourceFactorycreateDataSourceFactory(String className) static ThreadPoolcreateDefaultThreadPool(String tenantID, int poolSize) protected HybrisDataSourcecreateMasterDataSource(DataSourceFactory factory) voidAfter a alternative slave or master data source has been activated for the current thread it's necessary to de-activate it again! After this the base master data source is active (again).voidAfter slave data source has been activated for the current thread it's necessary to de-activate it again! After this the master data source is active (again).protected voidfinal voidfinal voidbooleanprotected final voidPerforms calling Init.Init() for all registered init instances and also performsTenantListener.afterTenantStartUp(Tenant)notification.extractCustomDBParams(ConfigIntf cfg, boolean stripPrefix) extractCustomDBParams(Map<String, String> map) extractCustomDBParams(Map<String, String> map, boolean stripPrefix) voidEnforces the usage of a master data source for all subsequent calls toDataSourceProvider.getDataSource()no matter if a slave data source has been activated or not.protected Collection<HybrisDataSource>getAllAlternativeDataSources(boolean asMaster) Provides IDs of all available alternative master data sources.Returns all known alternative master data sources as Collection.getAllAlterntiveDataSourceIDs(boolean asMaster) Provides IDs of all available slave data sources.Returns all known slave data sources as Collection.getCache()intDeprecated, for removal: This API element is subject to removal in a future version.abstract ConfigIntfstatic TenantReturns currently active data source.getDataSource(String className) Returns new data source.longReturns master data source no matter which one is currently active.protected AbstractTenant.DataSourceSelectionReturns the next availableAbstractTenant.DataSourceSelectionfinal AbstractTenant.StategetState()protected StringlonginthashCode()protected voidinitializeCache(HybrisDataSource masterDataSource) booleanTells whether the current active data source is a alternative master data source.booleanchecks if clustermode is enabledbooleanbooleanIf on the current data source (slave/master) the methodDataSourceProvider.forceMasterDataSource()was called then this method returns true.final booleanbooleanTells whether current data source is a slave data source.final booleanfinal booleanprotected ObjectreadParameters(DataSource dataSource) Checks READ_COMMITTED_SNAPSHOT and ALLOW_SNAPSHOT_ISOLATION parameters for MS SQL Serverprotected voidrelaseAdministrationLockIfNeeded(HybrisDataSource masterDataSource) Tries to release administration lock if lock was acquired by thisgetClusterID()node.voidvoidprotected final voidsetState(AbstractTenant.State state) voidsetSystemInit(Boolean state) voidsetTenantID(String id) abstract voidshutDown()protected voidabstract voidstartUp()toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface de.hybris.platform.core.Tenant
getAllItemLifecycleListeners, getTenantSpecificLocale, getTenantSpecificTimeZone
-
Field Details
-
SLAVE_DATASOURCE
- See Also:
-
ALT_DATASOURCE
- See Also:
-
MASTER_DATASOURCE_ID
- See Also:
-
-
Constructor Details
-
AbstractTenant
-
-
Method Details
-
getTenantSpecificExtensionNames
- Specified by:
getTenantSpecificExtensionNamesin interfaceTenant
-
getConfig
-
startUp
- Throws:
ConsistencyCheckException
-
shutDown
public abstract void shutDown() -
getCurrentTenant
-
setSystemInit
-
getTenantRestartMarker
public long getTenantRestartMarker()- Returns:
- a time stamp marker when current tenant was created/restarted for the last time. If no restart occurred points to creation time.
-
doInitialize
protected void doInitialize() -
relaseAdministrationLockIfNeeded
Tries to release administration lock if lock was acquired by thisgetClusterID()node. -
initializeCache
-
readParameters
Checks READ_COMMITTED_SNAPSHOT and ALLOW_SNAPSHOT_ISOLATION parameters for MS SQL Server -
doStartUp
- Throws:
ConsistencyCheckException
-
assureTypeSystemStructureIsUpToDate
protected void assureTypeSystemStructureIsUpToDate() -
doShutDown
public final void doShutDown() -
shutdownCache
-
executeInitsIfNecessary
protected final void executeInitsIfNecessary()Performs calling Init.Init() for all registered init instances and also performsTenantListener.afterTenantStartUp(Tenant)notification. Both is working in a thread-safe non-blocking mode now. -
cannotAccess
protected final boolean cannotAccess() -
getStateInfo
-
getState
-
setState
-
getTenantID
- Specified by:
getTenantIDin interfaceTenant
-
setTenantID
-
toString
-
getDataSource
Description copied from interface:DataSourceProviderReturns new data source. (experimental (related to PLA-7861))- Specified by:
getDataSourcein interfaceDataSourceProvider
-
getDataSource
Description copied from interface:DataSourceProviderReturns currently active data source.- Specified by:
getDataSourcein interfaceDataSourceProvider
-
cancelForceMasterMode
public void cancelForceMasterMode()Be careful! This method is intended for internal testing. Generally it's not recommended to cancel forceMaster mode since this would bear the danger of seeing stale data due to switching to slave data source is possible again. -
forceMasterDataSource
public void forceMasterDataSource()Description copied from interface:DataSourceProviderEnforces the usage of a master data source for all subsequent calls toDataSourceProvider.getDataSource()no matter if a slave data source has been activated or not.Please note that this does not affect chosen alternative master data sources. If you want to switch back to the main master data source use
DataSourceProvider.deactivateAlternativeDataSource().- Specified by:
forceMasterDataSourcein interfaceDataSourceProvider
-
createDataSourceFactory
-
createDataSourceFactory
-
getMasterDataSource
Description copied from interface:DataSourceProviderReturns master data source no matter which one is currently active.- Specified by:
getMasterDataSourcein interfaceDataSourceProvider
-
deactivateSlaveDataSource
public void deactivateSlaveDataSource()Description copied from interface:DataSourceProviderAfter slave data source has been activated for the current thread it's necessary to de-activate it again! After this the master data source is active (again).- Specified by:
deactivateSlaveDataSourcein interfaceDataSourceProvider- See Also:
-
deactivateAlternativeDataSource
public void deactivateAlternativeDataSource()Description copied from interface:DataSourceProviderAfter a alternative slave or master data source has been activated for the current thread it's necessary to de-activate it again! After this the base master data source is active (again).- Specified by:
deactivateAlternativeDataSourcein interfaceDataSourceProvider- See Also:
-
getAllSlaveDataSources
Description copied from interface:DataSourceProviderReturns all known slave data sources as Collection.- Specified by:
getAllSlaveDataSourcesin interfaceDataSourceProvider- Returns:
- a
SetwithHybrisDataSourceobjects
-
getAllAlternativeDataSources
-
getAllAlternativeMasterDataSources
Description copied from interface:DataSourceProviderReturns all known alternative master data sources as Collection.- Specified by:
getAllAlternativeMasterDataSourcesin interfaceDataSourceProvider- Returns:
- a
SetwithHybrisDataSourceobjects
-
getAllDataSourceIDs
- Specified by:
getAllDataSourceIDsin interfaceDataSourceProvider
-
getAllAlterntiveDataSourceIDs
-
getAllSlaveDataSourceIDs
Description copied from interface:DataSourceProviderProvides IDs of all available slave data sources.- Specified by:
getAllSlaveDataSourceIDsin interfaceDataSourceProvider
-
getAllAlternativeMasterDataSourceIDs
Description copied from interface:DataSourceProviderProvides IDs of all available alternative master data sources.- Specified by:
getAllAlternativeMasterDataSourceIDsin interfaceDataSourceProvider
-
activateSlaveDataSource
Description copied from interface:DataSourceProviderSwitches to a slave data source for the current thread. If the current data source is already a slave one this has no effect. Use as follows:Tenant t = Registry.getCurrentTenant(); try { t.activateSlaveDataSource(); // ... business logic ... } finally { t.deactivateSlaveSource(); }- Specified by:
activateSlaveDataSourcein interfaceDataSourceProvider- See Also:
-
canSwitch
-
activateSlaveDataSource
Description copied from interface:DataSourceProviderSwitches to a specified (by the id) slave data source for the current thread. If the current data source is already a slave one this has no effect. Use as follows:Tenant t = Registry.getCurrentTenant(); try { t.activateSlaveDataSource("your_slave_id"); // ... business logic ... } finally { t.deactivateSlaveSource(); }- Specified by:
activateSlaveDataSourcein interfaceDataSourceProvider- Parameters:
id- the id string of the slave data source- See Also:
-
activateAlternativeDataSource
-
activateAlternativeMasterDataSource
Description copied from interface:DataSourceProviderSwitches to a specified (by the id) master data source for the current thread. Use as follows:Tenant t = Registry.getCurrentTenant(); try { t.activateMasterDataSource("your_slave_id"); // ... business logic ... } finally { t.deactivateSlaveSource(); }- Specified by:
activateAlternativeMasterDataSourcein interfaceDataSourceProvider- Parameters:
id- the id string of the slave data source- See Also:
-
isForceMaster
public boolean isForceMaster()Description copied from interface:DataSourceProviderIf on the current data source (slave/master) the methodDataSourceProvider.forceMasterDataSource()was called then this method returns true. ADataSourceProvider.deactivateAlternativeDataSource()will reset this state.- Specified by:
isForceMasterin interfaceDataSourceProvider- Returns:
- true if the master data source is forced
-
isSlaveDataSource
public boolean isSlaveDataSource()Description copied from interface:DataSourceProviderTells whether current data source is a slave data source.- Specified by:
isSlaveDataSourcein interfaceDataSourceProvider- Returns:
- true if the
DataSourceProvideris a slave data source
-
isAlternativeMasterDataSource
public boolean isAlternativeMasterDataSource()Description copied from interface:DataSourceProviderTells whether the current active data source is a alternative master data source.- Specified by:
isAlternativeMasterDataSourcein interfaceDataSourceProvider
-
getNextSlave
Returns the next availableAbstractTenant.DataSourceSelection- Returns:
- null if no valid slave was found
-
getInvalidationManager
- Specified by:
getInvalidationManagerin interfaceTenant
-
getCache
-
getPersistencePool
- Specified by:
getPersistencePoolin interfaceTenant
-
getPersistenceManager
- Specified by:
getPersistenceManagerin interfaceTenant
-
getSystemEJB
- Specified by:
getSystemEJBin interfaceTenant
-
getThreadPool
- Specified by:
getThreadPoolin interfaceTenant
-
getWorkersThreadPool
- Specified by:
getWorkersThreadPoolin interfaceTenant
-
getSingletonCreator
- Specified by:
getSingletonCreatorin interfaceTenant
-
getSerialNumberGenerator
- Specified by:
getSerialNumberGeneratorin interfaceTenant
-
createDefaultThreadPool
-
createMasterDataSource
-
createAlternativeDataSources
protected List<AbstractTenant.DataSourceHolder> createAlternativeDataSources(DataSourceFactory defaultFactory, ConfigIntf cfg, Collection<HybrisDataSource> createdForRollback) -
createAlternativeDataSource
protected HybrisDataSource createAlternativeDataSource(DataSourceFactory factory, String id, Map<String, String> params, boolean readOnly) -
mergeSlaveDataSourceParameter
-
extractCustomDBParams
-
extractCustomDBParams
-
extractCustomDBParams
-
extractCustomDBParams
-
createCache
-
isClusteringEnabled
public boolean isClusteringEnabled()checks if clustermode is enabled- Returns:
- 'true' ONLY IF the correspondig property is set to 'true' AND the installed licence file supports this feature, too
- Since:
- 4.0.3
-
getClusterID
Deprecated, for removal: This API element is subject to removal in a future version.since ages - UseRegistry.getClusterID()instead. The cluster ID is a global setting and therefore not strictly depending on the current tenant. -
getDynamicClusterNodeID
public long getDynamicClusterNodeID() -
performWithinOwnSystem
-
getActiveSession
- Specified by:
getActiveSessionin interfaceTenant
-
setActiveSessionForCurrentThread
-
assertTenant
-
getActiveSessionContextList
-
getJaloConnection
- Specified by:
getJaloConnectionin interfaceTenant
-
cannotConnect
public boolean cannotConnect() -
isConnectionPoolCheckEnabled
public boolean isConnectionPoolCheckEnabled() -
connectionHasBeenBroken
public boolean connectionHasBeenBroken() -
clearConnectionHasBeenBroken
public void clearConnectionHasBeenBroken() -
writeReplace
- Throws:
ObjectStreamException
-
isStarting
public final boolean isStarting() -
isStopping
public final boolean isStopping() -
isNotifiyingListeners
public final boolean isNotifiyingListeners() -
createAndRegisterBackgroundThread
- Specified by:
createAndRegisterBackgroundThreadin interfaceTenant
-
backgroundThreadStarted
-
backgroundThreadFinished
-
resetTenantRestartMarker
public void resetTenantRestartMarker()- Specified by:
resetTenantRestartMarkerin interfaceTenant
-
equals
-
hashCode
public int hashCode()
-
Registry.getClusterID()instead.