use of io.nuls.core.event.BaseEvent in project nuls by nuls-io.
the class EventBusServiceImpl method publishEvent.
@Override
public void publishEvent(EventCategoryEnum category, byte[] bytes, String fromId) throws IllegalAccessException, NulsException, InstantiationException {
if (category == EventCategoryEnum.LOCAL) {
BaseEvent event = EventManager.getInstance(bytes);
this.publishLocalEvent(event);
} else {
this.publishNetworkEvent(bytes, fromId);
}
}
use of io.nuls.core.event.BaseEvent in project nuls by nuls-io.
the class NetworkEventService method publish.
public void publish(byte[] event, String nodeId) {
try {
BaseEvent eventObject = EventManager.getInstance(event);
this.publish(eventObject, nodeId);
} catch (NulsException e) {
Log.error(e);
}
}
use of io.nuls.core.event.BaseEvent in project nuls by nuls-io.
the class ConnectionManager method receiveMessage.
public void receiveMessage(ByteBuffer buffer, Node node) {
List<NulsMessage> list;
try {
buffer.flip();
if (!node.isAlive()) {
buffer.clear();
return;
}
list = new ArrayList<>();
while (buffer.hasRemaining()) {
NulsMessage message = new NulsMessage(buffer);
list.add(message);
}
for (NulsMessage message : list) {
if (MessageFilterChain.getInstance().doFilter(message)) {
BaseEvent event = EventManager.getInstance(message.getData());
MsgLog.info("get(" + node.getId() + "):\n" + Hex.encode(message.getHeader().serialize()) + "--" + Hex.encode(message.getData()));
processMessage(event, node);
}
}
} catch (NulsException e) {
// todo
Log.error(e);
} catch (Exception e) {
// todo
Log.error(e);
return;
} finally {
buffer.clear();
}
}
use of io.nuls.core.event.BaseEvent in project nuls by nuls-io.
the class GetEventBodyHandler method onEvent.
@Override
public void onEvent(GetEventBodyEvent event, String fromId) {
BaseEvent eventBody = eventCacheService.getEvent(event.getEventBody().getDigestHex());
if (null == eventBody) {
Log.warn("get event faild,node:" + fromId + ",event:" + event.getEventBody().getDigestHex());
return;
}
eventBroadcaster.sendToNode(eventBody, fromId);
}
Aggregations