Search in sources :

Example 11 with Factory

use of javax.cache.configuration.Factory in project ignite by apache.

the class CacheContinuousQueryFilterDeploymentFailedTest method testContinuousQueryFilterDeploymentFailed.

/**
 * Tests continuous query behavior in case of filter deployment obtaining failure.
 *
 * @throws Exception If failed.
 */
@Test
@SuppressWarnings({ "ThrowableNotThrown" })
public void testContinuousQueryFilterDeploymentFailed() throws Exception {
    startGrids(NODES_CNT - 1);
    IgniteEx cli = startClientGrid(NODES_CNT - 1);
    IgniteCache<Integer, Integer> cache = cli.createCache(DEFAULT_CACHE_NAME);
    ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>();
    Class<Factory<CacheEntryEventFilter<Integer, Integer>>> rmtFilterFactoryCls = (Class<Factory<CacheEntryEventFilter<Integer, Integer>>>) getExternalClassLoader().loadClass("org.apache.ignite.tests.p2p.CacheDeploymentEntryEventFilterFactory");
    qry.setRemoteFilterFactory(rmtFilterFactoryCls.newInstance());
    spi(grid(1)).blockMessages((node, msg) -> msg instanceof GridDeploymentRequest);
    assertThrowsWithCause(() -> cache.query(qry), CacheException.class);
    assertTrue(stopRoutineLatch.await(getTestTimeout(), MILLISECONDS));
    assertTrue(allGrids().stream().allMatch(g -> ((IgniteEx) g).context().systemView().view(CQ_SYS_VIEW).size() == 0));
}
Also used : Factory(javax.cache.configuration.Factory) TestRecordingCommunicationSpi.spi(org.apache.ignite.internal.TestRecordingCommunicationSpi.spi) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) GridTestUtils.assertThrowsWithCause(org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause) TestTcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TestTcpDiscoverySpi) Ignition.allGrids(org.apache.ignite.Ignition.allGrids) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteCache(org.apache.ignite.IgniteCache) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheEntryEventFilter(javax.cache.event.CacheEntryEventFilter) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) GridDeploymentRequest(org.apache.ignite.internal.managers.deployment.GridDeploymentRequest) CacheException(javax.cache.CacheException) CQ_SYS_VIEW(org.apache.ignite.internal.processors.continuous.GridContinuousProcessor.CQ_SYS_VIEW) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) StopRoutineDiscoveryMessage(org.apache.ignite.internal.processors.continuous.StopRoutineDiscoveryMessage) DiscoveryHook(org.apache.ignite.testframework.GridTestUtils.DiscoveryHook) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteEx(org.apache.ignite.internal.IgniteEx) Factory(javax.cache.configuration.Factory) GridDeploymentRequest(org.apache.ignite.internal.managers.deployment.GridDeploymentRequest) CacheEntryEventFilter(javax.cache.event.CacheEntryEventFilter) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 12 with Factory

use of javax.cache.configuration.Factory in project ignite by apache.

the class CacheContinuousQueryDeploymentToClientTest method testDeploymentToNewClient.

/**
 * Test starts 1 server node and 1 client node. The client node deploys
 * CQ for the cache {@link #CACHE_NAME}. After that another client node is started.
 * Expected that CQ won't be deployed to the new client, since the client doesn't
 * store any data.
 *
 * @throws Exception If failed.
 */
