Skip to content

Commit 0f264b3

Browse files
committed
Merge branch 'vertx'
2 parents 4d19a3e + c7c74a5 commit 0f264b3

File tree

40 files changed

+1912
-46
lines changed

40 files changed

+1912
-46
lines changed

jooby/src/main/java/io/jooby/Jooby.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ public class Jooby implements Router, Registry {
7777

7878
private static Jooby owner;
7979
private static ExecutionMode BOOT_EXECUTION_MODE = ExecutionMode.DEFAULT;
80-
private static OutputFactory OUTPUT_FACTORY;
81-
private static ServerOptions SERVER_OPTIONS;
80+
private static Server BOOT_SERVER;
8281

8382
private RouterImpl router;
8483

@@ -125,11 +124,18 @@ public Jooby() {
125124
lateExtensions = new ArrayList<>();
126125
// NOTE: fallback to default, this is required for direct instance creation of class
127126
// app bootstrap always ensures server instance.
128-
router.setOutputFactory(Optional.ofNullable(OUTPUT_FACTORY).orElseGet(OutputFactory::create));
129-
router.setServerOptions(Optional.ofNullable(SERVER_OPTIONS).orElseGet(ServerOptions::new));
127+
router.setOutputFactory(
128+
Optional.ofNullable(BOOT_SERVER)
129+
.map(Server::getOutputFactory)
130+
.orElseGet(OutputFactory::create));
131+
router.setServerOptions(
132+
Optional.ofNullable(BOOT_SERVER).map(Server::getOptions).orElseGet(ServerOptions::new));
130133
} else {
131134
copyState(owner, this);
132135
}
136+
if (BOOT_SERVER != null) {
137+
BOOT_SERVER.init(this);
138+
}
133139
}
134140

