Search in sources :

Example 6 with Fltr

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...");
    }
}
Also used : Message(org.aion.api.server.pb.Message) Fltr(org.aion.api.server.types.Fltr) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Socket(org.zeromq.ZMQ.Socket)

Aggregations

Fltr (org.aion.api.server.types.Fltr)6 ArrayList (java.util.ArrayList)3 ArgFltr (org.aion.api.server.types.ArgFltr)3 ByteString (com.google.protobuf.ByteString)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 BigInteger (java.math.BigInteger)2 ByteBuffer (java.nio.ByteBuffer)2 AbstractMap (java.util.AbstractMap)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Set (java.util.Set)2 BlockingQueue (java.util.concurrent.BlockingQueue)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2