use of info.xiancloud.core.message.UnitResponse in project xian by happyyangyuan.
the class CacheListUtil method addAll.
public static boolean addAll(CacheConfigBean cacheConfigBean, String cacheKey, List list) {
UnitResponse unitResponseObject = SyncXian.call(CacheService.CACHE_SERVICE, "cacheListAddAll", new JSONObject() {
{
put("cacheConfig", cacheConfigBean);
put("key", cacheKey);
put("values", list);
}
});
unitResponseObject.throwExceptionIfNotSuccess();
return unitResponseObject.succeeded();
}
use of info.xiancloud.core.message.UnitResponse in project xian by happyyangyuan.
the class CacheListUtil method getRange.
/**
* 指定获取范围 (不推荐使用)
*/
@Deprecated
public static List getRange(CacheConfigBean cacheConfigBean, String cacheKey, int startIndex, int endIndex) {
UnitResponse unitResponseObject = SyncXian.call(CacheService.CACHE_SERVICE, "cacheListRange", new JSONObject() {
{
put("cacheConfig", cacheConfigBean);
put("key", cacheKey);
put("startIndex", startIndex);
put("endIndex", endIndex);
}
});
unitResponseObject.throwExceptionIfNotSuccess();
if (unitResponseObject.getData() != null)
return unitResponseObject.getData();
else
return null;
}
use of info.xiancloud.core.message.UnitResponse in project xian by happyyangyuan.
the class CacheListUtil method delete.
public static boolean delete(CacheConfigBean cacheConfigBean, String cacheKey) {
UnitResponse unitResponseObject = SyncXian.call(CacheService.CACHE_SERVICE, "cacheObjectRemove", new JSONObject() {
{
put("cacheConfig", cacheConfigBean);
put("key", cacheKey);
}
});
unitResponseObject.throwExceptionIfNotSuccess();
return unitResponseObject.succeeded();
}
use of info.xiancloud.core.message.UnitResponse in project xian by happyyangyuan.
the class CacheMapUtil method containsKey.
public static boolean containsKey(CacheConfigBean cacheConfigBean, String key, String field) {
UnitResponse unitResponseObject = SyncXian.call(CacheService.CACHE_SERVICE, "cacheMapExists", new JSONObject() {
{
put("cacheConfig", cacheConfigBean);
put("key", key);
put("field", field);
}
});
unitResponseObject.throwExceptionIfNotSuccess();
return (boolean) unitResponseObject.getData();
}
use of info.xiancloud.core.message.UnitResponse in project xian by happyyangyuan.
the class DistributedLock method lock.
/**
* @param cacheConfigBean cacheConfigBean
* @param key key
* @param value vlaue
* @param expireTimeInSecond 单位: 秒, KEY 过期时间
* @param timeOutInSecond 单位: 秒, 获取锁超时时间
* @return DistributedLock
* @throws TimeOutException
*/
public static DistributedLock lock(CacheConfigBean cacheConfigBean, String key, Object value, int expireTimeInSecond, int timeOutInSecond) throws TimeOutException, RuntimeException {
final long applyTime = System.currentTimeMillis();
final int _expireTimeInSecond = expireTimeInSecond < 1 ? 3 : expireTimeInSecond;
final int _timeOutInSecond = timeOutInSecond < 1 ? 3 : timeOutInSecond;
if (expireTimeInSecond != _expireTimeInSecond)
LOG.warn(String.format("key: %s, 原 expireTime: %s < 1, 校正为现 expireTime: %s", key, expireTimeInSecond, _expireTimeInSecond));
if (timeOutInSecond != _timeOutInSecond)
LOG.warn(String.format("key: %s, 原 timeOutInSecond: %s < 1, 校正为现 timeOutInSecond: %s", key, timeOutInSecond, _timeOutInSecond));
final String lockKey = "LOCK_" + key;
UnitResponse unitResponseObject = SyncXian.call("cache", "distributedLock", new JSONObject() {
{
put("cacheConfig", cacheConfigBean);
put("key", lockKey);
put("value", value);
put("expireTimeInSecond", _expireTimeInSecond);
put("timeOutInSecond", _timeOutInSecond);
}
});
final long receiveTime = System.currentTimeMillis();
if (unitResponseObject.succeeded()) {
int autoIncrement = AUTO_INCREMENT.incrementAndGet();
if (!EnvUtil.getEnv().equals(EnvUtil.PRODUCTION))
LOG.info(String.format("锁编号: %s, key: %s, lockKey: %s, value: %s, 分布式加锁, 成功, 耗时: %s 毫秒", autoIncrement, key, lockKey, value, (receiveTime - applyTime)));
return new DistributedLock(autoIncrement, key, lockKey, value);
} else if (unitResponseObject.getCode().equals(Group.CODE_TIME_OUT))
throw new TimeOutException(String.format("分布式加锁, 超时, key: %s, lockKey: %s, 耗时: %s 毫秒", key, lockKey, (receiveTime - applyTime)));
else
throw new RuntimeException(String.format("分布式加锁, 异常, key: %s, lockKey: %s, 耗时: %s 毫秒", key, lockKey, (receiveTime - applyTime)));
}
Aggregations