<commit_before>/*
 * Copyright (c) 2012-2014 The original author or authors
 * ------------------------------------------------------
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Apache License v2.0 which accompanies this distribution.
 *
 * The Eclipse Public License is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * The Apache License v2.0 is available at
 * http://www.opensource.org/licenses/apache2.0.php
 *
 * You may elect to redistribute this code under either of these licenses.
 */
package org.eclipse.moquette.spi.impl;

import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import com.lmax.disruptor.BlockingWaitStrategy;
import com.lmax.disruptor.EventHandler;
import com.lmax.disruptor.RingBuffer;
import com.lmax.disruptor.WorkHandler;
import com.lmax.disruptor.dsl.Disruptor;
import com.lmax.disruptor.dsl.ProducerType;
import io.netty.util.concurrent.DefaultThreadFactory;
import org.HdrHistogram.Histogram;
import org.eclipse.moquette.commons.Constants;
import org.eclipse.moquette.proto.messages.AbstractMessage;
import org.eclipse.moquette.server.IAuthenticator;
import org.eclipse.moquette.server.ServerChannel;
import org.eclipse.moquette.spi.IMessagesStore;
import org.eclipse.moquette.spi.IMessaging;
import org.eclipse.moquette.spi.ISessionsStore;
import org.eclipse.moquette.spi.impl.events.LostConnectionEvent;
import org.eclipse.moquette.spi.impl.events.MessagingEvent;
import org.eclipse.moquette.spi.impl.events.ProtocolEvent;
import org.eclipse.moquette.spi.impl.events.StopEvent;
import org.eclipse.moquette.spi.impl.subscriptions.SubscriptionsStore;
import org.eclipse.moquette.spi.impl.thinkjoy.AreaAuthenticator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * Singleton class that orchestrate the execution of the protocol.
 *
 * Uses the LMAX Disruptor to serialize the incoming, requests, because it work in a evented fashion;
 * the requests income from front Netty connectors and are dispatched to the
 * ProtocolProcessor.
 *
 * @author andrea
 */

/**
 * 将事件分为两类进行分发：一类是带有io操作的事件(connect, subscribe)，一类不带io操作的事件(publish)。
 * 带有io操作的事件，被多线程分发器(io_disruptor)所分发
 * 不带io操作的事件，被单线程分发器(m_disruptor)所分发。
 */
public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {

	private static final Logger LOG = LoggerFactory.getLogger(SimpleMessaging.class);
	private static SimpleMessaging INSTANCE;
	private final ProtocolProcessor m_processor = new ProtocolProcessor();
	private final AnnotationSupport annotationSupport = new AnnotationSupport();
	CountDownLatch m_stopLatch;
	Histogram histogram = new Histogram(5);
	long delay = 0L;
	String formatString = "%d | %f |  %d \n";
	private SubscriptionsStore subscriptions;
	private RingBuffer<ValueEvent> m_ringBuffer, io_ringBuffer;
	private IMessagesStore m_storageService;
	private ISessionsStore m_sessionsStore;
	private ExecutorService m_executor, io_executor;
	private Disruptor<ValueEvent> m_disruptor, io_disruptor;
	private boolean benchmarkEnabled = false;
	private long count = 0L;<commit_msg>添加指标统计<commit_after>/*
 * Copyright (c) 2012-2014 The original author or authors
 * ------------------------------------------------------
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Apache License v2.0 which accompanies this distribution.
 *
 * The Eclipse Public License is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * The Apache License v2.0 is available at
 * http://www.opensource.org/licenses/apache2.0.php
 *
 * You may elect to redistribute this code under either of these licenses.
 */
package org.eclipse.moquette.spi.impl;

import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import com.lmax.disruptor.BlockingWaitStrategy;
import com.lmax.disruptor.EventHandler;
import com.lmax.disruptor.RingBuffer;
import com.lmax.disruptor.WorkHandler;
import com.lmax.disruptor.dsl.Disruptor;
import com.lmax.disruptor.dsl.ProducerType;
import io.netty.util.concurrent.DefaultThreadFactory;
import org.eclipse.moquette.commons.Constants;
import org.eclipse.moquette.proto.messages.AbstractMessage;
import org.eclipse.moquette.server.IAuthenticator;
import org.eclipse.moquette.server.ServerChannel;
import org.eclipse.moquette.spi.IMessagesStore;
import org.eclipse.moquette.spi.IMessaging;
import org.eclipse.moquette.spi.ISessionsStore;
import org.eclipse.moquette.spi.impl.events.LostConnectionEvent;
import org.eclipse.moquette.spi.impl.events.MessagingEvent;
import org.eclipse.moquette.spi.impl.events.ProtocolEvent;
import org.eclipse.moquette.spi.impl.events.StopEvent;
import org.eclipse.moquette.spi.impl.subscriptions.SubscriptionsStore;
import org.eclipse.moquette.spi.impl.thinkjoy.AreaAuthenticator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * Singleton class that orchestrate the execution of the protocol.
 *
 * Uses the LMAX Disruptor to serialize the incoming, requests, because it work in a evented fashion;
 * the requests income from front Netty connectors and are dispatched to the
 * ProtocolProcessor.
 *
 * @author andrea
 */

/**
 * 将事件分为两类进行分发：一类是带有io操作的事件(connect, subscribe)，一类不带io操作的事件(publish)。
 * 带有io操作的事件，被多线程分发器(io_disruptor)所分发
 * 不带io操作的事件，被单线程分发器(m_disruptor)所分发。
 */
public class SimpleMessaging implements IMessaging, EventHandler<ValueEvent> {

	private static final Logger LOG = LoggerFactory.getLogger(SimpleMessaging.class);
	private static SimpleMessaging INSTANCE;
	private final ProtocolProcessor m_processor = new ProtocolProcessor();
	private final AnnotationSupport annotationSupport = new AnnotationSupport();
	private final String formatString = "%d | %f |  %d \n";
	CountDownLatch m_stopLatch;
	long delay = 0L;
	long count = 0L;
	private SubscriptionsStore subscriptions;
	private RingBuffer<ValueEvent> m_ringBuffer, io_ringBuffer;
	private IMessagesStore m_storageService;
	private ISessionsStore m_sessionsStore;
	private ExecutorService m_executor, io_executor;
	private Disruptor<ValueEvent> m_disruptor, io_disruptor;
	private boolean benchmarkEnabled = false;
{'fraction_non_alphanumeric': 0.10293891367902755, 'fraction_numerical': 0.006924142175719341, 'mean_word_length': 5.178707224334601, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3404226', 'n_tokens_mistral': 2076, 'n_tokens_neox': 2018, 'n_words': 474}