Java Code Examples for org.apache.ignite.configuration.IgniteConfiguration#setLifecycleBeans()

The following examples show how to use org.apache.ignite.configuration.IgniteConfiguration#setLifecycleBeans() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GridFactorySelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param igniteInstanceName Ignite instance name.
 * @throws Exception If test failed.
 */
private void checkLifecycleBeans(@Nullable String igniteInstanceName) throws Exception {
    TestLifecycleBean bean1 = new TestLifecycleBean();
    TestLifecycleBean bean2 = new TestLifecycleBean();

    IgniteConfiguration cfg = new IgniteConfiguration();

    cfg.setLifecycleBeans(bean1, bean2);
    cfg.setIgniteInstanceName(igniteInstanceName);

    cfg.setEventStorageSpi(new MemoryEventStorageSpi());

    cfg.setConnectorConfiguration(null);

    try (Ignite g = IgniteSpring.start(cfg, new GenericApplicationContext())) {
        bean1.checkState(igniteInstanceName, true);
        bean2.checkState(igniteInstanceName, true);
    }

    bean1.checkState(igniteInstanceName, false);
    bean2.checkState(igniteInstanceName, false);

    checkLifecycleBean(bean1, igniteInstanceName);
    checkLifecycleBean(bean2, igniteInstanceName);
}
 
Example 2
Source File: GridCacheDhtPreloadUnloadSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);

    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setCacheMode(PARTITIONED);
    cc.setRebalanceBatchSize(preloadBatchSize);
    cc.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
    cc.setRebalanceMode(preloadMode);
    cc.setAffinity(new RendezvousAffinityFunction(false, partitions));
    cc.setBackups(backups);
    cc.setAtomicityMode(TRANSACTIONAL);

    if (lbean != null)
        c.setLifecycleBeans(lbean);

    c.setCacheConfiguration(cc);
    c.setDeploymentMode(CONTINUOUS);
    c.setNetworkTimeout(netTimeout);

    return c;
}
 
Example 3
Source File: GridCacheDhtPreloadBigDataSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);

    CacheConfiguration cc = defaultCacheConfiguration();

    cc.setCacheMode(PARTITIONED);
    cc.setRebalanceBatchSize(preloadBatchSize);
    cc.setWriteSynchronizationMode(FULL_SYNC);
    cc.setRebalanceMode(preloadMode);
    cc.setAffinity(new RendezvousAffinityFunction(false, partitions));
    cc.setBackups(backups);

    if (lbean != null)
        c.setLifecycleBeans(lbean);

    c.setCacheConfiguration(cc);
    c.setDeploymentMode(CONTINUOUS);
    c.setNetworkTimeout(1000);

    return c;
}
 
Example 4
Source File: GridCachePreloadLifecycleAbstractTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
    @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
        IgniteConfiguration c = super.getConfiguration(igniteInstanceName);

        c.setIncludeEventTypes(EVT_TASK_FAILED, EVT_TASK_FINISHED, EVT_JOB_MAPPED);
        c.setIncludeProperties();
        c.setDeploymentMode(DeploymentMode.SHARED);
        c.setNetworkTimeout(10000);
        c.setConnectorConfiguration(null);

//        c.setPeerClassLoadingLocalClassPathExclude(GridCachePreloadLifecycleAbstractTest.class.getName(),
//            MyValue.class.getName());

        c.setPublicThreadPoolSize(10);
        c.setSystemThreadPoolSize(10);
        c.setPeerClassLoadingThreadPoolSize(3);

        c.setLifecycleBeans(lifecycleBean);

        return c;
    }
 
Example 5
Source File: IgniteLocalNodeMapBeforeStartTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testNodeLocalMapFromLifecycleBean() throws Exception {
    IgniteConfiguration cfg = getConfiguration(getTestIgniteInstanceName(0));

    LifecycleBeanTest lifecycleBean = new LifecycleBeanTest();

    // Provide lifecycle bean to configuration.
    cfg.setLifecycleBeans(lifecycleBean);

    try (Ignite ignite = Ignition.start(cfg)) {
        // No-op.
    }

    assertTrue(lifecycleBean.evtQueue.size() == 4);
    assertTrue(lifecycleBean.evtQueue.poll() == BEFORE_NODE_START);
    assertTrue(lifecycleBean.evtQueue.poll() == AFTER_NODE_START);
    assertTrue(lifecycleBean.evtQueue.poll() == BEFORE_NODE_STOP);
    assertTrue(lifecycleBean.evtQueue.poll() == AFTER_NODE_STOP);
}
 
