public void addChannel(SocketChannel channel) {

        // judge current connected channels is saturated
        if (sharedChannels.size() < SHAREDS) {
            String k = channel.socket().getRemoteSocketAddress().toString();
            System.out.println("As shared channel: " + channel.socket().getRemoteSocketAddress());
            sharedChannels.put(k, channel);
        } else {
            List<String> sharedKeys = new ArrayList(sharedChannels.keySet());
            if (replicationChannels.size() == 0) {

                // hasn't a replication
                List<SocketChannel> reList = new ArrayList<SocketChannel>();
                reList.add(channel);
                String sharedKey = sharedKeys.get(0);
                System.out
                        .println("As replication channel: " + channel.socket().getRemoteSocketAddress() + " of " + sharedKey + " shared channel---");
                replicationChannels.put(sharedKey, reList);
            } else {
                boolean allHasRepli = true;
                for (String sharedKey : sharedKeys) {
                    if (!replicationChannels.containsKey(sharedKey)) {

                        // current shared has not replication
                        allHasRepli = false;
                        List<SocketChannel> reList = new ArrayList<SocketChannel>();
                        reList.add(channel);
                        System.out.println("As replication channel: " + channel.socket().getRemoteSocketAddress() + " of " + sharedKey
                                + " shared channel---");
                        replicationChannels.put(sharedKey, reList);
                        break;
                    }
                }

                // all shared has replication
                if (allHasRepli) {

                    // judge every replication size
                    String smallSharedKey = "";
                    int smallSize = Integer.MAX_VALUE;
                    for (String sharedKey : sharedKeys) {
                        List<SocketChannel> chs = replicationChannels.get(sharedKey);
                        if (chs != null) {
                            if (chs.size() < smallSize) {
                                smallSize = chs.size();
                                smallSharedKey = sharedKey;
                            }
                        }
                    }
                    List<SocketChannel> chs = replicationChannels.get(smallSharedKey);
                    if (chs != null) {
                        System.out.println("As replication channel: " + channel.socket().getRemoteSocketAddress() + " of " + smallSharedKey
                                + " shared channel---");
                        chs.add(channel);
                    }
                }
            }
        }
    }