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()));
}
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));
}
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;
}
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.");
}
}
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);
}
Aggregations