Search in sources :

Example 1 with CacheEntryListenerException

use of javax.cache.event.CacheEntryListenerException in project camel by apache.

the class JCacheConsumerTest method createRegistry.

@Override
protected JndiRegistry createRegistry() throws Exception {
    JndiRegistry registry = super.createRegistry();
    registry.bind("myFilter", new CacheEntryEventFilter<Object, Object>() {

        @Override
        public boolean evaluate(CacheEntryEvent<?, ?> event) throws CacheEntryListenerException {
            if (event.getEventType() == EventType.REMOVED) {
                return false;
            }
            return !event.getValue().toString().startsWith("to-filter-");
        }
    });
    return registry;
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException)

Example 2 with CacheEntryListenerException

use of javax.cache.event.CacheEntryListenerException in project ignite by apache.

the class JavaThinClient method continuousQueries.

void continuousQueries() throws Exception {
    ClientConfiguration clientCfg = new ClientConfiguration().setAddresses("127.0.0.1:10800");
    try (IgniteClient client = Ignition.startClient(clientCfg)) {
        // tag::continuous-queries[]
        ClientCache<Integer, String> cache = client.getOrCreateCache("myCache");
        ContinuousQuery<Integer, String> query = new ContinuousQuery<>();
        query.setLocalListener(new CacheEntryUpdatedListener<Integer, String>() {

            @Override
            public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends String>> events) throws CacheEntryListenerException {
            // react to the update events here
            }
        });
        ClientDisconnectListener disconnectListener = new ClientDisconnectListener() {

            @Override
            public void onDisconnected(Exception reason) {
            // react to the disconnect event here
            }
        };
        cache.query(query, disconnectListener);
    // end::continuous-queries[]
    }
}
Also used : ClientDisconnectListener(org.apache.ignite.client.ClientDisconnectListener) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) CacheEntryEvent(javax.cache.event.CacheEntryEvent) ClientException(org.apache.ignite.client.ClientException) ClientConnectionException(org.apache.ignite.client.ClientConnectionException) ClientAuthenticationException(org.apache.ignite.client.ClientAuthenticationException) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) IgniteClient(org.apache.ignite.client.IgniteClient) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) ThinClientConfiguration(org.apache.ignite.configuration.ThinClientConfiguration)

Example 3 with CacheEntryListenerException

use of javax.cache.event.CacheEntryListenerException in project ignite by apache.

the class UsingContinuousQueries method localListenerExample.

public static void localListenerExample() {
    try (Ignite ignite = Ignition.start()) {
        // tag::localListener[]
        IgniteCache<Integer, String> cache = ignite.getOrCreateCache("myCache");
        ContinuousQuery<Integer, String> query = new ContinuousQuery<>();
        query.setLocalListener(new CacheEntryUpdatedListener<Integer, String>() {

            @Override
            public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends String>> events) throws CacheEntryListenerException {
            // react to the update events here
            }
        });
        cache.query(query);
    // end::localListener[]
    }
}
Also used : ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) Ignite(org.apache.ignite.Ignite) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) CacheEntryEvent(javax.cache.event.CacheEntryEvent)

Example 4 with CacheEntryListenerException

use of javax.cache.event.CacheEntryListenerException in project ignite by apache.

the class PlatformContinuousQueryRemoteFilter method evaluate.

/**
 * {@inheritDoc}
 */
@Override
public boolean evaluate(CacheEntryEvent evt) throws CacheEntryListenerException {
    long ptr0 = ptr;
    if (ptr0 == 0)
        deploy();
    lock.readLock().lock();
    try {
        if (closed)
            throw new CacheEntryListenerException("Failed to evaluate the filter because it has been closed.");
        PlatformContext platformCtx = PlatformUtils.platformContext(grid);
        return PlatformUtils.evaluateContinuousQueryEvent(platformCtx, ptr, evt);
    } finally {
        lock.readLock().unlock();
    }
}
Also used : PlatformContext(org.apache.ignite.internal.processors.platform.PlatformContext) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException)

Example 5 with CacheEntryListenerException

use of javax.cache.event.CacheEntryListenerException in project ignite by apache.

the class PlatformContinuousQueryRemoteFilter method deploy.

/**
 * Deploy filter to native platform.
 */
private void deploy() {
    lock.writeLock().lock();
    try {
        // 1. Do not deploy if the filter has been closed concurrently.
        if (closed)
            throw new CacheEntryListenerException("Failed to deploy the filter because it has been closed.");
        // 2. Deploy.
        PlatformContext ctx = PlatformUtils.platformContext(grid);
        try (PlatformMemory mem = ctx.memory().allocate()) {
            PlatformOutputStream out = mem.output();
            BinaryRawWriterEx writer = ctx.writer(out);
            writer.writeObject(filter);
            out.synchronize();
            ptr = ctx.gateway().continuousQueryFilterCreate(mem.pointer());
        } catch (Exception e) {
            // 3. Close in case of failure.
            close();
            throw new CacheEntryListenerException("Failed to deploy the filter.", e);
        }
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : PlatformContext(org.apache.ignite.internal.processors.platform.PlatformContext) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException) PlatformOutputStream(org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream) BinaryRawWriterEx(org.apache.ignite.internal.binary.BinaryRawWriterEx) PlatformMemory(org.apache.ignite.internal.processors.platform.memory.PlatformMemory) IOException(java.io.IOException) CacheEntryListenerException(javax.cache.event.CacheEntryListenerException)

Aggregations

CacheEntryListenerException (javax.cache.event.CacheEntryListenerException)22 CacheEntryEvent (javax.cache.event.CacheEntryEvent)15 ContinuousQuery (org.apache.ignite.cache.query.ContinuousQuery)15 Ignite (org.apache.ignite.Ignite)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)6 CacheEntryEventSerializableFilter (org.apache.ignite.cache.CacheEntryEventSerializableFilter)5 QueryCursor (org.apache.ignite.cache.query.QueryCursor)5 Test (org.junit.Test)5 CacheException (javax.cache.CacheException)4 IgniteException (org.apache.ignite.IgniteException)4 ContinuousQueryWithTransformer (org.apache.ignite.cache.query.ContinuousQueryWithTransformer)4 CacheEntryUpdatedListener (javax.cache.event.CacheEntryUpdatedListener)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 AbstractContinuousQuery (org.apache.ignite.cache.query.AbstractContinuousQuery)3 PlatformMemory (org.apache.ignite.internal.processors.platform.memory.PlatformMemory)3 PlatformOutputStream (org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream)3 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Cache (javax.cache.Cache)2