Search in sources :

Example 21 with UnitRequest

use of info.xiancloud.core.message.UnitRequest in project xian by happyyangyuan.

the class QCloudBaseUnit method execute.

@Override
public UnitResponse execute(UnitRequest msg) {
    // 填充请求参数
    TreeMap<String, String> params = fillRequestArgs(msg);
    // 生成签名
    String sign = createSignature(params);
    params.put("Signature", sign);
    LOG.info(String.format("腾讯云API调用,请求参数:%s", JSON.toJSONString(params)));
    try {
        Request request = HttpKit.get("https://" + getAPIHost() + HHTP_APIURL);
        for (Entry<String, String> param : params.entrySet()) {
            request.addParam(param.getKey(), param.getValue());
        }
        request.setSSL(null, null);
        String result = request.executeLocal().string();
        return UnitResponse.success(convert(result));
    } catch (ConnectException e) {
        LOG.error("调用腾讯云API连接超时", e);
        throw new RuntimeException("调用腾讯云API连接超时");
    } catch (SocketTimeoutException e) {
        LOG.error("调用腾讯云API响应超时", e);
        throw new RuntimeException("调用腾讯云API响应超时");
    } catch (Exception e) {
        LOG.error("调用腾讯云API出错", e);
        throw new RuntimeException("调用腾讯云API出错");
    }
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) Request(info.xiancloud.core.util.http.Request) UnitRequest(info.xiancloud.core.message.UnitRequest) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException) ConnectException(java.net.ConnectException)

Example 22 with UnitRequest

use of info.xiancloud.core.message.UnitRequest in project xian by happyyangyuan.

the class CacheMapRemoveUnit method execute.

@Override
public UnitResponse execute(UnitRequest msg) {
    String key = msg.getArgMap().get("key").toString();
    String field = msg.getArgMap().get("field").toString();
    CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
    long length;
    try {
        length = Redis.call(cacheConfigBean, jedis -> jedis.hdel(key, field));
    } catch (Exception e) {
        return UnitResponse.exception(e);
    }
    return UnitResponse.success(length);
}
Also used : Group(info.xiancloud.core.Group) Unit(info.xiancloud.core.Unit) Input(info.xiancloud.core.Input) CacheConfigBean(info.xiancloud.core.support.cache.CacheConfigBean) Redis(info.xiancloud.cache.redis.Redis) UnitRequest(info.xiancloud.core.message.UnitRequest) CacheGroup(info.xiancloud.cache.service.CacheGroup) UnitResponse(info.xiancloud.core.message.UnitResponse) UnitMeta(info.xiancloud.core.UnitMeta) CacheConfigBean(info.xiancloud.core.support.cache.CacheConfigBean)

Example 23 with UnitRequest

use of info.xiancloud.core.message.UnitRequest 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());
    }
}
Also used : UnitRequest(info.xiancloud.core.message.UnitRequest) UnitResponse(info.xiancloud.core.message.UnitResponse) JSONArray(com.alibaba.fastjson.JSONArray) NotifyHandler(info.xiancloud.core.NotifyHandler)

Example 24 with UnitRequest

use of info.xiancloud.core.message.UnitRequest 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());
    }
}
Also used : UnitRequest(info.xiancloud.core.message.UnitRequest) UnitResponse(info.xiancloud.core.message.UnitResponse) JSONArray(com.alibaba.fastjson.JSONArray) NotifyHandler(info.xiancloud.core.NotifyHandler)

Aggregations

UnitRequest (info.xiancloud.core.message.UnitRequest)24 UnitResponse (info.xiancloud.core.message.UnitResponse)17 JSONObject (com.alibaba.fastjson.JSONObject)9 NotifyHandler (info.xiancloud.core.NotifyHandler)8 Unit (info.xiancloud.core.Unit)7 UnitMeta (info.xiancloud.core.UnitMeta)6 CacheGroup (info.xiancloud.cache.service.CacheGroup)5 Group (info.xiancloud.core.Group)5 Input (info.xiancloud.core.Input)5 JSONArray (com.alibaba.fastjson.JSONArray)4 Redis (info.xiancloud.cache.redis.Redis)4 CacheConfigBean (info.xiancloud.core.support.cache.CacheConfigBean)4 UnitInstance (info.xiancloud.core.distribution.service_discovery.UnitInstance)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 MessageType (info.xiancloud.core.distribution.MessageType)2 UnitOfflineException (info.xiancloud.core.distribution.exception.UnitOfflineException)2 UnitUndefinedException (info.xiancloud.core.distribution.exception.UnitUndefinedException)2 DefaultLocalAsyncSender (info.xiancloud.core.message.sender.local.DefaultLocalAsyncSender)2 ThreadPoolManager (info.xiancloud.core.thread_pool.ThreadPoolManager)2 LOG (info.xiancloud.core.util.LOG)2