-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Server stops just after starting #71
Comments
Hi Patrick,
The NettHttpService starts up background daemon threads to listen for incoming traffic. You do need to block your main thread in order to prevent the JVM to exit. The simplest you can do is something like this in Java (I am not familiar with the Kotlin language, but I believe you can do pretty much the same).
public class Server {
public static void main(String[] args) throws Exception {
NettyHttpService httpService = NettyHttpService.builder("the-app")
.setPort(8080)
.setHttpHandlers(new AuthenticationController())
.build();
CountDownLatch shutdownLatch = new CountDownLatch(1);
httpService.start();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
httpService.stop();
} catch (Exception e) {
e.printStackTrace();
} finally {
shutdownLatch.countDown();
}
}));
shutdownLatch.await();
}
}
Terence
Terence Yim | Staff Software Engineer | [email protected] <mailto:[email protected]> |
… On Mar 25, 2019, at 3:48 AM, Patrick Sauts ***@***.***> wrote:
I'm trying to use your project on a kotlin project but when I start the server it stops just after starting.
If I put a breakpoint on NettyHttpService:184 then I can use the server.
am I missing something ?
class Server {
companion object {
@JvmStatic
fun main(args: Array<String>) {
val handlers = ArrayList<HttpHandler>()
handlers.add(AuthenticationController())
val service = NettyHttpService.builder("the-app")
.setPort(8080)
.setHttpHandlers(handlers)
.build()
service.start()
}
}
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub <#71>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AA2BKAmc0ame1XIKOg2IyDHoWYP2b-Jeks5vaKmEgaJpZM4cGlLV>.
|
Thank you Terence I had done a similar thing but I wasn't sure if it was intended. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm trying to use your project on a kotlin project but when I start the server it stops just after starting.
If I put a breakpoint on NettyHttpService:184 then I can use the server.
am I missing something ?
The text was updated successfully, but these errors were encountered: