Mina代码跟踪(1)

1  NioSocketAcceptor类关系图

  

1.1 NioSocketAcceptor acceptor = new NioSocketAcceptor(5);

NioSocketAcceptor 初始化顺序

  AbstractIoService构造函数

    protected AbstractIoService(IoSessionConfig sessionConfig, Executor executor) {
        if (sessionConfig == null) {
            throw new IllegalArgumentException("sessionConfig");
        }

        if (getTransportMetadata() == null) {
            throw new IllegalArgumentException("TransportMetadata");
        }

        if (!getTransportMetadata().getSessionConfigType().isAssignableFrom(
                sessionConfig.getClass())) {
            throw new IllegalArgumentException("sessionConfig type: "
                    + sessionConfig.getClass() + " (expected: "
                    + getTransportMetadata().getSessionConfigType() + ")");
        }

        // Create the listeners, and add a first listener : a activation listener
        // for this service, which will give information on the service state.
        listeners = new IoServiceListenerSupport(this);
        listeners.add(serviceActivationListener);

        // Stores the given session configuration
        this.sessionConfig = sessionConfig;

        // Make JVM load the exception monitor before some transports
        // change the thread context class loader.
        ExceptionMonitor.getInstance();

        if (executor == null) {
            this.executor = Executors.newCachedThreadPool();
            createdExecutor = true;
        } else {
            this.executor = executor;
            createdExecutor = false;
        }

        threadName = getClass().getSimpleName() + ‘-‘ + id.incrementAndGet();
    }
    protected AbstractIoAcceptor(IoSessionConfig sessionConfig, Executor executor) {
        super(sessionConfig, executor);
        defaultLocalAddresses.add(null);
    }

AbstractPollingIoAcceptor 构造函数

    private AbstractPollingIoAcceptor(IoSessionConfig sessionConfig,
            Executor executor, IoProcessor<S> processor,
            boolean createdProcessor) {
        super(sessionConfig, executor);

        if (processor == null) {
            throw new IllegalArgumentException("processor");
        }

        this.processor = processor;
        this.createdProcessor = createdProcessor;

        try {
            // Initialize the selector
            init();

            // The selector is now ready, we can switch the
            // flag to true so that incoming connection can be accepted
            selectable = true;
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new RuntimeIoException("Failed to initialize.", e);
        } finally {
            if (!selectable) {
                try {
                    destroy();
                } catch (Exception e) {
                    ExceptionMonitor.getInstance().exceptionCaught(e);
                }
            }
        }
    }

NioSocketAcceptor 构造函数

    public NioSocketAcceptor(int processorCount) {
        super(new DefaultSocketSessionConfig(), NioProcessor.class, processorCount);
        ((DefaultSocketSessionConfig) getSessionConfig()).init(this);
    }

1.2 IoFilterChain 过滤链

acceptor.getFilterChain().addLast("logger", new LoggingFilter());

    /**  AbstractIoService
     * {@inheritDoc}
     */
    public final DefaultIoFilterChainBuilder getFilterChain() {
        if (filterChainBuilder instanceof DefaultIoFilterChainBuilder) {
            return (DefaultIoFilterChainBuilder) filterChainBuilder;
        }

        throw new IllegalStateException(
                    "Current filter chain builder is not a DefaultIoFilterChainBuilder.");
    }

源代码:

public class DefaultIoFilterChainBuilder implements IoFilterChainBuilder {

    private final static Logger LOGGER =
        LoggerFactory.getLogger(DefaultIoFilterChainBuilder.class);
    private final List<Entry> entries;

    /**
     * Creates a new instance with an empty filter list.
     */
    public DefaultIoFilterChainBuilder() {
        entries = new CopyOnWriteArrayList<Entry>();
    }

    /**
     * Creates a new copy of the specified {@link DefaultIoFilterChainBuilder}.
     */
    public DefaultIoFilterChainBuilder(DefaultIoFilterChainBuilder filterChain) {
        if (filterChain == null) {
            throw new IllegalArgumentException("filterChain");
        }
        entries = new CopyOnWriteArrayList<Entry>(filterChain.entries);
    }

addLast

