@Override
	public void run() {
		logger.info("start the NioServer");

		while (true) {
			try {
				// / process any pending changes
				synchronized (this.changeRequests) {
					Iterator<ChangeRequest> changes = this.changeRequests.iterator();
					while (changes.hasNext()) {
						ChangeRequest change = changes.next();
						switch (change.type) {
						case ChangeRequest.CHANGEEOPS:
							SelectionKey key = change.socket.keyFor(this.selector);
							key.interestOps(change.ops);
						}
					}
				}

				this.selector.select();

				Iterator<SelectionKey> selectKeys = this.selector.selectedKeys().iterator();
				while (selectKeys.hasNext()) {
					SelectionKey key = selectKeys.next();
					selectKeys.remove();
					logger.debug("selector on key [{}]", key);

					if (!key.isValid()) {
						continue;
					}

					if (key.isAcceptable()) {
						this.accept(key);
					} else if (key.isReadable()) {
						this.read(key);
					} else if (key.isWritable()) {
						this.write(key);
					}
				}

			} catch (Exception e) {
				logger.error("caught an exception in the Selector event loop", e);
			}
		}
	}