Search in sources :

Example 21 with UnitResponse

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

the class CacheListGetByIndexUnit method execute.

@Override
public UnitResponse execute(UnitRequest msg) {
    String key = msg.getArgMap().get("key").toString();
    Long index = msg.getArgMap().get("index") != null ? Long.parseLong(msg.getArgMap().get("index").toString()) : 0;
    CacheConfigBean cacheConfigBean = msg.get("cacheConfig", CacheConfigBean.class);
    String element = null;
    try {
        element = Redis.call(cacheConfigBean, (jedis) -> jedis.lindex(key, index));
        if (element != null && element.toString().equals("nil"))
            element = null;
    } catch (Exception e) {
        return UnitResponse.exception(e);
    }
    return UnitResponse.success(element);
}
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 22 with UnitResponse

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

the class RuleController method work.

// 执行
private void work() {
    if (next.equals(END)) {
        end();
    } else {
        Map<String, Object> params = processParams();
        LOG.info("[RuleController] params = " + params);
        Xian.call(next.split("_")[0], next.split("_")[1], params, new NotifyHandler() {

            protected void handle(UnitResponse unitResponse1) {
                unitResponse = unitResponse1;
                processReturnParams();
                callNext();
                work();
            }
        });
    }
}
Also used : UnitResponse(info.xiancloud.core.message.UnitResponse) NotifyHandler(info.xiancloud.core.NotifyHandler)

Example 23 with UnitResponse

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

the class HttpUnit method execute.

@Override
public UnitResponse execute(UnitRequest msg) {
    ObjectInputStream ois = null;
    try {
        String reqBase64 = msg.get("req", String.class);
        ois = new ObjectInputStream(new ByteArrayInputStream(Base64.getDecoder().decode(reqBase64)));
        Request request = (Request) ois.readObject();
        Response response;
        try {
            response = request.executeLocal();
        } catch (ConnectException e) {
            return UnitResponse.error(ISocketGroup.CODE_CONNECT_TIMEOUT, null, "Connect timeout: " + request.getUrl());
        } catch (SocketTimeoutException e) {
            return UnitResponse.error(ISocketGroup.CODE_SOCKET_TIMEOUT, null, "Read timeout: " + request.getUrl());
        } catch (Throwable e) {
            return UnitResponse.exception(e);
        }
        JSONObject retJson = new JSONObject();
        retJson.put("status", response.getStatus());
        retJson.put("headers", response.getHeaders());
        retJson.put("entity", response.string());
        return UnitResponse.success(retJson);
    } catch (Throwable e) {
        return UnitResponse.exception(e);
    } finally {
    }
}
Also used : UnitResponse(info.xiancloud.core.message.UnitResponse) Response(info.xiancloud.core.util.http.Response) SocketTimeoutException(java.net.SocketTimeoutException) JSONObject(com.alibaba.fastjson.JSONObject) ByteArrayInputStream(java.io.ByteArrayInputStream) Request(info.xiancloud.core.util.http.Request) UnitRequest(info.xiancloud.core.message.UnitRequest) ObjectInputStream(java.io.ObjectInputStream) ConnectException(java.net.ConnectException)

Example 24 with UnitResponse

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

the class CacheSetUtil method removes.

public static final long removes(CacheConfigBean cacheConfigBean, String key, Set members) {
    UnitResponse response = SyncXian.call(CacheService.CACHE_SERVICE, "cacheSetRemoves", new JSONObject() {

        {
            put("cacheConfig", cacheConfigBean);
            put("key", key);
            put("members", members);
        }
    });
    response.throwExceptionIfNotSuccess();
    return (long) response.getData();
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) UnitResponse(info.xiancloud.core.message.UnitResponse)

Example 25 with UnitResponse

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

the class CacheSetUtil method values.

public static Set<String> values(CacheConfigBean cacheConfigBean, String key) {
    UnitResponse unitResponseObject = SyncXian.call(CacheService.CACHE_SERVICE, "cacheSetMembers", new JSONObject() {

        {
            put("cacheConfig", cacheConfigBean);
            put("key", key);
        }
    });
    unitResponseObject.throwExceptionIfNotSuccess();
    return unitResponseObject.getData();
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) UnitResponse(info.xiancloud.core.message.UnitResponse)

Aggregations

UnitResponse (info.xiancloud.core.message.UnitResponse)106 JSONObject (com.alibaba.fastjson.JSONObject)74 HashMap (java.util.HashMap)22 UnitRequest (info.xiancloud.core.message.UnitRequest)17 NotifyHandler (info.xiancloud.core.NotifyHandler)16 JSONArray (com.alibaba.fastjson.JSONArray)9 Unit (info.xiancloud.core.Unit)6 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 CountDownLatch (java.util.concurrent.CountDownLatch)5 Redis (info.xiancloud.cache.redis.Redis)4 CacheConfigBean (info.xiancloud.core.support.cache.CacheConfigBean)4 ThreadPoolManager (info.xiancloud.core.thread_pool.ThreadPoolManager)3 LOG (info.xiancloud.core.util.LOG)3 Set (java.util.Set)3 Test (org.junit.Test)3 MessageType (info.xiancloud.core.distribution.MessageType)2 UnitUndefinedException (info.xiancloud.core.distribution.exception.UnitUndefinedException)2