class NettyServer extends AbstractServer implements StatisticCallback {
    // default io thread is Runtime.getRuntime().availableProcessors() * 2
    private final static ChannelFactory channelFactory = new NioServerSocketChannelFactory(
            Executors.newCachedThreadPool(new DefaultThreadFactory("nettyServerBoss", true)),
            Executors.newCachedThreadPool(new DefaultThreadFactory("nettyServerWorker", true)));
    protected NettyServerChannelManage channelManage = null;
    // 单端口需要对应单executor 1) 为了更好的隔离性 2) 为了防止被动releaseExternalResources:
    private StandardThreadExecutor standardThreadExecutor = null;
    private org.jboss.netty.channel.Channel serverChannel;
    private ServerBootstrap bootstrap;
    private MessageHandler messageHandler;
    private NettyChannelHandler nettyChannelHandler;

    public NettyServer(URL url, MessageHandler messageHandler) {
        super(url);
        this.messageHandler = messageHandler;
    }

    @Override
    public Response request(Request request) throws TransportException {
        throw new MotanFrameworkException("NettyServer request(Request request) method unSupport: url: " + url);
    }

    @Override
    public synchronized boolean open() {
        if (isAvailable()) {
            LoggerUtil.warn("NettyServer ServerChannel already Open: url=" + url);
            return true;
        }

        LoggerUtil.info("NettyServer ServerChannel start Open: url=" + url);

        initServerBootstrap();

        serverChannel = bootstrap.bind(new InetSocketAddress(url.getPort()));
        setLocalAddress((InetSocketAddress) serverChannel.getLocalAddress());
        if (url.getPort() == 0) {
            url.setPort(getLocalAddress().getPort());
        }
        state = ChannelState.ALIVE;

        StatsUtil.registryStatisticCallback(this);
        LoggerUtil.info("NettyServer ServerChannel finish Open: url=" + url);

        return state.isAliveState();
    }

    private synchronized void initServerBootstrap() {
        boolean shareChannel = url.getBooleanParameter(URLParamType.shareChannel.getName(),
                URLParamType.shareChannel.getBooleanValue());
        final int maxContentLength = url.getIntParameter(URLParamType.maxContentLength.getName(),
                URLParamType.maxContentLength.getIntValue());
        int maxServerConnection = url.getIntParameter(URLParamType.maxServerConnection.getName(),
                URLParamType.maxServerConnection.getIntValue());
        int workerQueueSize = url.getIntParameter(URLParamType.workerQueueSize.getName(),
                URLParamType.workerQueueSize.getIntValue());

        int minWorkerThread, maxWorkerThread;

        if (shareChannel) {
            minWorkerThread = url.getIntParameter(URLParamType.minWorkerThread.getName(),
                    MotanConstants.NETTY_SHARECHANNEL_MIN_WORKDER);
            maxWorkerThread = url.getIntParameter(URLParamType.maxWorkerThread.getName(),
                    MotanConstants.NETTY_SHARECHANNEL_MAX_WORKDER);
        } else {
            minWorkerThread = url.getIntParameter(URLParamType.minWorkerThread.getName(),
                    MotanConstants.NETTY_NOT_SHARECHANNEL_MIN_WORKDER);
            maxWorkerThread = url.getIntParameter(URLParamType.maxWorkerThread.getName(),
                    MotanConstants.NETTY_NOT_SHARECHANNEL_MAX_WORKDER);
        }


        standardThreadExecutor = (standardThreadExecutor != null && !standardThreadExecutor.isShutdown()) ? standardThreadExecutor
                : new StandardThreadExecutor(minWorkerThread, maxWorkerThread, workerQueueSize,
                new DefaultThreadFactory("NettyServer-" + url.getServerPortStr(), true));
        standardThreadExecutor.prestartAllCoreThreads();

        // 连接数的管理，进行最大连接数的限制
        channelManage = new NettyServerChannelManage(maxServerConnection);

        bootstrap = new ServerBootstrap(channelFactory);
        bootstrap.setOption("child.tcpNoDelay", true);
        bootstrap.setOption("child.keepAlive", true);

        nettyChannelHandler = new NettyChannelHandler(NettyServer.this, messageHandler, standardThreadExecutor);
        StatsUtil.registryStatisticCallback(nettyChannelHandler);

        // FrameDecoder非线程安全，每个连接一个 Pipeline
        bootstrap.setPipelineFactory(() -> {
            ChannelPipeline pipeline = Channels.pipeline();
            pipeline.addLast("channel_manage", channelManage);
            pipeline.addLast("decoder", new NettyDecoder(codec, NettyServer.this, maxContentLength));
            pipeline.addLast("encoder", new NettyEncoder(codec, NettyServer.this));
            pipeline.addLast("nettyChannelHandler", nettyChannelHandler);
            return pipeline;
        });
    }

