Commit 933320329c026ffd598c98e9f452a02c262f3859
1 parent
ef08a724
尝试精简websocket 传输...
Showing
3 changed files
with
45 additions
and
56 deletions
src/main/java/com/bsth/data/directive/DirectivesPstThread.java
| @@ -45,7 +45,8 @@ public class DirectivesPstThread extends Thread { | @@ -45,7 +45,8 @@ public class DirectivesPstThread extends Thread { | ||
| 45 | for (int i = 0; i < 1000; i++) { | 45 | for (int i = 0; i < 1000; i++) { |
| 46 | try { | 46 | try { |
| 47 | directive = list.poll(); | 47 | directive = list.poll(); |
| 48 | - | 48 | + //日期 |
| 49 | + directive.setRq(fmtyyyyMMdd.print(directive.getTimestamp())); | ||
| 49 | if (directive instanceof D60) { | 50 | if (directive instanceof D60) { |
| 50 | D60 d60 = (D60) directive; | 51 | D60 d60 = (D60) directive; |
| 51 | if(d60.isDispatch()){ | 52 | if(d60.isDispatch()){ |
| @@ -56,8 +57,6 @@ public class DirectivesPstThread extends Thread { | @@ -56,8 +57,6 @@ public class DirectivesPstThread extends Thread { | ||
| 56 | continue; | 57 | continue; |
| 57 | } | 58 | } |
| 58 | } | 59 | } |
| 59 | - //日期 | ||
| 60 | - d60.setRq(fmtyyyyMMdd.print(d60.getTimestamp())); | ||
| 61 | d60Repository.save(d60); | 60 | d60Repository.save(d60); |
| 62 | } | 61 | } |
| 63 | 62 |
src/main/java/com/bsth/data/directive/GatewayHttpUtils.java
| @@ -12,61 +12,51 @@ import org.apache.http.util.EntityUtils; | @@ -12,61 +12,51 @@ import org.apache.http.util.EntityUtils; | ||
| 12 | import org.slf4j.Logger; | 12 | import org.slf4j.Logger; |
| 13 | import org.slf4j.LoggerFactory; | 13 | import org.slf4j.LoggerFactory; |
| 14 | 14 | ||
| 15 | -import java.io.IOException; | ||
| 16 | - | ||
| 17 | /** | 15 | /** |
| 18 | - * | ||
| 19 | - * @ClassName: GatewayHttpUtils | ||
| 20 | - * @Description: TODO(和网关HTTP通讯工具类) | ||
| 21 | * @author PanZhao | 16 | * @author PanZhao |
| 22 | - * @date 2016年8月14日 下午9:50:46 | ||
| 23 | - * | 17 | + * @ClassName: GatewayHttpUtils |
| 18 | + * @Description: TODO(和网关HTTP通讯工具类) | ||
| 19 | + * @date 2016年8月14日 下午9:50:46 | ||
| 24 | */ | 20 | */ |
| 25 | public class GatewayHttpUtils { | 21 | public class GatewayHttpUtils { |
| 26 | - static Logger logger = LoggerFactory.getLogger(GatewayHttpUtils.class); | ||
| 27 | - | ||
| 28 | - static String url; | ||
| 29 | - | ||
| 30 | - static{ | ||
| 31 | - url = ConfigUtil.get("http.send.directive"); | ||
| 32 | - } | ||
| 33 | - | ||
| 34 | - public static int postJson(String jsonStr){ | ||
| 35 | - logger.info("send : " + jsonStr); | ||
| 36 | - | ||
| 37 | - CloseableHttpClient httpClient = null; | ||
| 38 | - int code = -1; | ||
| 39 | - try{ | ||
| 40 | - httpClient = HttpClients.createDefault(); | ||
| 41 | - | ||
| 42 | - //超时时间 | ||
| 43 | - RequestConfig requestConfig = RequestConfig.custom() | ||
| 44 | - .setConnectTimeout(1500).setConnectionRequestTimeout(1000) | ||
| 45 | - .setSocketTimeout(1500).build(); | ||
| 46 | - | ||
| 47 | - HttpPost post = new HttpPost(url); | ||
| 48 | - | ||
| 49 | - post.setConfig(requestConfig); | ||
| 50 | - | ||
| 51 | - post.setEntity(new StringEntity(jsonStr, "utf-8")); | ||
| 52 | - | ||
| 53 | - CloseableHttpResponse response = httpClient.execute(post); | 22 | + static Logger logger = LoggerFactory.getLogger(GatewayHttpUtils.class); |
| 23 | + | ||
| 24 | + static String url; | ||
| 25 | + static CloseableHttpClient httpClient = null; | ||
| 26 | + static HttpPost post; | ||
| 27 | + static RequestConfig requestConfig; | ||
| 28 | + static CloseableHttpResponse response; | ||
| 29 | + | ||
| 30 | + static { | ||
| 31 | + url = ConfigUtil.get("http.send.directive"); | ||
| 32 | + httpClient = HttpClients.createDefault(); | ||
| 33 | + post = new HttpPost(url); | ||
| 34 | + requestConfig = RequestConfig.custom() | ||
| 35 | + .setConnectTimeout(2000).setConnectionRequestTimeout(1000) | ||
| 36 | + .setSocketTimeout(2000).build(); | ||
| 37 | + post.setConfig(requestConfig); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + public static int postJson(String jsonStr) { | ||
| 41 | + logger.info("send : " + jsonStr); | ||
| 42 | + | ||
| 43 | + int code = -1; | ||
| 44 | + try { | ||
| 45 | + post.setEntity(new StringEntity(jsonStr, "utf-8")); | ||
| 46 | + | ||
| 47 | + response = httpClient.execute(post); | ||
| 48 | + | ||
| 49 | + JSONObject json = JSONObject.parseObject(EntityUtils.toString(response.getEntity())); | ||
| 50 | + if (null != json && json.getInteger("errCode") == 0) | ||
| 51 | + code = 0; | ||
| 52 | + else | ||
| 53 | + logger.error("和网关http通讯失败,rs: " + json); | ||
| 54 | 54 | ||
| 55 | - JSONObject json = JSONObject.parseObject(EntityUtils.toString(response.getEntity())); | ||
| 56 | - if(null != json && json.getInteger("errCode") == 0) | ||
| 57 | - code = 0; | ||
| 58 | - else | ||
| 59 | - logger.error("和网关http通讯失败,rs: " + json); | ||
| 60 | - }catch(Exception e){ | ||
| 61 | - logger.error("", e); | ||
| 62 | - }finally { | ||
| 63 | - try { | ||
| 64 | - if(httpClient != null) | ||
| 65 | - httpClient.close(); | ||
| 66 | - } catch (IOException e) { | ||
| 67 | - logger.error("", e); | ||
| 68 | - } | ||
| 69 | - } | ||
| 70 | - return code; | ||
| 71 | - } | 55 | + if (null != response) |
| 56 | + response.close(); | ||
| 57 | + } catch (Exception e) { | ||
| 58 | + logger.error("", e); | ||
| 59 | + } | ||
| 60 | + return code; | ||
| 61 | + } | ||
| 72 | } | 62 | } |
src/main/java/com/bsth/data/gpsdata_v2/DataHandleProcess.java
| @@ -123,7 +123,7 @@ public class DataHandleProcess { | @@ -123,7 +123,7 @@ public class DataHandleProcess { | ||
| 123 | if (Math.abs(gps.getTimestamp() - gps.getServerTimestamp()) > 1000 * 60 * 20) | 123 | if (Math.abs(gps.getTimestamp() - gps.getServerTimestamp()) > 1000 * 60 * 20) |
| 124 | continue; | 124 | continue; |
| 125 | 125 | ||
| 126 | - //gpsStateProcess.process(gps);//状态处理 | 126 | + gpsStateProcess.process(gps);//状态处理 |
| 127 | stationInsideProcess.process(gps);//场站内外判定 | 127 | stationInsideProcess.process(gps);//场站内外判定 |
| 128 | reverseRouteProcess.process(gps);//反向路由处理 | 128 | reverseRouteProcess.process(gps);//反向路由处理 |
| 129 | abnormalStateProcess.process(gps);//超速越界 | 129 | abnormalStateProcess.process(gps);//超速越界 |