org.wso2.carbon.context.internal
Class CarbonContextDataHolder

java.lang.Object
  extended by org.wso2.carbon.context.internal.CarbonContextDataHolder

public final class CarbonContextDataHolder
extends Object

This class will preserve an instance the current CarbonContext as a thread local variable. If a CarbonContext is available on a global-scope (i.e. HTTP Session or AxisConfiguration) this class will do the required lookup and obtain the corresponding instance.

The CarbonContext provides the API for sub-tenant/super-tenant programming around WSO2 Carbon and WSO2 Stratos.


Field Summary
protected  org.wso2.carbon.registry.api.Registry configSystemRegistry
          The name of the property that stores a reference to the configuration registry instance of the current tenant, as visible to the system.
protected  org.wso2.carbon.registry.api.Registry configUserRegistry
          The name of the property that stores a reference to the configuration registry instance of the current tenant, as visible to a user.
protected  org.wso2.carbon.registry.api.Registry governanceSystemRegistry
          The name of the property that stores a reference to the governance registry instance of the current tenant, as visible to the system.
protected  org.wso2.carbon.registry.api.Registry governanceUserRegistry
          The name of the property that stores a reference to the governance registry instance of the current tenant, as visible to a user.
protected  org.wso2.carbon.registry.api.Registry localRepository
          The name of the property that stores a reference to the local repository instance of the current tenant.
protected  org.wso2.carbon.user.api.UserRealm userRealm
          The name of the property that stores a reference to the UserRealm instance of the current tenant, as visible to a user.
 
Constructor Summary
CarbonContextDataHolder(CarbonContextDataHolder carbonContextHolder)
          Constructor that can be used to create clones.
 
Method Summary
static void destroyCurrentCarbonContextHolder()
          This method will destroy the current CarbonContext holder.
 void endTenantFlow()
          This will end the tenant flow and restore the previous CarbonContext.
 String getApplicationName()
           
 org.wso2.carbon.registry.api.Registry getConfigSystemRegistry()
           
 org.wso2.carbon.registry.api.Registry getConfigUserRegistry()
           
static CarbonContextDataHolder getCurrentCarbonContextHolderBase()
          Method to obtain the current carbon context holder's base.
static org.wso2.carbon.base.DiscoveryService getDiscoveryServiceProvider()
          Method to obtain an instance to the Discovery Service.
 org.wso2.carbon.registry.api.Registry getGovernanceSystemRegistry()
           
 org.wso2.carbon.registry.api.Registry getGovernanceUserRegistry()
           
 org.wso2.carbon.registry.api.Registry getLocalRepository()
           
 Object getProperty(String name)
          Method to obtain a property on this CarbonContext instance.
 String getTenantDomain()
          Method to obtain the tenant domain on this CarbonContext instance.
 int getTenantId()
          Method to obtain the tenant id on this CarbonContext instance.
static CarbonContextDataHolder getThreadLocalCarbonContextHolder()
          This method will always attempt to obtain an instance of the current CarbonContext from the thread-local copy.
 String getUsername()
          Method to obtain the username on this CarbonContext instance.
 org.wso2.carbon.user.api.UserRealm getUserRealm()
           
static void registerUnloadTenantTask(org.wso2.carbon.base.UnloadTenantTask unloadTenantTask)
          Method to register a task that will be executed when a tenant is unloaded.
 void removeQueueManager()
          This method will remove the current multi-tenant queue manager instance.
 void setApplicationName(String applicationName)
           
 void setConfigSystemRegistry(org.wso2.carbon.registry.api.Registry configSystemRegistry)
           
 void setConfigUserRegistry(org.wso2.carbon.registry.api.Registry configUserRegistry)
           
