• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

knowledgepixels / nanopub-query / 27336340710

11 Jun 2026 09:09AM UTC coverage: 59.604% (-0.3%) from 59.878%
27336340710

push

github

ashleycaselli
refactor(logging): replace 'log' with 'logger' for consistency across classes and improve logs in general

480 of 896 branches covered (53.57%)

Branch coverage included in aggregate %.

1416 of 2285 relevant lines covered (61.97%)

9.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

24.6
src/main/java/com/knowledgepixels/query/JellyNanopubLoader.java
1
package com.knowledgepixels.query;
2

3
import org.apache.http.client.methods.CloseableHttpResponse;
4
import org.apache.http.client.methods.HttpGet;
5
import org.apache.http.client.methods.HttpHead;
6
import org.apache.http.impl.client.CloseableHttpClient;
7
import org.apache.http.impl.client.HttpClientBuilder;
8
import org.apache.http.util.EntityUtils;
9
import org.nanopub.NanopubUtils;
10
import org.nanopub.jelly.NanopubStream;
11
import org.slf4j.Logger;
12
import org.slf4j.LoggerFactory;
13

14
import java.io.IOException;
15
import java.util.concurrent.atomic.AtomicLong;
16

17
/**
18
 * Loads nanopubs from the attached Nanopub Registry via a restartable Jelly stream.
19
 */