135141
@NonNull @Override
@@ -874,7 +880,7 @@ public Jooby setStartupSummary(List<StartupSummary> startupSummary) {
874880
* @param server Server.
875881
* @return This application.
876882
*/
877-
public @NonNull Jooby start(@NonNull Server server) {
883+
public Jooby start(@NonNull Server server) {
878884
Path tmpdir = getTmpdir();
879885
ensureTmpdir(tmpdir);
880886

@@ -1301,14 +1307,12 @@ public static Jooby createApp(
13011307

13021308
Jooby app;
13031309
try {
1304-
Jooby.OUTPUT_FACTORY = server.getOutputFactory();
1305-
Jooby.SERVER_OPTIONS = server.getOptions();
1310+
Jooby.BOOT_SERVER = server;
13061311
Jooby.BOOT_EXECUTION_MODE = executionMode;
13071312
app = provider.get();
13081313
} finally {
13091314
Jooby.BOOT_EXECUTION_MODE = executionMode;
1310-
Jooby.OUTPUT_FACTORY = null;
1311-
Jooby.SERVER_OPTIONS = null;
1315+
Jooby.BOOT_SERVER = null;
13121316
}
13131317

13141318
return app;

jooby/src/main/java/io/jooby/Server.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ abstract class Base implements Server {
9797

9898
private final AtomicBoolean stopping = new AtomicBoolean();
9999

100-
private boolean defaultOptions;
101-
102100
protected void fireStart(@NonNull List<Jooby> applications, @NonNull Executor defaultWorker) {
103101
for (Jooby app : applications) {
104102
app.setDefaultWorker(defaultWorker).start(this);
@@ -141,7 +139,11 @@ public Server setOptions(@NonNull ServerOptions options) {
141139
}
142140
}
143141

144-
@NonNull OutputFactory getOutputFactory();
142+
default Server init(Jooby application) {
143+
return this;
144+
}
145+
146+
OutputFactory getOutputFactory();
145147

146148
/**
147149
* Set server options. This method should be called once, calling this method multiple times will
@@ -150,29 +152,29 @@ public Server setOptions(@NonNull ServerOptions options) {
150152
* @param options Server options.
151153
* @return This server.
152154
*/
153-
@NonNull Server setOptions(@NonNull ServerOptions options);
155+
Server setOptions(@NonNull ServerOptions options);
154156

155157
/**
156158
* Get server name.
157159
*
158160
* @return Server name.
159161
*/
160-
@NonNull String getName();
162+
String getName();
161163

162164
/**
163165
* Get server options.
164166
*
165167
* @return Server options.
166168
*/
167-
@NonNull ServerOptions getOptions();
169+
ServerOptions getOptions();
168170

169171
/**
170172
* Start an application.
171173
*
172174
* @param application Application to start.
173175
* @return This server.
174176
*/
175-
@NonNull Server start(@NonNull Jooby... application);
177+
Server start(@NonNull Jooby... application);
176178

177179
/**
178180
* Utility method to turn off odd logger. This helps to ensure same startup log lines across
@@ -182,7 +184,7 @@ public Server setOptions(@NonNull ServerOptions options) {
182184
*
183185
* @return Name of the logs we want to temporarily silent.
184186
*/
185-
default @NonNull List<String> getLoggerOff() {
187+
default List<String> getLoggerOff() {
186188
return emptyList();
187189
}
188190

@@ -191,7 +193,7 @@ public Server setOptions(@NonNull ServerOptions options) {
191193
*
192194
* @return Stop the server.
193195
*/
194-
@NonNull Server stop();
196+
Server stop();
195197

196198
/**
197199
* Add a connection lost predicate. On unexpected exception, this method allows to customize which

modules/jooby-netty/src/main/java/io/jooby/internal/netty/NettyEventLoopGroup.java renamed to modules/jooby-netty/src/main/java/io/jooby/internal/netty/NettyEventLoopGroupImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77

88
import java.util.concurrent.TimeUnit;
99

10+
import io.jooby.netty.NettyEventLoopGroup;
1011
import io.netty.channel.EventLoopGroup;
1112

12-
public class NettyEventLoopGroup {
13+
public class NettyEventLoopGroupImpl implements NettyEventLoopGroup {
1314
private final EventLoopGroup parent;
1415
private final EventLoopGroup child;
1516
private boolean closed;
1617

17-
public NettyEventLoopGroup(NettyTransport transport, boolean single, int ioThreads) {
18+
public NettyEventLoopGroupImpl(NettyTransport transport, boolean single, int ioThreads) {
1819
child = transport.createEventLoop(ioThreads, "eventloop", 100);
1920
if (single) {
2021
parent = child;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Jooby https://jooby.io
3+
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
4+
* Copyright 2014 Edgar Espina
5+
*/
6+
package io.jooby.netty;
7+
8+
import io.netty.channel.EventLoopGroup;
9+
10+
public interface NettyEventLoopGroup {
11+
EventLoopGroup getParent();
12+
13+
EventLoopGroup getChild();
14+
15+
void shutdown();
16+
}

modules/jooby-netty/src/main/java/io/jooby/netty/NettyServer.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import javax.net.ssl.SSLContext;
1818

1919
import edu.umd.cs.findbugs.annotations.NonNull;
20+
import edu.umd.cs.findbugs.annotations.Nullable;
2021
import io.jooby.*;
2122
import io.jooby.exception.StartupException;
2223
import io.jooby.internal.netty.*;
@@ -139,7 +140,11 @@ public Server start(@NonNull Jooby... application) {
139140
var classLoader = applications.get(0).getClassLoader();
140141

141142
var transport = NettyTransport.transport(classLoader);
142-
eventLoop = new NettyEventLoopGroup(transport, singleEventLoopGroup, options.getIoThreads());
143+
eventLoop = createEventLoopGroup();
144+
if (eventLoop == null) {
145+
eventLoop =
146+
new NettyEventLoopGroupImpl(transport, singleEventLoopGroup, options.getIoThreads());
147+
}
143148

144149
var outputFactory = (NettyOutputFactory) getOutputFactory();
145150
var allocator = outputFactory.getAllocator();
@@ -179,13 +184,17 @@ public Server start(@NonNull Jooby... application) {
179184
return this;
180185
}
181186

187+
protected @Nullable NettyEventLoopGroup createEventLoopGroup() {
188+
return null;
189+
}
190+
182191
private ServerBootstrap newBootstrap(
183192
ByteBufAllocator allocator,
184193
NettyTransport transport,
185194
NettyPipeline factory,
186195
NettyEventLoopGroup group) {
187196
return transport
188-
.configure(eventLoop.getParent(), eventLoop.getChild())
197+
.configure(group.getParent(), group.getChild())
189198
.childHandler(factory)
190199
.childOption(ChannelOption.ALLOCATOR, allocator)
191200
.childOption(ChannelOption.SO_REUSEADDR, true)
@@ -226,20 +235,16 @@ public synchronized Server stop() {
226235
// only for jooby build where close events may take longer.
227236
NettyWebSocket.all.clear();
228237

229-
eventLoop.shutdown();
238+
if (eventLoop != null) {
239+
eventLoop.shutdown();
240+
}
230241
if (worker != null) {
231242
worker.shutdown();
232243
worker = null;
233244
}
234245
return this;
235246
}
236247

237-
private void shutdown(EventLoopGroup eventLoopGroup, int quietPeriod) {
238-
if (eventLoopGroup != null) {
239-
eventLoopGroup.shutdownGracefully(quietPeriod, 15, TimeUnit.SECONDS);
240-
}
241-
}
242-
243248
private SslContext wrap(
244249
SSLContext sslContext, ClientAuth clientAuth, String[] protocol, boolean http2) {
245250
ApplicationProtocolConfig protocolConfig;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>io.jooby</groupId>
8+
<artifactId>modules</artifactId>
9+
<version>4.0.7</version>
10+
</parent>
11+
<artifactId>jooby-vertx-mysql-client</artifactId>
12+
<name>jooby-vertx-mysql-client</name>
13+
14+
<properties>
15+
<Module-Name>io.jooby.vertx.mysqlclient</Module-Name>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>io.jooby</groupId>
21+
<artifactId>jooby-vertx-sql-client</artifactId>
22+
<version>${jooby.version}</version>
23+
</dependency>
24+
25+
<dependency>
26+
<groupId>io.vertx</groupId>
27+
<artifactId>vertx-mysql-client</artifactId>
28+
<version>5.0.4</version>
29+
</dependency>
30+
31+
<!-- Test dependencies -->
32+
<dependency>
33+
<groupId>org.junit.jupiter</groupId>
34+
<artifactId>junit-jupiter-engine</artifactId>
35+
<scope>test</scope>
36+
</dependency>
37+
38+
<dependency>
39+
<groupId>org.jacoco</groupId>
40+
<artifactId>org.jacoco.agent</artifactId>
41+
<classifier>runtime</classifier>
42+
<scope>test</scope>
43+
</dependency>
44+
45+
<dependency>
46+
<groupId>org.mockito</groupId>
47+
<artifactId>mockito-core</artifactId>
48+
<scope>test</scope>
49+
</dependency>
50+
</dependencies>
51+
52+
<build>
53+
<plugins>
54+
<plugin>
55+
<groupId>org.apache.maven.plugins</groupId>
56+
<artifactId>maven-jar-plugin</artifactId>
57+
<version>${maven-jar-plugin.version}</version>
58+
<configuration>
59+
<archive>
60+
<manifestEntries>
61+
<Automatic-Module-Name>${Module-Name}</Automatic-Module-Name>
62+
</manifestEntries>
63+
</archive>
64+
</configuration>
65+
</plugin>
66+
</plugins>
67+
</build>
68+
69+
</project>

0 commit comments

Comments
 (0)