/** * Gets creator node. * * @return Creator node ID. */ public UUID creatorNodeId() { return id.globalId(); }
/** * If not root future, will return parent node ID (may be local node ID). * * @return Sender node ID. */ @Nullable public UUID senderNodeId() { return parentFutId == null ? null : parentFutId.globalId(); }
/** {@inheritDoc} */ @Override public int compareTo(GridUuid o) { if (o == this) return 0; if (o == null) return 1; return locId < o.locId ? -1 : locId > o.locId ? 1 : gid.compareTo(o.globalId()); }
/** * Writes {@link GridUuid} to output stream. This method is meant to be used by * implementations of {@link Externalizable} interface. * * @param out Output stream. * @param uid UUID to write. * @throws IOException If write failed. */ public static void writeGridUuid(DataOutput out, GridUuid uid) throws IOException { // Write null flag. out.writeBoolean(uid == null); if (uid != null) { out.writeLong(uid.globalId().getMostSignificantBits()); out.writeLong(uid.globalId().getLeastSignificantBits()); out.writeLong(uid.localId()); } }
/** * @param uuid {@link GridUuid}. * @return Whether value was fully written. */ public final boolean putGridUuid(@Nullable GridUuid uuid) { byte[] arr = null; if (uuid != null) { arr = new byte[24]; UNSAFE.putLong(arr, BYTE_ARR_OFF, uuid.globalId().getMostSignificantBits()); UNSAFE.putLong(arr, BYTE_ARR_OFF + 8, uuid.globalId().getLeastSignificantBits()); UNSAFE.putLong(arr, BYTE_ARR_OFF + 16, uuid.localId()); } return putByteArray(arr); }
/** * @param sndId Sender. * @param ldrId Loader ID. * @param userVer User version. * @param depMode Deployment mode. * @param participants Participants. */ private CachedDeploymentInfo(UUID sndId, GridUuid ldrId, String userVer, GridDeploymentMode depMode, Map<UUID, GridUuid> participants) { assert sndId.equals(ldrId.globalId()) || participants != null; this.sndId = sndId; this.ldrId = ldrId; this.userVer = userVer; this.depMode = depMode; this.participants = participants == null || participants.isEmpty() ? null : new ConcurrentLinkedHashMap<>(participants); }
/** * @param arr Array. * @param off Offset. * @param uid UUID. * @return Offset. */ public static long writeGridUuid(byte[] arr, long off, @Nullable GridUuid uid) { UNSAFE.putBoolean(arr, off++, uid != null); if (uid != null) { UNSAFE.putLong(arr, off, uid.globalId().getMostSignificantBits()); off += 8; UNSAFE.putLong(arr, off, uid.globalId().getLeastSignificantBits()); off += 8; UNSAFE.putLong(arr, off, uid.localId()); off += 8; } return off; }
/** * Converts GridUuid to bytes. * * @param uuid GridUuid to convert. * @param out Output array to write to. * @param off Offset from which to write. */ public static void gridUuidToBytes(GridUuid uuid, byte[] out, int off) { assert uuid != null; U.longToBytes(uuid.globalId().getMostSignificantBits(), out, off); U.longToBytes(uuid.globalId().getLeastSignificantBits(), out, off + 8); U.longToBytes(uuid.localId(), out, off + 16); }
/** * Adds new node and remote class loader id to this class loader. * Class loader will ask all associated nodes for the class/resource * until find it. * * @param nodeId Participating node ID. * @param ldrId Participating class loader id. */ void register(UUID nodeId, GridUuid ldrId) { assert nodeId != null; assert ldrId != null; assert nodeId.equals(ldrId.globalId()); assert !singleNode; synchronized (mux) { if (missedRsrcs != null) missedRsrcs.clear(); /* * We need to put passed in node into the * first position in the list. */ // 1. Remove passed in node if any. nodeList.remove(nodeId); // 2. Add passed in node to the first position. nodeList.addFirst(nodeId); // 3. Put to map. nodeLdrMap.put(nodeId, ldrId); } }
/** * @param newParticipants Participants to add. * @param cctx Cache context. * @return {@code True} if cached info is valid. */ boolean addParticipants(Map<UUID, GridUuid> newParticipants, GridCacheContext<K, V> cctx) { participantsLock.readLock().lock(); try { if (participants != null && participants.isEmpty()) return false; for (Map.Entry<UUID, GridUuid> e : newParticipants.entrySet()) { assert e.getKey().equals(e.getValue().globalId()); if (cctx.discovery().node(e.getKey()) != null) // Participant has left. continue; if (participants == null) participants = new ConcurrentLinkedHashMap<>(); if (!participants.containsKey(e.getKey())) participants.put(e.getKey(), e.getValue()); } return true; } finally { participantsLock.readLock().unlock(); } }
/** * Adds deployment info to deployment contexts queue. * * @param info Info to add. */ public void addDeploymentContext(GridDeploymentInfo info) { GridUuid ldrId = info.classLoaderId(); while (true) { CachedDeploymentInfo<K, V> depInfo = deps.get(ldrId); if (depInfo == null) { depInfo = new CachedDeploymentInfo<>(ldrId.globalId(), ldrId, info.userVersion(), info.deployMode(), info.participants()); CachedDeploymentInfo<K, V> old = deps.putIfAbsent(ldrId, depInfo); if (old != null) depInfo = old; else break; } Map<UUID, GridUuid> participants = info.participants(); if (participants != null) { if (!depInfo.addParticipants(participants, cctx)) { deps.remove(ldrId, depInfo); continue; } } break; } }
assert log != null; assert clsLdrId != null; assert nodeId.equals(clsLdrId.globalId());
/** {@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(); } }
UUID dstNodeId = futId.globalId();
GridStreamerResponse res = (GridStreamerResponse)msg; assert res.futureId().globalId().equals(ctx.localNodeId()) : "Wrong message received [res=" + res + ", sndNodeId=" + sndNodeId + ", locNodeId=" + ctx.localNodeId() + ']';