/** * @return Local node ID. */ public UUID nodeId() { return ctx.localNodeId(); }
/** {@inheritDoc} */ @Override public final GridProjection forRemotes() { return forOthers(Collections.singleton(ctx.localNodeId())); }
/** * Gets subject ID per call. * * @param subjId Optional already existing subject ID. * @return Subject ID per call. */ public UUID subjectIdPerCall(@Nullable UUID subjId) { if (subjId != null) return subjId; GridCacheProjectionImpl<K, V> prj = projectionPerCall(); if (prj != null) subjId = prj.subjectId(); if (subjId == null) subjId = ctx.localNodeId(); return subjId; }
/** * @param e Error. */ private void onLocalError(GridException e) { if (e instanceof GridGgfsOutOfSpaceException) onDone(new GridException("Failed to write data (not enough space on node): " + ggfsCtx.kernalContext().localNodeId(), e)); else onDone(new GridException( "Failed to wait for write completion (write failed on node): " + ggfsCtx.kernalContext().localNodeId(), e)); }
/** * @param e Error. */ private void onLocalError(GridException e) { if (e instanceof GridGgfsOutOfSpaceException) onDone(new GridException("Failed to write data (not enough space on node): " + ggfsCtx.kernalContext().localNodeId(), e)); else onDone(new GridException( "Failed to wait for write completion (write failed on node): " + ggfsCtx.kernalContext().localNodeId(), e)); }
/** * @param task Actual task. * @param arg Optional task argument. * @param sys If {@code true}, then system pool will be used. * @return Task future. * @param <T> Task argument type. * @param <R> Task return value type. */ public <T, R> GridComputeTaskFuture<R> execute(GridComputeTask<T, R> task, @Nullable T arg, boolean sys) { lock.readLock(); try { if (stopping) throw new IllegalStateException("Failed to execute task due to grid shutdown: " + task); return startTask(null, null, task, GridUuid.fromUuid(ctx.localNodeId()), arg, sys); } finally { lock.readUnlock(); } }
@Override public void apply(GridFuture<Object> t) { BatchExecutionFuture fut = (BatchExecutionFuture)t; if (log.isDebugEnabled()) log.debug("Completed batch execution future: " + fut); batchFuts.remove(futId, fut); if (!fut.isCancelled() && atLeastOnce) completeParentStage(ctx.localNodeId(), batch.futureId(), fut.error()); } });
/** {@inheritDoc} */ @Override public void scheduleExecutions(GridStreamerStageExecutionFuture fut, Map<UUID, GridStreamerExecutionBatch> execs) throws GridException { for (Map.Entry<UUID, GridStreamerExecutionBatch> entry : execs.entrySet()) { UUID nodeId = entry.getKey(); GridStreamerExecutionBatch batch = entry.getValue(); if (ctx.localNodeId().equals(nodeId)) scheduleLocal(batch); else { if (log.isDebugEnabled()) log.debug("Sending batch execution request to remote node [nodeId=" + nodeId + ", futId=" + batch.futureId() + ", stageName=" + batch.stageName() + ']'); sendWithRetries(nodeId, createExecutionRequest(batch)); if (!ctx.discovery().alive(nodeId)) fut.onNodeLeft(nodeId); } } }
/** * @param nodeId Node ID. * @param topic Topic. * @param msg Message. * @param plc Policy. * @throws GridException In case of error. */ public void send(UUID nodeId, Object topic, GridGgfsCommunicationMessage msg, GridIoPolicy plc) throws GridException { if (!kernalContext().localNodeId().equals(nodeId)) msg.prepareMarshal(kernalContext().config().getMarshaller()); kernalContext().io().send(nodeId, topic, msg, plc); }
/** * @param ctx Grid kernal context. */ @SuppressWarnings("deprecation") public GridIoManager(GridKernalContext ctx) { super(ctx, ctx.config().getCommunicationSpi()); locNodeId = ctx.localNodeId(); discoDelay = ctx.config().getDiscoveryStartupDelay(); marsh = ctx.config().getMarshaller(); }
/** * @param nodeId Node ID. * @param topic Topic. * @param msg Message. * @param plc Policy. * @throws GridException In case of error. */ public void send(UUID nodeId, Object topic, GridGgfsCommunicationMessage msg, GridIoPolicy plc) throws GridException { if (!kernalContext().localNodeId().equals(nodeId)) msg.prepareMarshal(kernalContext().config().getMarshaller()); kernalContext().io().send(nodeId, topic, msg, plc); }
/** * @param node Node. * @param topic Topic. * @param msg Message. * @param plc Policy. * @throws GridException In case of error. */ public void send(GridNode node, Object topic, GridGgfsCommunicationMessage msg, GridIoPolicy plc) throws GridException { if (!kernalContext().localNodeId().equals(node.id())) msg.prepareMarshal(kernalContext().config().getMarshaller()); kernalContext().io().send(node, topic, msg, plc); }
/** {@inheritDoc} */ @Override public void addEventsToStage(String stageName, Collection<?> evts) throws GridException { A.notNull(stageName, "stageName"); A.ensure(!F.isEmpty(evts), "evts cannot be empty or null"); ctx.gateway().readLock(); try { addEvents0(null, 0, U.currentTimeMillis(), null, Collections.singleton(ctx.localNodeId()), stageName, evts); } finally { ctx.gateway().readUnlock(); } }
/** * @param node Node. * @param topic Topic. * @param msg Message. * @param plc Policy. * @throws GridException In case of error. */ public void send(GridNode node, Object topic, GridGgfsCommunicationMessage msg, GridIoPolicy plc) throws GridException { if (!kernalContext().localNodeId().equals(node.id())) msg.prepareMarshal(kernalContext().config().getMarshaller()); kernalContext().io().send(node, topic, msg, plc); }
/** * Generates next affinity key for local node based on current topology. If previous affinity key maps * on local node, return previous affinity key to prevent unnecessary file map growth. * * @param prevAffKey Affinity key of previous block. * @return Affinity key. */ public GridUuid nextAffinityKey(@Nullable GridUuid prevAffKey) { // Do not generate affinity key for non-affinity nodes. if (!isAffinityNode(dataCache.configuration())) return null; UUID nodeId = ggfsCtx.kernalContext().localNodeId(); if (prevAffKey != null && dataCache.affinity().mapKeyToNode(prevAffKey).isLocal()) return prevAffKey; while (true) { GridUuid key = new GridUuid(nodeId, affKeyGen.getAndIncrement()); if (dataCache.affinity().mapKeyToNode(key).isLocal()) return key; } }
/** * Generates next affinity key for local node based on current topology. If previous affinity key maps * on local node, return previous affinity key to prevent unnecessary file map growth. * * @param prevAffKey Affinity key of previous block. * @return Affinity key. */ public GridUuid nextAffinityKey(@Nullable GridUuid prevAffKey) { // Do not generate affinity key for non-affinity nodes. if (!isAffinityNode(dataCache.configuration())) return null; UUID nodeId = ggfsCtx.kernalContext().localNodeId(); if (prevAffKey != null && dataCache.affinity().mapKeyToNode(prevAffKey).isLocal()) return prevAffKey; while (true) { GridUuid key = new GridUuid(nodeId, affKeyGen.getAndIncrement()); if (dataCache.affinity().mapKeyToNode(key).isLocal()) return key; } }
/** {@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 rsrcName Class name. * @return Grid cached task. */ @Nullable public GridDeployment getLocalDeployment(String rsrcName) { if (locDep != null) return locDep; String lambdaEnclosingClsName = U.lambdaEnclosingClassName(rsrcName); String clsName = lambdaEnclosingClsName == null ? rsrcName : lambdaEnclosingClsName; GridDeploymentMetadata meta = new GridDeploymentMetadata(); meta.record(true); meta.deploymentMode(ctx.config().getDeploymentMode()); meta.alias(rsrcName); meta.className(clsName); meta.senderNodeId(ctx.localNodeId()); return locStore.getDeployment(meta); }
/** * Constructor. * * @param ggfsCtx GGFS context. */ GridGgfsDeleteWorker(GridGgfsContext ggfsCtx) { super("ggfs-delete-worker%" + ggfsCtx.ggfs().name() + "%" + ggfsCtx.kernalContext().localNodeId() + "%"); this.ggfsCtx = ggfsCtx; meta = ggfsCtx.meta(); data = ggfsCtx.data(); evts = ggfsCtx.kernalContext().event(); String ggfsName = ggfsCtx.ggfs().name(); topic = F.isEmpty(ggfsName) ? TOPIC_GGFS : TOPIC_GGFS.topic(ggfsName); assert meta != null; assert data != null; log = ggfsCtx.kernalContext().log(GridGgfsDeleteWorker.class); }
/** * Constructor. * * @param ggfsCtx GGFS context. */ GridGgfsDeleteWorker(GridGgfsContext ggfsCtx) { super("ggfs-delete-worker%" + ggfsCtx.ggfs().name() + "%" + ggfsCtx.kernalContext().localNodeId() + "%"); assert ggfsCtx != null; this.ggfsCtx = ggfsCtx; meta = ggfsCtx.meta(); data = ggfsCtx.data(); evts = ggfsCtx.kernalContext().event(); String ggfsName = ggfsCtx.ggfs().name(); topic = F.isEmpty(ggfsName) ? TOPIC_GGFS : TOPIC_GGFS.topic(ggfsName); assert meta != null; assert data != null; log = ggfsCtx.kernalContext().log(GridGgfsDeleteWorker.class); }