/**
   * Initializes the serversocket and the multiplexer.
   *
   * @param selectorCreator The selector creator that will be used for creating a selector for the
   *     multiplexer.
   */
  private void init(SelectorCreator selectorCreator) {
    try {
      ServerSocketChannel channel = ServerSocketChannel.open();
      ServerSocket serverSocket = channel.socket();

      // Set the preference to bandwidth > short connection time && latency (only large messages
      // will be send / received here).
      serverSocket.setPerformancePreferences(0, 0, 2);

      serverSocket.bind(null);
      Config.setUsingPort(serverSocket.getLocalPort());

      channel.configureBlocking(false);
      selector = selectorCreator.getSelector();
      channel.register(selector, SelectionKey.OP_ACCEPT);

      ToolDataHandlerFactory toolDataHandlerFactory =
          new ToolDataHandlerFactory(InterToolDataHandler.class);
      multiplexer =
          new MultiThreadedMultiplexer(
              selectorCreator, Multiplexer.SERVERMODE, toolDataHandlerFactory);
      multiplexer.setDaemon(true);
      multiplexer.start();
    } catch (IOException ioex) {
      Logger.getInstance()
          .log(
              "An IOException occured while initializing the MultiplexingClientServer.",
              Logger.ERROR,
              ioex);
    }
  }
  /**
   * Constructor.
   *
   * @param selectorCreator The selectorCreator that contains the selector is used for activity
   *     notifications.
   * @param mode The 'mode' this multiplexer is running in (server/client mode, servers are also
   *     capable of accepting incoming connections).
   * @param toolDataHandlerFactory A factory for creating tooldataHandlers (only needed when running
   *     in server mode).
   */
  public MultiThreadedMultiplexer(
      SelectorCreator selectorCreator, byte mode, ToolDataHandlerFactory toolDataHandlerFactory) {
    super(selectorCreator, mode, toolDataHandlerFactory);

    threadPool = new BlockingThreadPool(Config.getNrOfConcurrentThreads(), true);

    this.selectorCreator = selectorCreator;
  }