use of info.xiancloud.core.NotifyHandler 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.NotifyHandler 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.NotifyHandler in project xian by happyyangyuan.
the class CloudFile method save.
/**
* @param path 文件相对路径
* @param data 文件内容
* @param async 是否异步执行,如果不清楚,请使用{@linkplain CloudFile#save(String, String)}
*/
public static void save(String path, String data, boolean async) {
Map map = new HashMap<String, Object>() {
{
put("path", path);
put("data", data);
}
};
if (async) {
Xian.call("cosService", "cosWrite", map, new NotifyHandler() {
@Override
protected void handle(UnitResponse unitResponse) {
LOG.info(unitResponse);
}
});
} else {
SyncXian.call("cosService", "cosWrite", map);
}
}
use of info.xiancloud.core.NotifyHandler in project xian by happyyangyuan.
the class TransactionalCache method rollbackDistributedTrans.
public static void rollbackDistributedTrans() {
JSONArray clientIds = JSON.parseObject(transMetas.get(MsgIdHolder.get())).getJSONArray("clientIds");
if (clientIds != null && !clientIds.isEmpty()) {
String clientId = clientIds.getString(0);
UnitRequest request = UnitRequest.create(Constant.SYSTEM_DAO_GROUP_NAME, "rollbackAndCloseTogether");
request.getContext().setDestinationNodeId(clientId);
LocalNodeManager.send(request, new NotifyHandler() {
protected void handle(UnitResponse unitResponse) {
LOG.info(clientId + "的事务已经回滚");
}
});
} else {
LOG.warn("回滚事务时,缓存中的事务信息竟然是空的!", new RuntimeException());
}
}
use of info.xiancloud.core.NotifyHandler in project xian by happyyangyuan.
the class TransactionalCache method commitDistributedTrans.
public static void commitDistributedTrans() {
decreaseCount();
JSONArray clientIds = JSON.parseObject(transMetas.get(MsgIdHolder.get())).getJSONArray("clientIds");
if (clientIds != null && !clientIds.isEmpty()) {
String clientId = clientIds.getString(0);
UnitRequest request = UnitRequest.create(Constant.SYSTEM_DAO_GROUP_NAME, "commitAndCloseTogether");
request.getContext().setDestinationNodeId(clientId);
LocalNodeManager.send(request, new NotifyHandler() {
protected void handle(UnitResponse unitResponse) {
LOG.info(clientId + "的事务已经提交");
}
});
} else {
LOG.warn("提交事务时,缓存中的事务信息竟然是空的!", new RuntimeException());
}
}
Aggregations