-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpTaskServer.java
More file actions
66 lines (52 loc) · 2.48 KB
/
HttpTaskServer.java
File metadata and controls
66 lines (52 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package http;
import com.sun.net.httpserver.HttpServer;
import http.handler.*;
import managers.Managers;
import managers.TaskManager;
import tasks.Epic;
import tasks.SubTask;
import tasks.Task;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.time.LocalDateTime;
public class HttpTaskServer {
public static final int PORT = 8080;
public final HttpServer httpServer;
public final TaskManager manager;
public HttpTaskServer(TaskManager manager) throws IOException {
this.manager = manager;
httpServer = HttpServer.create(new InetSocketAddress("localhost", PORT), 0);
httpServer.createContext("/tasks", new TaskHttpHandler(manager));
httpServer.createContext("/subtasks", new SubTaskHandler(manager));
httpServer.createContext("/epics", new EpicTaskHandler(manager));
httpServer.createContext("/history", new HistoryHandler(manager));
httpServer.createContext("/prioritized", new PrioritizedHandler(manager));
}
public void start() {
httpServer.start();
System.out.println("старт сервера на порту:" + PORT);
}
public void stop() {
httpServer.stop(0);
System.out.println("остановка сервера на порту:" + PORT);
}
public static void main(String[] args) throws IOException {
Task task1 = new Task("задача_5", "описание задачи_5", LocalDateTime.now().plusHours(2), 15);
Task task2 = new Task("задача_6", "описание задачи_6", LocalDateTime.now().plusHours(1), 25);
Epic epic1 = new Epic("эпик_7", "описание эпик_7");
Epic epic2 = new Epic("эпик_8", "описание эпик_8");
SubTask subTask1 = new SubTask("subtask1", "подзадача epic3", 3, LocalDateTime.now().plusHours(5), 25);
SubTask subTask2 = new SubTask("subtask2", "подзадача epic3", 3, LocalDateTime.now().plusHours(10), 225);
SubTask subTask3 = new SubTask("subtask3", "подзадача epic3", 3, LocalDateTime.now().plusHours(6), 25);
TaskManager manager = Managers.getDefault();
manager.newTack(task1);
manager.newTack(task2);
manager.newEpic(epic1);
manager.newEpic(epic2);
manager.newSubTask(subTask1);
manager.newSubTask(subTask2);
manager.newSubTask(subTask3);
HttpTaskServer taskServer = new HttpTaskServer(manager);
taskServer.start();
}
}