Search in sources :

Example 1 with LackParamException

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;
}
Also used : Input(info.xiancloud.core.Input) HashMap(java.util.HashMap) LackParamException(info.xiancloud.core.message.LackParamException) JSONObject(com.alibaba.fastjson.JSONObject)

Example 2 with LackParamException

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);
                }
            });
        }
    }
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture) UnitUndefinedException(info.xiancloud.core.distribution.exception.UnitUndefinedException) UnitResponse(info.xiancloud.core.message.UnitResponse) LackParamException(info.xiancloud.core.message.LackParamException)

Aggregations

LackParamException (info.xiancloud.core.message.LackParamException)2 JSONObject (com.alibaba.fastjson.JSONObject)1 Input (info.xiancloud.core.Input)1 UnitUndefinedException (info.xiancloud.core.distribution.exception.UnitUndefinedException)1 UnitResponse (info.xiancloud.core.message.UnitResponse)1 HashMap (java.util.HashMap)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1