// Path: src/main/java/io/hosuaby/restful/controllers/TeapotCommandController.java
// @RestController
// @RequestMapping("/actions/teapots")
// public class TeapotCommandController {
// 
//     /** Teapot CRUD service */
//     @Autowired
//     private TeapotCrudService crud;
// 
//     /** Teapot command service */
//     @Autowired
//     private TeapotCommandService commandService;
// 
//     /** Port holder */
//     @Autowired
//     private PortHolder portHolder;
// 
//     @RequestMapping(
//             value = "/{id}/startup",
//             method = RequestMethod.POST)
//     public void startup(@PathVariable String id)
//             throws TeapotNotExistsException, URISyntaxException,
//                 DeploymentException, IOException {
// 
//         /* Get teapot */
//         Teapot teapot = crud.find(id);
// 
//         /* Start teapot simulator */
//         TeapotSimulator simulator = new TeapotSimulator(
//                 teapot, portHolder.getPort());
//     }
// 
//     @RequestMapping(
//             value = "/{id}/shutdown",
//             method = RequestMethod.POST)
//     public void shutdown(@PathVariable String id)
//             throws IOException, TeapotNotConnectedException {
//         commandService.shutdown(id);
//     }
// 
//     @RequestMapping(
//             value = "/{teapotId}/cli",
//             method = RequestMethod.POST)
//     public DeferredResult<String> executeCommand(
//             @PathVariable String teapotId,
//             @RequestParam(required = true) String cmd,
//             HttpServletRequest req) throws IOException {
//         return commandService.sendMessage(req, teapotId, cmd);
//     }
// 
// }
// 
// Path: src/main/java/io/hosuaby/restful/services/exceptions/teapots/TeapotNotConnectedException.java
// public class TeapotNotConnectedException extends Exception {
// 
//     /**
//      * When teapot with defined id not exists.
//      */
//     private static final String ERR_TEAPOT_NOT_CONNECTED = "Teapot with id \"%s\" not connected to server";
// 
//     /**
//      * Serial ID.
//      */
//     private static final long serialVersionUID = 3484631448010563705L;
// 
//     /**
//      * Constructor from teapot id.
//      *
//      * @param teapotId    teapot id
//      */
//     public TeapotNotConnectedException(String teapotId) {
//         super(String.format(ERR_TEAPOT_NOT_CONNECTED, teapotId));
//     }
// 
// }


import io.hosuaby.restful.controllers.TeapotCommandController;
import io.hosuaby.restful.services.exceptions.teapots.TeapotNotConnectedException;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.socket.WebSocketSession;
package io.hosuaby.restful.services;





/**
 * Service that provides registration of teapots and communication with them via
 * web socket sessions.
 */
public interface TeapotCommandService {

    /**
     * Registers a newly connected teapot with associated websocket connection.
     *
     * @param teapotId    teapot id
     * @param session     teapot websocket session
     */
    void register(String teapotId, WebSocketSession session);

    /**
     * Unregisters disconnected teapot. This method don't close teapot session.
     * Teapot session must be closed prior to call of this method. Teapot must
     * be registered prior to call of this method.
     *
     * @param teapotSession    teapot websocket session
     */
    void unregister(WebSocketSession teapotSession);

    /**
     * Shutdown the connected teapot. This method is called by
     * {@link TeapotCommandController}.
     *
     * @param teapotId    teapot id.
     *
     * @throws IOException
     *      failed to close teapot session
     * @throws TeapotNotConnectedException
     *      teapot with defined id is not connected
     */
    void shutdown(String teapotId) throws IOException,
// Path: src/main/java/io/hosuaby/restful/controllers/TeapotCommandController.java
// @RestController
// @RequestMapping("/actions/teapots")
// public class TeapotCommandController {
// 
//     /** Teapot CRUD service */
//     @Autowired
//     private TeapotCrudService crud;
// 
//     /** Teapot command service */
//     @Autowired
//     private TeapotCommandService commandService;
// 
//     /** Port holder */
//     @Autowired
//     private PortHolder portHolder;
// 
//     @RequestMapping(
//             value = "/{id}/startup",
//             method = RequestMethod.POST)
//     public void startup(@PathVariable String id)
//             throws TeapotNotExistsException, URISyntaxException,
//                 DeploymentException, IOException {
// 
//         /* Get teapot */
//         Teapot teapot = crud.find(id);
// 
//         /* Start teapot simulator */
//         TeapotSimulator simulator = new TeapotSimulator(
//                 teapot, portHolder.getPort());
//     }
// 
//     @RequestMapping(
//             value = "/{id}/shutdown",
//             method = RequestMethod.POST)
//     public void shutdown(@PathVariable String id)
//             throws IOException, TeapotNotConnectedException {
//         commandService.shutdown(id);
//     }
// 
//     @RequestMapping(
//             value = "/{teapotId}/cli",
//             method = RequestMethod.POST)
//     public DeferredResult<String> executeCommand(
//             @PathVariable String teapotId,
//             @RequestParam(required = true) String cmd,
//             HttpServletRequest req) throws IOException {
//         return commandService.sendMessage(req, teapotId, cmd);
//     }
// 
// }
// 
// Path: src/main/java/io/hosuaby/restful/services/exceptions/teapots/TeapotNotConnectedException.java
// public class TeapotNotConnectedException extends Exception {
// 
//     /**
//      * When teapot with defined id not exists.
//      */
//     private static final String ERR_TEAPOT_NOT_CONNECTED = "Teapot with id \"%s\" not connected to server";
// 
//     /**
//      * Serial ID.
//      */
//     private static final long serialVersionUID = 3484631448010563705L;
// 
//     /**
//      * Constructor from teapot id.
//      *
//      * @param teapotId    teapot id
//      */
//     public TeapotNotConnectedException(String teapotId) {
//         super(String.format(ERR_TEAPOT_NOT_CONNECTED, teapotId));
//     }
// 
// }


// Path: src/main/java/io/hosuaby/restful/services/TeapotCommandService.java
import io.hosuaby.restful.controllers.TeapotCommandController;
import io.hosuaby.restful.services.exceptions.teapots.TeapotNotConnectedException;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.request.async.DeferredResult;
import org.springframework.web.socket.WebSocketSession;

package io.hosuaby.restful.services;





/**
 * Service that provides registration of teapots and communication with them via
 * web socket sessions.
 */
public interface TeapotCommandService {

    /**
     * Registers a newly connected teapot with associated websocket connection.
     *
     * @param teapotId    teapot id
     * @param session     teapot websocket session
     */
    void register(String teapotId, WebSocketSession session);

    /**
     * Unregisters disconnected teapot. This method don't close teapot session.
     * Teapot session must be closed prior to call of this method. Teapot must
     * be registered prior to call of this method.
     *
     * @param teapotSession    teapot websocket session
     */
    void unregister(WebSocketSession teapotSession);

    /**
     * Shutdown the connected teapot. This method is called by
     * {@link TeapotCommandController}.
     *
     * @param teapotId    teapot id.
     *
     * @throws IOException
     *      failed to close teapot session
     * @throws TeapotNotConnectedException
     *      teapot with defined id is not connected
     */
    void shutdown(String teapotId) throws IOException,
            TeapotNotConnectedException;