public static void main(String[] args) throws IOException, InterruptedException {

        System.out.println("Server started. For exit write " + '\"' + COMMAND_EXIT + '\"');
        startServerSocketListener();
        startActivityDeathListener();

        try {
            chatHistory.addMessageList(DbFactory.getMessages());
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            while (true) {
                String line = in.readLine();
                if (COMMAND_EXIT.equalsIgnoreCase(line)) {
                    for (Activity activity : activityMap.values()) {
                        activity.kill();
                    }
                    break;
                } else if (line != null && !line.equals("")) {
                    Message message = new Message(line);
                    DbFactory.saveMessage(message);
                    chatHistory.addMessage(message);
                    for (Activity activity : activityMap.values()) {
                        activity.sendMessage(new Message(line));
                    }
                }
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DbFactory.close();
            if (serverSocket != null) serverSocket.close();
        }
    }