40 Star 79 Fork 36

程序猿DD/consul-distributed-lock

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ContenderValue.java 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
程序猿DD 提交于 8年前 . init
package com.didispace.lock.consul;
import com.ecwid.consul.v1.kv.model.GetValue;
import com.google.gson.Gson;
import lombok.Data;
import lombok.SneakyThrows;
import sun.misc.BASE64Decoder;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* 信号量存储结构:并发上限值、当前持有者列表
*
* @author 翟永超
* @create 2017/4/12.
* @blog http://blog.didispace.com
*/
@Data
public class ContenderValue implements Serializable {
private Integer limit; // 上限值
private List<String> holders = new ArrayList<>(); // 持有者列表
/**
* 根据consul中获取的/.lock值来转换
*
* @param lockKeyContent
* @return
*/
@SneakyThrows
public static ContenderValue parse(GetValue lockKeyContent) {
// 获取Value信息,decode BASE64
BASE64Decoder decoder = new BASE64Decoder();
byte[] v = decoder.decodeBuffer(lockKeyContent.getValue());
String lockKeyValueDecode = new String(v);
// 根据json转换为ContenderValue对象
Gson gson = new Gson();
return gson.fromJson(lockKeyValueDecode, ContenderValue.class);
}
@Override
public String toString() {
return new Gson().toJson(this);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/didispace/consul-distributed-lock.git
git@gitee.com:didispace/consul-distributed-lock.git
didispace
consul-distributed-lock
consul-distributed-lock
master

搜索帮助