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

The following examples show how to use org.apache.ignite.configuration.IgniteConfiguration#setLocalEventListeners() . 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: GridLocalEventListenerSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    int idx = getTestIgniteInstanceIndex(igniteInstanceName);

    if (idx == 0) {
        Map<IgnitePredicate<? extends Event>, int[]> lsnrs = new HashMap<>();

        lsnrs.put(new IgnitePredicate<Event>() {
            @Override public boolean apply(Event evt) {
                fired.countDown();

                return true;
            }
        }, new int[] { EventType.EVT_NODE_JOINED } );

        cfg.setLocalEventListeners(lsnrs);
    }

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

    cfg.setCacheConfiguration(
        cacheConfig(firstCacheMode, 1, FIRST_CACHE_NAME),
        cacheConfig(secondCacheMode, 2, SECOND_CACHE_NAME));

    Map<IgnitePredicate<? extends Event>, int[]> listeners = new HashMap<>();

    listeners.put(new IgnitePredicate<CacheRebalancingEvent>() {
        @Override public boolean apply(CacheRebalancingEvent evt) {
            times.get(gridIdx(evt)).putIfAbsent(evt.cacheName(), evt.timestamp());
            return true;
        }
    }, new int[]{EventType.EVT_CACHE_REBALANCE_STOPPED});

    cfg.setLocalEventListeners(listeners);

    cfg.setIncludeEventTypes(EventType.EVTS_ALL);

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

    Map<IgnitePredicate<? extends Event>, int[]> map = new HashMap<>();

    // To make partitions exchanges longer.
    map.put(new P1<Event>() {
        @Override public boolean apply(Event evt) {
            try {
                Thread.sleep(10);
            }
            catch (InterruptedException e) {
                // No op.
            }

            return false;
        }
    }, new int[]{EVT_NODE_JOINED, EVT_NODE_FAILED, EVT_NODE_LEFT, EVT_DISCOVERY_CUSTOM_EVT});

    cfg.setLocalEventListeners(map);

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

    if (trackRebalanceEvts) {
        Map<IgnitePredicate<? extends Event>, int[]> listeners = new HashMap<>();

        listeners.put(new IgnitePredicate<CacheRebalancingEvent>() {
            @Override public boolean apply(CacheRebalancingEvent evt) {
                evtsList.add(evt);

                return true;
            }
        }, new int[] {EVT_CACHE_REBALANCE_STOPPED});

        cfg.setLocalEventListeners(listeners);

        cfg.setIncludeEventTypes(EventType.EVTS_ALL);
    }

    return cfg;
}
 
Example 5
Source File: CacheMvccClientReconnectTest.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);

    if (igniteInstanceName.contains("client")) {
        Map<IgnitePredicate<? extends Event>, int[]> lsnrs = new HashMap<>();

        lsnrs.put(new IgnitePredicate<Event>() {
            @Override public boolean apply(Event evt) {
                try {
                    // Wait for the discovery notifier worker processed client disconnection.
                    latch.await();
                }
                catch (InterruptedException e) {
                    log.error("Unexpected exception.", e);

                    fail("Unexpected exception: " + e.getMessage());
                }

                return true;
            }
        }, new int[] {EVT_NODE_JOINED});

        cfg.setLocalEventListeners(lsnrs);
    }

    return cfg;
}
 
Example 6
Source File: IgnitePdsStartWIthEmptyArchive.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);

    cfg.setConsistentId(igniteInstanceName);

    cfg.setCacheConfiguration(
        new CacheConfiguration(DEFAULT_CACHE_NAME)
    );

    cfg.setDataStorageConfiguration(
        new DataStorageConfiguration()
            // Checkpoint should not remove any WAL archive files.
            .setMaxWalArchiveSize(Long.MAX_VALUE)
            .setDefaultDataRegionConfiguration(
                new DataRegionConfiguration()
                    .setPersistenceEnabled(true)
            )
    );

    Map<IgnitePredicate<? extends Event>, int[]> lsnrs = new HashMap<>();

    lsnrs.put((e) -> {
        WalSegmentArchivedEvent archComplEvt = (WalSegmentArchivedEvent)e;

        log.info("EVT_WAL_SEGMENT_ARCHIVED: " + archComplEvt.getAbsWalSegmentIdx());

        evts.put(archComplEvt.getAbsWalSegmentIdx(), archComplEvt);

        return true;
    }, new int[] {EVT_WAL_SEGMENT_ARCHIVED});

    cfg.setLocalEventListeners(lsnrs);

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

    int[] evts = {EVT_NODE_JOINED, EVT_NODE_FAILED, EVT_NODE_LEFT};

    cfg.setIncludeEventTypes(evts);

    Map<IgnitePredicate<? extends Event>, int[]> lsnrs = new HashMap<>();

    lsnrs.put(new TestEventListener(), evts);

    cfg.setLocalEventListeners(lsnrs);

    return cfg;
}