Skip to content

Commit

Permalink
Most everything works
Browse files Browse the repository at this point in the history
  • Loading branch information
rferreira committed Feb 25, 2020
1 parent 0739c2b commit c5abbbf
Show file tree
Hide file tree
Showing 21 changed files with 355 additions and 184 deletions.
2 changes: 1 addition & 1 deletion jujube-benchmark/Readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Benchmark Module
All tests run in a 2017 MacBook Pro 13" with 16GB of RAM and AdoptOpenJDK 11.0.3+7.
All tests run in a 2017 MacBook Pro 13" with 16GB of RAM, NVME storage and AdoptOpenJDK 11.0.3+7.
All tests had a max heap setting (-xmx) of only 64MB.

## Results
Expand Down
4 changes: 2 additions & 2 deletions jujube-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<dependency>
<groupId>org.apache.httpcomponents.core5</groupId>
<artifactId>httpcore5-h2</artifactId>
<version>5.0-beta11</version>
<version>${httpComponentsCore.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down Expand Up @@ -47,7 +47,7 @@
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.0-beta7</version>
<version>5.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
24 changes: 19 additions & 5 deletions jujube-core/src/main/java/org/ophion/jujube/Jujube.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

/**
* Just enough logic to turn Apache Http Core into something suited for micro services
Expand Down Expand Up @@ -58,6 +57,14 @@ public void start() {
.setCanonicalHostName(config.getServerConfig().getCanonicalHostName())
.setVersionPolicy(config.getServerConfig().getVersionPolicy());

if (config.getServerConfig().getH2StreamListener() != null) {
bootstrap.setStreamListener(config.getServerConfig().getH2StreamListener());
}

if (config.getServerConfig().getHttp1StreamListener() != null) {
bootstrap.setStreamListener(config.getServerConfig().getHttp1StreamListener());
}

config.routes()
.forEach((k, v) -> bootstrap.register(k, () -> new JujubeServerExchangeHandler(config, v)));

Expand All @@ -83,11 +90,18 @@ public void start() {
}

public void stop() {
System.out.println("> HTTP server is shutting down, awaiting in-flight requests...");
instance.close(CloseMode.GRACEFUL);
instance.initiateShutdown();
var shutdownDelay = config.getServerConfig().getShutDownDelay();
System.out.println(String.format("> HTTP server is shutting down, awaiting %s for in-flight requests...", Durations.humanize(shutdownDelay)));
try {
instance.awaitShutdown(TimeValue.of(100, TimeUnit.MILLISECONDS));
if (shutdownDelay.isZero()) {
instance.close(CloseMode.IMMEDIATE);
instance.initiateShutdown();
instance.awaitShutdown(TimeValue.ZERO_MILLISECONDS);
} else {
instance.close(CloseMode.GRACEFUL);
instance.initiateShutdown();
instance.awaitShutdown(TimeValue.ofMilliseconds(shutdownDelay.toMillis()));
}
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import org.apache.hc.core5.function.Callback;
import org.apache.hc.core5.function.Supplier;
import org.apache.hc.core5.http.config.Http1Config;
import org.apache.hc.core5.http.impl.Http1StreamListener;
import org.apache.hc.core5.http.nio.AsyncServerExchangeHandler;
import org.apache.hc.core5.http.nio.ssl.BasicServerTlsStrategy;
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
import org.apache.hc.core5.http.protocol.LookupRegistry;
import org.apache.hc.core5.http.protocol.UriPatternOrderedMatcher;
import org.apache.hc.core5.http2.HttpVersionPolicy;
import org.apache.hc.core5.http2.config.H2Config;
import org.apache.hc.core5.http2.impl.nio.H2StreamListener;
import org.apache.hc.core5.http2.ssl.H2ServerTlsStrategy;
import org.apache.hc.core5.reactor.IOReactorConfig;
import org.apache.hc.core5.ssl.SSLContextBuilder;
Expand All @@ -22,6 +24,7 @@
import javax.net.ssl.SSLContext;
import java.security.KeyStore;
import java.security.cert.Certificate;
import java.time.Duration;
import java.util.concurrent.TimeUnit;

public class ServerConfig {
Expand All @@ -36,6 +39,9 @@ public class ServerConfig {
private TlsStrategy tlsStrategy;
private String canonicalHostName;
private Http1Config http1Config = Http1Config.DEFAULT;
private H2StreamListener h2StreamListener;
private Http1StreamListener http1StreamListener;
private Duration shutDownDelay = Duration.ofMillis(100);

public ServerConfig() {
this.ioReactorConfig = IOReactorConfig.custom()
Expand Down Expand Up @@ -67,6 +73,22 @@ public ServerConfig() {
}
}

public H2StreamListener getH2StreamListener() {
return h2StreamListener;
}

public void setH2StreamListener(H2StreamListener h2StreamListener) {
this.h2StreamListener = h2StreamListener;
}

public Http1StreamListener getHttp1StreamListener() {
return http1StreamListener;
}

public void setHttp1StreamListener(Http1StreamListener http1StreamListener) {
this.http1StreamListener = http1StreamListener;
}

public DataSize getRequestEntityLimit() {
return requestEntityLimit;
}
Expand Down Expand Up @@ -158,4 +180,12 @@ public Http1Config getHttp1Config() {
public void setHttp1Config(Http1Config http1Config) {
this.http1Config = http1Config;
}

public Duration getShutDownDelay() {
return shutDownDelay;
}

public void setShutDownDelay(Duration shutDownDelay) {
this.shutDownDelay = shutDownDelay;
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.ophion.jujube.context.ParameterSource;
import org.ophion.jujube.context.PrimitiveParameter;
import org.ophion.jujube.http.MultipartEntity;
import org.ophion.jujube.internal.consumers.ContentAwareRequestConsumer;
import org.ophion.jujube.internal.consumers.RequestEntityLimitExceeded;
import org.ophion.jujube.internal.util.Loggers;
import org.ophion.jujube.response.HttpResponseRequestTooLarge;
import org.ophion.jujube.response.HttpResponseServerError;
Expand Down Expand Up @@ -48,7 +50,7 @@ public JujubeServerExchangeHandler(JujubeConfig config, RouteHandler handler) {
protected AsyncRequestConsumer<Message<HttpRequest, HttpEntity>> supplyConsumer(HttpRequest request, EntityDetails entityDetails, HttpContext context) throws HttpException {
LOG.debug("handling request: {}", request.toString());

return new ContentAwareRequestConsumer<>(config, entityDetails, exceptionRef);
return new ContentAwareRequestConsumer(config, entityDetails, exceptionRef);
}

@Override
Expand Down Expand Up @@ -83,7 +85,6 @@ protected void handle(Message<HttpRequest, HttpEntity> requestMessage, AsyncServ
response = new HttpResponseServerError();
}
}

}

// handling response:
Expand Down
Loading

0 comments on commit c5abbbf

Please sign in to comment.