當前位置: 首頁>>代碼示例>>Java>>正文


Java ServerOperation類代碼示例

本文整理匯總了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);
                        }
                    });
                }
            });
}
 
開發者ID:Netflix,項目名稱:ribbon,代碼行數:19,代碼來源:MyUDPClient.java

示例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();
}
 
開發者ID:Netflix,項目名稱:ribbon,代碼行數:19,代碼來源:URLConnectionLoadBalancer.java

示例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));
}
 
開發者ID:spotify,項目名稱:ffwd,代碼行數:9,代碼來源:HttpClient.java

示例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);
                }
            });
        }
    };
}
 
開發者ID:Netflix,項目名稱:ribbon,代碼行數:40,代碼來源:LoadBalancingHttpClient.java

示例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();            
                }                    
            });
}
 
開發者ID:Netflix,項目名稱:ribbon,代碼行數:13,代碼來源:LoadBalancingRxClient.java


注:本文中的com.netflix.loadbalancer.reactive.ServerOperation類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。