public static void main(String[] args) {

		ProcessManager manager = new ProcessManager();

		try {
			ServerSocket master = new ServerSocket(SERVER_PORT);

			outer: while (true) {
				/*
				 * The process managers is polling for connections
				 */
				Socket connection = master.accept();
				System.out.println("connected");
				ObjectInputStream in = new ObjectInputStream(
						connection.getInputStream());
				Object o = in.readObject();
				ProcessMessage message = (ProcessMessage) o;
				OutputStream out = connection.getOutputStream();

				/*
				 * After receiving a message, the process manager behave
				 * according to the message
				 */

				switch (message.getMessage()) {
				case LAUNCH:
					/*
					 * The manager launches a process when receiving "launch"
					 * and give back the assigned pId
					 */
					int assignedId = manager.launch(message.getClassName(),
							message.getArgs());
					out.write(assignedId);
					break;
				case MIGRATE:
					/*
					 * The manager migrate the process
					 */
					manager.migrate(message.getpId());
					break;
				case SUSPEND:
					/*
					 * Suspend the process with the given ID
					 */
					manager.sendMessage(message.getpId(), Message.SUSPEND);
					break;
				case RESTART:
					/*
					 * Restart the process with the given ID
					 */
					manager.sendMessage(message.getpId(), Message.RESTART);
					break;
				case STOP:
					/*
					 * the process manager process stops upon receiving message
					 * /* of "STOP
					 */
					break outer;
				default:
					break;
				}

				connection.close();

			}

			/*
			 * Clean Up
			 */

			for (Process p : manager.runningNodes) {
				p.destroy();
			}
			master.close();

		} catch (IOException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}

	}