Skip to content

Commit 50d74b9

Browse files
authored
Merge pull request tronprotocol#5 from tronprotocol/mongodb
Mongodb
2 parents 9ef21d9 + 64069d5 commit 50d74b9

24 files changed

+1076
-2
lines changed

api/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ dependencies {
44
compileOnly (group: 'org.apache.commons', name: 'commons-lang3', version: '3.5')
55

66
testCompile group: 'junit', name: 'junit', version: '4.+'
7+
8+
compileOnly ("org.projectlombok:lombok:1.16.18") {
9+
exclude group: "org.slf4j"
10+
}
711
}

app/src/main/java/org/tron/eventplugin/app/PluginLauncher.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class PluginLauncher {
3434
private static final Logger logger = LoggerFactory.getLogger(PluginLauncher.class);
3535

3636
public static void main(String[] args) {
37-
String path = "/home/java-tron/plugin-kafka-1.0.0.zip";
37+
String path = "/Users/tron/workplace/java-tronSubmit/java-tronUseSubmit/develop_event_subscribe/eventplugin/build/plugins/plugin-mongodb-1.0.0.zip";
3838

3939
File dir = new File(path);
4040
// create the plugin manager
@@ -57,7 +57,7 @@ protected CompoundPluginDescriptorFinder createPluginDescriptorFinder() {
5757
if (Objects.isNull(eventListeners)) return;
5858

5959
eventListeners.forEach(listener -> {
60-
listener.setServerAddress("127.0.0.1:9092");
60+
listener.setServerAddress("127.0.0.1:27017");
6161
});
6262

6363
eventListeners.forEach(listener -> {

plugins/mongodbplugin/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build

plugins/mongodbplugin/build.gradle

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
dependencies {
2+
// compileOnly important!!! We do not want to put the api into the zip file since the main program has it already!
3+
compileOnly project(':api')
4+
compileOnly(group: 'org.pf4j', name: 'pf4j', version: "${pf4jVersion}") {
5+
exclude group: "org.slf4j"
6+
}
7+
compileOnly group: 'org.apache.commons', name: 'commons-lang3', version: '3.5'
8+
testCompile group: 'junit', name: 'junit', version: '4.+'
9+
10+
compileOnly (group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3') {
11+
exclude group: "org.slf4j"
12+
}
13+
14+
compileOnly ("org.projectlombok:lombok:1.16.18") {
15+
exclude group: "org.slf4j"
16+
}
17+
18+
compile ("org.springframework.data:spring-data-mongodb:2.0.0.RELEASE") {
19+
exclude group: "org.slf4j"
20+
}
21+
compile ("org.mongodb:mongo-java-driver:3.6.3"){
22+
exclude group: "org.slf4j"
23+
}
24+
25+
compileOnly group: 'com.alibaba', name: 'fastjson', version: '1.2.44'
26+
27+
compileOnly group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.5'
28+
compileOnly group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.8.5'
29+
30+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
version=1.0.0
2+
3+
pluginId=mongodb
4+
pluginClass=org.tron.eventplugin.MongodbLogFilterPlugin
5+
pluginProvider=Tron
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.tron.eventplugin;
2+
3+
public class Constant {
4+
public static final int BLOCK_TRIGGER = 0;
5+
public static final int TRANSACTION_TRIGGER = 1;
6+
public static final int CONTRACTLOG_TRIGGER = 2;
7+
public static final int CONTRACTEVENT_TRIGGER = 3;
8+
9+
public static final String BLOCK_TRIGGER_NAME = "blockTrigger";
10+
public static final String TRANSACTION_TRIGGER_NAME = "transactionTrigger";
11+
public static final String CONTRACTLOG_TRIGGER_NAME = "contractLogTrigger";
12+
public static final String CONTRACTEVENT_TRIGGER_NAME = "contractEventTrigger";
13+
14+
private Constant(){}
15+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package org.tron.eventplugin;
2+
3+
import org.pf4j.Extension;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
6+
import org.tron.common.logsfilter.IPluginEventListener;
7+
import java.util.Objects;
8+
9+
@Extension
10+
public class MongodbEventListener implements IPluginEventListener {
11+
12+
private static final Logger log = LoggerFactory.getLogger(MongodbEventListener.class);
13+
14+
@Override
15+
public void setServerAddress(String address) {
16+
17+
if (Objects.isNull(address) || address.length() == 0){
18+
return;
19+
}
20+
21+
MongodbSenderImpl.getInstance().setServerAddress(address);
22+
23+
// MessageSenderImpl should never init until server address is set
24+
MongodbSenderImpl.getInstance().init();
25+
}
26+
27+
@Override
28+
public void setTopic(int eventType, String topic) {
29+
MongodbSenderImpl.getInstance().setTopic(eventType, topic);
30+
}
31+
32+
@Override
33+
public void handleBlockEvent(Object data) {
34+
35+
if (Objects.isNull(data)){
36+
return;
37+
}
38+
39+
MongodbSenderImpl.getInstance().getTriggerQueue().offer((String)data);
40+
}
41+
42+
@Override
43+
public void handleTransactionTrigger(Object data) {
44+
if (Objects.isNull(data)){
45+
return;
46+
}
47+
48+
MongodbSenderImpl.getInstance().getTriggerQueue().offer((String)data);
49+
}
50+
51+
@Override
52+
public void handleContractLogTrigger(Object data) {
53+
if (Objects.isNull(data)){
54+
return;
55+
}
56+
57+
MongodbSenderImpl.getInstance().getTriggerQueue().offer((String)data);
58+
}
59+
60+
@Override
61+
public void handleContractEventTrigger(Object data) {
62+
if (Objects.isNull(data)){
63+
return;
64+
}
65+
66+
MongodbSenderImpl.getInstance().getTriggerQueue().offer((String)data);
67+
}
68+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.tron.eventplugin;
2+
3+
import org.pf4j.Plugin;
4+
import org.pf4j.PluginWrapper;
5+
6+
public class MongodbLogFilterPlugin extends Plugin {
7+
8+
public MongodbLogFilterPlugin(PluginWrapper wrapper) {
9+
super(wrapper);
10+
}
11+
12+
@Override
13+
public void start() {
14+
}
15+
16+
@Override
17+
public void stop() {
18+
MongodbSenderImpl.getInstance().close();
19+
}
20+
}

0 commit comments

Comments
 (0)