forked from jooby-project/jooby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerProvider.java
More file actions
44 lines (35 loc) · 1.12 KB
/
Copy pathServerProvider.java
File metadata and controls
44 lines (35 loc) · 1.12 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
package io.jooby.junit;
import static java.util.stream.StreamSupport.stream;
import java.util.ServiceLoader;
import java.util.function.Supplier;
import io.jooby.Server;
import io.jooby.jetty.Jetty;
import io.jooby.netty.Netty;
import io.jooby.utow.Utow;
public class ServerProvider implements Supplier<Server> {
private Class serverClass;
public ServerProvider(Class serverClass) {
this.serverClass = serverClass;
}
public boolean matchesEventLoopThread(String threadName) {
if (serverClass == Jetty.class) {
return threadName.startsWith("worker-");
}
if (serverClass == Netty.class) {
return threadName.startsWith("eventloop");
}
if (serverClass == Utow.class) {
return threadName.startsWith("worker I/O");
}
return false;
}
public String getName() {
return serverClass.getSimpleName();
}
@Override public Server get() {
return stream(ServiceLoader.load(Server.class).spliterator(), false)
.filter(s -> serverClass.isInstance(s))
.findFirst()
.orElseThrow(() -> new IllegalArgumentException("Server not found: " + serverClass));
}
}