LifecycleBase.start() -> Connector.startInternal() -> Protocol.start() (eg Http11NioProtocol) -> Endpoint.bind() (eg NioEndpoint)
NioEndpoint bind -> initServerSocket
LifecycleBase.start() -> Connector.startInternal() -> Protocol.start() (eg Http11NioProtocol) -> Endpoint.bind() (eg NioEndpoint)
NioEndpoint bind -> initServerSocket
| package playground | |
| import java.net.InetSocketAddress | |
| import java.nio.ByteBuffer | |
| import java.nio.channels.AsynchronousChannelGroup | |
| import java.nio.channels.AsynchronousServerSocketChannel | |
| import java.nio.channels.AsynchronousSocketChannel | |
| import java.nio.channels.CompletionHandler | |
| import java.nio.charset.StandardCharsets.UTF_8 | |
| import java.time.Clock |
produce a docker image with 3 main layers:
in build.gradle.kts:
| package mailhog | |
| /* | |
| dependencies: | |
| testImplementation("org.testcontainers:testcontainers:1.15.2") | |
| testImplementation(platform("org.http4k:http4k-bom:4.3.5.4")) | |
| testImplementation("org.http4k:http4k-core") | |
| testImplementation("org.http4k:http4k-client-apache") { | |
| because("mailhog http api messages access") |
| public class SafeCachingFactorizer implements Servlet { | |
| private static class FactorResult { BigInteger number; BigInteger[] factors; } | |
| private volatile FactorResult lastResult = null; | |
| public void service(ServletRequest req, ServletResponse resp) { | |
| BigInteger i = extractFromRequest(req); | |
| FactorResult result = this.lastResult; | |
| if (result == null || !i.equals(result.number)) { | |
| result = new FactorResult() { { number = i; factors = factor(i); } }; |
| import com.fasterxml.jackson.core.JsonParseException; | |
| import com.fasterxml.jackson.core.JsonParser; | |
| import com.fasterxml.jackson.core.JsonProcessingException; | |
| import com.fasterxml.jackson.core.JsonToken; | |
| import com.fasterxml.jackson.databind.BeanDescription; | |
| import com.fasterxml.jackson.databind.DeserializationConfig; | |
| import com.fasterxml.jackson.databind.DeserializationContext; | |
| import com.fasterxml.jackson.databind.DeserializationFeature; | |
| import com.fasterxml.jackson.databind.JsonDeserializer; | |
| import com.fasterxml.jackson.databind.JsonMappingException; |
| import com.fasterxml.jackson.core.JsonParser; | |
| import com.fasterxml.jackson.core.JsonProcessingException; | |
| import com.fasterxml.jackson.databind.DeserializationContext; | |
| import com.fasterxml.jackson.databind.JsonDeserializer; | |
| import com.fasterxml.jackson.databind.SerializerProvider; | |
| import com.fasterxml.jackson.databind.module.SimpleModule; | |
| import de.undercouch.bson4jackson.BsonGenerator; | |
| import de.undercouch.bson4jackson.serializers.BsonSerializer; |
| package restx.spring; | |
| import org.springframework.web.context.ContextLoaderListener; | |
| import org.springframework.web.context.WebApplicationContext; | |
| import org.springframework.web.context.support.WebApplicationContextUtils; | |
| import javax.servlet.ServletContextEvent; | |
| /** | |
| * User: xavierhanin |
| @Module(priority = -100) | |
| public class JongoModule { | |
| JacksonMapper.Builder getJacksonMapperBuilder() { | |
| return new JacksonMapper.Builder() | |
| .registerModule(new BsonJodaTimeModule()) | |
| .withView(Views.Private.class) | |
| ; | |
| } |
| // In AppModule class, or could be in a dedicated module. | |
| @Provides | |
| public DBI dbi(@Named("datasource") DataSource ds) { | |
| return new DBI(ds); | |
| } |