use of org.nutz.lang.util.NutMap in project nutz by nutzam.
the class Xmls method asMap.
/**
* 根据一个 XML 节点,将其变成一个 Map。
* <p/>
* <b>注意: 不支持混合节点</b>
*
* @param ele
* 元素
* @param lowFirst
* 是否把所有key的首字母都小写
*
* @return 一个 Map 对象
*/
public static NutMap asMap(Element ele, final boolean lowFirst) {
final NutMap map = new NutMap();
eachChildren(ele, new Each<Element>() {
public void invoke(int index, Element _ele, int length) throws ExitLoop, ContinueLoop, LoopException {
String key = _ele.getNodeName();
if (lowFirst)
key = Strings.lowerFirst(key);
Map<String, Object> tmp = asMap(_ele, lowFirst);
if (!tmp.isEmpty()) {
map.setv(key, tmp);
return;
}
String val = getText(_ele);
if (!Strings.isBlank(val)) {
map.setv(key, val);
}
}
});
return map;
}
use of org.nutz.lang.util.NutMap in project nutzboot by nutzam.
the class MainLauncher method make.
@AdaptBy(type = JsonAdaptor.class)
@At("/maker/make")
@Ok("json:full")
public NutMap make(@Param("..") NutMap params) throws IOException {
NutMap re = new NutMap();
String key = R.UU32();
File tmpRoot = Files.createDirIfNoExists(tmpDir + "/" + key);
build(tmpRoot, params);
re.put("key", key);
re.put("ok", true);
return re;
}
use of org.nutz.lang.util.NutMap in project nutzboot by nutzam.
the class EthModule method remoteAccounts.
@At("/remote/accounts")
public NutMap remoteAccounts() {
Map<String, Web3jAccount> accounts = new HashMap<>();
try {
List<String> accountAddrs = web3j.ethAccounts().send().getAccounts();
for (String address : accountAddrs) {
Web3jAccount account = new Web3jAccount();
account.setBanlance(web3j.ethGetBalance(address, DefaultBlockParameterName.LATEST).send().getBalance());
account.setAddress(address);
account.setName(address.substring(0, 8));
accounts.put(account.getName(), account);
}
return new NutMap("ok", true).setv("data", accounts);
} catch (IOException e) {
log.info("something happen", e);
return new NutMap("msg", e.getMessage());
}
}
use of org.nutz.lang.util.NutMap in project nutzcloud by nutzam.
the class LiteRpcLoachUpdater method onUpdate.
@SuppressWarnings("unchecked")
public void onUpdate(Map<String, List<NutMap>> services) {
if (services == null || services.isEmpty()) {
// fuck
return;
}
Map<String, List<NutMap>> rpcMap = new HashMap<>();
for (List<NutMap> _se : services.values()) {
for (NutMap server : _se) {
Map<String, List<String>> rpcKeys = (Map<String, List<String>>) server.get(LiteRpc.RPC_REG_KEY);
if (rpcKeys == null || rpcKeys.isEmpty())
continue;
for (Map.Entry<String, List<String>> en : rpcKeys.entrySet()) {
String klassName = en.getKey();
for (String methodSign : en.getValue()) {
methodSign = klassName + ":" + methodSign;
List<NutMap> servers = rpcMap.get(methodSign);
if (servers == null) {
servers = new ArrayList<>();
rpcMap.put(methodSign, servers);
}
servers.add(server);
}
}
}
}
liteRpc.setServices(rpcMap);
}
use of org.nutz.lang.util.NutMap in project nutzcloud by nutzam.
the class LoachClient method _ping.
protected boolean _ping() {
try {
String pingURL = url + "/ping/" + getServiceName() + "/" + id;
if (isDebug())
log.debug("Ping URL=" + pingURL);
Request req = Request.create(pingURL, METHOD.GET);
req.getHeader().clear();
req.getHeader().set("If-Not-Match", lastPingETag);
Response resp = Sender.create(req, conf.getInt("loach.client.ping.timeout", 1000)).setConnTimeout(1000).send();
String cnt = resp.getContent();
if (isDebug())
log.debug("Ping result : " + cnt);
if (resp.isOK()) {
lastPingETag = Strings.sBlank(resp.getHeader().get("ETag"), "ABC");
NutMap re = Json.fromJson(NutMap.class, cnt);
if (re != null && re.getBoolean("ok", false))
return true;
} else if (resp.getStatus() == 304) {
return true;
}
} catch (Throwable e) {
log.debugf("bad url? %s %s", url, e.getMessage());
}
return false;
}
Aggregations