@Override
	public void run() {
		// keep receiving messages and handling them. handlers are supposed to
		// send the acknowledgement message
		try {
			outputStream = new ObjectOutputStream(
					connectionSocket.getOutputStream());
			inputStream = new ObjectInputStream(
					connectionSocket.getInputStream());
			messageHandler = new ServerMessageHandler(this);
			Message message = (Message) inputStream.readObject();
			while (message != null) {
				// TODO: improve message handling to non-blocking
				messageHandler.handleMessage(message);
				message = (Message) inputStream.readObject();
			}
		} catch (IOException e) {
			// error trying to receive a new message. This means some network
			// problem occurred OR the remote socket was closed
			ServerLogger.error(Server.class,
					"Error on main server loop. Shutting server down.", e);

		} catch (ClassNotFoundException e) {
			ServerLogger
					.error(Server.class,
							"Unable to determine the class of received object. Shutting server down.",
							e);
		} finally {
			close();
		}

	}