com.atlassian.confluence.tenant
Class TenantGate

java.lang.Object
  extended by com.atlassian.confluence.tenant.TenantGate
All Implemented Interfaces:
org.springframework.beans.factory.FactoryBean

public abstract class TenantGate
extends java.lang.Object
implements org.springframework.beans.factory.FactoryBean

Prevents access to tenanted beans in case of a vacant (zero tenancy) instance.

The default behaviour is to escape with a VacantException, but the gate can also delegate to a vacant implementation which could behave somehow differently.

This class should be considered a temporary solution on the way to multi-tenancy. It's sole purpose is currently to delay the initialisation of SessionFactory beans until a system tenant arrived.

I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the TenantGate. All those moments will be lost in time... like tears in rain... Time to die.

Since:
5.6
See Also:
SystemTenant

Field Summary
protected  java.lang.Class[] proxyInterfaces
           
protected  TenantRegistry tenantRegistry
           
 
Constructor Summary
protected TenantGate(TenantRegistry tenantRegistry, java.lang.Class[] proxyInterfaces)
           
 
Method Summary
static
<T> java.util.concurrent.Callable<T>
close(java.util.concurrent.Callable<T> callback)
          Close all gates for the given closure on the current thread.
protected abstract  java.lang.Object createTenantedDelegate()
           
protected  java.lang.Object createVacantDelegate()
           
 java.lang.Object getObject()
           
 java.lang.Class getObjectType()
           
 boolean isPermitted()
           
 boolean isSingleton()
           
static
<T> java.util.concurrent.Callable<T>
open(java.util.concurrent.Callable<T> callback)
          Open all gates for the given closure on the current thread.
static
<T> java.util.concurrent.Callable<T>
permit(boolean permitted, java.util.concurrent.Callable<T> callback)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tenantRegistry

protected final TenantRegistry tenantRegistry

proxyInterfaces

protected final java.lang.Class[] proxyInterfaces
Constructor Detail

TenantGate

protected TenantGate(TenantRegistry tenantRegistry,
                     java.lang.Class[] proxyInterfaces)
Method Detail

isPermitted

public boolean isPermitted()
Returns:
checks if the current thread is allowed to pass through the gate

open

public static <T> java.util.concurrent.Callable<T> open(java.util.concurrent.Callable<T> callback)
Open all gates for the given closure on the current thread.

This only makes sense in a pre-tenanted state, e.g. during setup allow code to prepare the database before it's made available to a broader audience.

Parameters:
callback - the function allowed to pass through the gate
Returns:
the permitted function

close

public static <T> java.util.concurrent.Callable<T> close(java.util.concurrent.Callable<T> callback)
Close all gates for the given closure on the current thread.

This only makes sense in a pre-tenanted state, if you want to ensure that the given code can not access tenanted resources even though an outer closure might have granted that access, e.g. loading DefaultPluginManager.earlyStartup() plugins which should not be able to eagerly access tenanted resources.

Parameters:
callback - the function allowed to pass through the gate
Returns:
the permitted function

createVacantDelegate

protected java.lang.Object createVacantDelegate()

createTenantedDelegate

protected abstract java.lang.Object createTenantedDelegate()

getObject

public final java.lang.Object getObject()
                                 throws java.lang.Exception
Specified by:
getObject in interface org.springframework.beans.factory.FactoryBean
Throws:
java.lang.Exception

getObjectType

public final java.lang.Class getObjectType()
Specified by:
getObjectType in interface org.springframework.beans.factory.FactoryBean

isSingleton

public final boolean isSingleton()
Specified by:
isSingleton in interface org.springframework.beans.factory.FactoryBean

permit

public static <T> java.util.concurrent.Callable<T> permit(boolean permitted,
                                                          java.util.concurrent.Callable<T> callback)


Copyright © 2003-2014 Atlassian. All Rights Reserved.