use of info.xiancloud.core.message.UnitResponse in project xian by happyyangyuan.
the class App method main.
public static void main(String[] args) {
Map<String, Object> params = new HashMap<>();
params.put("content", "消息接口测试");
UnitResponse result = SyncXian.call("wxcp", "wxcpMessage", params);
System.out.println(result.toJSONString());
}
use of info.xiancloud.core.message.UnitResponse 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.UnitResponse 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);
}
}
use of info.xiancloud.core.message.UnitResponse in project xian by happyyangyuan.
the class RpcClientUnitHandler method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext ctx, JSONObject response) throws Exception {
try {
MsgIdHolder.set(response.getString("$msgId"));
logRpcFly(response, ctx);
String ssid = response.remove("$ssid").toString();
NotifyHandler handler = LocalNodeManager.handleMap.getIfPresent(ssid);
LocalNodeManager.handleMap.invalidate(ssid);
if (handler == null) {
LOG.error(String.format("ssid=%s的消息没有找到对应的notifyHandler!整个消息内容=%s,", ssid, response), new Throwable());
return;
}
UnitResponse responseUnitResponse = UnitResponse.create(response);
ThreadPoolManager.execute(() -> handler.callback(responseUnitResponse));
/*try {
不再需要单独检测线程池被销毁而使用独立线程了,threadPoolManager已支持
} catch (RejectedExecutionException threadPoolAlreadyShutdown) {
LOG.info("线程池已关闭,这里使用临时线程执行任务,针对停服务时线程池已关闭的情况。");
new Thread(() -> handler.callback(responseUnitResponse)).start();
}*/
} catch (Throwable e) {
LOG.error(e);
} finally {
MsgIdHolder.clear();
}
}
use of info.xiancloud.core.message.UnitResponse in project xian by happyyangyuan.
the class App method pauseClusterService.
/**
* 暂停服务更新
*/
static void pauseClusterService() {
// description
// Man.serial();
Map<String, Object> params = new HashMap<String, Object>();
params.put("clusterId", "cls-768pakpq");
params.put("serviceName", "my-mongodb");
UnitResponse result = SyncXian.call("qcloudContainerService", "pauseClusterService", params);
System.out.println(result.getData().toString());
}
Aggregations