Skip to content

Commit 4df77bf

Browse files
committed
Add abstract API with documentation
1 parent 2e0e867 commit 4df77bf

32 files changed

+552
-116
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package fr.epsilon.api;
2+
3+
import fr.epsilon.api.informer.EInstanceInformer;
4+
import fr.epsilon.api.instance.EInstance;
5+
import fr.epsilon.api.instance.EInstanceModule;
6+
import fr.epsilon.api.queue.EQueueModule;
7+
import fr.epsilon.api.template.ETemplate;
8+
9+
import java.util.concurrent.CompletableFuture;
10+
11+
public abstract class EpsilonAPI {
12+
private static EpsilonAPI singleton;
13+
14+
/**
15+
* Get EpsilonAPI from singleton
16+
*
17+
* @return Epsilon API
18+
*/
19+
public static EpsilonAPI get() {
20+
return singleton;
21+
}
22+
23+
/**
24+
* Run instance informer
25+
* This allows instances to be cached and retrieved synchronously.
26+
* However, with this technique certain fields of the instance are not updated in real time.
27+
* Such as the number of players online.
28+
*
29+
* @return Instance informer for get instance from store
30+
*/
31+
public abstract EInstanceInformer runInstanceInformer();
32+
33+
/**
34+
* Get current instance name
35+
*
36+
* @return Instance name of current instance
37+
*/
38+
public abstract String name();
39+
40+
/**
41+
* Get current template
42+
*
43+
* @return Template of current instance
44+
*/
45+
public abstract ETemplate template();
46+
47+
/**
48+
* Get current instance from CompletableFuture
49+
*
50+
* @return CompletableFuture of current instance
51+
*/
52+
public abstract CompletableFuture<? extends EInstance> instance();
53+
54+
/**
55+
* InstanceModule for interact with Epsilon instance
56+
*
57+
* @return InstanceModule
58+
*/
59+
public abstract EInstanceModule instanceModule();
60+
61+
/**
62+
* QueueModule for interact with Epsilon queue
63+
*
64+
* @return QueueModule
65+
*/
66+
public abstract EQueueModule queueModule();
67+
68+
public EpsilonAPI() {
69+
singleton = this;
70+
}
71+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package fr.epsilon.api.informer;
2+
3+
import fr.epsilon.api.instance.EInstance;
4+
import fr.epsilon.api.instance.EType;
5+
6+
public abstract class EInstanceInformer {
7+
/**
8+
* Get instance stored in informer
9+
* Some instance information may be outdated like online count
10+
*
11+
* @param name Instance name
12+
* @return Instance
13+
*/
14+
public abstract EInstance getInstance(String name);
15+
16+
/**
17+
* Get instances array stored in informer
18+
* Some template information may be outdated like online count
19+
*
20+
* @return All instances
21+
*/
22+
public abstract EInstance[] getInstances();
23+
24+
/**
25+
* Get instances array stored in informer filtered by template name
26+
* Some template information may be outdated like online count
27+
*
28+
* @param template Template name
29+
* @return All instances for specified template
30+
*/
31+
public abstract EInstance[] getInstances(String template);
32+
33+
/**
34+
* Get instances array stored in informer filtered by instance type
35+
* Some template information may be outdated like online count
36+
*
37+
* @param type Instance type
38+
* @return All instances for specified instance type
39+
*/
40+
public abstract EInstance[] getInstances(EType type);
41+
42+
/**
43+
* Register listener for watch new instance created and deleted
44+
*
45+
* @param listener Listener object
46+
*/
47+
public abstract void registerListener(EInstanceInformerListener listener);
48+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package fr.epsilon.api.informer;
2+
3+
import fr.epsilon.api.instance.EInstance;
4+
5+
public interface EInstanceInformerListener {
6+
void onInstanceUpdate(EInstance instance);
7+
8+
void onInstanceRemove(EInstance instance);
9+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package fr.epsilon.api.instance;
2+
3+
public abstract class EInstance {
4+
/**
5+
* Get instance name
6+
*
7+
* @return Name of instance
8+
*/
9+
public abstract String getName();
10+
11+
/**
12+
* Get template name
13+
*
14+
* @return Template name of instance
15+
*/
16+
public abstract String getTemplate();
17+
18+
/**
19+
* Get content with GSON
20+
*
21+
* @param classType Class type used for deserialization
22+
* @return Content object of instance
23+
*/
24+
public abstract <T> T getContent(Class<T> classType);
25+
26+
/**
27+
* Get if instance is hub
28+
*
29+
* @return Instance is hub or not
30+
*/
31+
public abstract boolean isHub();
32+
33+
/**
34+
* Get type
35+
*
36+
* @return Type of instance
37+
*/
38+
public abstract EType getType();
39+
40+
/**
41+
* Get state
42+
*
43+
* @return State of instance
44+
*/
45+
public abstract EState getState();
46+
47+
/**
48+
* Get slots
49+
*
50+
* @return Slots of instance
51+
*/
52+
public abstract int getSlots();
53+
54+
/**
55+
* Get online counts
56+
*
57+
* @return Online counts of instance
58+
*/
59+
public abstract int getOnlineCount();
60+
61+
/**
62+
* Get local ip address
63+
*
64+
* @return Ip Address of instance
65+
*/
66+
public abstract String getLocalIp();
67+
68+
/**
69+
* Enable EState.InGame
70+
*
71+
* @return Instance EState.InGame enable correctly or not
72+
*/
73+
public abstract boolean enableInGame();
74+
75+
/**
76+
* Close instance
77+
*
78+
* @return Instance close correctly or not
79+
*/
80+
public abstract boolean close();
81+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package fr.epsilon.api.instance;
2+
3+
import java.util.concurrent.CompletableFuture;
4+
5+
public abstract class EInstanceModule {
6+
/**
7+
* Get instance from CompletableFuture
8+
*
9+
* @param name Instance name
10+
* @return CompletableFuture of instance
11+
*/
12+
public abstract CompletableFuture<? extends EInstance> getInstance(String name);
13+
14+
/**
15+
* Get instances array from CompletableFuture
16+
*
17+
* @return CompletableFuture of all instances
18+
*/
19+
public abstract CompletableFuture<? extends EInstance[]> getInstances();
20+
21+
/**
22+
* Get instances array filtered by template name from CompletableFuture
23+
*
24+
* @param template Template name
25+
* @return CompletableFuture of all instances for specified template
26+
*/
27+
public abstract CompletableFuture<? extends EInstance[]> getInstances(String template);
28+
29+
/**
30+
* Get instances arrays filtered by instance type from CompletableFuture
31+
*
32+
* @param type Instance type
33+
* @return CompletableFuture of all instances for specified instance type
34+
*/
35+
public abstract CompletableFuture<? extends EInstance[]> getInstances(EType type);
36+
37+
/**
38+
* Open instance with template name
39+
*
40+
* @param template Template name
41+
* @return Instance opened correctly or not
42+
*/
43+
public abstract boolean openInstance(String template);
44+
45+
/**
46+
* Open instance with template name
47+
*
48+
* @param template Template name
49+
* @param content Content field of instance
50+
* @return Instance opened correctly or not
51+
*/
52+
public abstract <T> boolean openInstance(String template, T content);
53+
54+
/**
55+
* Close instance
56+
*
57+
* @param name Instance name
58+
* @return Instance closed correctly or not
59+
*/
60+
public abstract boolean closeInstance(String name);
61+
62+
/**
63+
* Enable EState.InGame on instance
64+
*
65+
* @param name Instance name
66+
* @return Instance EState.InGame enabled correctly
67+
*/
68+
public abstract boolean inGameInstance(String name);
69+
}

common/src/main/java/fr/epsilon/common/instance/EState.java renamed to api/src/main/java/fr/epsilon/api/instance/EState.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package fr.epsilon.common.instance;
1+
package fr.epsilon.api.instance;
22

33
public enum EState {
44
Starting, Running, InGame, Stopping

common/src/main/java/fr/epsilon/common/instance/EType.java renamed to api/src/main/java/fr/epsilon/api/instance/EType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package fr.epsilon.common.instance;
1+
package fr.epsilon.api.instance;
22

33
public enum EType {
44
Server, Proxy
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package fr.epsilon.api.queue;
2+
3+
import java.util.List;
4+
5+
public abstract class EQueueModule {
6+
/**
7+
* Join queue alone
8+
*
9+
* @param username Username of player
10+
* @param queue Queue name
11+
* @return Player queued correctly or not
12+
*/
13+
public abstract boolean join(String username, String queue);
14+
15+
/**
16+
* Join queue group
17+
*
18+
* @param usernames List of usernames in group
19+
* @param queue Queue name
20+
* @return Players queued correctly or not
21+
*/
22+
public abstract boolean join(List<String> usernames, String queue);
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package fr.epsilon.api.template;
2+
3+
public abstract class EResources {
4+
/**
5+
* Get minimum resource of instance
6+
*
7+
* @return Minimum resource
8+
*/
9+
public abstract EResource getMinimum();
10+
11+
/**
12+
* Get maximum resource of instance
13+
*
14+
* @return Maximum resource
15+
*/
16+
public abstract EResource getMaximum();
17+
18+
public static class EResource {
19+
private int cpu;
20+
private int ram;
21+
}
22+
}

0 commit comments

Comments
 (0)