static void setDiscoveryServiceProvider(org.wso2.carbon.base.DiscoveryService discoveryServiceProvider)
          Method to define the instance of the Discovery Service.
 void setGovernanceSystemRegistry(org.wso2.carbon.registry.api.Registry governanceSystemRegistry)
           
 void setGovernanceUserRegistry(org.wso2.carbon.registry.api.Registry governanceUserRegistry)
           
 void setLocalRepository(org.wso2.carbon.registry.api.Registry localRepository)
           
 void setProperty(String name, Object value)
          Method to set a property on this CarbonContext instance.
 void setQueueManager(MultitenantCarbonQueueManager queueManager)
          This method will set the current multi-tenant queue manager instance.
 void setTenantDomain(String domain)
          Method to set the tenant domain on this CarbonContext instance.
 void setTenantId(int tenantId)
          Method to set the tenant id on this CarbonContext instance.
 void setUsername(String username)
          Method to set the username on this CarbonContext instance.
 void setUserRealm(org.wso2.carbon.user.api.UserRealm userRealm)
           
 void startTenantFlow()
          Starts a tenant flow.
 void unloadTenant()
          Method to be called when this tenant is unloaded.
static void unloadTenant(int tenantId)
          Method that will be called when a tenant is unloaded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

localRepository

protected org.wso2.carbon.registry.api.Registry localRepository
The name of the property that stores a reference to the local repository instance of the current tenant.


configSystemRegistry

protected org.wso2.carbon.registry.api.Registry configSystemRegistry
The name of the property that stores a reference to the configuration registry instance of the current tenant, as visible to the system.


governanceSystemRegistry

protected org.wso2.carbon.registry.api.Registry governanceSystemRegistry
The name of the property that stores a reference to the governance registry instance of the current tenant, as visible to the system.


configUserRegistry

protected org.wso2.carbon.registry.api.Registry configUserRegistry
The name of the property that stores a reference to the configuration registry instance of the current tenant, as visible to a user.


governanceUserRegistry

protected org.wso2.carbon.registry.api.Registry governanceUserRegistry
The name of the property that stores a reference to the governance registry instance of the current tenant, as visible to a user.


userRealm

protected org.wso2.carbon.user.api.UserRealm userRealm
The name of the property that stores a reference to the UserRealm instance of the current tenant, as visible to a user.

Constructor Detail

CarbonContextDataHolder

public CarbonContextDataHolder(CarbonContextDataHolder carbonContextHolder)
Constructor that can be used to create clones.

Parameters:
carbonContextHolder - the CarbonContext holder instance of which the clone will be created from.
Method Detail

getLocalRepository

public org.wso2.carbon.registry.api.Registry getLocalRepository()

setLocalRepository

public void setLocalRepository(org.wso2.carbon.registry.api.Registry localRepository)

getConfigSystemRegistry

public org.wso2.carbon.registry.api.Registry getConfigSystemRegistry()

setConfigSystemRegistry

public void setConfigSystemRegistry(org.wso2.carbon.registry.api.Registry configSystemRegistry)

getGovernanceSystemRegistry

public org.wso2.carbon.registry.api.Registry getGovernanceSystemRegistry()

setGovernanceSystemRegistry

public void setGovernanceSystemRegistry(org.wso2.carbon.registry.api.Registry governanceSystemRegistry)

getConfigUserRegistry

public org.wso2.carbon.registry.api.Registry getConfigUserRegistry()

setConfigUserRegistry

public void setConfigUserRegistry(org.wso2.carbon.registry.api.Registry configUserRegistry)

getGovernanceUserRegistry

public org.wso2.carbon.registry.api.Registry getGovernanceUserRegistry()

setGovernanceUserRegistry

public void setGovernanceUserRegistry(org.wso2.carbon.registry.api.Registry governanceUserRegistry)

getUserRealm

public org.wso2.carbon.user.api.UserRealm getUserRealm()

setUserRealm

public void setUserRealm(org.wso2.carbon.user.api.UserRealm userRealm)

getApplicationName

public String getApplicationName()

setApplicationName

public void setApplicationName(String applicationName)

