Skip to content

Commit 224d9ee

Browse files
committed
output api: rename to buffered output + add buffer options
- update server implementations
1 parent 8efd0b2 commit 224d9ee

File tree

83 files changed

+513
-438
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+513
-438
lines changed

jooby/src/main/java/io/jooby/Context.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
import io.jooby.internal.ParamLookupImpl;
3535
import io.jooby.internal.ReadOnlyContext;
3636
import io.jooby.internal.WebSocketSender;
37-
import io.jooby.output.Output;
38-
import io.jooby.output.OutputFactory;
37+
import io.jooby.output.BufferedOutput;
38+
import io.jooby.output.BufferedOutputFactory;
3939
import io.jooby.value.Value;
4040
import io.jooby.value.ValueFactory;
4141

@@ -145,7 +145,7 @@ private static Selector single() {
145145
*/
146146
Router getRouter();
147147

148-
OutputFactory getOutputFactory();
148+
BufferedOutputFactory getOutputFactory();
149149

150150
/**
151151
* Forward executing to another route. We use the given path to find a matching route.
@@ -1312,7 +1312,7 @@ Context responseWriter(
13121312
* @param output Output.
13131313
* @return This context.
13141314
*/
1315-
Context send(@NonNull Output output);
1315+
Context send(@NonNull BufferedOutput output);
13161316

13171317
/**
13181318
* Send response data.

jooby/src/main/java/io/jooby/DefaultContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import io.jooby.internal.MissingValue;
3636
import io.jooby.internal.SingleValue;
3737
import io.jooby.internal.UrlParser;
38-
import io.jooby.output.OutputFactory;
38+
import io.jooby.output.BufferedOutputFactory;
3939
import io.jooby.value.Value;
4040
import io.jooby.value.ValueFactory;
4141

@@ -654,7 +654,7 @@ default Context sendError(@NonNull Throwable cause, @NonNull StatusCode code) {
654654
}
655655

656656
@Override
657-
default OutputFactory getOutputFactory() {
657+
default BufferedOutputFactory getOutputFactory() {
658658
return getRouter().getOutputFactory();
659659
}
660660
}

jooby/src/main/java/io/jooby/ForwardingContext.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
import edu.umd.cs.findbugs.annotations.NonNull;
2525
import edu.umd.cs.findbugs.annotations.Nullable;
2626
import io.jooby.exception.RegistryException;
27-
import io.jooby.output.Output;
28-
import io.jooby.output.OutputFactory;
27+
import io.jooby.output.BufferedOutput;
28+
import io.jooby.output.BufferedOutputFactory;
2929
import io.jooby.value.Value;
3030
import io.jooby.value.ValueFactory;
3131

@@ -671,7 +671,7 @@ public Router getRouter() {
671671
}
672672

673673
@Override
674-
public OutputFactory getOutputFactory() {
674+
public BufferedOutputFactory getOutputFactory() {
675675
return ctx.getOutputFactory();
676676
}
677677

@@ -1229,7 +1229,7 @@ public Context send(@NonNull ByteBuffer data) {
12291229
}
12301230

12311231
@Override
1232-
public Context send(@NonNull Output output) {
1232+
public Context send(@NonNull BufferedOutput output) {
12331233
ctx.send(output);
12341234
return this;
12351235
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
import io.jooby.internal.MutedServer;
5252
import io.jooby.internal.RegistryRef;
5353
import io.jooby.internal.RouterImpl;
54-
import io.jooby.output.OutputFactory;
54+
import io.jooby.output.BufferedOutputFactory;
5555
import io.jooby.problem.ProblemDetailsHandler;
5656
import io.jooby.value.ValueFactory;
5757
import jakarta.inject.Provider;
@@ -920,12 +920,12 @@ public Jooby setValueFactory(@NonNull ValueFactory valueFactory) {
920920
}
921921

922922
@NonNull @Override
923-
public OutputFactory getOutputFactory() {
923+
public BufferedOutputFactory getOutputFactory() {
924924
return router.getOutputFactory();
925925
}
926926

927927
@NonNull @Override
928-
public Jooby setOutputFactory(@NonNull OutputFactory outputFactory) {
928+
public Jooby setOutputFactory(@NonNull BufferedOutputFactory outputFactory) {
929929
router.setOutputFactory(outputFactory);
930930
return this;
931931
}

jooby/src/main/java/io/jooby/MessageEncoder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import edu.umd.cs.findbugs.annotations.NonNull;
99
import edu.umd.cs.findbugs.annotations.Nullable;
1010
import io.jooby.exception.NotAcceptableException;
11-
import io.jooby.output.Output;
11+
import io.jooby.output.BufferedOutput;
1212

1313
/**
1414
* Render a route output as a byte array.
@@ -36,5 +36,5 @@ public interface MessageEncoder {
3636
* @return Value as a byte array or <code>null</code> if given object isn't supported it.
3737
* @throws Exception If something goes wrong.
3838
*/
39-
@Nullable Output encode(@NonNull Context ctx, @NonNull Object value) throws Exception;
39+
@Nullable BufferedOutput encode(@NonNull Context ctx, @NonNull Object value) throws Exception;
4040
}