Example 6
Source File: IgniteExchangeLatchManagerDiscoHistoryTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    TcpDiscoveryIpFinder ipFinder = ((TcpDiscoverySpi)cfg.getDiscoverySpi()).getIpFinder();

    int topHistSize = victim ? TOPOLOGY_HISTORY_SIZE : TcpDiscoverySpi.DFLT_TOP_HISTORY_SIZE;

    CustomTcpDiscoverySpi discoSpi = new CustomTcpDiscoverySpi(topHistSize, ipFinder);

    cfg.setDiscoverySpi(discoSpi);

    if (victim) {
        cfg.setFailureHandler(new AbstractFailureHandler() {
            /** {@inheritDoc} */
            @Override protected boolean handle(Ignite ignite, FailureContext failureCtx) {
                cpFailureCtx.compareAndSet(null, failureCtx);

                // Invalidate kernel context.
                return true;
            }
        });

        cfg.setLifecycleBeans(lifecycleBean);

        disco = discoSpi;
    }

    return cfg;
}
 
Example 7
Source File: GridLifecycleBeanSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration c = super.getConfiguration(igniteInstanceName);

    c.setLifecycleBeans(bean);

    return c;
}
 
Example 8
Source File: SpringCacheManagerContextInjectionTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** */
@Bean(name = "mgr")
public SpringCacheManager springCacheManager() {
    IgniteConfiguration cfg = new IgniteConfiguration();

    cfg.setLocalHost("127.0.0.1");

    cfg.setIgniteInstanceName("scmt");

    cfg.setLifecycleBeans(bean1(), bean2());

    SpringCacheManager mgr = new SpringCacheManager();

    mgr.setConfiguration(cfg);

    return mgr;
}
 
Example 9
Source File: SpringTransactionManagerContextInjectionTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** */
@Bean(name = "mgr")
public SpringTransactionManager springTransactionManager() {
    IgniteConfiguration cfg = new IgniteConfiguration();

    cfg.setLocalHost("127.0.0.1");

    cfg.setIgniteInstanceName("stmcit");

    cfg.setLifecycleBeans(bean1(), bean2());

    SpringTransactionManager mgr = new SpringTransactionManager();

    mgr.setConfiguration(cfg);

    return mgr;
}
 
Example 10
Source File: IgniteCacheExample.java    From tutorials with MIT License 4 votes vote down vote up
private static void customInitialization() {

        IgniteConfiguration configuration = new IgniteConfiguration();
        configuration.setLifecycleBeans(new CustomLifecycleBean());
        Ignite ignite = Ignition.start(configuration);
    }
 
Example 11
Source File: GridLifecycleAwareSelfTest.java    From ignite with Apache License 2.0 2 votes vote down vote up
/** {@inheritDoc} */
@Override protected final IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    TestConnectorMessageInterceptor interceptor = new TestConnectorMessageInterceptor();

    ConnectorConfiguration clientCfg = new ConnectorConfiguration();

    clientCfg.setMessageInterceptor(interceptor);

    cfg.setConnectorConfiguration(clientCfg);

    lifecycleAwares.add(interceptor);

    TestSegmentationResolver segmentationRslvr = new TestSegmentationResolver();

    cfg.setSegmentationResolvers(segmentationRslvr);

    lifecycleAwares.add(segmentationRslvr);

    TestContextFactory ctxFactory = new TestContextFactory();

    clientCfg.setSslContextFactory(ctxFactory);

    lifecycleAwares.add(ctxFactory);

    TestLifecycleBean lifecycleBean = new TestLifecycleBean();

    cfg.setLifecycleBeans(lifecycleBean);

    lifecycleAwares.add(lifecycleBean);

    TestMarshaller marshaller = new TestMarshaller();

    cfg.setMarshaller(marshaller);

    lifecycleAwares.add(marshaller.lifecycleAware());

    TestLogger testLog = new TestLogger();

    cfg.setGridLogger(testLog);

    lifecycleAwares.add(testLog.lifecycleAware());

    return cfg;
}