List of usage examples for java.util UUID getLeastSignificantBits
public long getLeastSignificantBits()
From source file:org.hillview.dataset.RemoteDataSet.java
/** * Unsubscribes an operation. This method is safe to invoke multiple times because the * logic on the remote end is idempotent. *//*from w w w .j av a 2s .c o m*/ private void unsubscribe(final UUID id) { HillviewLogger.instance.info("Unsubscribe called", "{0}", id); final UnsubscribeOperation op = new UnsubscribeOperation(id); final byte[] serializedOp = SerializationUtils.serialize(op); final Command command = Command.newBuilder().setIdsIndex(this.remoteHandle) .setSerializedOp(ByteString.copyFrom(serializedOp)).setHighId(id.getMostSignificantBits()) .setLowId(id.getLeastSignificantBits()).build(); this.stub.withDeadlineAfter(TIMEOUT, TimeUnit.MILLISECONDS).unsubscribe(command, new StreamObserver<Ack>() { @Override public void onNext(final Ack ack) { } @Override public void onError(final Throwable throwable) { } @Override public void onCompleted() { } }); }
From source file:com.github.ambry.commons.BlobIdTest.java
/** * Build a string that resembles a bad blobId. * @param version The version number to be embedded in the blobId. * @param type The {@link BlobIdType} of the blobId. * @param datacenterId The datacenter id to be embedded in the blobId. * @param accountId The account id to be embedded in the blobId. * @param containerId The container id to be embedded in the blobId. * @param partitionId The partition id to be embedded in the blobId. * @param uuidLength The length of the uuid. * @param uuid The UUID to be embedded in the blobId. * @param extraChars Extra characters to put at the end of the ID. * @return a base-64 encoded {@link String} representing the blobId. *///from w w w . ja va2 s. c o m private String buildBadBlobId(short version, BlobIdType type, Byte datacenterId, Short accountId, Short containerId, PartitionId partitionId, int uuidLength, String uuid, String extraChars) { int idLength; ByteBuffer idBuf; switch (version) { case BLOB_ID_V1: idLength = 2 + partitionId.getBytes().length + 4 + uuid.length() + extraChars.length(); idBuf = ByteBuffer.allocate(idLength); idBuf.putShort(version); break; case BLOB_ID_V2: idLength = 2 + 1 + 1 + 2 + 2 + partitionId.getBytes().length + 4 + uuid.length() + extraChars.length(); idBuf = ByteBuffer.allocate(idLength); idBuf.putShort(version); idBuf.put((byte) 0); idBuf.put(datacenterId); idBuf.putShort(accountId); idBuf.putShort(containerId); break; case BLOB_ID_V3: case BLOB_ID_V4: case BLOB_ID_V5: case BLOB_ID_V6: idLength = 2 + 1 + 1 + 2 + 2 + partitionId.getBytes().length + 4 + uuid.length() + extraChars.length(); idBuf = ByteBuffer.allocate(idLength); idBuf.putShort(version); idBuf.put((byte) type.ordinal()); idBuf.put(datacenterId); idBuf.putShort(accountId); idBuf.putShort(containerId); break; default: idLength = 2 + partitionId.getBytes().length + 4 + uuid.length() + extraChars.length(); idBuf = ByteBuffer.allocate(idLength); idBuf.putShort(version); break; } idBuf.put(partitionId.getBytes()); switch (version) { case BLOB_ID_V6: UUID uuidObj = UUID.fromString(uuid); idBuf.putLong(uuidObj.getMostSignificantBits()); idBuf.putLong(uuidObj.getLeastSignificantBits()); break; default: idBuf.putInt(uuidLength); idBuf.put(uuid.getBytes()); } idBuf.put(extraChars.getBytes()); return Base64.encodeBase64URLSafeString(idBuf.array()); }
From source file:org.nordapp.web.servlet.AbstractControlImpl.java
/** * Generates the public key of a certificate into certID */// w w w .ja v a2 s . c om public void generateCert() { UUID uuid = UUID.randomUUID(); byte[] buffer = ByteBuffer.allocate(16).putLong(0, uuid.getMostSignificantBits()) .putLong(8, uuid.getLeastSignificantBits()).array(); field0 = buffer; certID = Base64.encodeBase64URLSafeString(buffer); }
From source file:com.opengamma.component.factory.engine.EngineConfigurationComponentFactory.java
/** * Creates a random logical server unique identifier. This is used if an explicit identifier is not set in the configuration file. * <p>/* www .j a va 2 s. c o m*/ * This is a 24 character string using base-64 characters, created using the algorithm from {@link GUIDGenerator} for uniqueness. * * @return the logical server unique identifier, not null */ protected String createLogicalServerId() { final UUID uuid = GUIDGenerator.generate(); final byte[] bytes = new byte[16]; long x = uuid.getMostSignificantBits(); bytes[0] = (byte) x; bytes[1] = (byte) (x >> 8); bytes[2] = (byte) (x >> 16); bytes[3] = (byte) (x >> 24); bytes[4] = (byte) (x >> 32); bytes[5] = (byte) (x >> 40); bytes[6] = (byte) (x >> 48); bytes[7] = (byte) (x >> 56); x = uuid.getLeastSignificantBits(); bytes[8] = (byte) x; bytes[9] = (byte) (x >> 8); bytes[10] = (byte) (x >> 16); bytes[11] = (byte) (x >> 24); bytes[12] = (byte) (x >> 32); bytes[13] = (byte) (x >> 40); bytes[14] = (byte) (x >> 48); bytes[15] = (byte) (x >> 56); return Base64.encodeBase64String(bytes); }
From source file:com.cognitect.transit.TransitTest.java
public void testReadUUID() throws IOException { UUID uuid = UUID.randomUUID(); long hi64 = uuid.getMostSignificantBits(); long lo64 = uuid.getLeastSignificantBits(); assertEquals(0, uuid.compareTo((UUID) reader("\"~u" + uuid.toString() + "\"").read())); assertEquals(0, uuid.compareTo((UUID) reader("{\"~#u\": [" + hi64 + ", " + lo64 + "]}").read())); }
From source file:org.apache.jackrabbit.core.persistence.AutoFixCorruptNode.java
private void destroyBundle(UUID id, String where) throws SQLException { Connection conn = DriverManager.getConnection("jdbc:derby:" + TEST_DIR + "/" + where + "/db"); String table = where.equals("version") ? "VERSION_BUNDLE" : "DEFAULT_BUNDLE"; PreparedStatement prep = conn .prepareStatement("delete from " + table + " where NODE_ID_HI=? and NODE_ID_LO=?"); prep.setLong(1, id.getMostSignificantBits()); prep.setLong(2, id.getLeastSignificantBits()); prep.executeUpdate();// ww w.j a va 2s. c om conn.close(); }
From source file:org.apache.jackrabbit.oak.segment.file.TarReader.java
/** * Collect reclaimable segments.//from www.j a v a2 s.c om * A data segment is reclaimable iff its generation is in the {@code reclaimGeneration} * predicate. * A bulk segment is reclaimable if it is in {@code bulkRefs} or if it is transitively * reachable through a non reclaimable data segment. * * @param bulkRefs bulk segment gc roots * @param reclaim reclaimable segments * @param reclaimGeneration reclaim generation predicate for data segments * @throws IOException */ void mark(Set<UUID> bulkRefs, Set<UUID> reclaim, Predicate<Integer> reclaimGeneration) throws IOException { Map<UUID, List<UUID>> graph = getGraph(true); TarEntry[] entries = getEntries(); for (int i = entries.length - 1; i >= 0; i--) { TarEntry entry = entries[i]; UUID id = new UUID(entry.msb(), entry.lsb()); if ((!isDataSegmentId(entry.lsb()) && !bulkRefs.remove(id)) || (isDataSegmentId(entry.lsb()) && reclaimGeneration.apply(entry.generation()))) { // non referenced bulk segment or old data segment reclaim.add(id); } else { if (isDataSegmentId(entry.lsb())) { for (UUID refId : getReferences(entry, id, graph)) { if (!isDataSegmentId(refId.getLeastSignificantBits())) { // keep the extra check for bulk segments for the case where a // pre-compiled graph is not available and getReferences also // includes data references if (!reclaim.remove(id)) { bulkRefs.add(refId); } } } } } } }
From source file:org.jaya.varanus.monitoring.Bytes.java
public static byte[] toBytes(UUID identifier) { long leastSignificativeBits = identifier.getLeastSignificantBits(); long mostSignificativeBits = identifier.getMostSignificantBits(); byte[] leastSignificativeBytes = Bytes.toBytes(leastSignificativeBits); byte[] mostSignificativeBytes = Bytes.toBytes(mostSignificativeBits); byte[] identifierBytes = Bytes.add(leastSignificativeBytes, mostSignificativeBytes); return (identifierBytes); }
From source file:org.agnitas.util.AgnUtils.java
public static byte[] convertToByteArray(UUID uuid) { long msb = uuid.getMostSignificantBits(); long lsb = uuid.getLeastSignificantBits(); byte[] buffer = new byte[16]; for (int i = 0; i < 8; i++) { buffer[i] = (byte) (msb >>> 8 * (7 - i)); }/*from ww w .j a va 2 s . com*/ for (int i = 8; i < 16; i++) { buffer[i] = (byte) (lsb >>> 8 * (7 - i)); } return buffer; }
From source file:org.apache.nifi.web.util.SnippetUtils.java
/** * Generates a new type 1 id (UUID) for the current id that is specified. If * seed is provided, it will be incorporated into generation logic of the * new ID.// w w w .j a v a 2 s . co m * The contract of this method is as follows: * - The 'currentId' must never be null and it must be String representation * of type-one UUID. * - If seed is provided, the new ID will be generated from the 'msb' extracted from * the 'currentId' and the 'lsb' extracted from the UUID generated via * UUID.nameUUIDFromBytes(currentId + seed). * - If seed is NOT provided and 'isCopy' flag is set the new ID will be generated from * the 'msb' extracted from the 'currentId' and random integer as 'lsb'. In this case * the new ID will always be > the previous ID essentially resulting in the new ID for * the component that being copied (e.g., copy/paste). * - If seed is NOT provided and 'isCopy' flag is NOT set the new ID will be generated from * the 'msb' extracted from the 'currentId' and random integer as 'lsb'. */ private String generateId(final String currentId, final String seed, boolean isCopy) { long msb = UUID.fromString(currentId).getMostSignificantBits(); UUID uuid; if (StringUtils.isBlank(seed)) { long lsb = randomGenerator.nextLong(); if (isCopy) { uuid = ComponentIdGenerator.generateId(msb, lsb, true); // will increment msb if necessary } else { // since msb is extracted from type-one UUID, the type-one semantics will be preserved uuid = new UUID(msb, lsb); } } else { UUID seedId = UUID.nameUUIDFromBytes((currentId + seed).getBytes(StandardCharsets.UTF_8)); if (isCopy) { // will ensure the type-one semantics for new UUID generated from msb extracted from seedId uuid = ComponentIdGenerator.generateId(seedId.getMostSignificantBits(), seedId.getLeastSignificantBits(), false); } else { uuid = new UUID(msb, seedId.getLeastSignificantBits()); } } logger.debug("Generating UUID {} from currentId={}, seed={}, isCopy={}", uuid, currentId, seed, isCopy); return uuid.toString(); }