send http

back_recharge
wangyuan 2019-07-05 14:13:59 +08:00
parent be52cac2bb
commit 99d2828a6c
6 changed files with 33 additions and 41 deletions

View File

@ -89,6 +89,7 @@ public class GameApplication {
MapLogic.getInstance().init(configurableApplicationContext);
SensitivewordFilter.init();
HttpPool.init();
// 加载lua文件
CheckFight.getInstance().init("luafight/BattleMain.lua");

View File

@ -1,9 +1,12 @@
package com.ljsd.jieling.config.reportData;
import com.alibaba.fastjson.JSON;
import com.google.gson.Gson;
import com.ljsd.common.mogodb.util.BlockingUniqueQueue;
import com.ljsd.jieling.ktbeans.KTSendBody;
import com.ljsd.jieling.util.http.HttpPool;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CopyOnWriteArrayList;
@ -11,39 +14,25 @@ import java.util.concurrent.CopyOnWriteArrayList;
public class DataMessageUtils {
static final BlockingQueue<Object> logQueue = new BlockingUniqueQueue<>();
static List<String> dataList = new CopyOnWriteArrayList<>();
private static Gson gson = new Gson();
private static final String sendUrl = "https://gskuld.receiver.extranet.kt007.com:8081/skuld/game/common/";
//入队列
public static void addLogQueue(Object info){
logQueue.offer(info);
}
//出队列
public static Object take(){
try {
return logQueue.take();
} catch (InterruptedException e) {
e.printStackTrace();
return null;
}
}
public static void manageData(Object take) {
List<String> sendDataList;
if(dataList.size() >= 10){
sendDataList = dataList;
dataList = new CopyOnWriteArrayList<>();
}else{
dataList.add(JSON.toJSONString(take));
return;
}
StringBuilder info = new StringBuilder("[");
for (int i =0 ; i < sendDataList.size() ; i++){
if (i >= (sendDataList.size() -1)){
info.append(sendDataList.get(i)).append(",");
}else{
info.append(sendDataList.get(i));
public static void manageData() {
List<Object> sendDataList = new ArrayList<>(10);
logQueue.drainTo(sendDataList,10);
if(sendDataList.isEmpty()){
try {
Thread.sleep(10);
return;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
info.append("]");
HttpPool.sendPost("",info.toString());
KTSendBody sendBody = new KTSendBody(gson.toJson(sendDataList));
// HttpPool.sendPost(sendUrl,gson.toJson(sendBody));
}
}

View File

@ -32,7 +32,7 @@ public class KtEventUtils {
public static void onKtEvent(User user,int eventType,Object ...parm){
/* ParamEventBean paramEventBean = new ParamEventBean(eventType);
ParamEventBean paramEventBean = new ParamEventBean(eventType);
switch (eventType){
case ParamEventBean.UserActivityEvent:
int activityId = (int)parm[0];
@ -92,10 +92,9 @@ public class KtEventUtils {
}
KTParam ktParam = ParamBuilder.paramBuild(user, eventType, paramEventBean);
/* KTParam ktParam = ParamBuilder.paramBuild(user, eventType, paramEventBean);
DataMessageUtils.addLogQueue(ktParam);
LOGGER.info("ktparm -- > {}",gson.toJson(ktParam));
*/
LOGGER.info("ktparm -- > {}",gson.toJson(ktParam));*/
}
public static ParamEnvironmentBean enviromentBuild(int uid){
return KTEnvironmentUtil.getUserEnviromentInfoById(uid);

View File

@ -37,7 +37,8 @@ public class ThreadManager {
public void init(ConfigurableApplicationContext configurableApplicationContext) {
platConfigureTask = configurableApplicationContext.getBean(PlatConfigureTask.class);
dataReportTask = configurableApplicationContext.getBean(DataReportTask.class);
DataReportTask dataReportTask = new DataReportTask();
dataReportTask.start();
go();
}
@ -83,9 +84,6 @@ public class ThreadManager {
int delayForMinute = 60 - (now%60);
LOGGER.info("delayForMinute---->>>>{}" ,delayForMinute);
scheduledExecutor.scheduleAtFixedRate(platConfigureTask, 10, SLEEP_INTEVAL_TIME, TimeUnit.SECONDS);
scheduledExecutor.scheduleAtFixedRate(dataReportTask, 10, SLEEP_INTEVAL_TIME, TimeUnit.SECONDS);
scheduledExecutor.scheduleAtFixedRate(new MinuteTask(), delayForMinute, 60, TimeUnit.SECONDS);
scheduledExecutor.scheduleAtFixedRate(new Thread(){
public void run () {

View File

@ -5,13 +5,15 @@ import org.springframework.stereotype.Component;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@Component
public class DataReportTask implements Runnable {
public class DataReportTask extends Thread {
public DataReportTask(){
setName("DataReportTaskThread");
}
@Override
public void run() {
while (true) {
Object take = DataMessageUtils.take();
DataMessageUtils.manageData(take);
DataMessageUtils.manageData();
}
}
// public static void startTlogThread(){

View File

@ -21,6 +21,7 @@ public class HttpPool {
private static int maxSendTimes = 2;
private static int sendIntervalTime = 1000;
private static String charset = "UTF-8";
public static void init(){
poolConnection.setMaxTotal(100);
poolConnection.setDefaultMaxPerRoute(100);
@ -33,6 +34,7 @@ public class HttpPool {
}
public static void sendPost(String url, String info) {
LOGGER.info("the data={}",info);
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse;
int sendTimes = 0;
@ -41,8 +43,8 @@ public class HttpPool {
StringEntity stringEntity = new StringEntity(info, charset);
httpPost.setEntity(stringEntity);
httpPost.setConfig(getRequestConfig());
httpPost.setHeader("Content-Type","application/json;charset=utf-8");
httpResponse = httpclient.execute(httpPost);
// retStr = EntityUtils.toString(responseEntity, charset);
HttpEntity responseEntity = httpResponse.getEntity();
EntityUtils.consume(responseEntity);
int statusCode = httpResponse.getStatusLine().getStatusCode();
@ -71,7 +73,8 @@ public class HttpPool {
}
public static void main (String [] args){
String send ="{\"gid\":\"129213\",\"time\":1562306610,\"sign\":\"10a518836c856344a00a97f0299b7cb0\",\"jsonStrs\":\"[{\\\"param_environment\\\":{},\\\"param_user\\\":{\\\"account_id_s\\\":\\\"10004165\\\"},\\\"param_role\\\":{\\\"role_id_s\\\":\\\"10004165\\\",\\\"role_name_s\\\":\\\"10004165\\\",\\\"level_i\\\":\\\"1\\\",\\\"vip_level_i\\\":0},\\\"param_event\\\":{\\\"event_s\\\":[\\\"currency_3_l\\\",\\\"source\\\",\\\"15\\\",\\\"19\\\",\\\"1\\\"]}},{\\\"param_environment\\\":{},\\\"param_user\\\":{\\\"account_id_s\\\":\\\"10004165\\\"},\\\"param_role\\\":{\\\"role_id_s\\\":\\\"10004165\\\",\\\"role_name_s\\\":\\\"10004165\\\",\\\"level_i\\\":\\\"1\\\",\\\"vip_level_i\\\":0},\\\"param_event\\\":{\\\"event_s\\\":[\\\"currency_3_l\\\",\\\"source\\\",\\\"15\\\",\\\"1001\\\",\\\"6000\\\"]}},{\\\"param_environment\\\":{},\\\"param_user\\\":{\\\"account_id_s\\\":\\\"10004165\\\"},\\\"param_role\\\":{\\\"role_id_s\\\":\\\"10004165\\\",\\\"role_name_s\\\":\\\"10004165\\\",\\\"level_i\\\":\\\"1\\\",\\\"vip_level_i\\\":0},\\\"param_event\\\":{\\\"event_s\\\":[\\\"currency_3_l\\\",\\\"source\\\",\\\"15\\\",\\\"28\\\",\\\"2\\\"]}},{\\\"param_environment\\\":{},\\\"param_user\\\":{\\\"account_id_s\\\":\\\"10004165\\\"},\\\"param_role\\\":{\\\"role_id_s\\\":\\\"10004165\\\",\\\"role_name_s\\\":\\\"10004165\\\",\\\"level_i\\\":\\\"1\\\",\\\"vip_level_i\\\":0},\\\"param_event\\\":{\\\"event_s\\\":[\\\"currency_3_l\\\",\\\"source\\\",\\\"15\\\",\\\"10046\\\",\\\"1\\\"]}},{\\\"param_environment\\\":{},\\\"param_user\\\":{\\\"account_id_s\\\":\\\"10004165\\\"},\\\"param_role\\\":{\\\"role_id_s\\\":\\\"10004165\\\",\\\"role_name_s\\\":\\\"10004165\\\",\\\"level_i\\\":\\\"1\\\",\\\"vip_level_i\\\":0},\\\"param_event\\\":{\\\"event_s\\\":[\\\"currency_3_l\\\",\\\"source\\\",\\\"29\\\",\\\"27\\\",\\\"3\\\"]}},{\\\"param_environment\\\":{},\\\"param_user\\\":{\\\"account_id_s\\\":\\\"10004165\\\"},\\\"param_role\\\":{\\\"role_id_s\\\":\\\"10004165\\\",\\\"role_name_s\\\":\\\"10004165\\\",\\\"level_i\\\":\\\"1\\\",\\\"vip_level_i\\\":0},\\\"param_event\\\":{\\\"event_s\\\":[\\\"currency_3_l\\\",\\\"source\\\",\\\"29\\\",\\\"44\\\",\\\"10\\\"]}},{\\\"param_environment\\\":{},\\\"param_user\\\":{\\\"account_id_s\\\":\\\"10004165\\\"},\\\"param_role\\\":{\\\"role_id_s\\\":\\\"10004165\\\",\\\"role_name_s\\\":\\\"10004165\\\",\\\"level_i\\\":\\\"1\\\",\\\"vip_level_i\\\":0},\\\"param_event\\\":{\\\"event_s\\\":[\\\"register_0\\\"]}},{\\\"param_environment\\\":{\\\"wifi_b\\\":false},\\\"param_user\\\":{\\\"user_id_s\\\":\\\"24324\\\",\\\"account_id_s\\\":\\\"10004165\\\"},\\\"param_role\\\":{\\\"role_id_s\\\":\\\"10004165\\\",\\\"role_name_s\\\":\\\"10004165\\\",\\\"level_i\\\":\\\"1\\\",\\\"vip_level_i\\\":0},\\\"param_event\\\":{\\\"event_s\\\":[\\\"login_1\\\",\\\"LOGOUT\\\"]}}]\"}";
init();
sendPost("http://60.1.1.212:8080","111111111");
sendPost("https://gskuld.receiver.extranet.kt007.com:8081/skuld/game/common/",send);
}
}