    /**
     * @see IoFilterChain#addLast(String, IoFilter)
     */
    public synchronized void addLast(String name, IoFilter filter) {
        register(entries.size(), new EntryImpl(name, filter));
    }   private void register(int index, Entry e) {        if (contains(e.getName())) {            throw new IllegalArgumentException(                    "Other filter is using the same name: " + e.getName());        }

        entries.add(index, e);    }

1.3 IoFilter

1.4 IoSessionConfig

1.5 acceptor.bind(new InetSocketAddress(this.serverAddr, this.serverPort));

时间: 2024-08-12 02:23:59

Mina代码跟踪(1)的相关文章

openstack学习笔记一 虚拟机启动过程代码跟踪

本文主要通过对虚拟机创建过程的代码跟踪.观察虚拟机启动任务状态的变化,来透彻理解openstack各组件之间的作用过程. 当从horizon界面发送一个创建虚拟机请求,horizon api 将会依据前端给定的数据信息.调用novaclient 生成一个创建虚拟机的http post 请求来创建vm服务. >/usr/lib/python2.6/site-packages/horizon/api/nova.py(334)server_create() > /usr/lib/python2.6/

trace与代码跟踪服务

首先开篇引用<MVC2 2 in action>里面一段关于这个跟踪服务的话 When you called Trace.Write() in Web Forms, you were interacting with the Trace- Context class. This exists on your ViewPage in ASP.NET MVC, but this isn't where you would want to write tracing statements. By t

Linux 内核高-低端内存设置代码跟踪(ARM构架)

对于ARM中内核如何在启动的时候设置高低端内存的分界线(也是逻辑地址与虚拟地址分界线(虚拟地址)减去那个固定的偏移),这里我稍微引导下(内核分析使用Linux-3.0): 首先定位设置内核虚拟地址起始位置(也就是内核逻辑地址末端+1的地址)的文件:init.c (arch\arm\mm),在这个文件中的void __init bootmem_init(void)函数如下 void __init bootmem_init(void) { unsigned long min, max_low, ma

Spring JDBC查询返回对象代码跟踪

在封装方法的时候突然发现通过 ResultSetMetaData的getColumnCount()获取到的列明会多一列(ROWSTAT),而且每次的值都是1,目前没有找到相关信息,在国外网站上看到有类似的情况,但是都没有人回答.于是想到spring 的JDBC部分是怎么实现映射的,于是通过spring的源代码发现了大致的流程: (这里先说明一下自己得到收获:spring的query查询返回对象T的方法是首先获取要返回对象的所有的writeMethod,也就是set方法,然后存放在一个Proper

__FILE__,__LINE__,FUNCTION__实现代码跟踪调试(linux下c语言编程 )

[email protected]:~/cpropram/2# cat global.h //头文件#ifndef CLOBAL_H        #define GLOBAL_H        #include <stdio.h>        int funca(void);        int funcb(void);#endif[email protected]:~/cpropram/2# cat funca.c //函数a#include "global.h"i

Mac内核XNU的Mach子系统的一个完整过程的代码跟踪

一个完整的mach子系统 mach子系统包括了很多内核功能的实现,比如VM子系统(内存管理).host子系统(主机硬件信息的处理).thread子系统(thread相关实现).exc子系统(异常处理相关):现在拿thread_act为例来跟踪一下代码,希望能够简单地了解vm子系统的概况. (1)thread_act子系统的实现分为两部分: thread_actServer.c和thread_actUser.c,分别实现了内核中mach msg消息接收和发送的各个API. 基本逻辑是:调用thre

linux kernel i2c底层代码跟踪

其实跟上次跟的平台总线有关 在arch/arm/mach-mx6/board-mx6q_sabresd.c 文件中 1 static void __init mx6_sabresd_board_init(void) 2 { 3 ... 4 strcpy(mxc_i2c0_board_info[0].type, "wm8962"); 5 mxc_i2c0_board_info[0].platform_data = &wm8962_config_data; 6 7 imx6q_ad

idea调试代码跟踪到tomcat代码里面

在POM.xml文件里面加上如下代码即可: 1 <dependency> 2 <groupId>org.apache.tomcat</groupId> 3 <artifactId>tomcat-catalina</artifactId> 4 <version>8.5.3</version> 5 <scope>provided</scope> 6 </dependency> 原文地址:ht

解决zend studio代码无法自动提示以及代码跟踪函数和变量的问题

zend studio这工具会突然抽风,所有函数方法不能自动提示.下面是一些penngo用过的.收集整理的解决方法. 方法1.在不提示的项目上鼠标右键,打开菜单,选择Build Path->Configure Build Path,在弹出窗口中选择PHP Build Path->Add Folder...,把当前项目添加到build path. 如果函数突然不提示,可以先用这个方法检查build path有没有当前项目.但比较多情况是从外部导入项目(例如svn),会没有build path数据