@Override
    protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor,
                           StreamEventCloner streamEventCloner, WindowState state) {

        synchronized (this) {
            StreamEvent streamEvent = streamEventChunk.getFirst();
            streamEventChunk.clear();
            long currentTime = siddhiQueryContext.getSiddhiAppContext().getTimestampGenerator().currentTime();
            while (streamEvent != null) {
                StreamEvent next = streamEvent.getNext();
                streamEvent.setNext(null);

                StreamEvent clonedEvent = streamEventCloner.copyStreamEvent(streamEvent);
                clonedEvent.setType(StreamEvent.Type.EXPIRED);

                String key = generateKey(streamEvent);
                StreamEvent oldEvent = state.map.put(key, clonedEvent);
                if (oldEvent != null) {
                    state.countMap.put(key, state.countMap.get(key) + 1);
                    streamEventChunk.add(streamEvent);
                } else {
                    //  This is a new event
                    if (state.map.size() > mostFrequentCount) {
                        List<String> keys = new ArrayList<String>(state.countMap.keySet());
                        for (int i = 0; i < mostFrequentCount; i++) {
                            int count = state.countMap.get(keys.get(i)) - 1;
                            if (count == 0) {
                                state.countMap.remove(keys.get(i));
                                StreamEvent expiredEvent = state.map.remove(keys.get(i));
                                expiredEvent.setTimestamp(currentTime);
                                streamEventChunk.add(expiredEvent);
                            } else {
                                state.countMap.put(keys.get(i), count);
                            }
                        }
                        // now we have tried to remove one for newly added item
                        if (state.map.size() > mostFrequentCount) {
                            //nothing happend by the attempt to remove one from the
                            // map so we are ignoring this event
                            state.map.remove(key);
                            // Here we do nothing just drop the message
                        } else {
                            // we got some space, event is already there in map object
                            // we just have to add it to the countMap
                            state.countMap.put(key, 1);
                            streamEventChunk.add(streamEvent);
                        }
                    } else {
                        state.countMap.put(generateKey(streamEvent), 1);
                        streamEventChunk.add(streamEvent);
                    }
                }
                streamEvent = next;
            }
        }
        nextProcessor.process(streamEventChunk);
    }
Implementation of {@link WindowProcessor} which represent a Window operating based on frequency of incoming events.
Implementation uses a counting algorithm based on Misra-Gries counting algorithm
modules/siddhi-core/src/main/java/io/siddhi/core/query/processor/stream/window/FrequentWindowProcessor.java