From b86aa3f5c8e16b35c353973f3d15c9cde242a500 Mon Sep 17 00:00:00 2001 From: wanglihui <949764788@qq.com> Date: Mon, 20 Jul 2020 19:37:26 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=84=E7=90=86=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E6=8C=89=E7=85=A7=E6=96=87=E6=A1=A3=E5=88=86?= =?UTF-8?q?=E5=88=AB=E5=A4=84=E7=90=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/ac/iie/service/update/vertex/Fqdn.java | 21 +++++ .../cn/ac/iie/service/update/vertex/Ip.java | 79 +++++++++++++++++++ .../iie/service/update/vertex/Subscriber.java | 21 +++++ 3 files changed, 121 insertions(+) create mode 100644 ip-learning-java-test/src/main/java/cn/ac/iie/service/update/vertex/Fqdn.java create mode 100644 ip-learning-java-test/src/main/java/cn/ac/iie/service/update/vertex/Ip.java create mode 100644 ip-learning-java-test/src/main/java/cn/ac/iie/service/update/vertex/Subscriber.java diff --git a/ip-learning-java-test/src/main/java/cn/ac/iie/service/update/vertex/Fqdn.java b/ip-learning-java-test/src/main/java/cn/ac/iie/service/update/vertex/Fqdn.java new file mode 100644 index 0000000..c13ca8c --- /dev/null +++ b/ip-learning-java-test/src/main/java/cn/ac/iie/service/update/vertex/Fqdn.java @@ -0,0 +1,21 @@ +package cn.ac.iie.service.update.vertex; + +import cn.ac.iie.service.update.Vertex; +import cn.ac.iie.utils.ArangoDBConnect; +import com.arangodb.entity.BaseDocument; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CountDownLatch; + +public class Fqdn extends Vertex { + + public Fqdn(HashMap> newDocumentHashMap, + ArangoDBConnect arangoManger, + String collectionName, + ConcurrentHashMap historyDocumentMap, + CountDownLatch countDownLatch) { + super(newDocumentHashMap, arangoManger, collectionName, historyDocumentMap,countDownLatch); + } +} diff --git a/ip-learning-java-test/src/main/java/cn/ac/iie/service/update/vertex/Ip.java b/ip-learning-java-test/src/main/java/cn/ac/iie/service/update/vertex/Ip.java new file mode 100644 index 0000000..4cdedbd --- /dev/null +++ b/ip-learning-java-test/src/main/java/cn/ac/iie/service/update/vertex/Ip.java @@ -0,0 +1,79 @@ +package cn.ac.iie.service.update.vertex; + +import cn.ac.iie.service.update.Vertex; +import cn.ac.iie.utils.ArangoDBConnect; +import com.arangodb.entity.BaseDocument; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CountDownLatch; + +public class Ip extends Vertex { + + public Ip(HashMap> newDocumentHashMap, + ArangoDBConnect arangoManger, + String collectionName, + ConcurrentHashMap historyDocumentMap, + CountDownLatch countDownLatch) { + super(newDocumentHashMap, arangoManger, collectionName, historyDocumentMap,countDownLatch); + } + + @Override + protected void updateFunction(BaseDocument newDocument, BaseDocument historyDocument) { + super.updateFunction(newDocument, historyDocument); + updateIpByType(newDocument, historyDocument); + } + + @Override + protected void mergeFunction(Map properties, BaseDocument doc) { + super.mergeFunction(properties, doc); + mergeIpByType(properties,doc); + } + + private void mergeIpByType(Map properties, BaseDocument doc){ + Map mergeProperties = doc.getProperties(); + checkIpTypeProperty(properties,mergeProperties,"CLIENT_SESSION_COUNT"); + checkIpTypeProperty(properties,mergeProperties,"CLIENT_BYTES_SUM"); + checkIpTypeProperty(properties,mergeProperties,"SERVER_SESSION_COUNT"); + checkIpTypeProperty(properties,mergeProperties,"SERVER_BYTES_SUM"); + } + + private void checkIpTypeProperty(Map properties,Map mergeProperties,String property){ + try { + if (!properties.containsKey(property)){ + properties.put(property,0L); + checkIpTypeProperty(properties,mergeProperties,property); + }else if ("0".equals(properties.get(property).toString()) && mergeProperties.containsKey(property)){ + if (!"0".equals(mergeProperties.get(property).toString())){ + properties.put(property,Long.parseLong(mergeProperties.get(property).toString())); + } + } + }catch (Exception e){ + e.printStackTrace(); + } + } + + private void updateIpByType(BaseDocument newDocument, BaseDocument historyDocument){ + addProperty(newDocument,historyDocument,"CLIENT_SESSION_COUNT"); + addProperty(newDocument,historyDocument,"CLIENT_BYTES_SUM"); + addProperty(newDocument,historyDocument,"SERVER_SESSION_COUNT"); + addProperty(newDocument,historyDocument,"SERVER_BYTES_SUM"); + } + + private void addProperty(BaseDocument newDocument, BaseDocument historyDocument,String property){ + try { + if (historyDocument.getProperties().containsKey(property)){ + long newProperty = Long.parseLong(newDocument.getAttribute(property).toString()); + long hisProperty = Long.parseLong(historyDocument.getAttribute(property).toString()); + historyDocument.updateAttribute(property,newProperty+hisProperty); + }else { + historyDocument.addAttribute(property,0L); + } + }catch (Exception e){ + e.printStackTrace(); + } + } + +} diff --git a/ip-learning-java-test/src/main/java/cn/ac/iie/service/update/vertex/Subscriber.java b/ip-learning-java-test/src/main/java/cn/ac/iie/service/update/vertex/Subscriber.java new file mode 100644 index 0000000..02f1468 --- /dev/null +++ b/ip-learning-java-test/src/main/java/cn/ac/iie/service/update/vertex/Subscriber.java @@ -0,0 +1,21 @@ +package cn.ac.iie.service.update.vertex; + +import cn.ac.iie.service.update.Vertex; +import cn.ac.iie.utils.ArangoDBConnect; +import com.arangodb.entity.BaseDocument; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CountDownLatch; + +public class Subscriber extends Vertex { + + public Subscriber(HashMap> newDocumentHashMap, + ArangoDBConnect arangoManger, + String collectionName, + ConcurrentHashMap historyDocumentMap, + CountDownLatch countDownLatch) { + super(newDocumentHashMap, arangoManger, collectionName, historyDocumentMap, countDownLatch); + } +}