JAVA菜鸟一枚,这段代码看了很久了,硬是没看懂
一段客户端往服务端传送数据的代码,谁来帮我解读下,感激不尽
private static void Post(ServiceClient client, String url,
JSONObject jobj, boolean allowRetry) {
Request request = new Request(Method.POST, client.getDefaultRequestRoot()
+ url);
request.setEntity(new JsonRepresentation(jobj));
long start = System.currentTimeMillis();
try {
Response response = null;
if (apps != null) {
request.setResourceRef(url);
response = new Response(request);
for (Application app : apps) {
Router router = (Router) app.getInboundRoot();
Restlet restlet = router.getNext(request, response);
if (restlet != null) {
response.setStatus(Status.SUCCESS_OK);
restlet.handle(request, response);
break;
}
}
} else {
response = client.handle(request);
}
long end = System.currentTimeMillis();
if (g_Log.isInfoEnabled() && (end - start) > 500) {
g_Log.info("POST " + url + " in " + (end - start) + "ms");
}
Status st = response.getStatus();
switch (st.getCode()) {
case 404: {
g_Log.error("POST " + url + " - code : 404");
return;
}
case 200:
case 204:
removeCache(client.getName(), url);
return;
case 1002: {
if (allowRetry) {
try {
g_Log.info("链接丢失,重试一次...");
Thread.sleep(300);