本文整理汇总了Java中io.reactivex.netty.pipeline.PipelineConfigurators类的典型用法代码示例。如果您正苦于以下问题:Java PipelineConfigurators类的具体用法?Java PipelineConfigurators怎么用?Java PipelineConfigurators使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PipelineConfigurators类属于io.reactivex.netty.pipeline包,在下文中一共展示了PipelineConfigurators类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createServer
import io.reactivex.netty.pipeline.PipelineConfigurators; //导入依赖的package包/类
public HttpServer<ByteBuf, ByteBuf> createServer() {
HttpServer<ByteBuf, ByteBuf> server = RxNetty.newHttpServerBuilder(port, new RequestHandler<ByteBuf, ByteBuf>() {
@Override
public Observable<Void> handle(HttpServerRequest<ByteBuf> request, final HttpServerResponse<ByteBuf> response) {
if (request.getPath().contains("/v2/apps")) {
if (request.getHttpMethod().equals(HttpMethod.POST)) {
return handleTest(request, response);
}
}
response.setStatus(HttpResponseStatus.NOT_FOUND);
return response.close();
}
}).pipelineConfigurator(PipelineConfigurators.<ByteBuf, ByteBuf>httpServerConfigurator()).enableWireLogging(LogLevel.ERROR).build();
System.out.println("RxTetstServer server started...");
return server;
}
示例2: onCreate
import io.reactivex.netty.pipeline.PipelineConfigurators; //导入依赖的package包/类
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
server = RxNetty.createTcpServer(PORT, PipelineConfigurators.textOnlyConfigurator(),
connection -> {
mainHandler.post(() -> adapter.add("New client connection established."));
connection.writeAndFlush("Welcome! \n\n");
return connection.getInput().flatMap(msg -> {
Log.d(TAG, "Server onNext: " + msg);
msg = msg.trim();
if (!msg.isEmpty()) {
return connection.writeAndFlush("echo => " + msg + '\n');
} else {
return Observable.empty();
}
});
});
}
示例3: createServer
import io.reactivex.netty.pipeline.PipelineConfigurators; //导入依赖的package包/类
private HttpServer<ByteBuf, ByteBuf> createServer(RestHttpServerConfiguration configuration) {
ServerBootstrap serverBootstrap = createServerBootstrap(configuration.getInterface(), configuration.getPort());
HttpServerBuilder<ByteBuf, ByteBuf> httpServerBuilder =
new HttpServerBuilder<>(serverBootstrap, configuration.getPort(),
createServiceRequestHandler(configuration.getRestServices(), configuration.getConverters()))
.pipelineConfigurator(PipelineConfigurators.<ByteBuf, ByteBuf>httpServerConfigurator())
.withRequestProcessingThreads(configuration.getRequestProcessingThreads())
.enableWireLogging(LogLevel.DEBUG);
String message = "starting http server on port %s at interface %s, with %s processing threads ...";
log.info(String.format(message, configuration.getPort(), configuration.getInterface(), configuration.getRequestProcessingThreads()));
logServices(configuration.getRestServices());
return httpServerBuilder.build();
}
示例4: getResponse
import io.reactivex.netty.pipeline.PipelineConfigurators; //导入依赖的package包/类
private Observable<HttpClientResponse<ByteBuf>> getResponse(String externalHealthCheckURL) {
String host = "localhost";
int port = DEFAULT_APPLICATION_PORT;
String path = "/healthcheck";
try {
URL url = new URL(externalHealthCheckURL);
host = url.getHost();
port = url.getPort();
path = url.getPath();
} catch (MalformedURLException e) {
//continue
}
Integer timeout = DynamicProperty.getInstance("prana.host.healthcheck.timeout").getInteger(DEFAULT_CONNECTION_TIMEOUT);
HttpClient<ByteBuf, ByteBuf> httpClient = RxNetty.<ByteBuf, ByteBuf>newHttpClientBuilder(host, port)
.pipelineConfigurator(PipelineConfigurators.<ByteBuf, ByteBuf>httpClientConfigurator())
.channelOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, timeout)
.build();
return httpClient.submit(HttpClientRequest.createGet(path));
}
示例5: createServer
import io.reactivex.netty.pipeline.PipelineConfigurators; //导入依赖的package包/类
public HttpServer<ByteBuf, ByteBuf> createServer() {
HttpServer<ByteBuf, ByteBuf> server = RxNetty.newHttpServerBuilder(port, new RequestHandler<ByteBuf, ByteBuf>() {
@Override
public Observable<Void> handle(HttpServerRequest<ByteBuf> request, final HttpServerResponse<ByteBuf> response) {
if (request.getPath().contains("/users")) {
if (request.getHttpMethod().equals(HttpMethod.GET)) {
return handleRecommendationsByUserId(request, response);
} else {
return handleUpdateRecommendationsForUser(request, response);
}
}
if (request.getPath().contains("/recommendations")) {
return handleRecommendationsBy(request, response);
}
if (request.getPath().contains("/movies")) {
return handleRegisterMovie(request, response);
}
response.setStatus(HttpResponseStatus.NOT_FOUND);
return response.close();
}
}).pipelineConfigurator(PipelineConfigurators.<ByteBuf, ByteBuf>httpServerConfigurator()).enableWireLogging(LogLevel.ERROR).build();
System.out.println("RxMovie server started...");
return server;
}
示例6: main
import io.reactivex.netty.pipeline.PipelineConfigurators; //导入依赖的package包/类
public static void main(String[] args) {
Observable<ObservableConnection<String, String>> connectionObservable =
RxNetty.createTcpClient("localhost", 8181, PipelineConfigurators.stringMessageConfigurator()).connect();
connectionObservable.flatMap(new Func1<ObservableConnection<String, String>, Observable<?>>() {
@Override
public Observable<?> call(ObservableConnection<String, String> connection) {
return connection.getInput().map(new Func1<String, String>() {
@Override
public String call(String msg) {
return msg.trim();
}
});
}
}).toBlockingObservable().forEach(new Action1<Object>() {
@Override
public void call(Object o) {
System.out.println("onNext event => " + o);
}
});
}
示例7: main
import io.reactivex.netty.pipeline.PipelineConfigurators; //导入依赖的package包/类
public static void main(final String[] args) {
final int port = 8181;
RxNetty.createTcpServer(port, PipelineConfigurators.textOnlyConfigurator(),
new ConnectionHandler<String, String>() {
@Override
public Observable<Void> handle(
final ObservableConnection<String, String> connection) {
System.out.println("New client connection established.");
connection.writeAndFlush("Welcome! \n\n");
return connection.getInput().flatMap(new Func1<String, Observable<Void>>() {
@Override
public Observable<Void> call(String msg) {
System.out.println("onNext: " + msg);
msg = msg.trim();
if (!msg.isEmpty()) {
return connection.writeAndFlush("echo => " + msg + '\n');
} else {
return COMPLETED_OBSERVABLE;
}
}
});
}
}).startAndWait();
}
示例8: main
import io.reactivex.netty.pipeline.PipelineConfigurators; //导入依赖的package包/类
public static void main(String[] args) {
Observable<ObservableConnection<String, String>> connectionObservable =
RxNetty.createTcpClient("localhost", 8181, PipelineConfigurators.stringMessageConfigurator()).connect();
connectionObservable.flatMap(new Func1<ObservableConnection<String, String>, Observable<?>>() {
@Override
public Observable<?> call(ObservableConnection<String, String> connection) {
return connection.getInput().map(new Func1<String, String>() {
@Override
public String call(String msg) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return msg.trim();
}
});
}
}).toBlockingObservable().forEach(new Action1<Object>() {
@Override
public void call(Object o) {
System.out.println("onNext event => " + o);
}
});
}
示例9: testNonChunkingStream
import io.reactivex.netty.pipeline.PipelineConfigurators; //导入依赖的package包/类
@Test
public void testNonChunkingStream() throws Exception {
HttpClient<ByteBuf, ServerSentEvent> client = RxNetty.createHttpClient("localhost", port,
PipelineConfigurators.<ByteBuf>sseClientConfigurator());
Observable<HttpClientResponse<ServerSentEvent>> response =
client.submit(HttpClientRequest.createGet("test/nochunk_stream"));
final List<String> result = new ArrayList<String>();
response.flatMap(new Func1<HttpClientResponse<ServerSentEvent>, Observable<ServerSentEvent>>() {
@Override
public Observable<ServerSentEvent> call(HttpClientResponse<ServerSentEvent> httpResponse) {
return httpResponse.getContent();
}
}).toBlockingObservable().forEach(new Action1<ServerSentEvent>() {
@Override
public void call(ServerSentEvent event) {
result.add(event.getEventData());
}
});
assertEquals(RequestProcessor.smallStreamContent, result);
}
示例10: initializeStream
import io.reactivex.netty.pipeline.PipelineConfigurators; //导入依赖的package包/类
private Observable<String> initializeStream() {
HttpClient<ByteBuf, ServerSentEvent> client =
RxNetty.createHttpClient("localhost", port, PipelineConfigurators.<ByteBuf>clientSseConfigurator());
return client.submit(HttpClientRequest.createGet("/hello")).
flatMap(response -> {
printResponseHeader(response);
return response.getContent();
}).map(serverSentEvent -> serverSentEvent.contentAsString());
}
示例11: createServer
import io.reactivex.netty.pipeline.PipelineConfigurators; //导入依赖的package包/类
public HttpServer<ByteBuf, ServerSentEvent> createServer() {
HttpServer<ByteBuf, ServerSentEvent> server = RxNetty.createHttpServer(port,
(request, response) -> {
response.getHeaders().set(ACCESS_CONTROL_ALLOW_ORIGIN, "*");
response.getHeaders().set(CACHE_CONTROL, "no-cache");
response.getHeaders().set(CONNECTION, "keep-alive");
response.getHeaders().set(CONTENT_TYPE, "text/event-stream");
return getIntervalObservable(request, response);
}, PipelineConfigurators.<ByteBuf>serveSseConfigurator());
System.out.println("HTTP Server Sent Events server started...");
return server;
}
示例12: HystrixReader
import io.reactivex.netty.pipeline.PipelineConfigurators; //导入依赖的package包/类
/**
* Creates a new hystrix reader.
*
* @param configuration The configuration to use.
* @param cluster The cluster to read from.
*/
public HystrixReader(Configuration configuration, String cluster)
{
this.configuration = configuration;
this.cluster = cluster;
HttpClientBuilder<ByteBuf, ServerSentEvent> builder = RxNetty.newHttpClientBuilder(configuration.getTurbineHost(), configuration.getTurbinePort());
builder.pipelineConfigurator(PipelineConfigurators.clientSseConfigurator());
if (configuration.isSecure())
{
builder.withSslEngineFactory(DefaultFactories.trustAll());
}
rxNetty = builder.build();
}
示例13: postMessage
import io.reactivex.netty.pipeline.PipelineConfigurators; //导入依赖的package包/类
public Observable<HttpClientResponse<ByteBuf>> postMessage(String message) {
PipelineConfigurator<HttpClientResponse<ByteBuf>, HttpClientRequest<ByteBuf>> pipelineConfigurator
= PipelineConfigurators.httpClientConfigurator();
HttpClient<ByteBuf, ByteBuf> client = RxNetty.<ByteBuf, ByteBuf>newHttpClientBuilder(networkAddress.getIpAddress(), port)
.pipelineConfigurator(pipelineConfigurator)
.enableWireLogging(LogLevel.ERROR).build();
HttpClientRequest<ByteBuf> request = HttpClientRequest.createPost("/v2/apps");
request.withRawContentSource(Observable.just(message), StringTransformer.DEFAULT_INSTANCE);
request.withHeader("Content-Type", "application/json");
return client.submit(request);
}
示例14: getResponse
import io.reactivex.netty.pipeline.PipelineConfigurators; //导入依赖的package包/类
private HttpClientResponse<ByteBuf> getResponse(String serviceUrl) throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
String host, path;
int port;
URL url = new URL(serviceUrl);
host = url.getHost();
port = url.getPort();
path = url.getPath();
System.out.println(url);
HttpClient<ByteBuf, ByteBuf> httpClient = RxNetty.<ByteBuf, ByteBuf>newHttpClientBuilder(host, port)
.pipelineConfigurator(PipelineConfigurators.<ByteBuf, ByteBuf>httpClientConfigurator())
.build();
return httpClient.submit(HttpClientRequest.createGet(path)).toBlocking().toFuture().get(checkTimeout, TimeUnit.MILLISECONDS);
}
示例15: observeJson
import io.reactivex.netty.pipeline.PipelineConfigurators; //导入依赖的package包/类
@Override
public Observable<String> observeJson() {
if(jsonObservable != null) {
return jsonObservable;
}
HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet(url.getPath() + "?" + url.getQuery());
int port = url.getPort() < 0 ? url.getDefaultPort() : url.getPort();
HttpClient<ByteBuf, ServerSentEvent> client = RxNetty.<ByteBuf, ServerSentEvent>newHttpClientBuilder(url.getHost(), port)
.withNoConnectionPooling()
.pipelineConfigurator(PipelineConfigurators.<ByteBuf>clientSseConfigurator())
.build();
jsonObservable = client.submit(request)
.doOnError(t -> LOG.error("Error connecting to " + url, t))
.flatMap(response -> {
if (response.getStatus().code() != 200) {
return Observable.error(new RuntimeException("Failed to connect: " + response.getStatus()));
}
return response.getContent()
.doOnSubscribe(() -> LOG.info("Turbine => Aggregate Stream from URL: " + url))
.doOnUnsubscribe(() -> LOG.info("Turbine => Unsubscribing Stream: " + url))
.map(ServerSentEvent::contentAsString);
}
)
.timeout(120, TimeUnit.SECONDS)
.retryWhen(attempts -> attempts.zipWith(Observable.range(1, Integer.MAX_VALUE), (k, i) -> i)
.flatMap(n -> {
int waitTimeSeconds = Math.min(6, n) * 10; // wait in 10 second increments up to a max of 1 minute
LOG.info("Turbine => Retrying connection to: " + this.url + " in {} seconds", waitTimeSeconds);
return Observable.timer(waitTimeSeconds, TimeUnit.SECONDS);
})
)
.repeat()
.share();
return jsonObservable;
}