use of info.xiancloud.core.message.LackParamException in project xian by happyyangyuan.
the class SequentialDataProvider method getSequentialData.
static Map<String, Object> getSequentialData(String group, String unit, JSONObject argMap) throws LackParamException {
Map<String, Object> sequentialData = new HashMap<>();
for (Input.Obj aSequential : LocalUnitsManager.getLocalUnit(group, unit).getInput().getSequential()) {
String key = aSequential.getName();
Object value = argMap.get(key);
if (value == null) {
throw new LackParamException(group, unit, key);
}
sequentialData.put(key, value);
}
return sequentialData;
}
use of info.xiancloud.core.message.LackParamException in project xian by happyyangyuan.
the class AbstractLocalAsyncSender method asyncSend.
@Override
protected void asyncSend() {
final long start = System.nanoTime();
Unit unit = LocalUnitsManager.getLocalUnit(unitRequest.getContext().getGroup(), unitRequest.getContext().getUnit());
if (unit == null) {
UnitResponse unitResponse = new UnitUndefinedException(unitRequest.getContext().getGroup(), unitRequest.getContext().getUnit()).toUnitResponse();
responseCallback(unitResponse, start);
} else {
Set<Input.Obj> required = getRequired(unit, unitRequest);
if (!required.isEmpty()) {
String[] requiredParamNames = required.stream().map(Input.Obj::getName).toArray(String[]::new);
LackParamException lackParamException = new LackParamException(unitRequest.getContext().getGroup(), unitRequest.getContext().getUnit(), requiredParamNames);
UnitResponse unitResponse = UnitResponse.createError(Group.CODE_LACK_OF_PARAMETER, lackParamException.getLacedParams(), lackParamException.getMessage());
responseCallback(unitResponse, start);
} else {
ScheduledFuture future = timeoutAfter(unitRequest.getContext().getTimeOutInMilli(), start);
ThreadPoolManager.execute(() -> {
// And let the caller to decide whether or not to block.
try {
unit.execute(unitRequest, unitResponse -> {
boolean msgIdWritten = MsgIdHolder.set(unitResponse.getContext().getMsgId());
try {
future.cancel(true);
responseCallback(unitResponse, start);
} finally {
if (msgIdWritten) {
MsgIdHolder.clear();
}
}
});
} catch (Throwable e) {
future.cancel(true);
responseCallback(UnitResponse.createException(e), start);
}
});
}
}
}
Aggregations