@Test
public void testDeploymentToNewClient() throws Exception {
    startGrid(0);
    IgniteEx client1 = startClientGrid(1);
    IgniteCache<Integer, String> cache = client1.cache(CACHE_NAME);
    AbstractContinuousQuery<Integer, String> qry = new ContinuousQuery<Integer, String>().setLocalListener(evts -> {
    // No-op.
    }).setRemoteFilterFactory((Factory<CacheEntryEventFilter<Integer, String>>) () -> evt -> true);
    cache.query(qry);
    IgniteEx client2 = startClientGrid(2);
    GridContinuousProcessor proc = client2.context().continuous();
    assertEquals(0, ((Map<?, ?>) U.field(proc, "locInfos")).size());
    assertEquals(0, ((Map<?, ?>) U.field(proc, "rmtInfos")).size());
    assertEquals(0, ((Map<?, ?>) U.field(proc, "startFuts")).size());
    assertEquals(0, ((Map<?, ?>) U.field(proc, "stopFuts")).size());
    assertEquals(0, ((Map<?, ?>) U.field(proc, "bufCheckThreads")).size());
}
Also used : Factory(javax.cache.configuration.Factory) AbstractContinuousQuery(org.apache.ignite.cache.query.AbstractContinuousQuery) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteCache(org.apache.ignite.IgniteCache) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheEntryEventFilter(javax.cache.event.CacheEntryEventFilter) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Map(java.util.Map) GridContinuousProcessor(org.apache.ignite.internal.processors.continuous.GridContinuousProcessor) AbstractContinuousQuery(org.apache.ignite.cache.query.AbstractContinuousQuery) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteEx(org.apache.ignite.internal.IgniteEx) GridContinuousProcessor(org.apache.ignite.internal.processors.continuous.GridContinuousProcessor) CacheEntryEventFilter(javax.cache.event.CacheEntryEventFilter) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 13 with Factory

use of javax.cache.configuration.Factory in project ignite by apache.

the class CacheContinuousQueryDeploymentToClientTest method testDeploymentToExistingClient.

/**
 * Test starts 1 server node and 2 client nodes. The first client node deploys
 * CQ for the cache {@link #CACHE_NAME}.
 * Expected that CQ won't be deployed to the second client, since the client doesn't
 * store any data.
 *
 * @throws Exception If failed.
 */
@Test
public void testDeploymentToExistingClient() throws Exception {
    startGrid(0);
    IgniteEx client1 = startClientGrid(1);
    IgniteCache<Integer, String> cache = client1.cache(CACHE_NAME);
    IgniteEx client2 = startClientGrid(2);
    AbstractContinuousQuery<Integer, String> qry = new ContinuousQuery<Integer, String>().setLocalListener(evts -> {
    // No-op.
    }).setRemoteFilterFactory((Factory<CacheEntryEventFilter<Integer, String>>) () -> evt -> true);
    cache.query(qry);
    GridContinuousProcessor proc = client2.context().continuous();
    assertEquals(0, ((Map<?, ?>) U.field(proc, "locInfos")).size());
    assertEquals(0, ((Map<?, ?>) U.field(proc, "rmtInfos")).size());
    assertEquals(0, ((Map<?, ?>) U.field(proc, "startFuts")).size());
    assertEquals(0, ((Map<?, ?>) U.field(proc, "stopFuts")).size());
    assertEquals(0, ((Map<?, ?>) U.field(proc, "bufCheckThreads")).size());
}
Also used : Factory(javax.cache.configuration.Factory) AbstractContinuousQuery(org.apache.ignite.cache.query.AbstractContinuousQuery) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteCache(org.apache.ignite.IgniteCache) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CacheEntryEventFilter(javax.cache.event.CacheEntryEventFilter) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Map(java.util.Map) GridContinuousProcessor(org.apache.ignite.internal.processors.continuous.GridContinuousProcessor) AbstractContinuousQuery(org.apache.ignite.cache.query.AbstractContinuousQuery) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteEx(org.apache.ignite.internal.IgniteEx) GridContinuousProcessor(org.apache.ignite.internal.processors.continuous.GridContinuousProcessor) CacheEntryEventFilter(javax.cache.event.CacheEntryEventFilter) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 14 with Factory

use of javax.cache.configuration.Factory in project Payara by payara.

the class CompleteConfigurationProxy method proxyWriter.

