Search in sources :

Example 1 with Unit

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

the class GroupBean method getUnitNames.

/**
 * @return group在本地节点下的unit名称列表视图
 */
public List<String> getUnitNames() {
    if (unitNames == null) {
        unitNames = new ArrayList<>();
        LocalUnitsManager.unitMap(untMap -> {
            untMap.forEach((group, unitList) -> {
                for (Unit unit : unitList) {
                    if (Objects.equals(group, getName()))
                        unitNames.add(unit.getName());
                }
            });
        });
    }
    return unitNames;
}
Also used : Unit(info.xiancloud.core.Unit)

Example 2 with Unit

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

the class UnitRequestTest method testGetList.

@Test
public void testGetList() {
    List<Integer> list = new UnitRequest(new JSONObject() {

        {
            put("yy", new int[] { 0, 1 });
        }
    }).getList("yy");
    Assert.assertTrue(list.get(0) == 0);
    Assert.assertTrue(list.get(1) == 1);
    List<Unit> unitList = new UnitRequest(new JSONObject() {

        {
            put("yy", new Unit[] { new UnitResponseTestUnit() });
        }
    }).getList("yy");
    Assert.assertTrue(unitList.get(0).getName().equals(new UnitResponseTestUnit().getName()));
    List<UnitProxy> proxyList = new UnitRequest(new JSONObject() {

        {
            put("yy", new String[] { new UnitResponseTestUnit().toJSONString() });
        }
    }).getList("yy", UnitProxy.class);
    Assert.assertTrue(proxyList.get(0).getName().equals(new UnitResponseTestUnit().getName()));
}
Also used : UnitResponseTestUnit(info.xiancloud.core.test.output_test.UnitResponseTestUnit) UnitRequest(info.xiancloud.core.message.UnitRequest) JSONObject(com.alibaba.fastjson.JSONObject) Unit(info.xiancloud.core.Unit) UnitResponseTestUnit(info.xiancloud.core.test.output_test.UnitResponseTestUnit) UnitProxy(info.xiancloud.core.distribution.UnitProxy) Test(org.junit.Test)

Example 3 with Unit

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

the class IUnitAop method unintercept.

/**
 * 注销aop拦截
 *
 * @deprecated 该功能未测试,请暂时不要使用
 */
default void unintercept() {
    Collection<Unit> proxies = getUnitCollection();
    for (Unit proxy : proxies) {
        if (!Proxy.isProxyClass(proxy.getClass())) {
            LOG.warn(proxy.getName() + " 已经不是代理对象了!  不允许重复取消拦截!");
        }
        ProxyBuilder<Unit> proxyBuilder = ProxyBuilder.removeProxyBuilder(proxy.hashCode());
        Unit originUnit = proxyBuilder.getOriginalTarget();
        LocalUnitsManager.replaceUnit(originUnit);
    }
}
Also used : Unit(info.xiancloud.core.Unit)

Example 4 with Unit

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

the class UnitRouter method localInstance.

public UnitInstance localInstance(String fullUnitName) {
    Unit localUnit = LocalUnitsManager.getLocalUnit(fullUnitName);
    if (localUnit != null) {
        // 本地有,就直接用即可
        UnitInstance unitInstance = new UnitInstance();
        unitInstance.setPayload(UnitProxy.create(localUnit));
        unitInstance.setRegistrationTimestamp(LocalNodeManager.singleton.getSimpleStatus().getInitTime());
        unitInstance.setPort(Node.RPC_PORT);
        unitInstance.setName(fullUnitName);
        unitInstance.setEnabled(true);
        unitInstance.setAddress(EnvUtil.getLocalIp());
        unitInstance.setId(new UnitInstanceIdBean(fullUnitName, LocalNodeManager.LOCAL_NODE_ID).getUnitInstanceId());
        return unitInstance;
    }
    return null;
}
Also used : UnitInstance(info.xiancloud.core.distribution.service_discovery.UnitInstance) UnitInstanceIdBean(info.xiancloud.core.distribution.service_discovery.UnitInstanceIdBean) Unit(info.xiancloud.core.Unit)

Example 5 with Unit

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

the class AbstractMdApidocUnit method specifyBuild.

/**
 * 返回生成MD的文件字符串
 */
private static String specifyBuild(String description, String docName, IUnitFilter filter) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ApiBuilder.build(new UnitMdBuilderHandler(description, docName, filter).callback(data -> {
        try {
            bos.write(data);
            if (data.length > 0) {
                LOG.info("api-doc接口文档unit文档大小 : " + data.length);
                LOG.info("api-doc接口文档unit发布成功");
            } else {
                LOG.info("api-doc接口文档unit暂无扫描到相关数据");
            }
        } catch (Exception e) {
            LOG.error("api-doc接口文档生成unit接口文档出错", e);
        }
    }));
    return bos.toString();
}
Also used : ApiBuilder(info.xiancloud.apidoc.ApiBuilder) Group(info.xiancloud.core.Group) Unit(info.xiancloud.core.Unit) Input(info.xiancloud.core.Input) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UnitRequest(info.xiancloud.core.message.UnitRequest) UnitMdBuilderHandler(info.xiancloud.apidoc.handler.UnitMdBuilderHandler) IUnitFilter(info.xiancloud.apidoc.handler.filter.IUnitFilter) UnitResponse(info.xiancloud.core.message.UnitResponse) LOG(info.xiancloud.core.util.LOG) ApidocGroup(info.xiancloud.apidoc.ApidocGroup) UnitMeta(info.xiancloud.core.UnitMeta) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UnitMdBuilderHandler(info.xiancloud.apidoc.handler.UnitMdBuilderHandler)

Aggregations

Unit (info.xiancloud.core.Unit)10 JSONObject (com.alibaba.fastjson.JSONObject)3 UnitRequest (info.xiancloud.core.message.UnitRequest)3 Input (info.xiancloud.core.Input)2 UnitResponse (info.xiancloud.core.message.UnitResponse)2 ApiBuilder (info.xiancloud.apidoc.ApiBuilder)1 ApidocGroup (info.xiancloud.apidoc.ApidocGroup)1 UnitMdBuilderHandler (info.xiancloud.apidoc.handler.UnitMdBuilderHandler)1 IUnitFilter (info.xiancloud.apidoc.handler.filter.IUnitFilter)1 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 UnitMeta (info.xiancloud.core.UnitMeta)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 DefaultSequencer (info.xiancloud.core.sequence.default_sequencer.DefaultSequencer)1 NoSequenceGuaranteeSequencer (info.xiancloud.core.sequence.sequence_no_garantee.NoSequenceGuaranteeSequencer)1 UnitResponseTestUnit (info.xiancloud.core.test.output_test.UnitResponseTestUnit)1