use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class SpringPentahoObjectReference method getObject.
@Override
@SuppressWarnings("unchecked")
public T getObject() {
IPentahoSession sessionToUse = session != null ? session : PentahoSessionHolder.getSession();
SpringScopeSessionHolder.SESSION.set(sessionToUse);
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
Object obj = context.getBeanFactory().getBean(name);
SpringScopeSessionHolder.SESSION.set(null);
if (obj instanceof IPentahoInitializer) {
((IPentahoInitializer) obj).init(sessionToUse);
}
return (T) obj;
} finally {
Thread.currentThread().setContextClassLoader(originalClassLoader);
}
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class InheritableThreadLocalPentahoSessionHolderStrategy method removeSession.
/**
* Removes the IPentahoSession for the current thread. It is important that the framework calls this to prevent
* session bleed- through between requests as threads are re-used by the server.
*/
public void removeSession() {
IPentahoSession sess = perThreadSession.get();
if (sess != null) {
if (logger.isDebugEnabled()) {
logger.debug(// $NON-NLS-1$
Messages.getInstance().getString(// $NON-NLS-1$
"PentahoSessionHolder.DEBUG_REMOVING_SESSION", Thread.currentThread().getName(), String.valueOf(Thread.currentThread().getId())));
}
if (logger.isTraceEnabled()) {
StackTraceElement[] elements = Thread.currentThread().getStackTrace();
// $NON-NLS-1$
logger.trace(Messages.getInstance().getString("PentahoSessionHolder.DEBUG_THREAD_STACK_TRACE"));
for (int i = 0; i < elements.length; i++) {
logger.trace(elements[i]);
}
}
// If the session is a custom/stand-alone session, we need to remove references
// to it from other objects which may be holding on to it. We do this to prevent
// memory leaks. In the future, this should not be necessary since objects
// should not need to have setSesssion methods, but instead use PentahoSessionHolder.getSession()
//
// Disabled as this is one of the points why the Trusted User Filter stopped working
/*
if ( sess instanceof StandaloneSession ) {
if ( logger.isDebugEnabled() ) {
logger.debug( Messages.getInstance().getString( "PentahoSessionHolder.DEBUG_DESTROY_STANDALONE_SESSION", //$NON-NLS-1$
String.valueOf( sess.getId() ), sess.getName(), String.valueOf( Thread.currentThread().getId() ) ) );
}
( (StandaloneSession) sess ).destroy();
}
*/
perThreadSession.remove();
}
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class SessionCachingMetadataDomainRepository method getDomainIds.
@Override
public Set<String> getDomainIds() {
final IPentahoSession session = PentahoSessionHolder.getSession();
final String domainKey = generateDomainIdCacheKeyForSession(session);
Set<String> domainIds;
if (domainIdsCacheEnabled) {
domainIds = (Set<String>) cacheManager.getFromRegionCache(CACHE_REGION, domainKey);
if (domainIds != null) {
boolean dirtyCache = false;
for (String domain : domainIds) {
if (delegate instanceof IAclAwarePentahoMetadataDomainRepositoryImporter && !((IAclAwarePentahoMetadataDomainRepositoryImporter) delegate).hasAccessFor(domain)) {
domainIds.remove(domain);
removeDomainFromIDCache(domain);
dirtyCache = true;
}
}
if (dirtyCache) {
cacheManager.putInRegionCache(CACHE_REGION, domainKey, new HashSet<String>(domainIds));
}
// We've previously cached domainIds available for this session
return domainIds;
}
} else {
delegate.reloadDomains();
}
// Domains are accessible by anyone. What they contain may be different so rely on the lookup to be
// session-specific.
domainIds = delegate.getDomainIds();
if (domainIdsCacheEnabled) {
cacheManager.putInRegionCache(CACHE_REGION, domainKey, new HashSet<String>(domainIds));
}
return domainIds;
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class DefaultPluginManager method reload.
@Override
public final boolean reload() {
IPentahoSession session = PentahoSessionHolder.getSession();
boolean anyErrors = false;
IPluginProvider pluginProvider = PentahoSystem.get(IPluginProvider.class, "IPluginProvider", session);
List<IPlatformPlugin> providedPlugins = null;
try {
synchronized (registeredPlugins) {
this.unloadPlugins();
}
// the plugin may fail to load during getPlugins without an exception thrown if the provider
// is capable of discovering the plugin fine but there are structural problems with the plugin
// itself. In this case a warning should be logged by the provider, but, again, no exception
// is expected.
providedPlugins = pluginProvider.getPlugins(session);
} catch (PlatformPluginRegistrationException e1) {
String msg = // $NON-NLS-1$
Messages.getInstance().getErrorString("PluginManager.ERROR_0012_PLUGIN_DISCOVERY_FAILED");
Logger.error(getClass().toString(), msg, e1);
PluginMessageLogger.add(msg);
anyErrors = true;
}
synchronized (providedPlugins) {
for (IPlatformPlugin plugin : providedPlugins) {
try {
registeredPlugins.put(plugin.getId(), plugin);
ClassLoader loader = setPluginClassLoader(plugin);
initializeBeanFactory(plugin, loader);
} catch (Throwable t) {
// this has been logged already
anyErrors = true;
String msg = Messages.getInstance().getErrorString("PluginManager.ERROR_0011_FAILED_TO_REGISTER_PLUGIN", // $NON-NLS-1$
plugin.getId());
Logger.error(getClass().toString(), msg, t);
PluginMessageLogger.add(msg);
}
}
registeredPlugins.clear();
for (IPlatformPlugin plugin : providedPlugins) {
try {
GenericApplicationContext beanFactory = beanFactoryMap.get(plugin.getId());
if (beanFactory != null) {
beanFactory.refresh();
}
registerPlugin(plugin);
registeredPlugins.put(plugin.getId(), plugin);
} catch (Throwable t) {
// this has been logged already
anyErrors = true;
String msg = Messages.getInstance().getErrorString("PluginManager.ERROR_0011_FAILED_TO_REGISTER_PLUGIN", // $NON-NLS-1$
plugin.getId());
Logger.error(getClass().toString(), msg, t);
PluginMessageLogger.add(msg);
}
}
}
IServiceManager svcManager = PentahoSystem.get(IServiceManager.class, null);
if (svcManager != null) {
try {
svcManager.initServices();
} catch (ServiceInitializationException e) {
String msg = Messages.getInstance().getErrorString(// $NON-NLS-1$
"PluginManager.ERROR_0022_SERVICE_INITIALIZATION_FAILED");
Logger.error(getClass().toString(), msg, e);
PluginMessageLogger.add(msg);
}
}
return !anyErrors;
}
use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.
the class PentahoSystemPluginManager method registerContentGenerators.
private void registerContentGenerators(IPlatformPlugin plugin, ClassLoader loader, final GenericApplicationContext beanFactory) throws PlatformPluginRegistrationException {
// register the content generators
for (final IContentGeneratorInfo cgInfo : plugin.getContentGenerators()) {
// define the bean in the factory
BeanDefinition beanDef = BeanDefinitionBuilder.rootBeanDefinition(cgInfo.getClassname()).setScope(BeanDefinition.SCOPE_PROTOTYPE).getBeanDefinition();
// register bean with alias of content generator id (old way)
beanFactory.registerBeanDefinition(cgInfo.getId(), beanDef);
// register bean with alias of type (with default perspective) as well (new way)
beanFactory.registerAlias(cgInfo.getId(), cgInfo.getType());
PluginMessageLogger.add(Messages.getInstance().getString("PluginManager.USER_CONTENT_GENERATOR_REGISTERED", cgInfo.getId(), plugin.getId()));
final HashMap<String, Object> attributes = new HashMap<String, Object>();
attributes.put(PLUGIN_ID, plugin.getId());
attributes.put(CONTENT_TYPE, cgInfo.getType());
final IPentahoObjectRegistration referenceHandle = PentahoSystem.registerReference(new PrototypePentahoObjectReference.Builder<IContentGenerator>(IContentGenerator.class).creator(new IObjectCreator<IContentGenerator>() {
@Override
public IContentGenerator create(IPentahoSession session) {
return (IContentGenerator) beanFactory.getBean(cgInfo.getId());
}
}).attributes(attributes).build(), IContentGenerator.class);
registerReference(plugin.getId(), referenceHandle);
}
// The remaining operations require a beanFactory
if (beanFactory == null) {
return;
}
String[] names = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory.getBeanFactory(), IContentGenerator.class);
ArrayList<String> ids = new ArrayList<String>();
for (String beanName : names) {
ids.add(beanName);
Collections.addAll(ids, beanFactory.getAliases(beanName));
}
for (final String beanName : ids) {
final HashMap<String, Object> attributes = new HashMap<String, Object>();
attributes.put(PLUGIN_ID, plugin.getId());
attributes.put(CONTENT_TYPE, beanName);
final IPentahoObjectRegistration referenceHandle = PentahoSystem.registerReference(new PrototypePentahoObjectReference.Builder<IContentGenerator>(IContentGenerator.class).creator(new IObjectCreator<IContentGenerator>() {
@Override
public IContentGenerator create(IPentahoSession session) {
return (IContentGenerator) beanFactory.getBean(beanName);
}
}).attributes(attributes).build(), IContentGenerator.class);
registerReference(plugin.getId(), referenceHandle);
}
}
Aggregations