mina一些理解

男人总是寂寞的,尤其是周末的晚上!
今夜寂寞难耐下了mina源码,写了写mina的小程序,顺便把源码也设置进去,写完后就开始ctrl+t,ctrl+左机,看看这个mina是怎么回事


5个接口:
1.IoConnector 理解成客户端好了
2.IoAcceptor 服务器端
3.IoSession 链接实例
4.IoHandler 业务处理
5.IoFilter 过滤器,悬接通讯层与业务层


先说服务端NioSocketAcceptor,声明为final,继承自AbstractPollingIoAccptor,并实现SocketAcceptor,是mina实现通信的实现类之一,还有DatagramAccepter,VmPipeAccepter.

mina2.0的线程池,我只看了NioSocketAccptor这块,

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


调用父类的构造方法,将要设置的容量传近去

AbstractPollingIoAccptor再调用自己的私有构造方法

protected AbstractPollingIoAcceptor(IoSessionConfig sessionConfig,
Class<? extends IoProcessor<T>> processorClass, int processorCount) {
this(sessionConfig, null, new SimpleIoProcessorPool<T>(processorClass,
processorCount), true);
}

//调用父类的构造方法


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

if (processor == null) {
throw new NullPointerException("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);
}
}
}
}


//AbstractIoAcceptor


protected AbstractIoAcceptor(IoSessionConfig sessionConfig, Executor executor) {
super(sessionConfig, executor);
defaultLocalAddresses.add(null);
}


//AbstractIoService

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

if (getTransportMetadata() == null) {
throw new NullPointerException("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();
}


终于明白2.0说的线程池不需要设置的原因。。。。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值