Example usage for java.util UUID getLeastSignificantBits

List of usage examples for java.util UUID getLeastSignificantBits

Introduction

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

Prototype

public long getLeastSignificantBits() 

Source Link

Document

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

Usage

From source file:org.apache.cassandra.db.marshal.TypeCompareTest.java

License:asdf

@Test
public void testTimeUUID() {
    // two different UUIDs w/ the same timestamp
    UUID uuid1 = UUID.fromString("1077e700-c7f2-11de-86d5-f5bcc793a028");
    byte[] bytes1 = new byte[16];
    ByteBuffer bb1 = ByteBuffer.wrap(bytes1);
    bb1.putLong(uuid1.getMostSignificantBits());
    bb1.putLong(uuid1.getLeastSignificantBits());

    UUID uuid2 = UUID.fromString("1077e700-c7f2-11de-982e-6fad363d5f29");
    byte[] bytes2 = new byte[16];
    ByteBuffer bb2 = ByteBuffer.wrap(bytes2);
    bb2.putLong(uuid2.getMostSignificantBits());
    bb2.putLong(uuid2.getLeastSignificantBits());

    assert new TimeUUIDType().compare(bytes1, bytes2) != 0;
}

From source file:io.warp10.quasar.encoder.QuasarTokenEncoder.java

private ByteBuffer toByteBuffer(String strUUID) {
    ByteBuffer buffer = ByteBuffer.allocate(16);
    buffer.order(ByteOrder.BIG_ENDIAN);

    UUID uuid = UUID.fromString(strUUID);

    buffer.putLong(uuid.getMostSignificantBits());
    buffer.putLong(uuid.getLeastSignificantBits());

    buffer.position(0);// ww w.  j a  v a2 s.c  o m
    return buffer;
}

From source file:com.wisemapping.service.UserServiceImpl.java

@NotNull
public User createUser(@NotNull User user, boolean emailConfirmEnabled, boolean welcomeEmail)
        throws WiseMappingException {
    final UUID uuid = UUID.randomUUID();
    user.setCreationDate(Calendar.getInstance());
    user.setActivationCode(uuid.getLeastSignificantBits());

    if (emailConfirmEnabled) {
        user.setActivationDate(null);/*  w  ww  .  ja v  a2 s.  c  o m*/

    } else {
        user.setActivationDate(Calendar.getInstance());
    }

    Collaborator col = userManager.getCollaboratorBy(user.getEmail());

    if (col != null) {
        userManager.createUser(user, col);
    } else {
        userManager.createUser(user);
    }

    //create welcome map
    final Mindmap mindMap = buildTutorialMindmap(user.getFirstname());
    mindmapService.addMindmap(mindMap, user);

    // Send registration email.
    if (emailConfirmEnabled) {
        notificationService.sendRegistrationEmail(user);
    } else if (welcomeEmail) {
        // Send a welcome email ..
        notificationService.newAccountCreated(user);
    }

    return user;
}

From source file:org.echocat.jomon.net.cluster.channel.tcp.TcpClusterChannelIntegrationTest.java

@Nonnull
@Override/*from ww w  .  ja v  a 2s.  co  m*/
protected TcpNode createNode(@Nonnull final UUID uuid) {
    return new TcpNodeSupport(uuid) {
        @Nonnull
        @Override
        public InetSocketAddress getAddress() {
            return new InetSocketAddress((int) uuid.getLeastSignificantBits());
        }
    };
}

From source file:org.midonet.benchmarks.mpi.MPIBenchApp.java

/**
 * Broadcast an UUID value from the 'source' process to the rest.
 * Note: an UUID with all bytes to zero is considered equivalent to null
 * (and therefore, converted to null).//from   w w  w .  ja v a2  s .c o m
 *
 * @param id     is the UUID to transmit, only needs to be set in the
 *               source process.
 * @param source is the rank of the source process.
 * @return for all processes, the transmitted UUID
 */
protected UUID broadcastUUID(UUID id, int source) throws MPIException {
    long[] msg = { 0, 0 };
    if (source == mpiRank) {
        if (id != null) {
            msg[0] = id.getMostSignificantBits();
            msg[1] = id.getLeastSignificantBits();
        }
    }
    MPI.COMM_WORLD.bcast(msg, 2, MPI.LONG, source);
    return (msg[0] == 0 && msg[1] == 0) ? null : new UUID(msg[0], msg[1]);
}

From source file:org.jboss.dashboard.workspace.WorkspacesManager.java

/**
 * Generate a unique workspace identifier
 *//*  www. ja  v a2  s  .  com*/
public synchronized String generateWorkspaceId() throws Exception {
    UUID uuid = UUID.randomUUID();
    ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
    bb.putLong(uuid.getMostSignificantBits());
    bb.putLong(uuid.getLeastSignificantBits());
    return Base64.encodeBase64URLSafeString(bb.array());
}

From source file:org.hillview.dataset.RemoteDataSet.java

