public synchronized ListenableFuture post()

in remote/src/main/java/com/spotify/metrics/remote/OkRemote.java [68:106]


    public synchronized ListenableFuture<Integer> post(String path, String shardKey, Map jsonObj) {
        if (closed) {
            log.warn("Calling post after shutdown. Call will be ignored.");
            return Futures.immediateCancelledFuture();
        }

        if ((path.length() > 0) && (path.charAt(0) != '/')) {
            path = "/" + path;
        }
        final String jsonStr;
        try {
            jsonStr = mapper.writeValueAsString(jsonObj);
        } catch (JsonProcessingException e) {
            return Futures.immediateFailedFuture(new RuntimeException("Invalid json input"));
        }
        final String url = "http://" + host + ":" + port + path;
        final RequestBody body = RequestBody.create(JSON, jsonStr);

        final Request request = new Request.Builder()
            .url(url)
            .addHeader(Sharder.SHARD_KEY, shardKey)
            .addHeader(CONTENT_TYPE_KEY, CONTENT_TYPE_VALUE)
            .post(body)
            .build();
        final SettableFuture<Integer> result = SettableFuture.create();
        client.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                result.set(503);
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                result.set(response.code());
                response.close();
            }
        });
        return result;
    }