private Factory<CacheWriter<? super K, ? super V>> proxyWriter(final Factory<CacheWriter<? super K, ? super V>> fact) {
    return new Factory<CacheWriter<? super K, ? super V>>() {

        @Override
        public CacheWriter<K, V> create() {
            @Cleanup Context ctx = ctxUtil.pushContext();
            @SuppressWarnings("unchecked") final CacheWriter<K, V> delegate = (CacheWriter<K, V>) fact.create();
            return new CacheWriterImpl(delegate);
        }

        @RequiredArgsConstructor
        class CacheWriterImpl implements CacheWriter<K, V> {

            @Override
            public void write(Cache.Entry<? extends K, ? extends V> entry) throws CacheWriterException {
                @Cleanup Context context = ctxUtil.pushRequestContext();
                delegate.write(entry);
            }

            @Override
            public void writeAll(Collection<Cache.Entry<? extends K, ? extends V>> clctn) throws CacheWriterException {
                @Cleanup Context context = ctxUtil.pushRequestContext();
                delegate.writeAll(clctn);
            }

            @Override
            public void delete(Object o) throws CacheWriterException {
                @Cleanup Context context = ctxUtil.pushRequestContext();
                delegate.delete(o);
            }

            @Override
            public void deleteAll(Collection<?> clctn) throws CacheWriterException {
                @Cleanup Context context = ctxUtil.pushRequestContext();
                delegate.deleteAll(clctn);
            }

            private final CacheWriter<K, V> delegate;
        }

        private static final long serialVersionUID = 1L;
    };
}
Also used : Context(org.glassfish.internal.api.JavaEEContextUtil.Context) Factory(javax.cache.configuration.Factory) Cleanup(lombok.Cleanup) CacheWriter(javax.cache.integration.CacheWriter) Cache(javax.cache.Cache) CacheWriterException(javax.cache.integration.CacheWriterException)

Example 15 with Factory

use of javax.cache.configuration.Factory in project ignite by apache.

the class UsingContinuousQueries method remoteTransformerExample.

public static void remoteTransformerExample() {
    try (Ignite ignite = Ignition.start()) {
        // tag::transformer[]
        IgniteCache<Integer, Person> cache = ignite.getOrCreateCache("myCache");
        // Create a new continuous query with a transformer.
        ContinuousQueryWithTransformer<Integer, Person, String> qry = new ContinuousQueryWithTransformer<>();
        // Factory to create transformers.
        Factory factory = FactoryBuilder.factoryOf(// Only this field will be sent over to the local listener.
        (IgniteClosure<CacheEntryEvent, String>) event -> ((Person) event.getValue()).getName());
        qry.setRemoteTransformerFactory(factory);
        // Listener that will receive transformed data.
        qry.setLocalListener(names -> {
            for (String name : names) System.out.println("New person name: " + name);
        });
        // end::transformer[]
        cache.query(qry);
        cache.put(1, new Person(1, "Vasya"));
    }
}
Also used : Factory(javax.cache.configuration.Factory) FactoryBuilder(javax.cache.configuration.FactoryBuilder) Ignite(org.apache.ignite.Ignite) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteCache(org.apache.ignite.IgniteCache) CacheEntryEvent(javax.cache.event.CacheEntryEvent) CacheEntryEventFilter(javax.cache.event.CacheEntryEventFilter) Ignition(org.apache.ignite.Ignition) IgniteClosure(org.apache.ignite.lang.IgniteClosure) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) QueryCursor(org.apache.ignite.cache.query.QueryCursor) Cache(javax.cache.Cache) ContinuousQueryWithTransformer(org.apache.ignite.cache.query.ContinuousQueryWithTransformer) CacheEntryUpdatedListener(javax.cache.event.CacheEntryUpdatedListener) ScanQuery(org.apache.ignite.cache.query.ScanQuery) ContinuousQueryWithTransformer(org.apache.ignite.cache.query.ContinuousQueryWithTransformer) Factory(javax.cache.configuration.Factory) Ignite(org.apache.ignite.Ignite) CacheEntryEvent(javax.cache.event.CacheEntryEvent)

Aggregations

Factory (javax.cache.configuration.Factory)20 CacheEntryEventFilter (javax.cache.event.CacheEntryEventFilter)10 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)10 IgniteCache (org.apache.ignite.IgniteCache)6 CacheEntryEvent (javax.cache.event.CacheEntryEvent)5 Ignite (org.apache.ignite.Ignite)5 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)5 IgniteEx (org.apache.ignite.internal.IgniteEx)5 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)5 Test (org.junit.Test)5 Map (java.util.Map)4 AbstractContinuousQuery (org.apache.ignite.cache.query.AbstractContinuousQuery)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 Cache (javax.cache.Cache)3 CacheException (javax.cache.CacheException)3 FactoryBuilder (javax.cache.configuration.FactoryBuilder)3 IgniteException (org.apache.ignite.IgniteException)3 ContinuousQueryWithTransformer (org.apache.ignite.cache.query.ContinuousQueryWithTransformer)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)3 GridDeploymentRequest (org.apache.ignite.internal.managers.deployment.GridDeploymentRequest)3