// Path: src/main/java/octopus/api/shell/ShellManager.java
// public class ShellManager {
// 
// 	public List<OctopusGremlinShell> getActiveShells()
// 	{
// 		return OctopusShellManager.getActiveShells();
// 	}
// 
// 	public int createNewShellThread(String projectName, String shellName) throws IOException
// 	{
// 		int port = OctopusShellManager.createNewShell(projectName, shellName);
// 		OctopusGremlinShell shell = OctopusShellManager.getShellForPort(port);
// 		startShellThread(shell);
// 		return port;
// 	}
// 
// 	private void startShellThread(OctopusGremlinShell shell) throws IOException
// 	{
// 		ShellRunnable runnable = new ShellRunnable(shell);
// 		Thread thread = new Thread(runnable);
// 		thread.start();
// 	}
// 
// }
// 
// Path: src/main/java/octopus/server/restServer/OctopusRestHandler.java
// public interface OctopusRestHandler {
// 
// 	public Object handle(Request req, Response resp);
// 
// }


import java.io.IOException;
import octopus.api.shell.ShellManager;
import octopus.server.restServer.OctopusRestHandler;
import spark.Request;
import spark.Response;
package octopus.server.restServer.handlers;



public class CreateShellHandler implements OctopusRestHandler {

	String projectName;
	String shellName;

	@Override
	public Object handle(Request req, Response resp) {

		extractParameters(req);
		int port = createNewShell();
		return String.format("%d\n", port);
	}

	private void extractParameters(Request req)
	{
		projectName = req.params(":projectName");
		shellName = req.params(":shellname");
	}

	private int createNewShell()
	{
		int port;
		try {
// Path: src/main/java/octopus/api/shell/ShellManager.java
// public class ShellManager {
// 
// 	public List<OctopusGremlinShell> getActiveShells()
// 	{
// 		return OctopusShellManager.getActiveShells();
// 	}
// 
// 	public int createNewShellThread(String projectName, String shellName) throws IOException
// 	{
// 		int port = OctopusShellManager.createNewShell(projectName, shellName);
// 		OctopusGremlinShell shell = OctopusShellManager.getShellForPort(port);
// 		startShellThread(shell);
// 		return port;
// 	}
// 
// 	private void startShellThread(OctopusGremlinShell shell) throws IOException
// 	{
// 		ShellRunnable runnable = new ShellRunnable(shell);
// 		Thread thread = new Thread(runnable);
// 		thread.start();
// 	}
// 
// }
// 
// Path: src/main/java/octopus/server/restServer/OctopusRestHandler.java
// public interface OctopusRestHandler {
// 
// 	public Object handle(Request req, Response resp);
// 
// }


// Path: src/main/java/octopus/server/restServer/handlers/CreateShellHandler.java
import java.io.IOException;
import octopus.api.shell.ShellManager;
import octopus.server.restServer.OctopusRestHandler;
import spark.Request;
import spark.Response;

package octopus.server.restServer.handlers;



public class CreateShellHandler implements OctopusRestHandler {

	String projectName;
	String shellName;

	@Override
	public Object handle(Request req, Response resp) {

		extractParameters(req);
		int port = createNewShell();
		return String.format("%d\n", port);
	}

	private void extractParameters(Request req)
	{
		projectName = req.params(":projectName");
		shellName = req.params(":shellname");
	}

	private int createNewShell()
	{
		int port;
		try {
			port = (new ShellManager()).createNewShellThread(projectName, shellName);