jooby/src/main/java/io/jooby/Router.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import io.jooby.exception.MissingValueException;
3737
import io.jooby.handler.AssetHandler;
3838
import io.jooby.handler.AssetSource;
39-
import io.jooby.output.OutputFactory;
39+
import io.jooby.output.BufferedOutputFactory;
4040
import io.jooby.value.ValueFactory;
4141
import jakarta.inject.Provider;
4242

@@ -536,9 +536,9 @@ default Object execute(@NonNull Context context) {
536536
*/
537537
@NonNull Router setDefaultWorker(@NonNull Executor worker);
538538

539-
@NonNull OutputFactory getOutputFactory();
539+
@NonNull BufferedOutputFactory getOutputFactory();
540540

541-
@NonNull Router setOutputFactory(@NonNull OutputFactory outputFactory);
541+
@NonNull Router setOutputFactory(@NonNull BufferedOutputFactory outputFactory);
542542

543543
/**
544544
* Attach a filter to the route pipeline.

jooby/src/main/java/io/jooby/Sender.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import edu.umd.cs.findbugs.annotations.NonNull;
1212
import edu.umd.cs.findbugs.annotations.Nullable;
13-
import io.jooby.output.Output;
13+
import io.jooby.output.BufferedOutput;
1414

1515
/**
1616
* Non-blocking sender. Reactive responses use this class to send partial data in a non-blocking
@@ -94,7 +94,7 @@ interface Callback {
9494
*/
9595
Sender write(@NonNull byte[] data, @NonNull Callback callback);
9696

97-
Sender write(@NonNull Output output, @NonNull Callback callback);
97+
Sender write(@NonNull BufferedOutput output, @NonNull Callback callback);
9898

9999
/** Close the sender. */
100100
void close();

jooby/src/main/java/io/jooby/ServerOptions.java

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import edu.umd.cs.findbugs.annotations.NonNull;
2727
import edu.umd.cs.findbugs.annotations.Nullable;
2828
import io.jooby.internal.SslContextProvider;
29+
import io.jooby.output.BufferOptions;
2930

3031
/**
3132
* Available server options. To load server options from configuration files, just do:
@@ -47,7 +48,7 @@ public class ServerOptions {
4748
public static final int SERVER_PORT = Integer.parseInt(System.getProperty("server.port", "8080"));
4849

4950
/**
50-
* Default application secure port <code>8443</code> or the value of system property <code>
51+
* Default application secures port <code>8443</code> or the value of system property <code>
5152
* server.securePort</code>.
5253
*/
5354
public static final int SEVER_SECURE_PORT =
@@ -70,9 +71,6 @@ public class ServerOptions {
7071

7172
private static final String LOCAL_HOST = "0.0.0.0";
7273

73-
/** Buffer size used by server. Usually for reading/writing data. */
74-
private int bufferSize = _16KB;
75-
7674
/** Number of available threads, but never smaller than <code>2</code>. */
7775
public static final int IO_THREADS = Runtime.getRuntime().availableProcessors() * 2;
7876

@@ -100,6 +98,8 @@ public class ServerOptions {
10098
/** Name of server: Jetty, Netty or Undertow. */
10199
private String server;
102100

101+
private BufferOptions buffer = BufferOptions.defaults();
102+
103103
/**
104104
* Maximum request size in bytes. Request exceeding this value results in {@link
105105
* io.jooby.StatusCode#REQUEST_ENTITY_TOO_LARGE} response. Default is <code>10mb</code>.
@@ -143,8 +143,11 @@ public class ServerOptions {
143143
if (conf.hasPath("server.name")) {
144144
options.setServer(conf.getString("server.name"));
145145
}
146-
if (conf.hasPath("server.bufferSize")) {
147-
options.setBufferSize(conf.getInt("server.bufferSize"));
146+
if (conf.hasPath("server.buffer.size")) {
147+
options.buffer.setSize(conf.getInt("server.buffer.size"));
148+
}
149+
if (conf.hasPath("server.buffer.useDirectBuffers")) {
150+
options.buffer.setDirectBuffers(conf.getBoolean("server.buffer.useDirectBuffers"));
148151
}
149152
if (conf.hasPath("server.defaultHeaders")) {
150153
options.setDefaultHeaders(conf.getBoolean("server.defaultHeaders"));
@@ -191,7 +194,7 @@ public String toString() {
191194
buff.append(", ioThreads: ").append(Optional.ofNullable(ioThreads).orElse(IO_THREADS));
192195
}
193196
buff.append(", workerThreads: ").append(getWorkerThreads());
194-
buff.append(", bufferSize: ").append(bufferSize);
197+
buff.append(", buffer: ").append(getBuffer());
195198
buff.append(", maxRequestSize: ").append(maxRequestSize);
196199
buff.append(", httpsOnly: ").append(httpsOnly);
197200
if (compressionLevel != null) {
@@ -405,24 +408,12 @@ public boolean getDefaultHeaders() {
405408
return this;
406409
}
407410

408-
/**
409-
* Server buffer size in bytes. Default is: <code>16kb</code>. Used for reading/writing data.
410-
*
411-
* @return Server buffer size in bytes. Default is: <code>16kb</code>. Used for reading/writing
412-
* data.
413-
*/
414-
public int getBufferSize() {
415-
return bufferSize;
411+
public BufferOptions getBuffer() {
412+
return buffer;
416413
}
417414

418-
/**
419-
* Set buffer size.
420-
*
421-
* @param bufferSize Buffer size.
422-
* @return This options.
423-
*/
424-
public @NonNull ServerOptions setBufferSize(int bufferSize) {
425-
this.bufferSize = bufferSize;
415+
public ServerOptions setBuffer(@NonNull BufferOptions buffer) {
416+
this.buffer = buffer;
426417
return this;
427418
}
428419

jooby/src/main/java/io/jooby/ServerSentMessage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public ServerSentMessage(@NonNull Object data) {
132132
* @param ctx Web context. To encode complex objects.
133133
* @return Encoded data.
134134
*/
135-
public @NonNull Output encode(@NonNull Context ctx) {
135+
public @NonNull BufferedOutput encode(@NonNull Context ctx) {
136136
try {
137137
var route = ctx.getRoute();
138138
var encoder = route.getEncoder();

jooby/src/main/java/io/jooby/TemplateEngine.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import java.util.List;
1010

1111
import edu.umd.cs.findbugs.annotations.NonNull;
12-
import io.jooby.output.Output;
12+
import io.jooby.output.BufferedOutput;
1313

1414
/**
1515
* Template engine renderer. This class renderer instances of {@link ModelAndView} objects. Template
@@ -34,10 +34,10 @@ public interface TemplateEngine extends MessageEncoder {
3434
* @return Rendered template.
3535
* @throws Exception If something goes wrong.
3636
*/
37-
Output render(Context ctx, ModelAndView<?> modelAndView) throws Exception;
37+
BufferedOutput render(Context ctx, ModelAndView<?> modelAndView) throws Exception;
3838

3939
@Override
40-
default Output encode(@NonNull Context ctx, @NonNull Object value) throws Exception {
40+
default BufferedOutput encode(@NonNull Context ctx, @NonNull Object value) throws Exception {
4141
// initialize flash and session attributes (if any)
4242
ctx.flashOrNull();
4343
ctx.sessionOrNull();

0 commit comments

Comments
 (0)