    @Override
    public synchronized void close() {
        close(0);
    }

    @Override
    public synchronized void close(int timeout) {<FILL_FUNCTION_BODY>}

    public void cleanup() {
        // close listen socket
        if (serverChannel != null) {
            serverChannel.close();
        }
        // close all client's channel
        if (channelManage != null) {
            channelManage.close();
        }
        // shutdown the threadPool
        if (standardThreadExecutor != null) {
            standardThreadExecutor.shutdownNow();
        }
        // 取消统计回调的注册
        StatsUtil.unRegistryStatisticCallback(nettyChannelHandler);
        StatsUtil.unRegistryStatisticCallback(this);
    }

    @Override
    public boolean isClosed() {
        return state.isCloseState();
    }

    @Override
    public boolean isAvailable() {
        return state.isAliveState();
    }

    @Override
    public URL getUrl() {
        return url;
    }

    /**
     * 统计回调接口
     */
    @Override
    public String statisticCallback() {
        return String.format(
                "identity: %s connectionCount: %s taskCount: %s queueCount: %s maxThreadCount: %s maxTaskCount: %s",
                url.getIdentity(), channelManage.getChannels().size(), standardThreadExecutor.getSubmittedTasksCount(),
                standardThreadExecutor.getQueue().size(), standardThreadExecutor.getMaximumPoolSize(),
                standardThreadExecutor.getMaxSubmittedTaskCount());
    }

    /**
     * 是否已经绑定端口
     */
    @Override
    public boolean isBound() {
        return serverChannel != null && serverChannel.isBound();
    }

    public MessageHandler getMessageHandler() {
        return messageHandler;
    }

    public void setMessageHandler(MessageHandler messageHandler) {
        this.messageHandler = messageHandler;
    }

    @Override
    public Map<String, Object> getRuntimeInfo() {
        Map<String, Object> infos = super.getRuntimeInfo();
        infos.put(RuntimeInfoKeys.CONNECTION_COUNT_KEY, channelManage.getChannels().size());
        infos.put(RuntimeInfoKeys.TASK_COUNT_KEY, standardThreadExecutor.getSubmittedTasksCount());
        infos.putAll(messageHandler.getRuntimeInfo());
        return infos;
    }
}

        if (state.isCloseState()) {
            return;
        }

        try {
            cleanup();
            if (state.isUnInitState()) {
                LoggerUtil.info("NettyServer close fail: state={}, url={}", state.value, url.getUri());
                return;
            }

            // 设置close状态
            state = ChannelState.CLOSE;
            LoggerUtil.info("NettyServer close Success: url={}", url.getUri());
        } catch (Exception e) {
            LoggerUtil.error("NettyServer close Error: url=" + url.getUri(), e);
        }
    
<methods>public void <init>() ,public void <init>(com.weibo.api.motan.rpc.URL) ,public com.weibo.api.motan.transport.Channel getChannel(java.net.InetSocketAddress) ,public Collection<com.weibo.api.motan.transport.Channel> getChannels() ,public java.net.InetSocketAddress getLocalAddress() ,public java.net.InetSocketAddress getRemoteAddress() ,public Map<java.lang.String,java.lang.Object> getRuntimeInfo() ,public void setCodec(com.weibo.api.motan.codec.Codec) ,public void setLocalAddress(java.net.InetSocketAddress) ,public void setRemoteAddress(java.net.InetSocketAddress) ,public void setUrl(com.weibo.api.motan.rpc.URL) <variables>protected com.weibo.api.motan.codec.Codec codec,protected java.net.InetSocketAddress localAddress,protected java.net.InetSocketAddress remoteAddress,protected volatile com.weibo.api.motan.common.ChannelState state,protected com.weibo.api.motan.rpc.URL url