mirror of
https://gitee.com/BDWare/cm
synced 2025-01-10 01:44:04 +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();
|
||||
// 9000
|
||||
if (request.getRequester() != null && !request.getRequester().startsWith("event")) {
|
||||
if (null != request.getRequester() && !request.getRequester().startsWith("event")) {
|
||||
if (client.contractMeta.sigRequired) {
|
||||
if (!request.verifySignature()) {
|
||||
cr = new ContractResult(Status.Error, new JsonPrimitive("sign verified failed"));
|
||||
|
@ -47,7 +47,7 @@ public class EventCenter {
|
||||
msg.setSemantics(semantics);
|
||||
msg.doSignature(instance.nodeCenterConn.getNodeKeyPair());
|
||||
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;
|
||||
}
|
||||
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
|
||||
*
|
||||
* @param eStr event string
|
||||
* @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) {
|
||||
instance.masterStub.deliverEvent(eStr, target);
|
||||
instance.masterStub.deliverEvent(target, eStr);
|
||||
}
|
||||
}
|
||||
}
|
@ -75,10 +75,12 @@ public class ContractConsumer implements IEventConsumer {
|
||||
cr.setRequestID(options[0]);
|
||||
ContractClient cc = ContractManager.instance.getClient(contract);
|
||||
if (null == cc) {
|
||||
LOGGER.error("contract " + contract + " doesn't exists!");
|
||||
rc.onResult((String) null);
|
||||
return;
|
||||
}
|
||||
AtomicInteger callCount = new AtomicInteger(0);
|
||||
// TODO sending requests at a high frequency maybe cause that some requests are ignored
|
||||
ScheduledFuture<?> future = ContractManager.scheduledThreadPool.scheduleAtFixedRate(
|
||||
() -> ContractManager.instance.executeContractInternal(cr, new ResultCallback() {
|
||||
@Override
|
||||
@ -90,6 +92,7 @@ public class ContractConsumer implements IEventConsumer {
|
||||
if (callCount.get() == TIMEOUT_COUNT ||
|
||||
(result.status == ContractResult.Status.Exception &&
|
||||
result.result.toString().contains("not exported"))) {
|
||||
LOGGER.warn("receiving event error: request failed!");
|
||||
rc.onResult((String) null);
|
||||
} else {
|
||||
ret = false;
|
||||
|
@ -33,7 +33,7 @@ public class NodeConsumer implements IEventConsumer {
|
||||
|
||||
@Override
|
||||
public void publishEvent(Object msg, ResultCallback rc, String... options) {
|
||||
center.publishEvent(msg.toString(), nodeId);
|
||||
center.publishEvent(nodeId, msg.toString());
|
||||
if (null != rc) {
|
||||
rc.onResult("");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user