本文整理汇总了Java中io.reactivex.netty.pipeline.PipelineConfigurators类的典型用法代码示例。如果您正苦于以下问题:Java PipelineConfigurators类的具体用法?Java PipelineConfigurators怎么用?Java PipelineConfigurators使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PipelineConfigurators类属于io.reactivex.netty.pipeline包,在下文中一共展示了PipelineConfigurators类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:schibsted,项目名称:triathlon,代码行数:18,代码来源:RxTestServer.java
示例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();
}
});
});
}
开发者ID:AndrewReitz,项目名称:RxNetty-Android,代码行数:18,代码来源:ServerFragment.java
示例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();
}
开发者ID:adrobisch,项目名称:nibbler,代码行数:18,代码来源:NettyHttpServer.java
示例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));
}
开发者ID:Netflix,项目名称:Prana,代码行数:21,代码来源:HealthCheckHandler.java
示例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;
}
开发者ID:Netflix,项目名称:ribbon,代码行数:26,代码来源:RxMovieServer.java
示例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);
}
});
}
开发者ID:allenxwang,项目名称:RxNetty,代码行数:22,代码来源:TcpEventStreamClientFast.java
示例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();
}
开发者ID:allenxwang,项目名称:RxNetty,代码行数:25,代码来源:TcpEchoServer.java
示例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);
}
});
}
开发者ID:allenxwang,项目名称:RxNetty,代码行数:27,代码来源:TcpEventStreamClientSlow.java
示例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);
}
开发者ID:allenxwang,项目名称:RxNetty,代码行数:21,代码来源:HttpClientTest.java
示例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());
}
开发者ID:RxHandsOn,项目名称:MarketData,代码行数:11,代码来源:RxNettyEventEventStreamClient.java
示例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;
}
开发者ID:RxHandsOn,项目名称:MarketData,代码行数:13,代码来源:RxNettyEventServer.java
示例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();
}
开发者ID:OskarKjellin,项目名称:vizceral-hystrix,代码行数:19,代码来源:HystrixReader.java
示例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);
}
开发者ID:schibsted,项目名称:triathlon,代码行数:14,代码来源:MarathonClient.java
示例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);
}
开发者ID:schibsted,项目名称:triathlon,代码行数:16,代码来源:HealthCheck.java
示例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;
}
开发者ID:bbcom,项目名称:argos-dashboard,代码行数:41,代码来源:DefaultHystrixClusterMonitor.java
示例16: startClient
import io.reactivex.netty.pipeline.PipelineConfigurators; //导入依赖的package包/类
@OnClick(R.id.client_button) void startClient() {
Observable<ObservableConnection<String, String>> connectionObservable =
RxNetty.createTcpClient("localhost", PORT, PipelineConfigurators.textOnlyConfigurator()).connect();
connectionObservable.flatMap(connection -> {
Observable<String> helloMessage = connection.getInput()
.take(1).map(String::trim);
// output 10 values at intervals and receive the echo back
Observable<String> intervalOutput =
Observable.interval(500, TimeUnit.MILLISECONDS)
.flatMap(aLong -> connection.writeAndFlush(String.valueOf(aLong + 1))
.map(aVoid -> ""));
// capture the output from the server
Observable<String> echo = connection.getInput().map(String::trim);
// wait for the helloMessage then start the output and receive echo input
return Observable.concat(helloMessage, Observable.merge(intervalOutput, echo));
})
.take(10)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Object>() {
@Override public void onCompleted() {
Log.d(TAG, "Client Complete!");
}
@Override public void onError(Throwable throwable) {
Log.e(TAG, "onError: " + throwable.getMessage());
}
@Override public void onNext(Object o) {
final String message = o.toString();
Log.d(TAG, "Client onNext: " + message);
adapter.add(message);
}
});
}
开发者ID:AndrewReitz,项目名称:RxNetty-Android,代码行数:41,代码来源:ServerFragment.java
示例17: createServer
import io.reactivex.netty.pipeline.PipelineConfigurators; //导入依赖的package包/类
public HttpServer<ByteBuf, ServerSentEvent> createServer(int port) {
System.out.println("Start " + getClass().getSimpleName() + " on port: " + port);
// declare handler chain (wrapped in Hystrix)
// TODO create a better way of chaining these (related https://github.com/ReactiveX/RxNetty/issues/232 and https://github.com/ReactiveX/RxNetty/issues/202)
HystrixMetricsStreamHandler<ByteBuf, ServerSentEvent> handlerChain
= new HystrixMetricsStreamHandler<>(metrics, "/hystrix.stream", 1000, (request, response) -> {
try {
long startTime = System.currentTimeMillis();
return handleRequest(request, response)
.doOnCompleted(() -> System.out.println("Response => " + request.getPath() + " Time => " + (int) (System.currentTimeMillis() - startTime) + "ms"))
.doOnCompleted(() -> metrics.getRollingPercentile().addValue((int) (System.currentTimeMillis() - startTime)))
.doOnCompleted(() -> metrics.getRollingNumber().add(Metrics.EventType.SUCCESS, 1))
.doOnError(t -> metrics.getRollingNumber().add(Metrics.EventType.FAILURE, 1));
} catch (Throwable e) {
e.printStackTrace();
System.err.println("Server => Error [" + request.getPath() + "] => " + e);
response.setStatus(HttpResponseStatus.BAD_REQUEST);
return response.writeStringAndFlush("data: Error 500: Bad Request\n" + e.getMessage() + "\n");
}
});
return RxNetty.createHttpServer(port, (request, response) -> {
// System.out.println("Server => Request: " + request.getPath());
return handlerChain.handle(request, response);
}, PipelineConfigurators.<ByteBuf> serveSseConfigurator());
}
开发者ID:Netflix,项目名称:ReactiveLab,代码行数:28,代码来源:AbstractMiddleTierService.java
示例18: setUp
import io.reactivex.netty.pipeline.PipelineConfigurators; //导入依赖的package包/类
@Before
public void setUp() {
super.setUp();
externalServer = RxNetty.newHttpServerBuilder(0, new ExternalServerHandler())
.pipelineConfigurator(PipelineConfigurators.<ByteBuf, ByteBuf>httpServerConfigurator()).build();
externalServer.start();
this.externalServerPort = externalServer.getServerPort();
}
开发者ID:Netflix,项目名称:Prana,代码行数:9,代码来源:HealthCheckHandlerTest.java
示例19: setUp
import io.reactivex.netty.pipeline.PipelineConfigurators; //导入依赖的package包/类
@Before
public void setUp() {
server = RxNetty.newHttpServerBuilder(0, getHandler())
.pipelineConfigurator(PipelineConfigurators.<ByteBuf, ByteBuf>httpServerConfigurator()).build();
server.start();
client = RxNetty.<ByteBuf, ByteBuf>newHttpClientBuilder("localhost", server.getServerPort())
.pipelineConfigurator(PipelineConfigurators.<ByteBuf, ByteBuf>httpClientConfigurator())
.channelOption(ChannelOption.CONNECT_TIMEOUT_MILLIS, 2000)
.build();
}
开发者ID:Netflix,项目名称:Prana,代码行数:12,代码来源:AbstractIntegrationTest.java
示例20: main
import io.reactivex.netty.pipeline.PipelineConfigurators; //导入依赖的package包/类
public static void main(String[] args) {
RxNetty.createTcpServer(8181, PipelineConfigurators.textOnlyConfigurator(),
new ConnectionHandler<String, String>() {
@Override
public Observable<Void> handle(ObservableConnection<String, String> newConnection) {
return startEventStream(newConnection);
}
}).startAndWait();
}
开发者ID:allenxwang,项目名称:RxNetty,代码行数:10,代码来源:TcpEventStreamServer.java
注:本文中的io.reactivex.netty.pipeline.PipelineConfigurators类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论