Search in sources :

Example 1 with StreamReceiver

use of org.apache.ignite.stream.StreamReceiver in project ignite by apache.

the class DataStreamerUpdateJob method call.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public Object call() throws Exception {
    if (log.isDebugEnabled())
        log.debug("Running put job [nodeId=" + ctx.localNodeId() + ", size=" + col.size() + ']');
    IgniteCacheProxy cache = ctx.cache().jcache(cacheName).cacheNoGate();
    cache.context().awaitStarted();
    if (skipStore)
        cache = (IgniteCacheProxy<?, ?>) cache.withSkipStore();
    if (keepBinary)
        cache = (IgniteCacheProxy<?, ?>) cache.withKeepBinary();
    if (ignoreDepOwnership)
        cache.context().deploy().ignoreOwnership(true);
    try {
        final GridCacheContext cctx = cache.context();
        for (DataStreamerEntry e : col) {
            e.getKey().finishUnmarshal(cctx.cacheObjectContext(), cctx.deploy().globalLoader());
            CacheObject val = e.getValue();
            if (val != null) {
                checkSecurityPermission(SecurityPermission.CACHE_PUT);
                val.finishUnmarshal(cctx.cacheObjectContext(), cctx.deploy().globalLoader());
            } else
                checkSecurityPermission(SecurityPermission.CACHE_REMOVE);
        }
        StreamReceiver receiver = SecurityUtils.sandboxedProxy(ctx, StreamReceiver.class, rcvr);
        if (unwrapEntries()) {
            Collection<Map.Entry> col0 = F.viewReadOnly(col, new C1<DataStreamerEntry, Map.Entry>() {

                @Override
                public Map.Entry apply(DataStreamerEntry e) {
                    return e.toEntry(cctx, keepBinary);
                }
            });
            receiver.receive(cache, col0);
        } else
            receiver.receive(cache, col);
        return null;
    } finally {
        if (ignoreDepOwnership)
            cache.context().deploy().ignoreOwnership(false);
        if (log.isDebugEnabled())
            log.debug("Update job finished on node: " + ctx.localNodeId());
    }
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) StreamReceiver(org.apache.ignite.stream.StreamReceiver) IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject)

Example 2 with StreamReceiver

use of org.apache.ignite.stream.StreamReceiver in project ignite by apache.

the class DataStreaming method streamReceiverExample.

@Test
void streamReceiverExample() {
    try (Ignite ignite = Ignition.start()) {
        ignite.getOrCreateCache("myCache");
        // tag::streamReceiver[]
        try (IgniteDataStreamer<Integer, String> stmr = ignite.dataStreamer("myCache")) {
            stmr.allowOverwrite(true);
            stmr.receiver((StreamReceiver<Integer, String>) (cache, entries) -> entries.forEach(entry -> {
                // do something with the entry
                cache.put(entry.getKey(), entry.getValue());
            }));
        }
    // end::streamReceiver[]
    }
}
Also used : Test(org.junit.jupiter.api.Test) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignition(org.apache.ignite.Ignition) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Map(java.util.Map) HashMap(java.util.HashMap) IgniteDataStreamer(org.apache.ignite.IgniteDataStreamer) Ignite(org.apache.ignite.Ignite) StreamReceiver(org.apache.ignite.stream.StreamReceiver) StreamTransformer(org.apache.ignite.stream.StreamTransformer) StreamVisitor(org.apache.ignite.stream.StreamVisitor) IgniteCache(org.apache.ignite.IgniteCache) Ignite(org.apache.ignite.Ignite) Test(org.junit.jupiter.api.Test)

Aggregations

StreamReceiver (org.apache.ignite.stream.StreamReceiver)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Ignite (org.apache.ignite.Ignite)1 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteDataStreamer (org.apache.ignite.IgniteDataStreamer)1 Ignition (org.apache.ignite.Ignition)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)1 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)1 IgniteCacheProxy (org.apache.ignite.internal.processors.cache.IgniteCacheProxy)1 StreamTransformer (org.apache.ignite.stream.StreamTransformer)1 StreamVisitor (org.apache.ignite.stream.StreamVisitor)1 Test (org.junit.jupiter.api.Test)1