Search in sources :

Example 6 with PortalContainer

use of org.exoplatform.container.PortalContainer 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", null, 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 7 with PortalContainer

use of org.exoplatform.container.PortalContainer in project kernel by exoplatform.

the class TestGuiceContainer method testIntegration.

public void testIntegration() {
    URL rootURL = getClass().getResource("test-exo-container.xml");
    URL portalURL = getClass().getResource("test-exo-container2.xml");
    assertNotNull(rootURL);
    assertNotNull(portalURL);
    // 
    new ContainerBuilder().withRoot(rootURL).withPortal(portalURL).build();
    RootContainer root = RootContainer.getInstance();
    testIntegration(root);
    ComponentAdapter<H> adapterH = root.getComponentAdapterOfType(H.class);
    assertNull(adapterH);
    PortalContainer portal = PortalContainer.getInstance();
    adapterH = portal.getComponentAdapterOfType(H.class);
    assertNotNull(adapterH);
    H h = root.getComponentInstanceOfType(H.class);
    assertNull(h);
    h = portal.getComponentInstanceOfType(H.class);
    assertNotNull(h);
    assertSame(h, portal.getComponentInstanceOfType(H.class));
    assertSame(h, adapterH.getComponentInstance());
    List<ComponentAdapter<H>> adapters = root.getComponentAdaptersOfType(H.class);
    assertTrue(adapters == null || adapters.isEmpty());
    adapters = portal.getComponentAdaptersOfType(H.class);
    assertNotNull(adapters);
    assertEquals(1, adapters.size());
    assertSame(h, adapters.get(0).getComponentInstance());
    List<H> allH = root.getComponentInstancesOfType(H.class);
    assertTrue(allH == null || allH.isEmpty());
    allH = portal.getComponentInstancesOfType(H.class);
    assertNotNull(allH);
    assertEquals(1, allH.size());
    assertSame(h, allH.get(0));
}
Also used : ContainerBuilder(org.exoplatform.container.ContainerBuilder) RootContainer(org.exoplatform.container.RootContainer) URL(java.net.URL) ComponentAdapter(org.exoplatform.container.spi.ComponentAdapter) PortalContainer(org.exoplatform.container.PortalContainer)

Example 8 with PortalContainer

use of org.exoplatform.container.PortalContainer in project kernel by exoplatform.

the class TestPortalContainerManagedIntegration method testManagementContext.

public void testManagementContext() {
    URL rootURL = TestPortalContainerManagedIntegration.class.getResource("root-configuration.xml");
    URL portalURL = TestPortalContainerManagedIntegration.class.getResource("portal-configuration.xml");
    // 
    RootContainer root = new ContainerBuilder().withRoot(rootURL).withPortal(portalURL).build();
    ManagementContextImpl rootManagementContext = (ManagementContextImpl) root.getManagementContext();
    // 
    PortalContainer portal = PortalContainer.getInstance();
    ManagementContextImpl portalManagementContext = (ManagementContextImpl) portal.getManagementContext();
    assertSame(root.getManagementContext(), portalManagementContext.getParent());
    assertNotNull(portalManagementContext.findContainer());
    // 
    SimpleManagementAware rootManagementAware = (SimpleManagementAware) root.getComponentInstance("RootManagementAware");
    ManagementContextImpl rootManagementAwareContext = (ManagementContextImpl) rootManagementAware.context;
    assertSame(rootManagementContext, rootManagementAwareContext.getParent());
    // 
    SimpleManagementAware portalManagementAware = (SimpleManagementAware) portal.getComponentInstance("PortalManagementAware");
    ManagementContextImpl portalManagementAwareContext = (ManagementContextImpl) portalManagementAware.context;
    assertSame(portalManagementContext, portalManagementAwareContext.getParent());
}
Also used : ContainerBuilder(org.exoplatform.container.ContainerBuilder) RootContainer(org.exoplatform.container.RootContainer) ManagementContextImpl(org.exoplatform.container.management.ManagementContextImpl) SimpleManagementAware(org.exoplatform.container.jmx.support.SimpleManagementAware) URL(java.net.URL) PortalContainer(org.exoplatform.container.PortalContainer)

Example 9 with PortalContainer

use of org.exoplatform.container.PortalContainer in project kernel by exoplatform.

the class TestContainer method testComponent2.

public void testComponent2() throws Exception {
    RootContainer rootContainer = RootContainer.getInstance();
    PortalContainer pcontainer = rootContainer.getPortalContainer("portal");
    assertNotNull(pcontainer);
    MultibleComponent c = (MultibleComponent) pcontainer.getComponentInstanceOfType(MultibleComponent.class);
    assertNotNull(c);
    c = (MultibleComponent) pcontainer.getComponentInstanceOfType(MultibleComponent.class);
    assertNotNull(c);
    c = (MultibleComponent) pcontainer.getComponentInstanceOfType(MultibleComponent.class);
    assertNotNull(c);
}
Also used : RootContainer(org.exoplatform.container.RootContainer) PortalContainer(org.exoplatform.container.PortalContainer)

Example 10 with PortalContainer

use of org.exoplatform.container.PortalContainer in project kernel by exoplatform.

the class TestContainer method testPortalContainer.

public void testPortalContainer() throws Exception {
    RootContainer rootContainer = RootContainer.getInstance();
    PortalContainer pcontainer = rootContainer.getPortalContainer("portal");
    Object parent = pcontainer.getParent();
    assertTrue("Root container should not be null", parent != null);
    // performance test
    int INSERTLOOP = 0;
    for (int i = 0; i < INSERTLOOP; i++) {
        rootContainer.getPortalContainer("name-" + Integer.toString(i));
    }
    int LOOP = 10000000;
    for (int i = 0; i < LOOP; i++) {
        pcontainer = (PortalContainer) rootContainer.getComponentInstance("portal");
        assertTrue("not null", pcontainer != null);
    }
}
Also used : RootContainer(org.exoplatform.container.RootContainer) PortalContainer(org.exoplatform.container.PortalContainer)

Aggregations

PortalContainer (org.exoplatform.container.PortalContainer)24 RootContainer (org.exoplatform.container.RootContainer)9 ExoContainer (org.exoplatform.container.ExoContainer)7 URL (java.net.URL)4 ContainerBuilder (org.exoplatform.container.ContainerBuilder)4 ComponentAdapter (org.exoplatform.container.spi.ComponentAdapter)3 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 ComponentPlugin (org.exoplatform.container.component.ComponentPlugin)1 ConfigurationManager (org.exoplatform.container.configuration.ConfigurationManager)1 SimpleManagementAware (org.exoplatform.container.jmx.support.SimpleManagementAware)1 ManagementContextImpl (org.exoplatform.container.management.ManagementContextImpl)1 PriorityService (org.exoplatform.mocks.PriorityService)1 ExoCacheConfig (org.exoplatform.services.cache.ExoCacheConfig)1 ExoCacheFactoryImpl (org.exoplatform.services.cache.impl.infinispan.ExoCacheFactoryImpl)1 DistributedCacheManager (org.exoplatform.services.ispn.DistributedCacheManager)1 QueueTasks (org.exoplatform.services.scheduler.QueueTasks)1 Task (org.exoplatform.services.scheduler.Task)1 KeyAffinityService (org.infinispan.affinity.KeyAffinityService)1 DistributionManager (org.infinispan.distribution.DistributionManager)1