public class TenantContainer extends Object
TenantContainer.run
Constructor and Description |
---|
TenantContainer() |
Modifier and Type | Method and Description |
---|---|
void |
addShutdownHook(Thread hook)
Register a new tenant shutdown hook.
|
String |
clearProperty(String key)
Removes the property indicated by the specified key.
|
static TenantContainer |
containerOf(Object obj)
Retrieve the tenant container where
obj is allocated in |
static TenantContainer |
create(String name,
TenantConfiguration configuration)
Create tenant container by the name and configuration
|
static TenantContainer |
create(TenantConfiguration configuration)
Create tenant container by the configuration
|
static TenantContainer |
create(TenantContainer parent,
String name,
TenantConfiguration configuration)
Create tenant container by the name and configuration
|
static TenantContainer |
create(TenantContainer parent,
TenantConfiguration configuration)
Create tenant container by the configuration
|
static TenantContainer |
current()
Gets the TenantContainer attached to the current thread.
|
void |
destroy()
Destroy this tenant container and release occupied resources including memory, cpu, FD, etc.
|
long |
getAllocatedMemory()
Get total allocated memory of this tenant.
|
static List<Long> |
getAllTenantIds()
Gets the tenant id list
|
Thread[] |
getAttachedThreads() |
<K,T> T |
getFieldValue(K obj,
String fieldName)
Gets the field value stored in the data repository of this tenant, which is same to call the
TenantData.getFieldValue on the tenant data object retrieved by TenantContainer.getTenantData . |
<K,T> T |
getFieldValue(K obj,
String fieldName,
Supplier<T> supplier)
Gets the field value stored in the data repository of this tenant, which is same to call the
TenantData.getFieldValue on the tenant data object retrieved by TenantContainer.getTenantData . |
String |
getName()
Returns this tenant's name.
|
long |
getOccupiedMemory()
Gets the heap space occupied by this tenant
|
long |
getProcessCpuTime()
Gets the cpu time consumed by this tenant
|
Properties |
getProperties()
Gets the properties of tenant
|
String |
getProperty(String key)
Gets the property indicated by the specified key.
|
ResourceContainer |
getResourceContainer() |
TenantState |
getState() |
static TenantContainer |
getTenantContainerById(long id)
Get the tenant container by id
|
TenantData |
getTenantData()
Retrieves the data repository used by this tenant.
|
long |
getTenantId()
Returns the tenant' id
|
static void |
primitiveRunInRoot(Runnable runnable)
Runs a block of code in the root tenant.
|
static <T> T |
primitiveRunInRoot(Supplier<T> supplier)
Runs
Supplier.get in the root tenant. |
boolean |
removeShutdownHook(Thread hook)
De-registers a previously-registered tenant shutdown hook.
|
void |
run(Runnable runnable)
Runs the code in the target tenant container
|
void |
setProperties(Properties props)
Sets the tenant properties to the one specified by argument.
|
String |
setProperty(String key,
String value)
Sets the property indicated by the specified key.
|
public long getAllocatedMemory()
public TenantData getTenantData()
public void setProperties(Properties props)
props
- the properties to be set, CoW the system properties if it is null.public Properties getProperties()
public String setProperty(String key, String value)
key
- the name of the property.value
- the value of the property.public String getProperty(String key)
key
- the name of the property.public String clearProperty(String key)
key
- the name of the property to be removed.public void destroy()
Destroy this tenant container and release occupied resources including memory, cpu, FD, etc.
Properties to control the behavioral details of TenantContainer.shutdown:
destroy()
method
from return, if still live threads more aggressive approaches may be employed to kill threads. If not
speicified, will block TenantContainer.destroy()
until all spawned threads got killed.
public TenantState getState()
public long getTenantId()
public String getName()
public Thread[] getAttachedThreads()
public static TenantContainer getTenantContainerById(long id)
id
- tenant id.public static TenantContainer create(TenantConfiguration configuration)
configuration
- used to create tenantpublic static TenantContainer create(TenantContainer parent, TenantConfiguration configuration)
parent
- parent tenant containerconfiguration
- used to create tenantpublic static TenantContainer create(String name, TenantConfiguration configuration)
name
- the tenant nameconfiguration
- used to create tenantpublic static TenantContainer create(TenantContainer parent, String name, TenantConfiguration configuration)
parent
- parent tenant containername
- the tenant nameconfiguration
- used to create tenantpublic static List<Long> getAllTenantIds()
public static TenantContainer current()
public long getProcessCpuTime()
public long getOccupiedMemory()
IllegalStateException
- if -XX:+TenantHeapThrottling is not enabled.public void run(Runnable runnable) throws TenantException
runnable
- the code to runTenantException
public static TenantContainer containerOf(Object obj)
obj
is allocated inobj
- object to be searchedobj
,
or null if ROOT tenant containerpublic <K,T> T getFieldValue(K obj, String fieldName, Supplier<T> supplier)
TenantData.getFieldValue
on the tenant data object retrieved by TenantContainer.getTenantData
.obj
- Object the field associates withfieldName
- Field namesupplier
- Responsible for creating the initial field valuepublic <K,T> T getFieldValue(K obj, String fieldName)
TenantData.getFieldValue
on the tenant data object retrieved by TenantContainer.getTenantData
.obj
- Object the field associates withfieldName
- Field namepublic static <T> T primitiveRunInRoot(Supplier<T> supplier)
Supplier.get
in the root tenant.supplier
- target used to callSupplier.get
public static void primitiveRunInRoot(Runnable runnable)
runnable
- the code to runpublic void addShutdownHook(Thread hook)
hook
- An initialized but unstarted Thread
objectpublic boolean removeShutdownHook(Thread hook)
hook
- the hook to removepublic ResourceContainer getResourceContainer()
ResourceContainer
of this tenant"Copyright 2018, Alibaba, Inc."