use of org.aion.api.server.types.Fltr in project aion by aionnetwork.
the class ProtocolProcessor method eventRun.
private void eventRun(Context ctx) {
Socket sock = ctx.socket(ZMQ.DEALER);
sock.connect(AION_ZMQ_EV_TH);
while (!shutDown.get()) {
Map<Long, Fltr> filters = ((HdlrZmq) this.handler).getFilter();
for (Long i : filters.keySet()) {
Fltr f = filters.get(i);
if (LOG.isTraceEnabled()) {
LOG.trace("ProtocolProcessor.eventRun fltr type:{}", f.getType());
}
if (f.getType() == Fltr.Type.EVENT) {
Object[] objs = f.poll();
List<Message.t_EventCt> al = new ArrayList<>();
for (Object obj : objs) {
al.add(((EvtContract) obj).getMsgEventCt());
if (LOG.isTraceEnabled()) {
LOG.trace("ProtocolProcessor.eventRun fltr event[{}]", ((EvtContract) obj).toJSON());
}
}
if (!al.isEmpty()) {
Message.rsp_EventCtCallback ecb = Message.rsp_EventCtCallback.newBuilder().addAllEc(al).build();
byte[] rsp = ((HdlrZmq) this.handler).toRspEvtMsg(ecb.toByteArray());
try {
byte[] socketId = ByteBuffer.allocate(5).put(ByteUtil.longToBytes(i), 3, 5).array();
sock.send(socketId, ZMQ.SNDMORE);
sock.send(rsp, ZMQ.DONTWAIT);
} catch (Exception e) {
LOG.error("ProtocolProcessor.callbackRun sock.send exception: " + e.getMessage());
}
}
}
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
LOG.error("eventRun InterruptedException {}", e);
}
}
sock.close();
if (LOG.isDebugEnabled()) {
LOG.debug("close eventRun sockets...");
}
}
Aggregations