mirror of
https://gitee.com/BDWare/cm
synced 2025-12-28 12:49:25 +00:00
Compare commits
7 Commits
v1.6.6
...
feat/consi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2f8ab528b | ||
|
|
a87549a4c9 | ||
|
|
bb368c8bee | ||
|
|
1ec1cac894 | ||
|
|
4315992b73 | ||
|
|
893be2e954 | ||
|
|
b1eb54c26b |
10
build.gradle
10
build.gradle
@@ -2,7 +2,9 @@ plugins {
|
|||||||
id 'java'
|
id 'java'
|
||||||
id 'java-library'
|
id 'java-library'
|
||||||
}
|
}
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
java {
|
java {
|
||||||
@@ -24,14 +26,12 @@ sourceSets {
|
|||||||
|
|
||||||
sourceCompatibility = 1.8
|
sourceCompatibility = 1.8
|
||||||
|
|
||||||
repositories {
|
|
||||||
mavenCentral()
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
api project(":common")
|
api project(":common")
|
||||||
api 'io.prometheus:simpleclient:0.12.0'
|
api 'io.prometheus:simpleclient:0.12.0'
|
||||||
api 'org.knowhowlab.osgi:sigar:1.6.5_01'
|
api 'org.knowhowlab.osgi:sigar:1.6.5_01'
|
||||||
|
api 'org.bdware.doip:doip-sdk:1.1.0'
|
||||||
|
|
||||||
api fileTree(dir: 'libs', include: '*.jar')
|
api fileTree(dir: 'libs', include: '*.jar')
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@@ -75,7 +75,6 @@ public class ContractManager {
|
|||||||
Executors.newScheduledThreadPool(10);
|
Executors.newScheduledThreadPool(10);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static int logStage = 0;
|
public static int logStage = 0;
|
||||||
public static Sigar sigar = null; // 获取network等资源什么
|
public static Sigar sigar = null; // 获取network等资源什么
|
||||||
|
|
||||||
@@ -1674,11 +1673,14 @@ public class ContractManager {
|
|||||||
if (o2.id.equals(firstID)) {
|
if (o2.id.equals(firstID)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (o1.name != null && o2.name != null) {
|
String str1 = o1.name;
|
||||||
return o1.name.compareTo(o2.name);
|
String str2 = o2.name;
|
||||||
} else {
|
if (o1.name == null)
|
||||||
return -1;
|
str1 = "";
|
||||||
}
|
if (o2.name == null)
|
||||||
|
str2 = "";
|
||||||
|
return str1.compareTo(str2);
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ public class EventBroker {
|
|||||||
doSubscribe(event);
|
doSubscribe(event);
|
||||||
// save & try to sub in center
|
// save & try to sub in center
|
||||||
recorder.appendEvent(event);
|
recorder.appendEvent(event);
|
||||||
center.subInCenter(event.getTopic(), event.getSemantics());
|
center.subInCenter(event.getTopic(), event.getSemantics(), event.getCenter());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case UNSUBSCRIBE:
|
case UNSUBSCRIBE:
|
||||||
|
|||||||
@@ -15,17 +15,18 @@ public class EventCenter {
|
|||||||
* get the nearest node to the topic in the hash function range
|
* get the nearest node to the topic in the hash function range
|
||||||
*
|
*
|
||||||
* @param topic the topic
|
* @param topic the topic
|
||||||
|
* @param k the number of centers
|
||||||
* @return id of the node
|
* @return id of the node
|
||||||
*/
|
*/
|
||||||
public String getCenterByTopic(String topic) {
|
public String[] getCenterByTopic(String topic, int k) {
|
||||||
if (null == instance.nodeCenterConn) {
|
if (null == instance.nodeCenterConn) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
String[] centers = DHTUtil.getClusterByKey(topic, 1);
|
String[] centers = DHTUtil.getClusterByKey(topic, k);
|
||||||
if (null == centers || centers.length == 0) {
|
if (null == centers || centers.length == 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return centers[0];
|
return centers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,21 +34,34 @@ public class EventCenter {
|
|||||||
*
|
*
|
||||||
* @param topic event topic
|
* @param topic event topic
|
||||||
* @param semantics event semantics, used to mark PRESUB events
|
* @param semantics event semantics, used to mark PRESUB events
|
||||||
|
* @param center id of event center if the subscribing has been handled
|
||||||
*/
|
*/
|
||||||
public void subInCenter(String topic, REvent.REventSemantics semantics) {
|
public void subInCenter(String topic, REvent.REventSemantics semantics, String center) {
|
||||||
if (null == instance.nodeCenterConn) {
|
if (null == instance.nodeCenterConn) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
REvent msg = new REvent(
|
REvent msg = new REvent(topic,
|
||||||
topic,
|
|
||||||
REvent.REventType.SUBSCRIBE,
|
REvent.REventType.SUBSCRIBE,
|
||||||
String.format("{\"subscriber\":\"%s\"}",
|
String.format("{\"subscriber\":\"%s\"}",
|
||||||
instance.nodeCenterConn.getNodeId()),
|
instance.nodeCenterConn.getNodeId()),
|
||||||
"");
|
"");
|
||||||
msg.setSemantics(semantics);
|
msg.setSemantics(semantics);
|
||||||
msg.doSignature(instance.nodeCenterConn.getNodeKeyPair());
|
msg.doSignature(instance.nodeCenterConn.getNodeKeyPair());
|
||||||
String nodeId = getCenterByTopic(topic);
|
msg.setCenter(center);
|
||||||
instance.masterStub.deliverEvent(nodeId, JsonUtil.toJson(msg));
|
String[] centers = getCenterByTopic(topic, 2);
|
||||||
|
if (null == centers) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (null != center) {
|
||||||
|
if (centers[0].equals(center) && centers.length > 1) {
|
||||||
|
instance.masterStub.deliverEvent(centers[1], JsonUtil.toJson(msg));
|
||||||
|
} else {
|
||||||
|
instance.masterStub.deliverEvent(centers[0], JsonUtil.toJson(msg));
|
||||||
|
}
|
||||||
|
} else if (!instance.masterStub.deliverEvent(centers[0], JsonUtil.toJson(msg)) && centers.length > 1) {
|
||||||
|
msg.setCenter(centers[0]);
|
||||||
|
instance.masterStub.deliverEvent(centers[1], JsonUtil.toJson(msg));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,8 +75,11 @@ public class EventCenter {
|
|||||||
if (null == instance.masterStub) {
|
if (null == instance.masterStub) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String nodeId = getCenterByTopic(topic);
|
String[] centers = getCenterByTopic(topic, 1);
|
||||||
return instance.masterStub.deliverEvent(nodeId, JsonUtil.toJson(event));
|
if (null == centers) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return instance.masterStub.deliverEvent(centers[0], JsonUtil.toJson(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -5,9 +5,17 @@ import org.bdware.sc.conn.Node;
|
|||||||
import org.bdware.sc.conn.OnHashCallback;
|
import org.bdware.sc.conn.OnHashCallback;
|
||||||
import org.bdware.sc.conn.ResultCallback;
|
import org.bdware.sc.conn.ResultCallback;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public interface ContractExecutor {
|
public interface ContractExecutor {
|
||||||
void execute(String requestID, ContractRequest req, ResultCallback rcb, OnHashCallback hcb);
|
void execute(String requestID, ContractRequest req, ResultCallback rcb, OnHashCallback hcb);
|
||||||
|
|
||||||
|
default void onRecover(Map<String, Object> args) {
|
||||||
|
}
|
||||||
|
|
||||||
|
default void onDeliverBlock(String data) {
|
||||||
|
}
|
||||||
|
|
||||||
default void close() {
|
default void close() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package org.bdware.server.trustedmodel;
|
||||||
|
|
||||||
|
public class MultiReqSeq {
|
||||||
|
public final int seq;
|
||||||
|
public final long startTime;
|
||||||
|
|
||||||
|
public MultiReqSeq(int s){
|
||||||
|
seq = s;
|
||||||
|
startTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user