Search in sources :

Example 1 with BaseEvent

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);
    }
}
Also used : BaseEvent(io.nuls.core.event.BaseEvent)

Example 2 with BaseEvent

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);
    }
}
Also used : NulsException(io.nuls.core.exception.NulsException) BaseEvent(io.nuls.core.event.BaseEvent)

Example 3 with BaseEvent

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();
    }
}
Also used : NulsMessage(io.nuls.core.mesasge.NulsMessage) NulsException(io.nuls.core.exception.NulsException) BaseEvent(io.nuls.core.event.BaseEvent) NulsException(io.nuls.core.exception.NulsException) IOException(java.io.IOException)

Example 4 with BaseEvent

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);
}
Also used : BaseEvent(io.nuls.core.event.BaseEvent)

Aggregations

BaseEvent (io.nuls.core.event.BaseEvent)4 NulsException (io.nuls.core.exception.NulsException)2 NulsMessage (io.nuls.core.mesasge.NulsMessage)1 IOException (java.io.IOException)1