/** * 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. */ protected Object readResolve() throws ObjectStreamException { return prj.compute().executorService(); }
/** {@inheritDoc} */ @Override protected Void run(Map<UUID, Set<GridUuid>> arg) throws GridException { Set<GridUuid> sesIds = arg.get(g.localNode().id()); if (sesIds != null && !sesIds.isEmpty()) { GridCompute compute = g.forLocal().compute(); for (GridUuid sesId : sesIds) compute.cancelTask(sesId); } return null; }
/** {@inheritDoc} */ @Override public <T> Future<T> submit(Callable<T> task) { A.notNull(task, "task != null"); checkShutdown(); return addFuture(prj.compute().call(task)); }
/** {@inheritDoc} */ @Override public Future<?> submit(Runnable task) { A.notNull(task, "task != null"); checkShutdown(); return addFuture(prj.compute().run(task)); }
/** {@inheritDoc} */ @Override public void execute(Runnable cmd) { A.notNull(cmd, "cmd != null"); checkShutdown(); addFuture(prj.compute().run(cmd)); }
/** {@inheritDoc} */ @Override public <T> Future<T> submit(Runnable task, final T res) { A.notNull(task, "task != null"); checkShutdown(); GridFuture<T> fut = prj.compute().run(task).chain(new CX1<GridFuture<?>, T>() { @Override public T applyx(GridFuture<?> fut) throws GridException { fut.get(); return res; } }); return addFuture(fut); }
/** {@inheritDoc} */ @Override public void restartNodes(Collection<UUID> ids) throws GridException { guard(); try { forNodeIds(ids).compute().execute(GridKillTask.class, true).get(); } finally { unguard(); } }
/** {@inheritDoc} */ @Override public void stopNodes(Collection<UUID> ids) throws GridException { guard(); try { forNodeIds(ids).compute().execute(GridKillTask.class, false).get(); } finally { unguard(); } }
/** {@inheritDoc} */ @Override public void clear() { try { cache.gridProjection().compute().broadcast(new ClearClosure(cache)).get(); } catch (GridException e) { throw new GridRuntimeException("Failed to clear cache [cacheName=" + cache.name() + ']', e); } }
if (restart && !neighbors.isEmpty()) { try { forNodes(neighbors).compute().execute(GridKillTask.class, false).get();
GridFuture<T> fut = prj.compute().call(cmd);
/** * @param cacheName Cache name. * @param c Closure to execute. * @return Execution future. */ private GridFuture<GridRestResponse> broadcast(String cacheName, Callable<Object> c) { GridFuture<Collection<Object>> fut = ctx.grid().forCache(cacheName). compute().withNoFailover().broadcast(c); return fut.chain(new C1<GridFuture<Collection<Object>>, GridRestResponse>() { @Override public GridRestResponse apply(GridFuture<Collection<Object>> fut) { try { fut.get(); return new GridRestResponse(); } catch (GridException e) { throw new GridClosureException(e); } } }); }
/** * Executes command on cache. Checks {@code destId} to find * if command could be performed locally or routed to a remote node. * * @param destId Target node Id for the operation. * If {@code null} - operation could be executed anywhere. * @param clientId Client ID. * @param cacheName Cache name. * @param key Key to set affinity mapping in the response. * @param op Operation to perform. * @return Operation result in future. * @throws GridException If failed */ private GridFuture<GridRestResponse> executeCommand( @Nullable UUID destId, UUID clientId, final String cacheName, final Object key, final CacheCommand op) throws GridException { final boolean locExec = destId == null || destId.equals(ctx.localNodeId()) || ctx.cache().cache(cacheName) != null; if (locExec) { final GridCacheProjection<Object, Object> cache = localCache(cacheName).forSubjectId(clientId); return op.apply(cache, ctx).chain(resultWrapper(cache, key)); } else { return ctx.grid().forPredicate(F.nodeForNodeId(destId)).compute().withNoFailover(). call(new CacheOperationCallable(clientId, cacheName, op, key)); } }
/** * Execute method on grid. * * @param subgrid Subgrid. * @param cls Joint point signature class. * @param arg GridifyArgument with all method signature parameters. * @param nodeFilter Node filter. * @param threshold Parameter that defines the minimal value below which the * execution will NOT be grid-enabled. * @param splitSize Size of elements to send in job argument. * @param timeout Execution timeout. * @return Result. * @throws GridException If execution failed. */ protected Object execute(GridProjection subgrid, Class<?> cls, GridifyRangeArgument arg, GridifyNodeFilter nodeFilter, int threshold, int splitSize, long timeout) throws GridException { long now = U.currentTimeMillis(); long end = timeout == 0 ? Long.MAX_VALUE : timeout + now; // Prevent overflow. if (end < 0) end = Long.MAX_VALUE; if (now > end) throw new GridComputeTaskTimeoutException("Timeout occurred while waiting for completion."); Collection<?> res = subgrid.compute().withTimeout(timeout == 0 ? 0L : (end - now)).execute( new GridifyDefaultRangeTask(cls, nodeFilter, threshold, splitSize, false), arg).get(); return result(arg.getMethodReturnType(), res); }
/** * Executes given closure either locally or on specified node. * * @param destId Destination node ID. * @param cacheName Cache name. * @param c Closure to execute. * @return Execution future. */ private GridFuture<GridRestResponse> execute(UUID destId, String cacheName, Callable<GridRestResponse> c) { boolean locExec = destId == null || destId.equals(ctx.localNodeId()) || replicatedCacheAvailable(cacheName); if (locExec) return ctx.closure().callLocalSafe(c, false); else { if (ctx.discovery().node(destId) == null) return new GridFinishedFutureEx<>(new GridException("Destination node ID has left the grid (retry " + "the query): " + destId)); return ctx.grid().forNodeId(destId).compute().withNoFailover().call(c); } }
res = subgrid.compute().withTimeout(timeout == 0 ? 0L : (end - now)).execute( new GridifyDefaultRangeTask(cls, nodeFilter, threshold, splitSize, true), taskArg).get();
/** {@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(); } }
/** {@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(); } }