本文整理汇总了Java中com.netflix.loadbalancer.reactive.ServerOperation类的典型用法代码示例。如果您正苦于以下问题:Java ServerOperation类的具体用法?Java ServerOperation怎么用?Java ServerOperation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ServerOperation类属于com.netflix.loadbalancer.reactive包,在下文中一共展示了ServerOperation类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: submit
import com.netflix.loadbalancer.reactive.ServerOperation; //导入依赖的package包/类
public Observable<DatagramPacket> submit(final String content) {
return LoadBalancerCommand.<DatagramPacket>builder()
.withLoadBalancerContext(lbContext)
.build()
.submit(new ServerOperation<DatagramPacket>() {
@Override
public Observable<DatagramPacket> call(Server server) {
RxClient<DatagramPacket, DatagramPacket> rxClient = getOrCreateRxClient(server);
return rxClient.connect().flatMap(new Func1<ObservableConnection<DatagramPacket, DatagramPacket>, Observable<? extends DatagramPacket>>() {
@Override
public Observable<? extends DatagramPacket> call(ObservableConnection<DatagramPacket, DatagramPacket> connection) {
connection.writeStringAndFlush(content);
return connection.getInput().timeout(10, TimeUnit.MILLISECONDS).take(1);
}
});
}
});
}
示例2: call
import com.netflix.loadbalancer.reactive.ServerOperation; //导入依赖的package包/类
public String call(final String path) throws Exception {
return LoadBalancerCommand.<String>builder()
.withLoadBalancer(loadBalancer)
.build()
.submit(new ServerOperation<String>() {
@Override
public Observable<String> call(Server server) {
URL url;
try {
url = new URL("http://" + server.getHost() + ":" + server.getPort() + path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
return Observable.just(conn.getResponseMessage());
} catch (Exception e) {
return Observable.error(e);
}
}
}).toBlocking().first();
}
示例3: sendBatch
import com.netflix.loadbalancer.reactive.ServerOperation; //导入依赖的package包/类
public Observable<Void> sendBatch(final Batch batch) {
return buildCommand().submit(new ServerOperation<Void>() {
@Override
public Observable<Void> call(final Server server) {
return HttpClient.this.clientFactory.newClient(server).sendBatch(batch);
}
}).retryWhen(new RetryWithDelay(retries, baseDelayMillis, maxDelayMillis));
}
示例4: requestToOperation
import com.netflix.loadbalancer.reactive.ServerOperation; //导入依赖的package包/类
/**
* Convert an HttpClientRequest to a ServerOperation
*
* @param server
* @param request
* @param rxClientConfig
* @return
*/
protected ServerOperation<HttpClientResponse<O>> requestToOperation(final HttpClientRequest<I> request, final ClientConfig rxClientConfig) {
Preconditions.checkNotNull(request);
return new ServerOperation<HttpClientResponse<O>>() {
final AtomicInteger count = new AtomicInteger(0);
@Override
public Observable<HttpClientResponse<O>> call(Server server) {
HttpClient<I,O> rxClient = getOrCreateRxClient(server);
setHostHeader(request, server.getHost());
Observable<HttpClientResponse<O>> o;
if (rxClientConfig != null) {
o = rxClient.submit(request, rxClientConfig);
}
else {
o = rxClient.submit(request);
}
return o.concatMap(new Func1<HttpClientResponse<O>, Observable<HttpClientResponse<O>>>() {
@Override
public Observable<HttpClientResponse<O>> call(HttpClientResponse<O> t1) {
if (t1.getStatus().code()/100 == 4 || t1.getStatus().code()/100 == 5)
return responseToErrorPolicy.call(t1, backoffStrategy.call(count.getAndIncrement()));
else
return Observable.just(t1);
}
});
}
};
}
示例5: connect
import com.netflix.loadbalancer.reactive.ServerOperation; //导入依赖的package包/类
@Override
public Observable<ObservableConnection<O, I>> connect() {
return LoadBalancerCommand.<ObservableConnection<O, I>>builder()
.withLoadBalancerContext(lbContext)
.build()
.submit(new ServerOperation<ObservableConnection<O, I>>() {
@Override
public Observable<ObservableConnection<O, I>> call(Server server) {
return getOrCreateRxClient(server).connect();
}
});
}