use of zipkin2.Callback in project Tusky by tuskyapp.
the class ReportActivity method fetchRecentStatuses.
private void fetchRecentStatuses(String accountId) {
Callback<List<Status>> callback = new Callback<List<Status>>() {
@Override
public void onResponse(Call<List<Status>> call, Response<List<Status>> response) {
if (!response.isSuccessful()) {
onFetchStatusesFailure(new Exception(response.message()));
return;
}
List<Status> statusList = response.body();
List<ReportAdapter.ReportStatus> itemList = new ArrayList<>();
for (Status status : statusList) {
if (status.getReblog() == null) {
ReportAdapter.ReportStatus item = new ReportAdapter.ReportStatus(status.getId(), status.getContent(), false);
itemList.add(item);
}
}
adapter.addItems(itemList);
}
@Override
public void onFailure(Call<List<Status>> call, Throwable t) {
onFetchStatusesFailure((Exception) t);
}
};
mastodonApi.accountStatuses(accountId, null, null, null, null).enqueue(callback);
}
use of zipkin2.Callback in project EssayJoke by qiyei2015.
the class OkHttpEngine method post.
@Override
public void post(HttpRequest httpRequest, final IHttpCallback callback) {
RequestBody requestBody = buildPostRequest(httpRequest);
Request request = new Request.Builder().url(httpRequest.getUrl()).post(requestBody).build();
LogManager.e("Post请求路径:", httpRequest.getUrl());
mClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
callback.onFail(e);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response != null && response.isSuccessful()) {
callback.onSuccess(response.body().string());
} else {
callback.onFail(new Exception("error"));
}
}
});
}
use of zipkin2.Callback in project butter-android by butterproject.
the class ButterUpdateManager method downloadFile.
private void downloadFile(final String location) {
Request request = new Request.Builder().url(location).build();
mHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
// uhoh
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.isSuccessful()) {
String fileName = location.substring(location.lastIndexOf('/') + 1);
File downloadedFile = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), fileName);
BufferedSink sink = Okio.buffer(Okio.sink(downloadedFile));
sink.writeAll(response.body().source());
sink.close();
String updateFilePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/" + fileName;
prefManager.getPrefs().edit().putString(SHA1_KEY, hashSHA1(updateFilePath)).putString(UPDATE_FILE, updateFilePath).putLong(SHA1_TIME, System.currentTimeMillis()).apply();
if (mListener != null) {
mListener.updateAvailable(updateFilePath);
}
}
}
});
}
use of zipkin2.Callback in project AnyMemo by helloworld1.
the class DropboxApiHelper method getUserInfo.
public Single<UserInfo> getUserInfo(@NonNull final String token) {
return Single.create(new SingleOnSubscribe<UserInfo>() {
@Override
public void subscribe(@NonNull final SingleEmitter<UserInfo> emitter) throws Exception {
RequestBody requestBody = RequestBody.create(null, new byte[0]);
Request request = new Request.Builder().url(USER_INFO_ENDPOINT).addHeader("Authorization", "Bearer " + token).post(requestBody).build();
okHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
emitter.onError(e);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (!response.isSuccessful()) {
emitter.onError(new IOException(getResponseErrorString(call.request(), response)));
return;
}
UserInfo userInfo = new UserInfo();
try {
JSONObject userInfoObject = new JSONObject(response.body().string());
userInfo.accountId = userInfoObject.getString("account_id");
userInfo.email = userInfoObject.getString("email");
JSONObject nameObject = userInfoObject.getJSONObject("name");
userInfo.displayName = nameObject.getString("display_name");
emitter.onSuccess(userInfo);
} catch (JSONException e) {
emitter.onError(e);
}
}
});
}
});
}
use of zipkin2.Callback in project syndesis by syndesisio.
the class KubernetesSupport method watchLog.
/*
* Feeds the controller of the given podName to the callback handler for processing.
*
* We do this instead of using the watchLog() feature of the k8s client lib because it really sucks due to:
* 1. You can't configure the timestamps option or the sinceTime option. Need to resume log downloads.
* 2. It seems to need extra threads..
* 3. It might be hiding some of the http failure conditions.
*
*/
protected void watchLog(String podName, Consumer<InputStream> handler, String sinceTime, Executor executor) throws IOException {
try {
PodOperationsImpl pod = (PodOperationsImpl) client.pods().withName(podName);
StringBuilder url = new StringBuilder().append(pod.getResourceUrl().toString()).append("/log?pretty=false&follow=true×tamps=true");
if (sinceTime != null) {
url.append("&sinceTime=");
}
Request request = new Request.Builder().url(new URL(url.toString())).get().build();
OkHttpClient clone = okHttpClient.newBuilder().readTimeout(0, TimeUnit.MILLISECONDS).build();
clone.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
LOG.info("Failure occurred getting controller for pod: {},", podName, e);
handler.accept(null);
}
@Override
public void onResponse(final Call call, final Response response) throws IOException {
executor.execute(() -> {
try {
if (response.code() == 200) {
handler.accept(response.body().byteStream());
} else {
LOG.info("Failure occurred while processing controller for pod: {}, http status: {}, details: {}", podName, response.code(), response.body().string());
handler.accept(null);
}
} catch (IOException e) {
LOG.error("Unexpected Error", e);
}
});
}
});
} catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") RuntimeException t) {
throw new IOException("Unexpected Error", t);
}
}
Aggregations