use of zipkin2.Callback in project edx-app-android by edx.
the class DownloadSpeedService method performDownload.
private synchronized void performDownload(DownloadDescriptor file) {
final long startTime;
try {
startTime = System.nanoTime();
OkHttpClient client = okHttpClientProvider.getNonOAuthBased().newBuilder().connectTimeout(getResources().getInteger(R.integer.speed_test_timeout_in_milliseconds), TimeUnit.MILLISECONDS).build();
Request request = new Request.Builder().url(file.getUrl()).build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException throwable) {
logger.error(throwable);
// If it times out, set a low value for download speed
setCurrentDownloadSpeed(0.01f);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (!response.isSuccessful()) {
logger.debug("Download Speed Test Failed");
} else {
long length = response.body().string().length();
double seconds = (System.nanoTime() - startTime) / NS_PER_SEC;
if (seconds != 0) {
final float downloadSpeedKps = (float) ((length / seconds) / 1024);
setCurrentDownloadSpeed(downloadSpeedKps);
reportDownloadSpeed(downloadSpeedKps);
}
}
}
});
} catch (Exception ex) {
logger.error(ex);
}
}
use of zipkin2.Callback in project coolweather by yeliheng.
the class AutoUpdateService method updateBingPic.
/*
* 更新必应每日一图
* */
private void updateBingPic() {
// 必应图片接口
String requestBingPic = "http://guolin.tech/api/bing_pic";
HttpUtil.sendOkHttpRequest(requestBingPic, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
final String bingPic = response.body().string();
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(AutoUpdateService.this).edit();
// 将从服务器获取到的图片地址存储到SD卡
editor.putString("bing_pic", bingPic);
editor.apply();
}
});
}
use of zipkin2.Callback in project coolweather by yeliheng.
the class AutoUpdateService method updateWeather.
/*
* 更新天气信息
* */
private void updateWeather() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String weatherString = prefs.getString("weather", null);
if (weatherString != null) {
Weather weather = Utility.handleWeatherResponse(weatherString);
String weatherId = weather.basic.weatherId;
// 请求地址
String weatherUrl = "http://guolin.tech/api/weather?cityid=" + weatherId + "&key=" + key;
HttpUtil.sendOkHttpRequest(weatherUrl, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String responseText = response.body().string();
Weather weather = Utility.handleWeatherResponse(responseText);
if (weather != null && "ok".equals(weather.status)) {
// 判断信息是否有效
// 存储数据到SD卡
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(AutoUpdateService.this).edit();
editor.putString("weather", responseText);
editor.apply();
}
}
});
}
}
use of zipkin2.Callback in project okHttp-Util-gson by xwdz.
the class HttpManager method execute.
public void execute(final Request request, final CallBack callBack, final Class c) {
Call call = mClient.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
if (callBack != null) {
callBack.error(call, e);
}
}
@Override
public void onResponse(final Call call, final Response response) {
if (callBack != null) {
mHandler.post(new Runnable() {
@Override
public void run() {
if (!response.isSuccessful()) {
IOException ioException = new IOException("request failed , reponse's code is : " + response.code());
callBack.error(call, ioException);
return;
}
if (call.isCanceled()) {
callBack.error(call, new IOException("Canceled!"));
return;
}
try {
final String json = response.body().string();
final Object object = Parser.getInstance().parser(json, c);
callBack.onNativeResponse(call, response);
callBack.response(call, object);
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
}
});
mCalls.add(call);
}
use of zipkin2.Callback in project mapbox-events-android by mapbox.
the class TelemetryClientMapEventsTest method sendsTheCorrectBodyPostingMultipleEvents.
@Test
public void sendsTheCorrectBodyPostingMultipleEvents() throws Exception {
TelemetryClient telemetryClient = obtainATelemetryClient("anyAccessToken", "anyUserAgent");
Event.Type load = Event.Type.MAP_LOAD;
Event loadEvent = obtainMapEvent(load);
Event.Type click = Event.Type.MAP_CLICK;
Event clickEvent = obtainMapEvent(click);
Callback mockedCallback = mock(Callback.class);
enqueueMockResponse();
List<Event> events = obtainEvents(loadEvent, clickEvent);
telemetryClient.sendEvents(events, mockedCallback);
String expectedRequestBody = obtainExpectedRequestBody(new GsonBuilder(), events.get(0), events.get(1));
assertRequestBodyEquals(expectedRequestBody);
}
Aggregations