20
public class JellyNanopubLoader {
×
21
    static final String registryUrl;
22
    private static long lastCommittedCounter = -1;
6✔
23
    private static Long lastKnownSetupId = null;
6✔
24
    // Latest registry metadata fields, updated on each metadata fetch and forwarded to clients
25
    static volatile String lastCoverageTypes = null;
6✔
26
    static volatile String lastCoverageAgents = null;
6✔
27
    static volatile String lastTestInstance = null;
6✔
28
    static volatile String lastNanopubCount = null;
6✔
29
    private static final CloseableHttpClient metadataClient;
30
    private static final CloseableHttpClient jellyStreamClient;
31

32
    private static final int MAX_RETRIES_METADATA = 10;
33
    private static final int RETRY_DELAY_METADATA = 3000;
34
    private static final int RETRY_DELAY_JELLY = 5000;
35

36
    /**
37
     * Circuit-breaker state. Counts consecutive {@code loadUpdates} invocations in
38
     * which the catch block fired; resets to zero on the next successful batch.
39
     * Scheduled on the single-threaded executor in {@link MainVerticle}, so a plain
40
     * {@code int} is enough — no concurrency.
41
     *
42
     * <p>When the counter reaches {@link #BREAKER_THRESHOLD}, the next invocation
43
     * sleeps {@link #BREAKER_PAUSE_MS} before proceeding. Lets the saturated RDF4J
44
     * drain instead of being hammered every {@link #UPDATES_POLL_INTERVAL} ms.
45
     *
46
     * <p>Depends on {@link com.knowledgepixels.query.TripleStore}'s socket timeouts
47
     * (change 1 of the fix plan) to turn parked commits into propagating exceptions;
48
     * without them, {@code loadBatch} can park forever, the catch never fires, and
49
     * this counter stays at zero.
50
     */
51
    static volatile int consecutiveBatchFailures = 0;
6✔
52

53
    static final int BREAKER_THRESHOLD = 3;
54
    static final long BREAKER_PAUSE_MS = 30_000L;
55

56
    /**
57
     * Epoch-millis of the last successful {@code loadUpdates} invocation (whether it
58
     * actually loaded a batch or was a "caught up, nothing to do" tick). Read by
59
     * {@link MetricsCollector} to expose {@code registry.loader.last_successful_batch_age_seconds}
60
     * so an operator can tell at a glance from Grafana whether an instance is still
61
     * making progress. Updated on every non-exceptional return from loadUpdates,
62
     * including idle returns — an instance that is caught up and correctly polling
63
     * still counts as alive.
64
     */
65
    static volatile long lastSuccessfulBatchAtMs = 0L;
6✔
66

67
    /**
68
     * Heartbeat counter for loadUpdates invocations. A summary log line is emitted
69
     * every {@link #HEARTBEAT_INTERVAL_INVOCATIONS} invocations so a truncated or
70
     * sampled log still shows the loader's state evolving. At the default 2 s poll
71
     * interval, 30 invocations ≈ 1 line per minute.
72
     */
73
    private static long loadUpdatesInvocations = 0L;
6✔
74
    private static final long HEARTBEAT_INTERVAL_INVOCATIONS = 30;
75

76
    private static final Logger logger = LoggerFactory.getLogger(JellyNanopubLoader.class);
9✔
77

78
    /**
79
     * Registry metadata returned by a HEAD request.
80
     */
81
    record RegistryMetadata(long loadCounter, Long setupId, String coverageTypes,
72✔
82
                            String coverageAgents, String testInstance, String nanopubCount,
83
                            String trustStateHash) {
84
    }
85

86
    /**
87
     * The interval in milliseconds at which the updates loader should poll for new nanopubs.
88
     */
89
    public static final int UPDATES_POLL_INTERVAL = 2000;
90

91
    enum LoadingType {
×
92
        INITIAL,
×
93
        UPDATE,
×
94
    }
95

96
    static {
97
        // Initialize registryUrl
98
        var url = Utils.getEnvString(
12✔
99
                "REGISTRY_FIXED_URL", "https://registry.knowledgepixels.com/"
100
        );
101
        if (!url.endsWith("/")) {
12!
102
            url += "/";
×
103
        }
104
        registryUrl = url;
6✔
105

106
        metadataClient = HttpClientBuilder.create().setDefaultRequestConfig(Utils.getHttpRequestConfig()).build();
15✔
107
        jellyStreamClient = NanopubUtils.getHttpClient();
6✔
108
    }
3✔
109

110
    /**
111
     * Start or continue (after restart) the initial loading procedure. This simply loads all
112
     * nanopubs from the attached Registry.
113
     *
114
     * @param afterCounter which counter to start from (-1 for the beginning)
115
     */
116
    public static void loadInitial(long afterCounter) {
117
        RegistryMetadata metadata = fetchRegistryMetadata();
6✔
118
        updateForwardingMetadata(metadata);
6✔
119
        TrustStateLoader.maybeUpdate(metadata.trustStateHash());
9✔
120
        long targetCounter = metadata.loadCounter();
9✔
121
        logger.info("Fetched Registry load counter: {}", targetCounter);
15✔
122
        // Store setupId on initial load
123
        if (metadata.setupId() != null && lastKnownSetupId == null) {
9!
124
            lastKnownSetupId = metadata.setupId();
×
125
            StatusController.get().setRegistrySetupId(metadata.setupId());
×
126
        }
127
        lastCommittedCounter = afterCounter;
6✔
128
        while (lastCommittedCounter < targetCounter) {
12!
129
            // Same circuit-breaker logic as loadUpdates: after BREAKER_THRESHOLD
130
            // consecutive failed batches, pause before retrying so a saturated RDF4J
131
            // (e.g. during a restart storm) can drain instead of being hammered on the
132
            // 5-second RETRY_DELAY_JELLY cadence.
133
            if (consecutiveBatchFailures >= BREAKER_THRESHOLD) {
×
134
                logger.warn("Circuit breaker active during initial load after {} consecutive batch failures; pausing {} ms before next attempt",
×
135
                        consecutiveBatchFailures, BREAKER_PAUSE_MS);
×
136
                try {
137
                    Thread.sleep(BREAKER_PAUSE_MS);
×
138
                } catch (InterruptedException e) {
×
139
                    Thread.currentThread().interrupt();
×
140
                    throw new RuntimeException("Interrupted while waiting for circuit breaker.");
×
141
                }
×
142
            }
143
            try {
144
                loadBatch(lastCommittedCounter, LoadingType.INITIAL);
×
145
                consecutiveBatchFailures = 0;
×
146
                logger.info("Initial load: loaded batch up to counter {}", lastCommittedCounter);
×
147
            } catch (Exception e) {
×
148
                consecutiveBatchFailures++;
×
149
                logger.info("Failed to load batch starting from counter {} (consecutive failures: {})",
×
150
                        lastCommittedCounter, consecutiveBatchFailures);
×
151
                logger.info("Failure reason: ", e);
×
152
                try {
153
                    Thread.sleep(RETRY_DELAY_JELLY);
×
154
                } catch (InterruptedException e2) {
×
155
                    throw new RuntimeException("Interrupted while waiting to retry loading batch.");
×
156
                }
×
157
            }
×
158
        }
159
        logger.info("Initial load complete.");
9✔
160
    }
3✔
161

162
    /**
163
     * Check if the Registry has any new nanopubs. If it does, load them.
164
     * This method should be called periodically, and you should wait for it to finish before
165
     * calling it again.
166
     */
167
    public static void loadUpdates() {
168
        // Circuit breaker: after BREAKER_THRESHOLD consecutive failed batches, pause
169
        // before the next attempt so a saturated RDF4J can drain. Check happens before
170
        // any RDF4J-touching work so the sleep isn't itself under the broken regime.
171
        if (consecutiveBatchFailures >= BREAKER_THRESHOLD) {
×
172
            logger.warn("Circuit breaker active after {} consecutive batch failures; pausing {} ms before next attempt",
×
173
                    consecutiveBatchFailures, BREAKER_PAUSE_MS);
×
174
            try {
175
                Thread.sleep(BREAKER_PAUSE_MS);
×
176
            } catch (InterruptedException e) {
×
177
                // Preserve interruption semantics so a graceful shutdown (e.g. via
178
                // MainVerticle's shutdown hook) isn't blocked by the pause.
179
                Thread.currentThread().interrupt();
×
180
                return;
×
181
            }
×
182
        }
183
        try {
184
            final var status = StatusController.get().getState();
×
185
            lastCommittedCounter = status.loadCounter;
×
186
            RegistryMetadata metadata = fetchRegistryMetadata();
×
187
            updateForwardingMetadata(metadata);
×
188
            TrustStateLoader.maybeUpdate(metadata.trustStateHash());
×
189
            long targetCounter = metadata.loadCounter();
×
190
            Long currentSetupId = metadata.setupId();
×
191

192
            // Detect reset via setupId change
193
            if (lastKnownSetupId != null && currentSetupId != null
×
194
                && !lastKnownSetupId.equals(currentSetupId)) {
×
195
                logger.warn("Registry reset detected: setupId {} -> {}", lastKnownSetupId, currentSetupId);
×
196
                performResync(currentSetupId);
×
197
                return;
×
198
            }
199
            // Detect reset via counter decrease (also covers first run after upgrade
200
            // where no setupId was persisted yet but the registry has already been reset)
201
            if (lastCommittedCounter > 0 && targetCounter >= 0
×
202
                && targetCounter < lastCommittedCounter) {
203
                logger.warn("Registry counter decreased {} -> {}, triggering resync",
×
204
                        lastCommittedCounter, targetCounter);
×
205
                performResync(currentSetupId);
×
206
                return;
×
207
            }
208

209
            // Update lastKnownSetupId on first successful poll
210
            if (currentSetupId != null && lastKnownSetupId == null) {
×
211
                if (lastCommittedCounter > 0) {
×
212
                    // Upgrade from a version without setupId tracking. The DB has data but
213
                    // we can't verify it matches the current registry. Force a resync.
214
                    logger.warn("No stored setupId but DB has data (counter: {}). "
×
215
                                + "Forcing resync to ensure data consistency.", lastCommittedCounter);
×
216
                    performResync(currentSetupId);
×
217
                    return;
×
218
                }
219
                lastKnownSetupId = currentSetupId;
×
220
                StatusController.get().setRegistrySetupId(currentSetupId);
×
221
            }
222

223
            if (lastCommittedCounter >= targetCounter) {
×
224
                // Nothing to do. Keep state at READY (setReady is idempotent) and
225
                // skip the redundant setLoadingUpdates → setReady admin-repo write
226
                // that the old flow did on every idle poll. Also reset the breaker
227
                // counter — a successful "nothing to do" is still a successful tick
228
                // and should clear stale failure state from earlier transient errors.
229
                StatusController.get().setReady();
×
230
                consecutiveBatchFailures = 0;
×
231
                lastSuccessfulBatchAtMs = System.currentTimeMillis();
×
232
                maybeLogHeartbeat(targetCounter, true);
×
233
                return;
×
234
            }
235
            StatusController.get().setLoadingUpdates(status.loadCounter);
×
236
            loadBatch(lastCommittedCounter, LoadingType.UPDATE);
×
237
            // Batch completed without an exception — reset the breaker counter.
238
            consecutiveBatchFailures = 0;
×
239
            lastSuccessfulBatchAtMs = System.currentTimeMillis();
×
240
            maybeLogHeartbeat(targetCounter, false);
×
241
            logger.info("Loaded {} update(s). Counter: {}, target was: {}",
×
242
                    lastCommittedCounter - status.loadCounter, lastCommittedCounter, targetCounter);
×
243
            if (lastCommittedCounter < targetCounter) {
×
244
                logger.info("Warning: expected to load nanopubs up to (inclusive) counter {} based on the counter reported in Registry's headers, but loaded only up to {}.", targetCounter, lastCommittedCounter);
×
245
            }
246
        } catch (Exception e) {
×
247
            consecutiveBatchFailures++;
×
248
            logger.warn("Failed to load updates. Current counter: {} (consecutive failures: {})",
×
249
                    lastCommittedCounter, consecutiveBatchFailures, e);
×
250
        } finally {
251
            try {
252
                StatusController.get().setReady();
×
253
            } catch (Exception e) {
×
254
                logger.info("Update loader: failed to set status to READY.");
×
255
                logger.info("Failure Reason: ", e);
×
256
            }
×
257
        }
258
    }
×
259

260
    /**
261
     * Emit a heartbeat summary log line roughly every
262
     * {@link #HEARTBEAT_INTERVAL_INVOCATIONS} invocations of {@link #loadUpdates}.
263
     * Lets an operator reconstruct loader progress from a sparse or sampled log
264
     * export, independent of Prometheus retention.
265
     */
266
    private static void maybeLogHeartbeat(long targetCounter, boolean idle) {
267
        loadUpdatesInvocations++;
×
268
        if (loadUpdatesInvocations % HEARTBEAT_INTERVAL_INVOCATIONS != 0) {
×
269
            return;
×
270
        }
271
        logger.info("Loader heartbeat: counter={} target={} idle={} consecutiveBatchFailures={} breakerActive={}",
×
272
                lastCommittedCounter, targetCounter, idle, consecutiveBatchFailures,
×
273
                consecutiveBatchFailures >= BREAKER_THRESHOLD);
×
274
    }
×
275

276
    /**
277
     * Re-stream all nanopubs from the registry after a reset is detected.
278
     * Existing nanopubs are skipped by NanopubLoader's per-repo dedup.
279
     *
280
     * @param newSetupId the new setup ID from the registry, or null if unknown
281
     */
282
    private static void performResync(Long newSetupId) {
283
        logger.warn("Starting resync with registry. New setupId: {}", newSetupId);
×
284
        StatusController.get().setResetting();
×
285
        lastKnownSetupId = newSetupId;
×
286
        if (newSetupId != null) {
×
287
            StatusController.get().setRegistrySetupId(newSetupId);
×
288
        }
289
        StatusController.get().setLoadingInitial(-1);
×
290
        loadInitial(-1);
×
291
        StatusController.get().setReady();
×
292
        logger.warn("Resync complete. Counter: {}", lastCommittedCounter);
×
293
    }
×
294

295
    /**
296
     * Load a batch of nanopubs from the Jelly stream.
297
     * <p>
298
     * The method requests the list of all nanopubs from the Registry and reads it for as long
299
     * as it can. If the stream is interrupted, the method will throw an exception, and you
300
     * can resume loading from the last known counter.
301
     *
302
     * @param afterCounter the last known nanopub counter to have been committed in the DB
303
     * @param type         the type of loading operation (initial or update)
304
     */
305
    static void loadBatch(long afterCounter, LoadingType type) {
306
        CloseableHttpResponse response;
307
        try {
308
            var request = new HttpGet(makeStreamFetchUrl(afterCounter));
×
309
            response = jellyStreamClient.execute(request);
×
310
        } catch (IOException e) {
×
311
            throw new RuntimeException("Failed to fetch Jelly stream from the Registry (I/O error).", e);
×
312
        }
×
313

314
        int httpStatus = response.getStatusLine().getStatusCode();
×
315
        if (httpStatus < 200 || httpStatus >= 300) {
×
316
            EntityUtils.consumeQuietly(response.getEntity());
×
317
            throw new RuntimeException("Jelly stream HTTP status is not 2xx: " + httpStatus + ".");
×
318
        }
319

320
        try (
321
                var is = response.getEntity().getContent();
×
322
                var npStream = NanopubStream.fromByteStream(is).getAsNanopubs()
×
323
        ) {
324
            AtomicLong checkpointTime = new AtomicLong(System.currentTimeMillis());
×
325
            AtomicLong checkpointCounter = new AtomicLong(lastCommittedCounter);
×
326
            AtomicLong lastSavedCounter = new AtomicLong(lastCommittedCounter);
×
327
            AtomicLong loaded = new AtomicLong(0L);
×
328

329
            npStream.forEach(m -> {
×
330
                if (!m.isSuccess()) {
×
331
                    throw new RuntimeException("Failed to load " +
×
332
                                               "nanopub from Jelly stream. Last known counter: " + lastCommittedCounter,
333
                            m.getException()
×
334
                    );
335
                }
336
                if (m.getCounter() < lastCommittedCounter) {
×
337
                    throw new RuntimeException("Received a nanopub with a counter lower than " +
×
338
                                               "the last known counter. Last known counter: " + lastCommittedCounter +
339
                                               ", received counter: " + m.getCounter());
×
340
                }
341
                NanopubLoader.load(m.getNanopub(), m.getCounter());
×
342
                // Bump the in-memory counter BEFORE persisting it. The previous order
343
                // wrote the *previous* nanopub's counter to the DB at each checkpoint,
344
                // so a crash-restart silently re-processed one extra nanopub and the
345
                // contract "saved counter == last fully loaded nanopub" was violated.
346
                lastCommittedCounter = m.getCounter();
×
347
                if (m.getCounter() % 10 == 0) {
×
348
                    // Save the committed counter only every 10 nanopubs to reduce DB load
349
                    saveCommittedCounter(type);
×
350
                    lastSavedCounter.set(m.getCounter());
×
351
                }
352
                loaded.getAndIncrement();
×
353

354
                if (loaded.get() % 50 == 0) {
×
355
                    long currTime = System.currentTimeMillis();
×
356
                    double speed = 50 / ((currTime - checkpointTime.get()) / 1000.0);
×
357
                    logger.info("Loading speed: {} np/s. Counter: {}", String.format("%.2f", speed), lastCommittedCounter);
×
358
                    checkpointTime.set(currTime);
×
359
                    checkpointCounter.set(lastCommittedCounter);
×
360
                }
361
            });
×
362
            // Make sure to save the last committed counter at the end of the batch
363
            if (lastCommittedCounter >= lastSavedCounter.get()) {
×
364
                saveCommittedCounter(type);
×
365
            }
366
        } catch (IOException e) {
×
367
            throw new RuntimeException("I/O error while reading the response Jelly stream.", e);
×
368
        } finally {
369
            try {
370
                response.close();
×
371
            } catch (IOException e) {
×
372
                logger.info("Failed to close the Jelly stream response.");
×
373
            }
×
374
        }
375
    }
×
376

377
    /**
378
     * Save the last committed counter to the DB. Do this every N nanopubs to reduce DB load.
379
     * Remember to call this method at the end of the batch as well.
380
     *
381
     * @param type the type of loading operation (initial or update)
382
     */
383
    private static void saveCommittedCounter(LoadingType type) {
384
        try {
385
            if (type == LoadingType.INITIAL) {
×
386
                StatusController.get().setLoadingInitial(lastCommittedCounter);
×
387
            } else {
388
                StatusController.get().setLoadingUpdates(lastCommittedCounter);
×
389
            }
390
        } catch (Exception e) {
×
391
            throw new RuntimeException("Could not update the nanopub counter in DB", e);
×
392
        }
×
393
    }
×
394

395
    /**
396
     * Set the last known setup ID. Called from MainVerticle on startup to restore persisted state.
397
     *
398
     * @param setupId the setup ID to set, or null if not known
399
     */
400
    static void setLastKnownSetupId(Long setupId) {
401
        lastKnownSetupId = setupId;
×
402
    }
×
403

404
    /**
405
     * Update the cached metadata fields used for forwarding to clients.
406
     */
407
    private static void updateForwardingMetadata(RegistryMetadata metadata) {
408
        lastCoverageTypes = metadata.coverageTypes();
9✔
409
        lastCoverageAgents = metadata.coverageAgents();
9✔
410
        lastTestInstance = metadata.testInstance();
9✔
411
        lastNanopubCount = metadata.nanopubCount();
9✔
412
    }
3✔
413

414
    /**
415
     * Run a HEAD request to the Registry to fetch its current metadata (load counter and setup ID).
416
     *
417
     * @return the registry metadata
418
     */
419
    static RegistryMetadata fetchRegistryMetadata() {
420
        int tries = 0;
6✔
421
        RegistryMetadata metadata = null;
6✔
422
        while (metadata == null && tries < MAX_RETRIES_METADATA) {
15!
423
            try {
424
                metadata = fetchRegistryMetadataInner();
6✔
425
            } catch (Exception e) {
×
426
                tries++;
×
427
                logger.info("Failed to fetch registry metadata, try {}. Retrying in {}ms...", tries, RETRY_DELAY_METADATA);
×
428
                logger.info("Failure Reason: ", e);
×
429
                try {
430
                    Thread.sleep(RETRY_DELAY_METADATA);
×
431
                } catch (InterruptedException e2) {
×
432
                    throw new RuntimeException(
×
433
                            "Interrupted while waiting to retry fetching registry metadata.");
434
                }
×
435
            }
3✔
436
        }
437
        if (metadata == null) {
6!
438
            throw new RuntimeException("Failed to fetch registry metadata after " + MAX_RETRIES_METADATA + " retries.");
×
439
        }
440
        return metadata;
6✔
441
    }
442

443
    /**
444
     * Inner logic for fetching the registry metadata via HEAD request.
445
     *
446
     * @return the registry metadata (load counter and setup ID)
447
     * @throws IOException if the HTTP request fails
448
     */
449
    private static RegistryMetadata fetchRegistryMetadataInner() throws IOException {
450
        var request = new HttpHead(registryUrl);
15✔
451
        try (var response = metadataClient.execute(request)) {
12✔
452
            int status = response.getStatusLine().getStatusCode();
12✔
453
            EntityUtils.consumeQuietly(response.getEntity());
9✔
454
            if (status < 200 || status >= 300) {
18!
455
                throw new RuntimeException("Registry metadata HTTP status is not 2xx: " +
×
456
                                           status + ".");
457
            }
458

459
            // Check if the registry is ready
460
            var hStatus = response.getHeaders("Nanopub-Registry-Status");
12✔
461
            if (hStatus.length == 0) {
9!
462
                throw new RuntimeException("Registry did not return a Nanopub-Registry-Status header.");
×
463
            }
464
            if (!"ready".equals(hStatus[0].getValue()) && !"updating".equals(hStatus[0].getValue())) {
21!
465
                throw new RuntimeException("Registry is not in ready state.");
×
466
            }
467

468
            // Get the load counter
469
            var hCounter = response.getHeaders("Nanopub-Registry-Load-Counter");
12✔
470
            if (hCounter.length == 0) {
9!
471
                throw new RuntimeException("Registry did not return a Nanopub-Registry-Load-Counter header.");
×
472
            }
473
            long loadCounter = Long.parseLong(hCounter[0].getValue());
18✔
474

475
            // Get the setup ID (optional — older registries may not have it)
476
            Long setupId = null;
6✔
477
            var hSetupId = response.getHeaders("Nanopub-Registry-Setup-Id");
12✔
478
            if (hSetupId.length > 0) {
9!
479
                try {
480
                    setupId = Long.parseLong(hSetupId[0].getValue());
21✔
481
                } catch (NumberFormatException e) {
×
482
                    logger.info("Could not parse Nanopub-Registry-Setup-Id header: {}", hSetupId[0].getValue());
×
483
                }
3✔
484
            }
485

486
            // Read metadata headers for forwarding to clients
487
            String coverageTypes = getHeaderValue(response, "Nanopub-Registry-Coverage-Types");
12✔
488
            String coverageAgents = getHeaderValue(response, "Nanopub-Registry-Coverage-Agents");
12✔
489
            String testInstance = getHeaderValue(response, "Nanopub-Registry-Test-Instance");
12✔
490
            String nanopubCount = getHeaderValue(response, "Nanopub-Registry-Nanopub-Count");
12✔
491
            // Optional — older registries (without trust calculation) won't set this header.
492
            String trustStateHash = getHeaderValue(response, "Nanopub-Registry-Trust-State-Hash");
12✔
493

494
            return new RegistryMetadata(loadCounter, setupId, coverageTypes, coverageAgents,
39✔
495
                    testInstance, nanopubCount, trustStateHash);
496
        }
497
    }
498

499
    private static String getHeaderValue(CloseableHttpResponse response, String name) {
500
        var headers = response.getHeaders(name);
12✔
501
        return headers.length > 0 ? headers[0].getValue() : null;
27!
502
    }
503

504
    /**
505
     * Construct the URL for fetching the Jelly stream.
506
     *
507
     * @param afterCounter the last known counter to have been committed in the DB
508
     * @return the URL for fetching the Jelly stream
509
     */
510
    private static String makeStreamFetchUrl(long afterCounter) {
511
        return registryUrl + "nanopubs.jelly?afterCounter=" + afterCounter;
×
512
    }
513
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc