diff --git a/conf/application.xml b/conf/application.xml index d4cef59..f812315 100644 --- a/conf/application.xml +++ b/conf/application.xml @@ -8,6 +8,10 @@ + + + + diff --git a/conf/logging.properties b/conf/logging.properties index 56a4cb8..fcd593e 100644 --- a/conf/logging.properties +++ b/conf/logging.properties @@ -11,7 +11,7 @@ javax.level = INFO com.sun.level = INFO sun.level = INFO jdk.level = INFO - +org.mongodb.driver.level = SEVERE java.util.logging.FileHandler.level = FINER #10M diff --git a/lib/bson-3.7.1.jar b/lib/bson-3.7.1.jar new file mode 100644 index 0000000..e198801 Binary files /dev/null and b/lib/bson-3.7.1.jar differ diff --git a/lib/mongodb-driver-3.7.1.jar b/lib/mongodb-driver-3.7.1.jar new file mode 100644 index 0000000..4ec7fa0 Binary files /dev/null and b/lib/mongodb-driver-3.7.1.jar differ diff --git a/lib/mongodb-driver-core-3.7.1.jar b/lib/mongodb-driver-core-3.7.1.jar new file mode 100644 index 0000000..8a5fc07 Binary files /dev/null and b/lib/mongodb-driver-core-3.7.1.jar differ diff --git a/libs/redbbs.jar b/libs/redbbs.jar index c5e0122..f9e7708 100644 Binary files a/libs/redbbs.jar and b/libs/redbbs.jar differ diff --git a/pom.xml b/pom.xml index 64498cf..fc065ff 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,11 @@ enjoy 3.4 --> + diff --git a/src/com/lxyer/bbs/base/BaseServlet.java b/src/com/lxyer/bbs/base/BaseServlet.java index 1db373f..2c2ed75 100644 --- a/src/com/lxyer/bbs/base/BaseServlet.java +++ b/src/com/lxyer/bbs/base/BaseServlet.java @@ -20,6 +20,7 @@ import org.redkale.util.AnyValue; import javax.annotation.Resource; import java.io.File; import java.io.IOException; +import java.util.Map; import static com.lxyer.bbs.base.kit.RetCodes.RET_USER_UNLOGIN; @@ -53,6 +54,9 @@ public class BaseServlet extends HttpServlet { @Resource protected CommentService commentService; + @Resource + protected TaskQueue logQueue; + @Override public void init(HttpContext context, AnyValue config) { @@ -87,6 +91,24 @@ public class BaseServlet extends HttpServlet { return; } + Kv visLog = new Kv();//ip、time、userid、uri、para + visLog.set("ip", request.getRemoteAddr()); + request.getHost(); + visLog.set("time", System.currentTimeMillis()); + visLog.set("userid", currentid); + visLog.set("uri", request.getRequestURI()); + + Kv para = Kv.create(); + for (String key : request.getParameterNames()){ + para.set(key, request.getParameter(key)); + } + visLog.set("para", para); + try { + logQueue.put(visLog); + } catch (InterruptedException e) { + e.printStackTrace(); + } + /*if ("/".equals(uri)){ finish("/front/index.html", Kv.by("","")); diff --git a/src/com/lxyer/bbs/base/TaskQueue.java b/src/com/lxyer/bbs/base/TaskQueue.java new file mode 100644 index 0000000..08e78ea --- /dev/null +++ b/src/com/lxyer/bbs/base/TaskQueue.java @@ -0,0 +1,69 @@ +package com.lxyer.bbs.base; + +import com.mongodb.MongoClient; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; +import org.bson.Document; +import org.redkale.util.AnyValue; + +import javax.annotation.Resource; +import java.util.Map; +import java.util.concurrent.LinkedBlockingQueue; + +/** + * Created by liangxianyou at 2018/6/20 22:54. + */ +public class TaskQueue extends BaseService implements Runnable { + + @Resource(name = "property.mongo.host") + private String mongoHost; + + protected static LinkedBlockingQueue queue = new LinkedBlockingQueue(); + + private static MongoClient mongoClient; + private static MongoDatabase redbbs; + private static MongoCollection visLog; + + public TaskQueue() { + new Thread(this).start(); + } + + @Override + public void init(AnyValue config) { + mongoClient = new MongoClient(mongoHost, 27017); + redbbs = mongoClient.getDatabase(winos ? "redbbs_dev": "redbbs"); + visLog = redbbs.getCollection("vis_log"); + } + + public T take() throws InterruptedException { + return (T) queue.take(); + } + + public void put(T t) throws InterruptedException { + queue.put(t); + } + + @Override + public void run() { + try { + while (true){ + Map take = (Map) take(); + + take.put("ftime", String.format("%1$tY%1$tm%1$td%1$tH%1$tM", take.get("time"))); + visLog.insertOne(new Document(take)); + + //在这里处理日志数据[访问量] + } + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + /*public static void main(String[] args) { + //测试mongodb 连通性 + FindIterable documents = visLog.find().limit(10); + documents.forEach((Block) x->{ + System.out.println(x); + }); + }*/ +}