/** * Creates new pseudo-random ID. * * @return Newly created pseudo-random ID. */ public static IgniteUuid randomUuid() { return new IgniteUuid(VM_ID, cntGen.incrementAndGet()); }
/** * @return Version represented as {@code GridUuid} */ public IgniteUuid asGridUuid() { return new IgniteUuid(new UUID(topVer, nodeOrderDrId), order); }
/** * Converts string into {@code GridUuid}. The String must be in the format generated * by {@link #toString() GridUuid.toString()} method. * * @param s String to convert to {@code GridUuid}. * @return {@code GridUuid} instance representing given string. */ public static IgniteUuid fromString(String s) { int firstDash = s.indexOf('-'); return new IgniteUuid( UUID.fromString(s.substring(firstDash + 1)), Long.valueOf(new StringBuilder(s.substring(0, firstDash)).reverse().toString(), 16) ); }
/** * Constructs new {@code GridUuid} based on global and local ID portions. * * @param id UUID instance. * @return Newly created pseudo-random ID. */ public static IgniteUuid fromUuid(UUID id) { A.notNull(id, "id"); return new IgniteUuid(id, cntGen.getAndIncrement()); }
/** * Reads {@link org.apache.ignite.lang.IgniteUuid} from input stream. This method is meant to be used by * implementations of {@link Externalizable} interface. * * @param in Input stream. * @return Read UUID. * @throws IOException If read failed. */ @Nullable public static IgniteUuid readGridUuid(DataInput in) throws IOException { // If UUID is not null. if (!in.readBoolean()) { long most = in.readLong(); long least = in.readLong(); UUID globalId = IgniteUuidCache.onIgniteUuidRead(new UUID(most, least)); long locId = in.readLong(); return new IgniteUuid(globalId, locId); } return null; }
/** * Read {@code IgniteUuid} instance. * * @param in Reader. * @return Value. */ @Nullable public static IgniteUuid readIgniteUuid(BinaryRawReader in) { if (in.readBoolean()) { UUID globalId = new UUID(in.readLong(), in.readLong()); return new IgniteUuid(globalId, in.readLong()); } else return null; }
/** * Converts bytes to GridUuid. * * @param in Input byte array. * @param off Offset from which start reading. * @return GridUuid instance. */ public static IgniteUuid bytesToIgniteUuid(byte[] in, int off) { long most = bytesToLong(in, off); long least = bytesToLong(in, off + 8); long locId = bytesToLong(in, off + 16); return new IgniteUuid(IgniteUuidCache.onIgniteUuidRead(new UUID(most, least)), locId); }
/** {@inheritDoc} */ @Override public IgniteUuid readIgniteUuid() { switch (uuidState) { case 0: boolean isNull = readBoolean(); if (!lastFinished || isNull) return null; uuidState++; case 1: uuidMost = readLong(); if (!lastFinished) return null; uuidState++; case 2: uuidLeast = readLong(); if (!lastFinished) return null; uuidState++; case 3: uuidLocId = readLong(); if (!lastFinished) return null; uuidState = 0; } IgniteUuid val = new IgniteUuid(new UUID(uuidMost, uuidLeast), uuidLocId); uuidMost = 0; uuidLeast = 0; uuidLocId = 0; return val; }
/** * 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. */ @SuppressWarnings("ConstantConditions") public IgniteUuid nextAffinityKey(@Nullable IgniteUuid prevAffKey) { // Do not generate affinity key for non-affinity nodes. if (!dataCache.context().affinityNode()) return null; UUID nodeId = igfsCtx.kernalContext().localNodeId(); if (prevAffKey != null && dataCache.affinity().mapKeyToNode(prevAffKey).isLocal()) return prevAffKey; while (true) { IgniteUuid key = new IgniteUuid(nodeId, affKeyGen.getAndIncrement()); if (dataCache.affinity().mapKeyToNode(key).isLocal()) return key; } }
/** * @param nodeId Sender node ID. * @param res Near get response. */ protected void processNearSingleGetResponse(UUID nodeId, GridNearSingleGetResponse res) { if (log.isDebugEnabled()) log.debug("Processing near get response [nodeId=" + nodeId + ", res=" + res + ']'); GridPartitionedSingleGetFuture fut = (GridPartitionedSingleGetFuture)ctx.mvcc() .future(new IgniteUuid(IgniteUuid.VM_ID, res.futureId())); if (fut == null) { if (log.isDebugEnabled()) log.debug("Failed to find future for get response [sender=" + nodeId + ", res=" + res + ']'); return; } fut.onResult(nodeId, res); }
/** @throws Exception If failed. */ @Test public void testCreateFileColocated() throws Exception { IgfsPath path = new IgfsPath("/colocated"); UUID uuid = UUID.randomUUID(); IgniteUuid affKey; long idx = 0; while (true) { affKey = new IgniteUuid(uuid, idx); if (grid(0).affinity(grid(0).igfsx("igfs").configuration().getDataCacheConfiguration() .getName()).mapKeyToNode(affKey).id().equals(grid(0).localNode().id())) break; idx++; } try (IgfsOutputStream out = fs.create(path, 1024, true, affKey, 0, 1024, null)) { // Write 5M, should be enough to test distribution. for (int i = 0; i < 15; i++) out.write(new byte[1024 * 1024]); } IgfsFile info = fs.info(path); Collection<IgfsBlockLocation> affNodes = fs.affinity(path, 0, info.length()); assertEquals(1, affNodes.size()); Collection<UUID> nodeIds = F.first(affNodes).nodeIds(); assertEquals(1, nodeIds.size()); assertEquals(grid(0).localNode().id(), F.first(nodeIds)); }
String msg = "msg"; UUID uuid = new UUID(1, 2); IgniteUuid igniteUuid = new IgniteUuid(uuid, 3);
/** * Creates new pseudo-random ID. * * @return Newly created pseudo-random ID. */ public static IgniteUuid randomUuid() { return new IgniteUuid(VM_ID, cntGen.incrementAndGet()); }
/** * @return Version represented as {@code GridUuid} */ public IgniteUuid asGridUuid() { return new IgniteUuid(new UUID(topVer, nodeOrderDrId), order); }
/** * Converts string into {@code GridUuid}. The String must be in the format generated * by {@link #toString() GridUuid.toString()} method. * * @param s String to convert to {@code GridUuid}. * @return {@code GridUuid} instance representing given string. */ public static IgniteUuid fromString(String s) { int firstDash = s.indexOf('-'); return new IgniteUuid( UUID.fromString(s.substring(firstDash + 1)), Long.valueOf(new StringBuilder(s.substring(0, firstDash)).reverse().toString(), 16) ); }
/** * Constructs new {@code GridUuid} based on global and local ID portions. * * @param id UUID instance. * @return Newly created pseudo-random ID. */ public static IgniteUuid fromUuid(UUID id) { A.notNull(id, "id"); return new IgniteUuid(id, cntGen.getAndIncrement()); }
/** * Converts bytes to GridUuid. * * @param in Input byte array. * @param off Offset from which start reading. * @return GridUuid instance. */ public static IgniteUuid bytesToIgniteUuid(byte[] in, int off) { long most = bytesToLong(in, off); long least = bytesToLong(in, off + 8); long locId = bytesToLong(in, off + 16); return new IgniteUuid(IgniteUuidCache.onIgniteUuidRead(new UUID(most, least)), locId); }
.future(new IgniteUuid(IgniteUuid.VM_ID, res.futureId()));
/** * Read {@code IgniteUuid} instance. * * @param in Reader. * @return Value. */ @Nullable public static IgniteUuid readIgniteUuid(BinaryRawReader in) { if (in.readBoolean()) { UUID globalId = new UUID(in.readLong(), in.readLong()); return new IgniteUuid(globalId, in.readLong()); } else return null; }
/** * @param nodeId Sender node ID. * @param res Near get response. */ protected void processNearSingleGetResponse(UUID nodeId, GridNearSingleGetResponse res) { if (log.isDebugEnabled()) log.debug("Processing near get response [nodeId=" + nodeId + ", res=" + res + ']'); GridPartitionedSingleGetFuture fut = (GridPartitionedSingleGetFuture)ctx.mvcc() .future(new IgniteUuid(IgniteUuid.VM_ID, res.futureId())); if (fut == null) { if (log.isDebugEnabled()) log.debug("Failed to find future for get response [sender=" + nodeId + ", res=" + res + ']'); return; } fut.onResult(nodeId, res); }