mirror of
https://gitee.com/BDWare/cm
synced 2025-01-10 09:54:03 +00:00
fix: fix bugs in event mechanism
fix bugs in EventCenter and NodeConsumer which they provide arguments in wrong order when delivering events into node center
This commit is contained in:
parent
9137563db8
commit
896cbfeb5b
@ -1295,7 +1295,7 @@ public class ContractManager {
|
|||||||
|
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
// 9000
|
// 9000
|
||||||
if (request.getRequester() != null && !request.getRequester().startsWith("event")) {
|
if (null != request.getRequester() && !request.getRequester().startsWith("event")) {
|
||||||
if (client.contractMeta.sigRequired) {
|
if (client.contractMeta.sigRequired) {
|
||||||
if (!request.verifySignature()) {
|
if (!request.verifySignature()) {
|
||||||
cr = new ContractResult(Status.Error, new JsonPrimitive("sign verified failed"));
|
cr = new ContractResult(Status.Error, new JsonPrimitive("sign verified failed"));
|
||||||
|
@ -47,7 +47,7 @@ public class EventCenter {
|
|||||||
msg.setSemantics(semantics);
|
msg.setSemantics(semantics);
|
||||||
msg.doSignature(instance.nodeCenterConn.getNodeKeyPair());
|
msg.doSignature(instance.nodeCenterConn.getNodeKeyPair());
|
||||||
String nodeId = getCenterByTopic(topic);
|
String nodeId = getCenterByTopic(topic);
|
||||||
instance.masterStub.deliverEvent(JsonUtil.toJson(msg), nodeId);
|
instance.masterStub.deliverEvent(nodeId, JsonUtil.toJson(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,18 +62,18 @@ public class EventCenter {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String nodeId = getCenterByTopic(topic);
|
String nodeId = getCenterByTopic(topic);
|
||||||
return instance.masterStub.deliverEvent(JsonUtil.toJson(event), nodeId);
|
return instance.masterStub.deliverEvent(nodeId, JsonUtil.toJson(event));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* publish an event to another node; used by NodeConsumer
|
* publish an event to another node; used by NodeConsumer
|
||||||
*
|
*
|
||||||
* @param eStr event string
|
|
||||||
* @param target id of the target node
|
* @param target id of the target node
|
||||||
|
* @param eStr event string
|
||||||
*/
|
*/
|
||||||
public void publishEvent(String eStr, String target) {
|
public void publishEvent(String target, String eStr) {
|
||||||
if (null != instance.masterStub) {
|
if (null != instance.masterStub) {
|
||||||
instance.masterStub.deliverEvent(eStr, target);
|
instance.masterStub.deliverEvent(target, eStr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -75,10 +75,12 @@ public class ContractConsumer implements IEventConsumer {
|
|||||||
cr.setRequestID(options[0]);
|
cr.setRequestID(options[0]);
|
||||||
ContractClient cc = ContractManager.instance.getClient(contract);
|
ContractClient cc = ContractManager.instance.getClient(contract);
|
||||||
if (null == cc) {
|
if (null == cc) {
|
||||||
|
LOGGER.error("contract " + contract + " doesn't exists!");
|
||||||
rc.onResult((String) null);
|
rc.onResult((String) null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AtomicInteger callCount = new AtomicInteger(0);
|
AtomicInteger callCount = new AtomicInteger(0);
|
||||||
|
// TODO sending requests at a high frequency maybe cause that some requests are ignored
|
||||||
ScheduledFuture<?> future = ContractManager.scheduledThreadPool.scheduleAtFixedRate(
|
ScheduledFuture<?> future = ContractManager.scheduledThreadPool.scheduleAtFixedRate(
|
||||||
() -> ContractManager.instance.executeContractInternal(cr, new ResultCallback() {
|
() -> ContractManager.instance.executeContractInternal(cr, new ResultCallback() {
|
||||||
@Override
|
@Override
|
||||||
@ -90,6 +92,7 @@ public class ContractConsumer implements IEventConsumer {
|
|||||||
if (callCount.get() == TIMEOUT_COUNT ||
|
if (callCount.get() == TIMEOUT_COUNT ||
|
||||||
(result.status == ContractResult.Status.Exception &&
|
(result.status == ContractResult.Status.Exception &&
|
||||||
result.result.toString().contains("not exported"))) {
|
result.result.toString().contains("not exported"))) {
|
||||||
|
LOGGER.warn("receiving event error: request failed!");
|
||||||
rc.onResult((String) null);
|
rc.onResult((String) null);
|
||||||
} else {
|
} else {
|
||||||
ret = false;
|
ret = false;
|
||||||
|
@ -33,7 +33,7 @@ public class NodeConsumer implements IEventConsumer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void publishEvent(Object msg, ResultCallback rc, String... options) {
|
public void publishEvent(Object msg, ResultCallback rc, String... options) {
|
||||||
center.publishEvent(msg.toString(), nodeId);
|
center.publishEvent(nodeId, msg.toString());
|
||||||
if (null != rc) {
|
if (null != rc) {
|
||||||
rc.onResult("");
|
rc.onResult("");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user