@Override
public Observable<PartialResult<ControlMessage.StatusList>> manage(ControlMessage message) {
    final ManageOperation manageOp = new ManageOperation(message);
    final byte[] serializedOp = SerializationUtils.serialize(manageOp);
    final UUID operationId = UUID.randomUUID();
    final Command command = Command.newBuilder().setIdsIndex(this.remoteHandle)
            .setSerializedOp(ByteString.copyFrom(serializedOp)).setHighId(operationId.getMostSignificantBits())
            .setLowId(operationId.getLeastSignificantBits()).build();
    final SerializedSubject<PartialResult<ControlMessage.StatusList>, PartialResult<ControlMessage.StatusList>> subj = createSerializedSubject();
    final StreamObserver<PartialResponse> responseObserver = new ManageObserver(subj, message, this);
    return subj.unsubscribeOn(ExecutorUtils.getUnsubscribeScheduler()).doOnSubscribe(
            () -> this.stub.withDeadlineAfter(TIMEOUT, TimeUnit.MILLISECONDS).manage(command, responseObserver))
            .doOnUnsubscribe(() -> this.unsubscribe(operationId));
}

From source file:org.hillview.dataset.RemoteDataSet.java

/**
 * Map operations on a RemoteDataSet result in only one onNext
 * invocation that will return the final IDataSet.
 *///w w  w.j a v a  2 s .  c  om
@Override
public <S> Observable<PartialResult<IDataSet<S>>> map(final IMap<T, S> mapper) {
    final MapOperation<T, S> mapOp = new MapOperation<T, S>(mapper);
    final byte[] serializedOp = SerializationUtils.serialize(mapOp);
    final UUID operationId = UUID.randomUUID();
    final Command command = Command.newBuilder().setIdsIndex(this.remoteHandle)
            .setSerializedOp(ByteString.copyFrom(serializedOp)).setHighId(operationId.getMostSignificantBits())
            .setLowId(operationId.getLeastSignificantBits()).build();
    final SerializedSubject<PartialResult<IDataSet<S>>, PartialResult<IDataSet<S>>> subj = createSerializedSubject();
    final StreamObserver<PartialResponse> responseObserver = new NewDataSetObserver<S>(subj);
    return subj.unsubscribeOn(ExecutorUtils.getUnsubscribeScheduler()).doOnSubscribe(
            () -> this.stub.withDeadlineAfter(TIMEOUT, TimeUnit.MILLISECONDS).map(command, responseObserver))
            .doOnUnsubscribe(() -> this.unsubscribe(operationId));
}

From source file:org.hillview.dataset.RemoteDataSet.java

@Override
public <S> Observable<PartialResult<IDataSet<S>>> flatMap(IMap<T, List<S>> mapper) {
    final FlatMapOperation<T, S> mapOp = new FlatMapOperation<T, S>(mapper);
    final byte[] serializedOp = SerializationUtils.serialize(mapOp);
    final UUID operationId = UUID.randomUUID();
    final Command command = Command.newBuilder().setIdsIndex(this.remoteHandle)
            .setSerializedOp(ByteString.copyFrom(serializedOp)).setHighId(operationId.getMostSignificantBits())
            .setLowId(operationId.getLeastSignificantBits()).build();
    final SerializedSubject<PartialResult<IDataSet<S>>, PartialResult<IDataSet<S>>> subj = createSerializedSubject();
    final StreamObserver<PartialResponse> responseObserver = new NewDataSetObserver<S>(subj);
    return subj/*from ww  w  .  j  av a  2s. c o m*/
            .unsubscribeOn(ExecutorUtils.getUnsubscribeScheduler()).doOnSubscribe(() -> this.stub
                    .withDeadlineAfter(TIMEOUT, TimeUnit.MILLISECONDS).flatMap(command, responseObserver))
            .doOnUnsubscribe(() -> this.unsubscribe(operationId));
}

From source file:org.hillview.dataset.RemoteDataSet.java

/**
 * Sketch operation that streams partial results from the server to the caller.
 *///from  ww w .  j  a  va 2 s.  com
@Override
public <R> Observable<PartialResult<R>> sketch(final ISketch<T, R> sketch) {
    final SketchOperation<T, R> sketchOp = new SketchOperation<T, R>(sketch);
    final byte[] serializedOp = SerializationUtils.serialize(sketchOp);
    final UUID operationId = UUID.randomUUID();
    final Command command = Command.newBuilder().setIdsIndex(this.remoteHandle)
            .setSerializedOp(ByteString.copyFrom(serializedOp)).setHighId(operationId.getMostSignificantBits())
            .setLowId(operationId.getLeastSignificantBits()).build();
    final SerializedSubject<PartialResult<R>, PartialResult<R>> subj = createSerializedSubject();
    final StreamObserver<PartialResponse> responseObserver = new SketchObserver<R>(subj);
    return subj
            .doOnSubscribe(() -> this.stub.withDeadlineAfter(TIMEOUT, TimeUnit.MILLISECONDS).sketch(command,
                    responseObserver))
            .unsubscribeOn(ExecutorUtils.getUnsubscribeScheduler())
            .doOnUnsubscribe(() -> this.unsubscribe(operationId));
}