mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-08-21 11:53:07 +09:00
pt 1 in reviving the android build (copied from pm 28a1, wish me luck)
This commit is contained in:
parent
efa9662725
commit
d7788a6d6d
4249 changed files with 468189 additions and 0 deletions
104
mobile/android/thirdparty/ch/boye/httpclientandroidlib/impl/execchain/BackoffStrategyExec.java
vendored
Normal file
104
mobile/android/thirdparty/ch/boye/httpclientandroidlib/impl/execchain/BackoffStrategyExec.java
vendored
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package ch.boye.httpclientandroidlib.impl.execchain;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.UndeclaredThrowableException;
|
||||
|
||||
import ch.boye.httpclientandroidlib.HttpException;
|
||||
import ch.boye.httpclientandroidlib.annotation.Immutable;
|
||||
import ch.boye.httpclientandroidlib.client.BackoffManager;
|
||||
import ch.boye.httpclientandroidlib.client.ConnectionBackoffStrategy;
|
||||
import ch.boye.httpclientandroidlib.client.methods.CloseableHttpResponse;
|
||||
import ch.boye.httpclientandroidlib.client.methods.HttpExecutionAware;
|
||||
import ch.boye.httpclientandroidlib.client.methods.HttpRequestWrapper;
|
||||
import ch.boye.httpclientandroidlib.client.protocol.HttpClientContext;
|
||||
import ch.boye.httpclientandroidlib.conn.routing.HttpRoute;
|
||||
import ch.boye.httpclientandroidlib.util.Args;
|
||||
|
||||
/**
|
||||
* @since 4.3
|
||||
*/
|
||||
@Immutable
|
||||
public class BackoffStrategyExec implements ClientExecChain {
|
||||
|
||||
private final ClientExecChain requestExecutor;
|
||||
private final ConnectionBackoffStrategy connectionBackoffStrategy;
|
||||
private final BackoffManager backoffManager;
|
||||
|
||||
public BackoffStrategyExec(
|
||||
final ClientExecChain requestExecutor,
|
||||
final ConnectionBackoffStrategy connectionBackoffStrategy,
|
||||
final BackoffManager backoffManager) {
|
||||
super();
|
||||
Args.notNull(requestExecutor, "HTTP client request executor");
|
||||
Args.notNull(connectionBackoffStrategy, "Connection backoff strategy");
|
||||
Args.notNull(backoffManager, "Backoff manager");
|
||||
this.requestExecutor = requestExecutor;
|
||||
this.connectionBackoffStrategy = connectionBackoffStrategy;
|
||||
this.backoffManager = backoffManager;
|
||||
}
|
||||
|
||||
public CloseableHttpResponse execute(
|
||||
final HttpRoute route,
|
||||
final HttpRequestWrapper request,
|
||||
final HttpClientContext context,
|
||||
final HttpExecutionAware execAware) throws IOException, HttpException {
|
||||
Args.notNull(route, "HTTP route");
|
||||
Args.notNull(request, "HTTP request");
|
||||
Args.notNull(context, "HTTP context");
|
||||
CloseableHttpResponse out = null;
|
||||
try {
|
||||
out = this.requestExecutor.execute(route, request, context, execAware);
|
||||
} catch (final Exception ex) {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
if (this.connectionBackoffStrategy.shouldBackoff(ex)) {
|
||||
this.backoffManager.backOff(route);
|
||||
}
|
||||
if (ex instanceof RuntimeException) {
|
||||
throw (RuntimeException) ex;
|
||||
}
|
||||
if (ex instanceof HttpException) {
|
||||
throw (HttpException) ex;
|
||||
}
|
||||
if (ex instanceof IOException) {
|
||||
throw (IOException) ex;
|
||||
}
|
||||
throw new UndeclaredThrowableException(ex);
|
||||
}
|
||||
if (this.connectionBackoffStrategy.shouldBackoff(out)) {
|
||||
this.backoffManager.backOff(route);
|
||||
} else {
|
||||
this.backoffManager.probe(route);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue