forked from polis-vk/2024-highload-dht
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServiceImpl.java
46 lines (37 loc) · 1.31 KB
/
ServiceImpl.java
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
package ru.vk.itmo.test.volkovnikita;
import ru.vk.itmo.Service;
import ru.vk.itmo.ServiceConfig;
import ru.vk.itmo.dao.Config;
import ru.vk.itmo.test.ServiceFactory;
import ru.vk.itmo.test.reference.dao.ReferenceDao;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
public class ServiceImpl implements Service {
public static final long FLUSH_THRESHOLD_BYTES = 4 * 1024L;
private HttpServerImpl server;
private final ServiceConfig config;
private ReferenceDao dao;
public ServiceImpl(ServiceConfig config) {
this.config = config;
}
@Override
public synchronized CompletableFuture<Void> start() throws IOException {
dao = new ReferenceDao(new Config(config.workingDir(), FLUSH_THRESHOLD_BYTES));
server = new HttpServerImpl(config, dao);
server.start();
return CompletableFuture.completedFuture(null);
}
@Override
public synchronized CompletableFuture<Void> stop() throws IOException {
server.stop();
dao.close();
return CompletableFuture.completedFuture(null);
}
@ServiceFactory(stage = 1)
public static class Factory implements ServiceFactory.Factory {
@Override
public Service create(ServiceConfig config) {
return new ServiceImpl(config);
}
}
}