/** * Reconstructs object on unmarshalling. * * @return Reconstructed object. * @throws ObjectStreamException Thrown in case of unmarshalling error. */ private Object readResolve() throws ObjectStreamException { return prj.compute(); } }
/** * Reconstructs object on unmarshalling. * * @return Reconstructed object. * @throws ObjectStreamException Thrown in case of unmarshalling error. */ private Object readResolve() throws ObjectStreamException { return prj.events(); } }
/** {@inheritDoc} */ @Override public void undeployTask(String taskName) throws GridException { A.notNull(taskName, "taskName"); guard(); try { ctx.deploy().undeployTask(taskName, prj.node(ctx.localNodeId()) != null, prj.forRemotes().nodes()); } finally { unguard(); } }
/** * @param prj Grid nodes projection. * @return Whether given projection contains any local node. */ private boolean hasLocalNode(GridProjection prj) { for (GridNode n : prj.nodes()) { if (n.isLocal()) return true; } return false; }
/** {@inheritDoc} */ @Override public <R> Collection<R> query(GridClosure<GridStreamerContext, R> clo, Collection<GridNode> nodes) throws GridException { ctx.gateway().readLock(); try { GridProjection prj = projection0(); if (!F.isEmpty(nodes)) prj = prj.forNodes(nodes); long startTime = U.currentTimeMillis(); Collection<R> res = prj.compute().execute(new GridStreamerQueryTask<>(clo, streamer.name()), null).get(); streamer.onQueryCompleted(U.currentTimeMillis() - startTime, prj.nodes().size()); return res; } finally { ctx.gateway().readUnlock(); } }
/** {@inheritDoc} */ @Override public void broadcast(GridInClosure<GridStreamerContext> clo, Collection<GridNode> nodes) throws GridException { ctx.gateway().readLock(); try { GridProjection prj = projection0(); if (!F.isEmpty(nodes)) prj = prj.forNodes(nodes); prj.compute().execute(new GridStreamerBroadcastTask(clo, streamer.name()), null).get(); } finally { ctx.gateway().readUnlock(); } }
prj = ctx.grid(); prj = prj.forCache(ctx.name()); if (prj.nodes().isEmpty()) throw new GridTopologyException("Failed to execute continuous query (projection is empty): " + this); Collection<GridNode> nodes = prj.nodes(); "ignored): " + this); prj = prj.forNode(ctx.localNode()); prj.predicate()).get();
/** {@inheritDoc} */ @Override public void cancelJob(GridUuid jobId) throws GridException { A.notNull(jobId, "jobId"); guard(); try { boolean loc = F.nodeIds(prj.nodes()).contains(ctx.localNodeId()); if (loc) ctx.job().cancelJob(null, jobId, false); ctx.io().send( prj.forRemotes().nodes(), TOPIC_JOB_CANCEL, new GridJobCancelRequest(null, jobId, false), SYSTEM_POOL ); } finally { unguard(); } }
@Override public boolean apply(GridNode n) { GridCacheDistributionMode mode = U.distributionMode(n, cctx.name()); return (mode == PARTITIONED_ONLY || mode == NEAR_PARTITIONED) && (prj == null || prj.node(n.id()) != null); } });
/** * Reconstructs object on unmarshalling. * * @return Reconstructed object. * @throws ObjectStreamException Thrown in case of unmarshalling error. */ private Object readResolve() throws ObjectStreamException { return prj.message(); } }
/** * Handles increment and decrement commands. * * @param cache Cache. * @param key Key. * @param req Request. * @param decr Whether to decrement (increment otherwise). * @return Future of operation result. * @throws GridException In case of error. */ private static GridFuture<?> incrementOrDecrement(GridCacheProjection<Object, Object> cache, String key, GridRestCacheRequest req, final boolean decr) throws GridException { assert cache != null; assert key != null; assert req != null; Long init = req.initial(); Long delta = req.delta(); if (delta == null) throw new GridException(GridRestCommandHandlerAdapter.missingParameter("delta")); final GridCacheAtomicLong l = cache.cache().dataStructures().atomicLong(key, init != null ? init : 0, true); final Long d = delta; return ((GridKernal)cache.gridProjection().grid()).context().closure().callLocalSafe(new Callable<Object>() { @Override public Object call() throws Exception { return l.addAndGet(decr ? -d : d); } }, false); }
/** * @param prj Grid nodes projection. * @return Whether given projection contains any local node. */ private boolean hasLocalNode(GridProjection prj) { for (GridNode n : prj.nodes()) { if (n.isLocal()) return true; } return false; }
/** {@inheritDoc} */ @Override public <R1, R2> R2 reduce(GridClosure<GridStreamerContext, R1> clo, GridReducer<R1, R2> rdc, Collection<GridNode> nodes) throws GridException { ctx.gateway().readLock(); try { GridProjection prj = projection0(); if (!F.isEmpty(nodes)) prj = prj.forNodes(nodes); return prj.compute().execute(new GridStreamerReduceTask<>(clo, rdc, streamer.name()), null).get(); } finally { ctx.gateway().readUnlock(); } }
/** {@inheritDoc} */ @Override public void globalClearAll(long timeout) throws GridException { try { // Send job to remote nodes only. Collection<GridNode> nodes = ctx.grid().forCache(name()).forRemotes().nodes(); GridFuture<Object> fut = null; if (!nodes.isEmpty()) { ctx.kernalContext().task().setThreadContext(TC_TIMEOUT, timeout); fut = ctx.closures().callAsyncNoFailover(BROADCAST, new GlobalClearAllCallable(name()), nodes, true); } // Clear local cache synchronously. clearAll(); if (fut != null) fut.get(); } catch (GridEmptyProjectionException ignore) { if (log.isDebugEnabled()) log.debug("All remote nodes left while cache clear [cacheName=" + name() + "]"); } catch (GridComputeTaskTimeoutException e) { U.warn(log, "Timed out waiting for remote nodes to finish cache clear (consider increasing " + "'networkTimeout' configuration property) [cacheName=" + name() + "]"); throw e; } }
/** {@inheritDoc} */ @Override public void cancelTask(GridUuid sesId) throws GridException { A.notNull(sesId, "sesId"); guard(); try { GridComputeTaskFuture<Object> task = ctx.task().taskFuture(sesId); if (task != null) // Cancel local task. task.cancel(); else if (prj.node(sesId.globalId()) != null) // Cancel remote task only if its master is in projection. ctx.io().send( sesId.globalId(), TOPIC_TASK_CANCEL, new GridTaskCancelRequest(sesId), SYSTEM_POOL ); } finally { unguard(); } }
/** * Sends optional message. If message is {@code null} - it's no-op. * * @param nodeId ID of the node to send message to. * @param respMsg Message to send. * @throws GridException Thrown in case of any errors. */ private void send(UUID nodeId, @Nullable Object respMsg) throws GridException { assert nodeId != null; if (respMsg != null) { GridNode node = grid.node(nodeId); if (node != null) grid.forNode(node).message().send(null, respMsg); // Can still fail. else throw new GridException("Failed to send message since destination node has " + "left topology (ignoring) [nodeId=" +nodeId + ", respMsg=" + respMsg + ']'); } }
GridKernalContext ctx = ((GridKernal)cache0.gridProjection().grid()).context(); GridLogger log = ctx.log(GridDrDataLoadCacheUpdater.class); GridCacheAdapter<K, V> cache = ctx.cache().internalCache(cacheName);
/** * Reconstructs object on unmarshalling. * * @return Reconstructed object. * @throws ObjectStreamException Thrown in case of unmarshalling error. */ protected Object readResolve() throws ObjectStreamException { return prj.compute().executorService(); }
/** {@inheritDoc} */ @Override public GridNode route(GridStreamerContext ctx, String stageName, Object evt) { Collection<GridNode> nodes = ctx.projection().nodes(); int idx = (int)(lastOrder.getAndIncrement() % nodes.size()); int i = 0; Iterator<GridNode> iter = nodes.iterator(); while (true) { if (!iter.hasNext()) iter = nodes.iterator(); GridNode node = iter.next(); if (idx == i++) return node; } } }