|
|
@@ -192,6 +192,17 @@ public class CommonService {
|
|
|
return base64;
|
|
|
}
|
|
|
|
|
|
+ public boolean isAcquire(String id, Long expiration, SuperMain superMain) {
|
|
|
+ if (StringUtils.isEmpty(id) || ObjectUtils.isEmpty(superMain)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (expiration == null) {
|
|
|
+ expiration = 5000L;
|
|
|
+ }
|
|
|
+ String lockKey = acquire(id, expiration, superMain);
|
|
|
+ return StringUtils.isEmpty(lockKey);
|
|
|
+ }
|
|
|
+
|
|
|
public String acquire(String id, Long expiration, SuperMain superMain) {
|
|
|
Query query = Query.query(Criteria.where("_id").is(id).and("token").isNull());
|
|
|
String token = TokenUtil.create();
|
|
|
@@ -213,11 +224,12 @@ public class CommonService {
|
|
|
}
|
|
|
|
|
|
public boolean release(String id, SuperMain superMain) {
|
|
|
+ log.info("release {}", id);
|
|
|
Query releaseQuery = Query.query(Criteria.where("_id").is(id));
|
|
|
Update releaseUpdate = new Update().set("expireAt", null).set("token", null);
|
|
|
- FindAndModifyOptions releaseOptions = new FindAndModifyOptions().upsert(true).returnNew(true);
|
|
|
+ FindAndModifyOptions releaseOptions = new FindAndModifyOptions().upsert(false).returnNew(true);
|
|
|
SuperMain flowDisposition = mongoTemplate.findAndModify(releaseQuery, releaseUpdate, releaseOptions, superMain.getClass());
|
|
|
- return StringUtils.isEmpty(flowDisposition.getToken());
|
|
|
+ return ObjectUtils.isNotEmpty(flowDisposition) && StringUtils.isEmpty(flowDisposition.getToken());
|
|
|
}
|
|
|
|
|
|
}
|