@Override public ILock acquireLock(final ILockKey lockKey, final String user) throws LockException { return storage.write( storeProvider -> { LockStore.Mutable lockStore = storeProvider.getLockStore(); Optional<ILock> existingLock = lockStore.fetchLock(lockKey); if (existingLock.isPresent()) { throw new LockException( String.format( "Operation for: %s is already in progress. Started at: %s. Current owner: %s.", formatLockKey(lockKey), new Date(existingLock.get().getTimestampMs()).toString(), existingLock.get().getUser())); } ILock lock = ILock.build( new Lock() .setKey(lockKey.newBuilder()) .setToken(tokenGenerator.createNew().toString()) .setTimestampMs(clock.nowMillis()) .setUser(user)); lockStore.saveLock(lock); return lock; }); }
/** * Generates a time-based UUID (similar to Flake IDs), which is preferred when generating an ID to * be indexed into a Lucene index as primary key. The id is opaque and the implementation is free * to change at any time! */ public static String base64UUID() { return TIME_UUID_GENERATOR.getBase64UUID(); }
public static Result index() { LOG.info("this is home:" + request().toString()); UUIDGenerator uuid = UUIDGenerator.findByUDID(request().username()); return ok(home.render(uuid.getUser().getUsername())); }