Search in sources :

Example 1 with UnitProxy

use of info.xiancloud.core.distribution.UnitProxy 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 2 with UnitProxy

use of info.xiancloud.core.distribution.UnitProxy in project xian by happyyangyuan.

the class TestDeserializeUnitBean method deserializeUnitBean.

@Test
public void deserializeUnitBean() {
    String json = "{" + "\"input\":{" + "\"list\":[" + "{" + "\"sequential\":false," + "\"name\":\"application\"," + "\"description\":\"all/null/applicationName  ,  为空或者为all表示全部节点\"," + "\"clazz\":\"java.lang.String\"," + "\"xhash\":false," + "\"required\":false" + "}" + "]" + "}," + "\"meta\":{" + "\"public\":true," + "\"readonly\":false," + "\"monitorEnabled\":false," + "\"transferable\":false," + "\"name\":\"threadPoolMonitor\"," + "\"description\":\"线程池使用情况监控\"," + "\"scopes\":[" + "\"api_all\"" + "]," + "\"transactional\":false," + "}" + "}";
    JSONObject jsonObject = JSON.parseObject(json);
    System.out.println(JSON.toJSONString(jsonObject, true));
    UnitProxy proxy = Reflection.toType(jsonObject, UnitProxy.class);
    System.out.println(Reflection.toType(proxy, String.class));
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) UnitProxy(info.xiancloud.core.distribution.UnitProxy) Test(org.junit.Test)

Example 3 with UnitProxy

use of info.xiancloud.core.distribution.UnitProxy in project xian by happyyangyuan.

the class UnitMdBuilderHandler method buildUnits.

private Multimap<String, UnitProxy> buildUnits() {
    Multimap<String, UnitProxy> groupedUnits = ArrayListMultimap.create();
    List<String> unitFullNames = UnitDiscovery.singleton.queryForNames();
    for (String unitFullName : unitFullNames) {
        UnitProxy unitProxy = UnitDiscovery.singleton.newestDefinition(unitFullName);
        if (unitProxy != null)
            groupedUnits.put(unitProxy.getGroup().getName(), unitProxy);
    }
    return groupedUnits;
}
Also used : UnitProxy(info.xiancloud.core.distribution.UnitProxy)

Example 4 with UnitProxy

use of info.xiancloud.core.distribution.UnitProxy in project xian by happyyangyuan.

the class UnitRegistrationBridge method execute.

@Override
public UnitResponse execute(UnitRequest msg) {
    UnitProxy unitProxy = msg.get("unit", UnitProxy.class);
    NodeStatus nodeStatus = msg.get("nodeStatus", NodeStatus.class);
    UnitInstance unitInstance = unitInstance(unitProxy, nodeStatus);
    try {
        UnitDiscovery.singleton.register(unitInstance);
        return UnitResponse.success();
    } catch (Exception e) {
        LOG.error(e);
        return UnitResponse.failure(null, "registration failed.");
    }
}
Also used : UnitInstance(info.xiancloud.core.distribution.service_discovery.UnitInstance) UnitProxy(info.xiancloud.core.distribution.UnitProxy) NodeStatus(info.xiancloud.core.distribution.NodeStatus)

Example 5 with UnitProxy

use of info.xiancloud.core.distribution.UnitProxy in project xian by happyyangyuan.

the class ZkUnitDiscovery method instance.

@Override
public UnitInstance instance(String unitInstanceId) {
    String name = new UnitInstanceIdBean(unitInstanceId).getFullName();
    ServiceInstance<UnitProxy> serviceInstance = serviceProviders.getUnchecked(name).getInstance(unitInstanceId);
    if (serviceInstance == null)
        serviceInstance = nonCachedInstanceProviders.getUnchecked(name).getInstance(unitInstanceId);
    return ZkServiceInstanceAdaptor.unitInstance(serviceInstance);
}
Also used : UnitInstanceIdBean(info.xiancloud.core.distribution.service_discovery.UnitInstanceIdBean) UnitProxy(info.xiancloud.core.distribution.UnitProxy)

Aggregations

UnitProxy (info.xiancloud.core.distribution.UnitProxy)7 JSONObject (com.alibaba.fastjson.JSONObject)2 NodeStatus (info.xiancloud.core.distribution.NodeStatus)2 UnitInstance (info.xiancloud.core.distribution.service_discovery.UnitInstance)2 Test (org.junit.Test)2 Input (info.xiancloud.core.Input)1 Obj (info.xiancloud.core.Input.Obj)1 Unit (info.xiancloud.core.Unit)1 GroupProxy (info.xiancloud.core.distribution.GroupProxy)1 UnitInstanceIdBean (info.xiancloud.core.distribution.service_discovery.UnitInstanceIdBean)1 UnitRequest (info.xiancloud.core.message.UnitRequest)1 UnitResponseTestUnit (info.xiancloud.core.test.output_test.UnitResponseTestUnit)1 BufferedWriter (java.io.BufferedWriter)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1