/** * Attempt to claim ownership of this token. When successful, this method returns {@code true}, otherwise * {@code false}. When a claim fails, this token should not be used, as it is already being used in another process. * <p> * If a claim exists, but it is older than given {@code claimTimeout}, the claim may be 'stolen'. * * @param owner The name of the current node, to register as owner. This name must be unique for multiple * instances of the same logical processor * @param claimTimeout The time after which a claim may be 'stolen' from its current owner * @return {@code true} if the claim succeeded, otherwise false */ public boolean claim(String owner, TemporalAmount claimTimeout) { if (!mayClaim(owner, claimTimeout)) { return false; } this.timestamp = formatInstant(clock.instant()); this.owner = owner; return true; }
/** * Attempt to claim ownership of this token. When successful, this method returns {@code true}, otherwise * {@code false}. When a claim fails, this token should not be used, as it is already being used in another process. * <p> * If a claim exists, but it is older than given {@code claimTimeout}, the claim may be 'stolen'. * * @param owner The name of the current node, to register as owner. This name must be unique for multiple * instances of the same logical processor * @param claimTimeout The time after which a claim may be 'stolen' from its current owner * @return {@code true} if the claim succeeded, otherwise false */ public boolean claim(String owner, TemporalAmount claimTimeout) { if (!mayClaim(owner, claimTimeout)) { return false; } this.timestamp = formatInstant(clock.instant()); this.owner = owner; return true; }
/** * Attempt to claim ownership of this token. When successful, this method returns {@code true}, otherwise * {@code false}. When a claim fails, this token should not be used, as it is already being used in another process. * <p> * If a claim exists, but it is older than given {@code claimTimeout}, the claim may be 'stolen'. * * @param owner The name of the current node, to register as owner. This name must be unique for multiple * instances of the same logical processor * @param claimTimeout The time after which a claim may be 'stolen' from its current owner * @return {@code true} if the claim succeeded, otherwise false */ public boolean claim(String owner, TemporalAmount claimTimeout) { if (!mayClaim(owner, claimTimeout)) { return false; } this.timestamp = formatInstant(clock.instant()); this.owner = owner; return true; }