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());
}
}
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[]
}
}
Aggregations