use of info.xiancloud.core.message.UnitRequest in project xian by happyyangyuan.
the class AbstractBodyNotRequiredAsyncForwarder method bodyParams.
@Override
protected UnitRequest bodyParams(String body, Map<String, String> headerIgnored) throws ReqBodyParseFailure {
JSONObject fromBodyMap = parseBody(body);
UnitRequest controllerRequest = UnitRequest.create();
controllerRequest.setArgMap(fromBodyMap);
return controllerRequest;
}
use of info.xiancloud.core.message.UnitRequest in project xian by happyyangyuan.
the class CachedGlobalHttpSessionCountMonitor method execute0.
@Override
public Object execute0() {
int totalSessionCount = 0;
try {
for (UnitInstance clientInfo : UnitRouter.singleton.allInstances(Unit.fullName("httpServer", "cachedLocalHttpSessionMonitor"))) {
int localSessionCount;
UnitRequest request = UnitRequest.create("httpServer", "cachedLocalHttpSessionMonitor");
request.getContext().setDestinationNodeId(clientInfo.getNodeId());
List<Integer> counts = SyncXian.call(request, 5 * 1000).dataToTypedList(Integer.class);
totalSessionCount = MathUtil.sum(counts);
}
} catch (UnitOfflineException | UnitUndefinedException e) {
LOG.error(e);
totalSessionCount = -1;
}
LOG.info("当前缓存的session总数量为:" + totalSessionCount);
return UnitResponse.success(totalSessionCount);
}
use of info.xiancloud.core.message.UnitRequest in project xian by happyyangyuan.
the class AppTransaction method commitAndCloseTogether.
@Override
public void commitAndCloseTogether() throws SQLException {
// 发送远程请求,将其他数据库事务提交和关闭
JSONArray clientIds = TransactionalCache.clear();
if (clientIds != null) {
for (int i = 0; i < clientIds.size(); i++) {
final String clientId = clientIds.getString(i);
if (!LocalNodeManager.LOCAL_NODE_ID.equals(clientId)) {
UnitRequest request = UnitRequest.create(CommitAndCloseTogetherUnit.class);
request.getContext().setDestinationNodeId(clientId);
LocalNodeManager.send(request, new NotifyHandler() {
protected void handle(UnitResponse unitResponse) {
LOG.info(clientId + "的事务已经提交");
}
});
}
}
}
// 提交和关闭自己的数据库事务
connection.commit();
connection.close();
// 清除本地事务
localTransMap.remove(transactionId);
}
use of info.xiancloud.core.message.UnitRequest in project xian by happyyangyuan.
the class JedisTestDistributedLock method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
int number = msg.get("number", int.class, 10000);
final CountDownLatch startCountDownLatch = new CountDownLatch(1);
final CountDownLatch finishCountDownLatch = new CountDownLatch(number);
final List<Long> consumeTimes = new CopyOnWriteArrayList<>();
for (int i = 0; i < number; i++) {
int _i = i;
ThreadPoolManager.execute(() -> {
try {
startCountDownLatch.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
long startTime = System.nanoTime();
// Redis Lock
DistributedLockSynchronizer.call("QPS_" + _i, 3, () -> {
return null;
}, 3);
// ZK Lock
// try
// {
// Synchronizer.call("QPS_" + _i, () -> {
// return null;
// }, 3L);
// }
// catch (Exception e)
// {
// LOG.error(e);
// }
finishCountDownLatch.countDown();
long endTime = System.nanoTime();
consumeTimes.add(endTime - startTime);
});
}
try {
startCountDownLatch.countDown();
finishCountDownLatch.await();
} catch (Exception e) {
LOG.error(e);
}
long totalConsumeTime = 0;
for (long consumeTime : consumeTimes) totalConsumeTime += consumeTime;
long avgConsumeTime = totalConsumeTime / number;
LongSummaryStatistics intSummaryStatistics = consumeTimes.stream().collect(Collectors.summarizingLong(value -> value));
String log = String.format("QPS, 加锁解锁, 任务数量: %s, 累计耗时: %s, %s, 平均耗时:%s, %s, %s", number, totalConsumeTime, totalConsumeTime / 1000000, avgConsumeTime, avgConsumeTime / 1000000, intSummaryStatistics);
LOG.info(log);
UnitResponse unitResponseObject = SyncXian.call("cache", "cacheKeys", new JSONObject() {
{
put("pattern", "LOCK_QPS_*");
}
});
if (unitResponseObject.succeeded() && unitResponseObject.getData() != null) {
Set<String> keys = unitResponseObject.getData();
LOG.info(String.format("分布锁剩余数量: %s", keys.size()));
}
SyncXian.call("diyMonitor", "jedisLockMonitor", new JSONObject() {
{
}
});
return UnitResponse.success(log);
}
use of info.xiancloud.core.message.UnitRequest in project xian by happyyangyuan.
the class CacheSetAddUnit method execute.
@Override
public UnitResponse execute(UnitRequest msg) {
String key = msg.get("key", String.class);
Set members = (Set) msg.getArgMap().get("members");
CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
try {
Long result = 0L;
if (members != null && !members.isEmpty()) {
result = Redis.call(cacheConfigBean, jedis -> {
String[] _members = new String[members.size()];
Iterator<Object> iterator = members.iterator();
int i = 0;
while (iterator.hasNext()) {
_members[i] = FormatUtil.formatValue(iterator.next());
i++;
}
return jedis.sadd(key, _members);
});
}
return UnitResponse.success(result);
} catch (Throwable e) {
return UnitResponse.exception(e);
}
}
Aggregations