unloadTenant

public void unloadTenant()
Method to be called when this tenant is unloaded. This will clear all the resources created by this tenant on the carbon contexts.


getThreadLocalCarbonContextHolder

public static CarbonContextDataHolder getThreadLocalCarbonContextHolder()
This method will always attempt to obtain an instance of the current CarbonContext from the thread-local copy.

Returns:
the CarbonContext holder.

setQueueManager

public void setQueueManager(MultitenantCarbonQueueManager queueManager)
                     throws org.wso2.carbon.queuing.QueuingException
This method will set the current multi-tenant queue manager instance.

Parameters:
queueManager - the multi-tenant queue manager.
Throws:
org.wso2.carbon.queuing.QueuingException - if the operation failed.

removeQueueManager

public void removeQueueManager()
                        throws org.wso2.carbon.queuing.QueuingException
This method will remove the current multi-tenant queue manager instance.

Throws:
org.wso2.carbon.queuing.QueuingException - if the operation failed.

getDiscoveryServiceProvider

public static org.wso2.carbon.base.DiscoveryService getDiscoveryServiceProvider()
Method to obtain an instance to the Discovery Service.

Returns:
instance of the Discovery Service

setDiscoveryServiceProvider

public static void setDiscoveryServiceProvider(org.wso2.carbon.base.DiscoveryService discoveryServiceProvider)
Method to define the instance of the Discovery Service.

Parameters:
discoveryServiceProvider - the Discovery Service instance.

getCurrentCarbonContextHolderBase

public static CarbonContextDataHolder getCurrentCarbonContextHolderBase()
Method to obtain the current carbon context holder's base.

Returns:
the current carbon context holder's base.

registerUnloadTenantTask

public static void registerUnloadTenantTask(org.wso2.carbon.base.UnloadTenantTask unloadTenantTask)
Method to register a task that will be executed when a tenant is unloaded.

Parameters:
unloadTenantTask - the task to run.
See Also:
UnloadTenantTask

unloadTenant

public static void unloadTenant(int tenantId)
Method that will be called when a tenant is unloaded. This will run all the corresponding tasks that have been registered to be called when a tenant is unloaded.

Parameters:
tenantId - the tenant's identifier.

startTenantFlow

public void startTenantFlow()
Starts a tenant flow. This will stack the current CarbonContext and begin a new nested flow which can have an entirely different context. This is ideal for scenarios where multiple super-tenant and sub-tenant phases are required within as a single block of execution.


endTenantFlow

public void endTenantFlow()
This will end the tenant flow and restore the previous CarbonContext.


getTenantId

public int getTenantId()
Method to obtain the tenant id on this CarbonContext instance.

Returns:
the tenant id.

setTenantId

public void setTenantId(int tenantId)
Method to set the tenant id on this CarbonContext instance.

Parameters:
tenantId - the tenant id.

getUsername

public String getUsername()
Method to obtain the username on this CarbonContext instance.

Returns:
the username.

setUsername

public void setUsername(String username)
Method to set the username on this CarbonContext instance.

Parameters:
username - the username.

getTenantDomain

public String getTenantDomain()
Method to obtain the tenant domain on this CarbonContext instance.

Returns:
the tenant domain.

setTenantDomain

public void setTenantDomain(String domain)
Method to set the tenant domain on this CarbonContext instance.

Parameters:
domain - the tenant domain.

getProperty

public Object getProperty(String name)
Method to obtain a property on this CarbonContext instance.

Parameters:
name - the property name.
Returns:
the value of the property by the given name.

setProperty

public void setProperty(String name,
                        Object value)
Method to set a property on this CarbonContext instance.

Parameters:
name - the property name.
value - the value to be set to the property by the given name.

destroyCurrentCarbonContextHolder

public static void destroyCurrentCarbonContextHolder()
This method will destroy the current CarbonContext holder.



Copyright © 2014 WSO2 Inc. All rights reserved.