io.polyglotted.applauncher.server.SpringServer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of app-launcher Show documentation
Show all versions of app-launcher Show documentation
Launch an in-process application
The newest version!
package io.polyglotted.applauncher.server;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import java.util.concurrent.CountDownLatch;
@Slf4j
@RequiredArgsConstructor
public class SpringServer implements Server {
private final Class>[] configurationClasses;
private AnnotationConfigApplicationContext applicationContext;
private final CountDownLatch latch = new CountDownLatch(1);
public SpringServer () {
this(defaultConfigurationClasses());
}
@Override
public void start() {
applicationContext = new AnnotationConfigApplicationContext();
applicationContext.register(configurationClasses);
applicationContext.refresh();
applicationContext.start();
new Thread(this::awaitLatch).start();
log.info("Server started");
}
@SneakyThrows
private void awaitLatch() {
latch.await();
}
@Override
public void stop() {
applicationContext.close();
latch.countDown();
}
@SneakyThrows
private static Class>[] defaultConfigurationClasses() {
return new Class[]{Class.forName("applauncher.spring.MainConfiguration")};
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy