Search in sources :

Example 1 with ConfigurationManager

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();
}
Also used : Configuration(org.exoplatform.container.xml.Configuration) Properties(java.util.Properties) ConfigurationManager(org.exoplatform.container.configuration.ConfigurationManager) ContainerException(org.exoplatform.container.spi.ContainerException) PrivilegedActionException(java.security.PrivilegedActionException)

Example 2 with ConfigurationManager

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();
}
Also used : InitParams(org.exoplatform.container.xml.InitParams) ValueParam(org.exoplatform.container.xml.ValueParam) ConfigurationManager(org.exoplatform.container.configuration.ConfigurationManager) RPCServiceImpl(org.exoplatform.services.rpc.jgv3.RPCServiceImpl) Before(org.junit.Before)

Example 3 with ConfigurationManager

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();
    }
}
Also used : Serializable(java.io.Serializable) KeyAffinityService(org.infinispan.affinity.KeyAffinityService) HashMap(java.util.HashMap) DistributedCacheManager(org.exoplatform.services.ispn.DistributedCacheManager) ExoCacheConfig(org.exoplatform.services.cache.ExoCacheConfig) ExoCacheFactoryImpl(org.exoplatform.services.cache.impl.infinispan.ExoCacheFactoryImpl) ConfigurationManager(org.exoplatform.container.configuration.ConfigurationManager) DistributionManager(org.infinispan.distribution.DistributionManager) PortalContainer(org.exoplatform.container.PortalContainer)

Example 4 with ConfigurationManager

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);
    }
}
Also used : ExoContainer(org.exoplatform.container.ExoContainer) ArrayList(java.util.ArrayList) ConcurrentContainerMT(org.exoplatform.container.ConcurrentContainerMT) ExternalComponentPlugins(org.exoplatform.container.xml.ExternalComponentPlugins) ComponentTask(org.exoplatform.container.ComponentTask) Component(org.exoplatform.container.xml.Component) ConfigurationManager(org.exoplatform.container.configuration.ConfigurationManager) HashSet(java.util.HashSet) Dependency(org.exoplatform.container.Dependency) CyclicDependencyException(org.exoplatform.container.CyclicDependencyException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Singleton(javax.inject.Singleton) ComponentLifecycle(org.exoplatform.container.component.ComponentLifecycle)

Example 5 with ConfigurationManager

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);
    }
}
Also used : InitParams(org.exoplatform.container.xml.InitParams) ArrayList(java.util.ArrayList) Dependency(org.exoplatform.container.Dependency) CyclicDependencyException(org.exoplatform.container.CyclicDependencyException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ComponentTask(org.exoplatform.container.ComponentTask) Component(org.exoplatform.container.xml.Component) ConfigurationManager(org.exoplatform.container.configuration.ConfigurationManager)

Aggregations

ConfigurationManager (org.exoplatform.container.configuration.ConfigurationManager)10 Component (org.exoplatform.container.xml.Component)6 InitParams (org.exoplatform.container.xml.InitParams)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 PrivilegedActionException (java.security.PrivilegedActionException)2 ArrayList (java.util.ArrayList)2 AbstractComponentAdapter (org.exoplatform.container.AbstractComponentAdapter)2 ComponentTask (org.exoplatform.container.ComponentTask)2 CyclicDependencyException (org.exoplatform.container.CyclicDependencyException)2 Dependency (org.exoplatform.container.Dependency)2 ComponentAdapter (org.exoplatform.container.spi.ComponentAdapter)2 ContainerException (org.exoplatform.container.spi.ContainerException)2 ExternalComponentPlugins (org.exoplatform.container.xml.ExternalComponentPlugins)2 AbstractModule (com.google.inject.AbstractModule)1 Binder (com.google.inject.Binder)1 Serializable (java.io.Serializable)1 Annotation (java.lang.annotation.Annotation)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Properties (java.util.Properties)1