-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathServiceManager.java
More file actions
70 lines (59 loc) · 1.71 KB
/
ServiceManager.java
File metadata and controls
70 lines (59 loc) · 1.71 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
67
68
69
70
package dev.tomr.hcloud.service;
import dev.tomr.hcloud.service.action.ActionService;
import dev.tomr.hcloud.service.server.ServerService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class ServiceManager {
private static ServiceManager instance;
private final ServerService serverService;
private final ActionService actionService;
private ExecutorService executor;
private ServiceManager() {
instance = this;
this.serverService = new ServerService(this);
this.actionService = new ActionService();
}
/**
* Get the ServiceManager Instance (Singleton)
* @return The {@code ServiceManager} Instance
*/
public static ServiceManager getInstance() {
if (instance == null) {
new ServiceManager();
}
return instance;
}
/**
* Get ServerService Instance
* @return the {@code ServerService} instance
*/
public ServerService getServerService() {
return serverService;
}
/**
* Get ActionService Instance
* @return the {@code ActionService} instance
*/
public ActionService getActionService() {
return actionService;
}
/**
* Get an Executor for threaded tasks
* @return The Existing or a new {@code ExecutorService}
*/
public ExecutorService getExecutor() {
if (executor == null) {
executor = Executors.newFixedThreadPool(4);
}
return executor;
}
/**
* Close the current Executor and remove it from memory
*/
public void closeExecutor() {
if (executor != null) {
executor.shutdown();
executor = null;
}
}
}