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);
}
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();
}
});
}
}
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 {
}
}
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();
}
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();
}
Aggregations