Search in sources :

Example 11 with Unit

use of info.xiancloud.core.Unit in project xian by happyyangyuan.

the class CountLatchEntity method getUnitCollection.

@Override
public Collection<Unit> getUnitCollection() {
    // 读取配置文件,获取要监控的unit
    String[] unitArray = XianConfig.getStringArray(MONITOR_UNIT_LIST);
    try {
        if (unitArray != null && unitArray.length > 0) {
            List<String> unitList = Arrays.asList(unitArray);
            return new HashSet<Unit>() {

                {
                    // 配置文件内指定的监控集
                    unitList.forEach(unitFullName -> {
                        // 配置文件格式 groupName.unitName
                        Pair<String, String> pair = Unit.parseFullName(unitFullName);
                        String groupName = pair.fst;
                        String unitName = pair.snd;
                        Unit unit = LocalUnitsManager.getLocalUnit(groupName, unitName);
                        if (unit != null) {
                            add(unit);
                            // 初始化对应的计数器并设置为0
                            countLatches.put(unitFullName, new CountLatchEntity());
                        }
                    });
                    LocalUnitsManager.searchUnitMap(searchUnitMap -> {
                        // unit自定义的监控集
                        for (Unit unit : searchUnitMap.values()) {
                            if (unit.getMeta().isMonitorEnabled()) {
                                add(unit);
                                countLatches.put(Unit.fullName(unit), new CountLatchEntity());
                            }
                        }
                    });
                }
            };
        }
    } catch (Exception e) {
        LOG.error("unit调用频率监控AOP 从配置文件中加载要监控的unit出错", e);
    }
    return null;
}
Also used : Unit(info.xiancloud.core.Unit)

Example 12 with Unit

use of info.xiancloud.core.Unit in project xian by happyyangyuan.

the class TransactionalUnitAop method getUnitCollection.

@Override
public Collection<Unit> getUnitCollection() {
    Set<Unit> collection = new HashSet<>();
    LocalUnitsManager.unitMap(unitMap -> {
        for (String groupName : unitMap.keySet()) {
            for (Unit unit : unitMap.get(groupName)) {
                if (unit.getMeta().isTransactional()) {
                    collection.add(unit);
                }
            }
        }
    });
    return collection;
}
Also used : Unit(info.xiancloud.core.Unit) HashSet(java.util.HashSet)

Aggregations

Unit (info.xiancloud.core.Unit)12 JSONObject (com.alibaba.fastjson.JSONObject)4 UnitRequest (info.xiancloud.core.message.UnitRequest)3 UnitResponse (info.xiancloud.core.message.UnitResponse)3 Input (info.xiancloud.core.Input)2 LOG (info.xiancloud.core.util.LOG)2 XianConnection (info.xiancloud.dao.core.connection.XianConnection)2 Single (io.reactivex.Single)2 Map (java.util.Map)2 CustomizedMdApidocUnit (info.xiancloud.apidoc.unit.md.CustomizedMdApidocUnit)1 FullMdApidocUnit (info.xiancloud.apidoc.unit.md.FullMdApidocUnit)1 GroupMdApidocUnit (info.xiancloud.apidoc.unit.md.GroupMdApidocUnit)1 Group (info.xiancloud.core.Group)1 Handler (info.xiancloud.core.Handler)1 XianConfig (info.xiancloud.core.conf.XianConfig)1 UnitProxy (info.xiancloud.core.distribution.UnitProxy)1 UnitInstance (info.xiancloud.core.distribution.service_discovery.UnitInstance)1 UnitInstanceIdBean (info.xiancloud.core.distribution.service_discovery.UnitInstanceIdBean)1 ExceptionWithUnitResponse (info.xiancloud.core.message.ExceptionWithUnitResponse)1 AsyncSequencer (info.xiancloud.core.sequence.default_sequencer.AsyncSequencer)1