use of org.exoplatform.container.configuration.ConfigurationManager in project kernel by exoplatform.
the class RootContainer method dynamicReload.
private void dynamicReload() {
final ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
final Properties currentSystemProperties = System.getProperties();
boolean hasChanged = false;
Configuration newConfig = null;
try {
Thread.currentThread().setContextClassLoader(loadingCL);
hasChanged = true;
System.setProperties(loadingSystemProperties);
ConfigurationManager cm = loadConfigurationManager(this, false);
if (cm != null) {
newConfig = cm.getConfiguration();
}
} catch (Exception e) {
if (LOG.isDebugEnabled()) {
LOG.debug("Could not load the new configuration of the root container", e);
}
} finally {
if (hasChanged) {
Thread.currentThread().setContextClassLoader(currentClassLoader);
System.setProperties(currentSystemProperties);
}
}
if (newConfig == null) {
// We have no way to know if the configuration of the root container has changed so
// we reload everything
LOG.info("The new configuration of the root container could not be loaded," + " thus everything will be reloaded");
reload();
return;
}
Configuration currentConfig = getConfiguration();
if (currentConfig == null) {
// We have no way to know if the configuration of the root container has changed so
// we reload everything
LOG.info("The current configuration of the root container could not be loaded," + " thus everything will be reloaded");
reload();
return;
}
if (newConfig.getCurrentSize() != currentConfig.getCurrentSize() || newConfig.getCurrentHash() != currentConfig.getCurrentHash()) {
// The root container has changed so we reload everything
LOG.info("The configuration of the root container has changed," + " thus everything will be reloaded");
reload();
return;
}
LOG.info("The configuration of the root container did not change," + " thus only affected portal containers will be reloaded");
for (String pc : portalContainer2Reload) {
// At least one dependency has changed so we reload all the affected portal containers
reload(pc);
}
onStartupComplete();
}
use of org.exoplatform.container.configuration.ConfigurationManager in project kernel by exoplatform.
the class TestSimpleReplicatedExoCache method init.
@Before
public void init() throws Exception {
container = PortalContainer.getInstance();
ConfigurationManager configManager = container.getComponentInstanceOfType(ConfigurationManager.class);
InitParams params = new InitParams();
ValueParam paramConf = new ValueParam();
paramConf.setName("jgroups-configuration");
paramConf.setValue("jar:/conf/portal/udp.xml");
params.addParameter(paramConf);
service1 = new RPCServiceImpl(container.getContext(), params, configManager);
service2 = new RPCServiceImpl(container.getContext(), params, configManager);
cache1 = new SimpleReplicatedExoCache<String, String>(container.getContext(), service1);
cache2 = new SimpleReplicatedExoCache<String, String>(container.getContext(), service2);
cache1.setName("TestSimpleReplicatedExoCache");
cache2.setName("TestSimpleReplicatedExoCache");
service1.start();
service2.start();
}
use of org.exoplatform.container.configuration.ConfigurationManager in project kernel by exoplatform.
the class TestDistributedExoCache method testDistributedCache.
/**
* WARNING: For Linux distributions the following JVM parameter must be set to true: java.net.preferIPv4Stack.
*
* @throws Exception
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testDistributedCache() throws Exception {
PortalContainer pc = PortalContainer.getInstance();
ExoCacheConfig config = new ExoCacheConfig();
config.setName("MyCacheDistributed");
config.setMaxSize(5);
config.setLiveTime(1);
config.setImplementation("LRU");
config.setDistributed(true);
Map<String, String> params = new HashMap<String, String>();
params.put("infinispan-num-owners", "1");
ConfigurationManager cm = (ConfigurationManager) pc.getComponentInstanceOfType(ConfigurationManager.class);
DistributedCacheManager dcm2 = new DistributedCacheManager("jar:/conf/portal/distributed-cache-configuration.xml", params, cm);
DistributedExoCache<Serializable, Object> cache1 = (DistributedExoCache<Serializable, Object>) ((ExoCacheFactory) pc.getComponentInstanceOfType(ExoCacheFactory.class)).createCache(config);
DistributionManager dm = cache1.getCache().getDistributionManager();
DistributedExoCache<Serializable, Object> cache2 = (DistributedExoCache<Serializable, Object>) new ExoCacheFactoryImpl((ExoContainerContext) pc.getComponentInstanceOfType(ExoContainerContext.class), "jar:/conf/portal/cache-configuration-template.xml", cm, dcm2).createCache(config);
KeyAffinityService kas1 = KeyAffinityServiceFactory.newLocalKeyAffinityService(cache1.getCache(), new MyKeyGenerator(cache1.getFullName()), Executors.newSingleThreadExecutor(), 100);
KeyAffinityService kas2 = KeyAffinityServiceFactory.newLocalKeyAffinityService(cache2.getCache(), new MyKeyGenerator(cache1.getFullName()), Executors.newSingleThreadExecutor(), 100);
try {
Object a, b, c;
for (int i = 0; i < 2; i++) {
if (i == 0) {
a = new MyKey("a", ((DistributedExoCache.CacheKey<MyKey>) kas1.getKeyForAddress(cache1.getCache().getRpcManager().getAddress())).getKey().value);
} else {
a = new MyKey("a", ((DistributedExoCache.CacheKey<MyKey>) kas2.getKeyForAddress(cache2.getCache().getRpcManager().getAddress())).getKey().value);
}
for (int j = 0; j < 2; j++) {
if (j == 0) {
b = new MyKey("b", ((DistributedExoCache.CacheKey<MyKey>) kas1.getKeyForAddress(cache1.getCache().getRpcManager().getAddress())).getKey().value);
} else {
b = new MyKey("b", ((DistributedExoCache.CacheKey<MyKey>) kas2.getKeyForAddress(cache2.getCache().getRpcManager().getAddress())).getKey().value);
}
for (int k = 0; k < 2; k++) {
if (k == 0) {
c = new MyKey("c", ((DistributedExoCache.CacheKey<MyKey>) kas1.getKeyForAddress(cache1.getCache().getRpcManager().getAddress())).getKey().value);
} else {
c = new MyKey("c", ((DistributedExoCache.CacheKey<MyKey>) kas2.getKeyForAddress(cache2.getCache().getRpcManager().getAddress())).getKey().value);
}
checkUseCase(cache1, cache2, dm, a, b, c);
}
}
}
} finally {
dcm2.stop();
}
}
use of org.exoplatform.container.configuration.ConfigurationManager in project kernel by exoplatform.
the class MX4JComponentAdapterMT method getInitTasks.
/**
* {@inheritDoc}
*/
protected Collection<ComponentTask<Void>> getInitTasks() {
Component component = null;
String componentKey;
boolean debug = false;
// Get the component
Object key = getComponentKey();
if (key instanceof String)
componentKey = (String) key;
else
componentKey = ((Class<?>) key).getName();
try {
ConfigurationManager manager = (ConfigurationManager) exocontainer.getComponentInstanceOfType(ConfigurationManager.class);
component = manager == null ? null : manager.getComponent(componentKey);
if (component != null) {
debug = component.getShowDeployInfo();
}
List<ComponentTask<Void>> tasks = new ArrayList<ComponentTask<Void>>();
Set<Dependency> dependencies = new HashSet<Dependency>();
final Class<T> implementationClass = getComponentImplementation();
boolean isSingleton = this.isSingleton;
boolean isInitialized = this.isInitialized;
if (debug)
LOG.debug("==> create component : " + implementationClass.getName());
boolean hasInjectableConstructor = !isSingleton || ContainerUtil.hasInjectableConstructor(implementationClass);
boolean hasOnlyEmptyPublicConstructor = !isSingleton || ContainerUtil.hasOnlyEmptyPublicConstructor(implementationClass);
if (hasInjectableConstructor || hasOnlyEmptyPublicConstructor) {
// There is at least one constructor JSR 330 compliant or we already know
// that it is not a singleton such that the new behavior is expected
List<Dependency> lDependencies = new ArrayList<Dependency>();
boolean isInjectPresent = container.initializeComponent(implementationClass, lDependencies, tasks, this);
dependencies.addAll(lDependencies);
isSingleton = manageScope(isSingleton, isInitialized, hasInjectableConstructor, isInjectPresent);
} else if (!isInitialized) {
// The adapter has not been initialized yet
// The old behavior is expected as there is no constructor JSR 330 compliant
isSingleton = this.isSingleton = true;
scope.set(Singleton.class);
}
if (component != null && component.getComponentPlugins() != null) {
addComponentPlugin(tasks, dependencies, debug, component.getComponentPlugins());
}
ExternalComponentPlugins ecplugins = manager == null ? null : manager.getConfiguration().getExternalComponentPlugins(componentKey);
if (ecplugins != null) {
addComponentPlugin(tasks, dependencies, debug, ecplugins.getComponentPlugins());
}
initDependencies.compareAndSet(null, new CopyOnWriteArraySet<Dependency>(dependencies));
tasks.add(new ComponentTask<Void>("initialize component " + getComponentImplementation().getName(), container, this, ComponentTaskType.INIT) {
public Void execute(CreationalContextComponentAdapter<?> cCtx) throws Exception {
// check if component implement the ComponentLifecycle
if (cCtx.get() instanceof ComponentLifecycle && exocontainer instanceof ExoContainer) {
ComponentLifecycle lc = (ComponentLifecycle) cCtx.get();
lc.initComponent((ExoContainer) exocontainer);
}
return null;
}
});
if (!isInitialized) {
this.isInitialized = true;
}
return tasks;
} catch (Exception e) {
String msg = "Cannot initialize component " + getComponentImplementation();
if (component != null) {
msg = "Cannot initialize component key=" + component.getKey() + " type=" + component.getType() + " found at " + component.getDocumentURL();
}
throw new RuntimeException(msg, e);
}
}
use of org.exoplatform.container.configuration.ConfigurationManager in project kernel by exoplatform.
the class MX4JComponentAdapterMT method getCreateTask.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
protected ComponentTask<T> getCreateTask() {
Component component = null;
String componentKey;
InitParams params = null;
boolean debug = false;
// Get the component
Object key = getComponentKey();
if (key instanceof String)
componentKey = (String) key;
else
componentKey = ((Class<?>) key).getName();
try {
ConfigurationManager manager = (ConfigurationManager) exocontainer.getComponentInstanceOfType(ConfigurationManager.class);
component = manager == null ? null : manager.getComponent(componentKey);
if (component != null) {
params = component.getInitParams();
debug = component.getShowDeployInfo();
}
if (debug)
LOG.debug("==> get constructor of the component : " + getComponentImplementation());
List<Dependency> lDependencies = new ArrayList<Dependency>();
Constructor<?> constructor = container.getConstructor(getComponentImplementation(), lDependencies);
setCreateDependencies(lDependencies);
if (debug)
LOG.debug("==> create component : " + getComponentImplementation());
return (ComponentTask<T>) container.createComponentTask(constructor, params, lDependencies, this);
} catch (Exception e) {
String msg = "Cannot instantiate component " + getComponentImplementation();
if (component != null) {
msg = "Cannot instantiate component key=" + component.getKey() + " type=" + component.getType() + " found at " + component.getDocumentURL();
}
throw new RuntimeException(msg, e);
}
}
Aggregations