Search in sources :

Example 1 with StringGenerator

use of test.r2.perf.StringGenerator in project rest.li by linkedin.

the class AbstractPerfServerFactory method createPureStreamServer.

public Server createPureStreamServer(int port, URI echoUri, final int msg_size, int numHeaders, int headerSize) {
    String headerContent = new StringGenerator(headerSize).nextMessage();
    StreamRequestHandler handler = new StreamRequestHandler() {

        @Override
        public void handleRequest(StreamRequest request, RequestContext requestContext, final Callback<StreamResponse> callback) {
            request.getEntityStream().setReader(new PerfStreamReader<>(new Callback<None>() {

                @Override
                public void onError(Throwable e) {
                    callback.onError(e);
                }

                @Override
                public void onSuccess(None result) {
                    StreamResponseBuilder builder = new StreamResponseBuilder();
                    for (int i = 0; i < numHeaders; i++) {
                        builder.setHeader(STATIC_HEADER_PREFIX + i, headerContent);
                    }
                    callback.onSuccess(builder.build(EntityStreams.newEntityStream(new PerfStreamWriter(msg_size))));
                }
            }, None.none()));
        }
    };
    final TransportDispatcher dispatcher = new TransportDispatcherBuilder().addStreamHandler(echoUri, handler).build();
    return createServer(port, dispatcher, true);
}
Also used : StreamResponseBuilder(com.linkedin.r2.message.stream.StreamResponseBuilder) TransportDispatcher(com.linkedin.r2.transport.common.bridge.server.TransportDispatcher) StreamRequest(com.linkedin.r2.message.stream.StreamRequest) PerfStreamWriter(test.r2.perf.PerfStreamWriter) StreamRequestHandler(com.linkedin.r2.transport.common.StreamRequestHandler) Callback(com.linkedin.common.callback.Callback) StringGenerator(test.r2.perf.StringGenerator) RequestContext(com.linkedin.r2.message.RequestContext) None(com.linkedin.common.util.None) TransportDispatcherBuilder(com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder)

Aggregations

Callback (com.linkedin.common.callback.Callback)1 None (com.linkedin.common.util.None)1 RequestContext (com.linkedin.r2.message.RequestContext)1 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)1 StreamResponseBuilder (com.linkedin.r2.message.stream.StreamResponseBuilder)1 StreamRequestHandler (com.linkedin.r2.transport.common.StreamRequestHandler)1 TransportDispatcher (com.linkedin.r2.transport.common.bridge.server.TransportDispatcher)1 TransportDispatcherBuilder (com.linkedin.r2.transport.common.bridge.server.TransportDispatcherBuilder)1 PerfStreamWriter (test.r2.perf.PerfStreamWriter)1 StringGenerator (test.r2.perf.StringGenerator)1