package cn.autoform.web.controller.resumable.redis.lock;
|
|
import java.io.Serializable;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
import cn.autoform.fw.exception.IEMRuntimeException;
|
import lombok.Data;
|
|
/**
|
* 锁列表实体
|
* @author wangyuxin
|
*
|
*/
|
@Data
|
public class LocksEntity implements Serializable{
|
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 8811304440312972451L;
|
|
/**
|
* 锁列表
|
*/
|
private Map<Lock, Lock> locks = new HashMap<>();
|
|
/**
|
* 获得钥匙的锁
|
*/
|
private Lock lock;
|
|
public Lock addLock() {
|
Lock lockObj = new Lock(RandomStringUtils.randomNumeric(16));
|
locks.put(lockObj, lockObj);
|
return lockObj;
|
}
|
|
public Lock addKey(String lockInfo, Long timeOut) {
|
if(this.lock != null && this.lock.getTimeOut() > System.currentTimeMillis()) {
|
throw new IEMRuntimeException("FORM_LOCK");
|
}
|
Lock lockObj = locks.get(new Lock(lockInfo));
|
if(lockObj == null) {
|
throw new IEMRuntimeException("FORM_UPDATE");
|
}
|
lockObj.setKey(new Key(RandomStringUtils.randomNumeric(16)));
|
lockObj.setTimeOut(timeOut);
|
this.lock = lockObj;
|
return lockObj;
|
}
|
}
|