Example usage for java.util UUID getMostSignificantBits

List of usage examples for java.util UUID getMostSignificantBits

Introduction

In this page you can find the example usage for java.util UUID getMostSignificantBits.

Prototype

public long getMostSignificantBits() 

Source Link

Document

Returns the most significant 64 bits of this UUID's 128 bit value.

Usage

From source file:org.apache.hadoop.hbase.regionserver.wal.HLogKey.java

public WALKey.Builder getBuilder(WALCellCodec.ByteStringCompressor compressor) throws IOException {
    WALKey.Builder builder = WALKey.newBuilder();
    if (compressionContext == null) {
        builder.setEncodedRegionName(HBaseZeroCopyByteString.wrap(this.encodedRegionName));
        builder.setTableName(HBaseZeroCopyByteString.wrap(this.tablename.getName()));
    } else {//from   ww  w  .j a  v a 2s.  c om
        builder.setEncodedRegionName(
                compressor.compress(this.encodedRegionName, compressionContext.regionDict));
        builder.setTableName(compressor.compress(this.tablename.getName(), compressionContext.tableDict));
    }
    builder.setLogSequenceNumber(this.logSeqNum);
    builder.setWriteTime(writeTime);
    if (this.nonce != HConstants.NO_NONCE) {
        builder.setNonce(nonce);
    }
    if (this.nonceGroup != HConstants.NO_NONCE) {
        builder.setNonceGroup(nonceGroup);
    }
    HBaseProtos.UUID.Builder uuidBuilder = HBaseProtos.UUID.newBuilder();
    for (UUID clusterId : clusterIds) {
        uuidBuilder.setLeastSigBits(clusterId.getLeastSignificantBits());
        uuidBuilder.setMostSigBits(clusterId.getMostSignificantBits());
        builder.addClusterIds(uuidBuilder.build());
    }
    if (scopes != null) {
        for (Map.Entry<byte[], Integer> e : scopes.entrySet()) {
            ByteString family = (compressionContext == null) ? HBaseZeroCopyByteString.wrap(e.getKey())
                    : compressor.compress(e.getKey(), compressionContext.familyDict);
            builder.addScopes(
                    FamilyScope.newBuilder().setFamily(family).setScopeType(ScopeType.valueOf(e.getValue())));
        }
    }
    return builder;
}

From source file:org.apache.hadoop.hbase.wal.WALKey.java

public org.apache.hadoop.hbase.protobuf.generated.WALProtos.WALKey.Builder getBuilder(
        WALCellCodec.ByteStringCompressor compressor) throws IOException {
    org.apache.hadoop.hbase.protobuf.generated.WALProtos.WALKey.Builder builder = org.apache.hadoop.hbase.protobuf.generated.WALProtos.WALKey
            .newBuilder();//from   ww w.j a  va 2  s .co  m
    if (compressionContext == null) {
        builder.setEncodedRegionName(ByteStringer.wrap(this.encodedRegionName));
        builder.setTableName(ByteStringer.wrap(this.tablename.getName()));
    } else {
        builder.setEncodedRegionName(
                compressor.compress(this.encodedRegionName, compressionContext.regionDict));
        builder.setTableName(compressor.compress(this.tablename.getName(), compressionContext.tableDict));
    }
    builder.setLogSequenceNumber(this.logSeqNum);
    builder.setWriteTime(writeTime);
    if (this.origLogSeqNum > 0) {
        builder.setOrigSequenceNumber(this.origLogSeqNum);
    }
    if (this.nonce != HConstants.NO_NONCE) {
        builder.setNonce(nonce);
    }
    if (this.nonceGroup != HConstants.NO_NONCE) {
        builder.setNonceGroup(nonceGroup);
    }
    HBaseProtos.UUID.Builder uuidBuilder = HBaseProtos.UUID.newBuilder();
    for (UUID clusterId : clusterIds) {
        uuidBuilder.setLeastSigBits(clusterId.getLeastSignificantBits());
        uuidBuilder.setMostSigBits(clusterId.getMostSignificantBits());
        builder.addClusterIds(uuidBuilder.build());
    }
    if (scopes != null) {
        for (Map.Entry<byte[], Integer> e : scopes.entrySet()) {
            ByteString family = (compressionContext == null) ? ByteStringer.wrap(e.getKey())
                    : compressor.compress(e.getKey(), compressionContext.familyDict);
            builder.addScopes(
                    FamilyScope.newBuilder().setFamily(family).setScopeType(ScopeType.valueOf(e.getValue())));
        }
    }
    return builder;
}

From source file:org.nordapp.web.servlet.AbstractControlImpl.java

/**
 * Generates the public key of a certificate into certID
 *//*  w w w. j  ava 2s.  c  o  m*/
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.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();//from   w w  w . ja  v  a2s  .co  m
    conn.close();
}

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   w  ww  .  ja  va2  s .c  om*/
    for (int i = 8; i < 16; i++) {
        buffer[i] = (byte) (lsb >>> 8 * (7 - i));
    }
    return buffer;
}

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.apache.nifi.web.api.ApplicationResource.java

protected String generateUuid() {
    final Optional<String> seed = getIdGenerationSeed();
    UUID uuid;//from w  w  w  .  java  2s.c o  m
    if (seed.isPresent()) {
        try {
            UUID seedId = UUID.fromString(seed.get());
            uuid = new UUID(seedId.getMostSignificantBits(), seed.get().hashCode());
        } catch (Exception e) {
            logger.warn(
                    "Provided 'seed' does not represent UUID. Will not be able to extract most significant bits for ID generation.");
            uuid = UUID.nameUUIDFromBytes(seed.get().getBytes(StandardCharsets.UTF_8));
        }
    } else {
        uuid = ComponentIdGenerator.generateId();
    }

    return uuid.toString();
}

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.//ww  w. j  av 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();
}

From source file:kx.c.java

void w(UUID uuid) {
    if (vt < 3)
        throw new RuntimeException("Guid not valid pre kdb+3.0");
    w(uuid.getMostSignificantBits());
    w(uuid.getLeastSignificantBits());/*w w  w  . j a  v a 2  s .  c o m*/
}