接:深入阅读Mina源码(3) —— Mina之IOAdapter(一))
4. AbstractPollingIoAcceptor
这个类在org.apache.mina.core.polling,这个包一共有四个类,这个类就可以代表整个包的内容了,细致说一下,之后就不再深入介绍这个包了。从名字可以看出包里面的类主要完成轮询。
AbstractPollingIoAcceptor主要完成了AbstractIoAcceptor定义的实际实现方法,如unbind0、bindInternal、dispose0,另外下方了一些更细致的accept、open、select、colse方法让子类实现,也清晰的可以看出它主要为Socket提供父类的一些实现,同时也有了NIO的影子。
看一下AbstractPollingIoAcceptor的属性字段,可以看到
- /** A lock used to protect the selector to be waked up before it's created */
- private final Semaphore lock = new Semaphore(1);
- private final IoProcessor<S> processor;
- private final boolean createdProcessor;
- private final Queue<AcceptorOperationFuture> registerQueue = new ConcurrentLinkedQueue<AcceptorOperationFuture>();
- private final Queue<AcceptorOperationFuture> cancelQueue = new ConcurrentLinkedQueue<AcceptorOperationFuture>();
- private final Map<SocketAddress, H> boundHandles = Collections.synchronizedMap(new HashMap<SocketAddress, H>());
- private final ServiceOperationFuture disposalFuture = new ServiceOperationFuture();
- /** A flag set when the acceptor has been created and initialized */
- private volatile boolean selectable;
- /** The thread responsible of accepting incoming requests */
- private AtomicReference<Acceptor> acceptorRef = new AtomicReference<Acceptor>();
- protected boolean reuseAddress = false;
- /**
- * Define the number of socket that can wait to be accepted. Default
- * to 50 (as in the SocketServer default).
- */
- protected int backlog = 50;